/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to breezy/tests/test_https_urllib.py

  • Committer: Jelmer Vernooij
  • Date: 2020-03-22 01:35:14 UTC
  • mfrom: (7490.7.6 work)
  • mto: This revision was merged to the branch mainline in revision 7499.
  • Revision ID: jelmer@jelmer.uk-20200322013514-7vw1ntwho04rcuj3
merge lp:brz/3.1.

Show diffs side-by-side

added added

removed removed

Lines of Context:
26
26
    trace,
27
27
)
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
31
30
 
32
31
 
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"))
54
53
        self.warnings = []
55
54
 
65
64
class CertReqsConfigTests(tests.TestCaseInTempDir):
66
65
 
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"))
70
69
 
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,
78
77
                          "ssl.cert_reqs")
79
78
 
80
79
 
81
80
class MatchHostnameTests(tests.TestCase):
82
81
 
83
 
    def setUp(self):
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')
89
 
 
90
82
    def test_no_certificate(self):
91
83
        self.assertRaises(ValueError,
92
84
                          ssl.match_hostname, {}, "example.com")
102
94
 
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')
 
101
        else:
 
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')
108
105