Skip to content

Commit

Permalink
[1.26] Complete test coverage of urllib3.util.ssl_match_hostname.matc…
Browse files Browse the repository at this point in the history
…h_hostname
  • Loading branch information
hramezani committed Jan 30, 2022
1 parent 048c0ba commit 834dd1e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/urllib3/util/ssl_match_hostname.py
Expand Up @@ -122,7 +122,7 @@ def match_hostname(cert, hostname):
# Divergence from upstream: Make ipaddress library optional
if ipaddress is None:
host_ip = None
else:
else: # Defensive
raise
dnsnames = []
san = cert.get("subjectAltName", ())
Expand Down
6 changes: 6 additions & 0 deletions test/test_connection.py
Expand Up @@ -28,6 +28,12 @@ def test_match_hostname_match(self):
asserted_hostname = "foo"
_match_hostname(cert, asserted_hostname)

def test_match_hostname_ipaddress_none(self):
cert = {"subjectAltName": [("DNS", "foo")]}
asserted_hostname = "foo"
with mock.patch("urllib3.util.ssl_match_hostname.ipaddress", None):
assert _match_hostname(cert, asserted_hostname) is None

def test_match_hostname_mismatch(self):
cert = {"subjectAltName": [("DNS", "foo")]}
asserted_hostname = "bar"
Expand Down

0 comments on commit 834dd1e

Please sign in to comment.