summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_ssl.py
diff options
context:
space:
mode:
authorAntoine Pitrou <solipsis@pitrou.net>2015-02-15 17:12:20 (GMT)
committerAntoine Pitrou <solipsis@pitrou.net>2015-02-15 17:12:20 (GMT)
commitc481bfb3f62787e9ef0947785df7383a173a23c3 (patch)
treec7d6b4745a46c9d535ce3f413c4dd0f69f488f84 /Lib/test/test_ssl.py
parent2d07b855855c13814c2050f2f062aadf936fa886 (diff)
downloadcpython-c481bfb3f62787e9ef0947785df7383a173a23c3.zip
cpython-c481bfb3f62787e9ef0947785df7383a173a23c3.tar.gz
cpython-c481bfb3f62787e9ef0947785df7383a173a23c3.tar.bz2
Issue #23239: ssl.match_hostname() now supports matching of IP addresses.
Diffstat (limited to 'Lib/test/test_ssl.py')
-rw-r--r--Lib/test/test_ssl.py24
1 files changed, 24 insertions, 0 deletions
diff --git a/Lib/test/test_ssl.py b/Lib/test/test_ssl.py
index 2f2e739..ce427b4 100644
--- a/Lib/test/test_ssl.py
+++ b/Lib/test/test_ssl.py
@@ -383,6 +383,8 @@ class BasicSocketTests(unittest.TestCase):
self.assertRaises(ssl.CertificateError,
ssl.match_hostname, cert, hostname)
+ # -- Hostname matching --
+
cert = {'subject': ((('commonName', 'example.com'),),)}
ok(cert, 'example.com')
ok(cert, 'ExAmple.cOm')
@@ -468,6 +470,28 @@ class BasicSocketTests(unittest.TestCase):
# Only commonName is considered
fail(cert, 'California')
+ # -- IPv4 matching --
+ cert = {'subject': ((('commonName', 'example.com'),),),
+ 'subjectAltName': (('DNS', 'example.com'),
+ ('IP Address', '10.11.12.13'),
+ ('IP Address', '14.15.16.17'))}
+ ok(cert, '10.11.12.13')
+ ok(cert, '14.15.16.17')
+ fail(cert, '14.15.16.18')
+ fail(cert, 'example.net')
+
+ # -- IPv6 matching --
+ cert = {'subject': ((('commonName', 'example.com'),),),
+ 'subjectAltName': (('DNS', 'example.com'),
+ ('IP Address', '2001:0:0:0:0:0:0:CAFE\n'),
+ ('IP Address', '2003:0:0:0:0:0:0:BABA\n'))}
+ ok(cert, '2001::cafe')
+ ok(cert, '2003::baba')
+ fail(cert, '2003::bebe')
+ fail(cert, 'example.net')
+
+ # -- Miscellaneous --
+
# Neither commonName nor subjectAltName
cert = {'notAfter': 'Dec 18 23:59:59 2011 GMT',
'subject': ((('countryName', 'US'),),