87
87
def test_no_certificate(self):
88
88
self.assertRaises(ValueError,
89
_urllib2_wrappers.match_hostname, {}, "example.com")
89
ssl.match_hostname, {}, "example.com")
91
91
def test_wildcards_in_cert(self):
92
92
def ok(cert, hostname):
93
_urllib2_wrappers.match_hostname(cert, hostname)
93
ssl.match_hostname(cert, hostname)
95
def not_ok(cert, hostname):
98
ssl.match_hostname, cert, hostname)
95
100
# Python Issue #17980: avoid denials of service by refusing more than
96
101
# one wildcard per fragment.
97
cert = {'subject': ((('commonName', 'a*b.com'),),)}
99
cert = {'subject': ((('commonName', 'a*b.co*'),),)}
101
cert = {'subject': ((('commonName', 'a*b*.com'),),)}
103
_urllib2_wrappers.match_hostname(cert, 'axxbxxc.com')
104
except ValueError as e:
105
self.assertIn("too many wildcards", str(e))
102
ok({'subject': ((('commonName', 'a*b.com'),),)}, 'axxb.com')
103
not_ok({'subject': ((('commonName', 'a*b.co*'),),)}, 'axxb.com')
104
not_ok({'subject': ((('commonName', 'a*b*.com'),),)}, 'axxbxxc.com')
107
106
def test_no_valid_attributes(self):
108
self.assertRaises(CertificateError, _urllib2_wrappers.match_hostname,
107
self.assertRaises(ssl.CertificateError, ssl.match_hostname,
109
108
{"Problem": "Solved"}, "example.com")
111
110
def test_common_name(self):
112
111
cert = {'subject': ((('commonName', 'example.com'),),)}
113
112
self.assertIs(None,
114
_urllib2_wrappers.match_hostname(cert, "example.com"))
115
self.assertRaises(CertificateError, _urllib2_wrappers.match_hostname,
113
ssl.match_hostname(cert, "example.com"))
114
self.assertRaises(ssl.CertificateError, ssl.match_hostname,
116
115
cert, "example.org")