28
28
from .. import tests
29
from ..transport.http import _urllib2_wrappers
30
from ..transport.http._urllib2_wrappers import ssl
29
from ..transport.http import ssl, opt_ssl_ca_certs
33
32
class CaCertsConfigTests(tests.TestCaseInTempDir):
49
48
def test_specified_doesnt_exist(self):
50
49
stack = self.get_stack('')
51
50
# Disable the default value mechanism to force the behavior we want
52
self.overrideAttr(_urllib2_wrappers.opt_ssl_ca_certs, 'default',
51
self.overrideAttr(opt_ssl_ca_certs, 'default',
53
52
os.path.join(self.test_dir, u"nonexisting.pem"))
65
64
class CertReqsConfigTests(tests.TestCaseInTempDir):
67
66
def test_default(self):
68
stack = config.MemoryStack("")
67
stack = config.MemoryStack(b"")
69
68
self.assertEqual(ssl.CERT_REQUIRED, stack.get("ssl.cert_reqs"))
71
70
def test_from_string(self):
72
stack = config.MemoryStack("ssl.cert_reqs = none\n")
71
stack = config.MemoryStack(b"ssl.cert_reqs = none\n")
73
72
self.assertEqual(ssl.CERT_NONE, stack.get("ssl.cert_reqs"))
74
stack = config.MemoryStack("ssl.cert_reqs = required\n")
73
stack = config.MemoryStack(b"ssl.cert_reqs = required\n")
75
74
self.assertEqual(ssl.CERT_REQUIRED, stack.get("ssl.cert_reqs"))
76
stack = config.MemoryStack("ssl.cert_reqs = invalid\n")
75
stack = config.MemoryStack(b"ssl.cert_reqs = invalid\n")
77
76
self.assertRaises(config.ConfigOptionValueError, stack.get,
81
80
class MatchHostnameTests(tests.TestCase):
84
super(MatchHostnameTests, self).setUp()
85
if sys.version_info < (2, 7, 9):
86
raise tests.TestSkipped(
87
'python version too old to provide proper'
88
' https hostname verification')
90
82
def test_no_certificate(self):
91
83
self.assertRaises(ValueError,
92
84
ssl.match_hostname, {}, "example.com")
103
95
# Python Issue #17980: avoid denials of service by refusing more than
104
96
# one wildcard per fragment.
105
ok({'subject': ((('commonName', 'a*b.com'),),)}, 'axxb.com')
97
if sys.version_info[:2] >= (3, 7):
98
# Python 3.7 dropped support for partial wildcards, see
99
# https://docs.python.org/3/whatsnew/3.7.html#ssl
100
not_ok({'subject': ((('commonName', 'a*b.com'),),)}, 'axxb.com')
102
ok({'subject': ((('commonName', 'a*b.com'),),)}, 'axxb.com')
106
103
not_ok({'subject': ((('commonName', 'a*b.co*'),),)}, 'axxb.com')
107
104
not_ok({'subject': ((('commonName', 'a*b*.com'),),)}, 'axxbxxc.com')