summaryrefslogtreecommitdiff
path: root/Lib/test/test_httplib.py
diff options
context:
space:
mode:
authorBenjamin Peterson <benjamin@python.org>2014-12-07 13:18:25 -0500
committerBenjamin Peterson <benjamin@python.org>2014-12-07 13:18:25 -0500
commit33ddfca80b6d9db38222f87511b6e5699cc10870 (patch)
treeb971bbcb44131c190728a9c8a57ed29fb0de5b81 /Lib/test/test_httplib.py
parent56a97a93bddb879711a239b8f174bba951b55fe4 (diff)
downloadcpython-33ddfca80b6d9db38222f87511b6e5699cc10870.tar.gz
HTTPSConnection: prefer the context's check_hostname attribute over the constructor parameter (#22959)
Diffstat (limited to 'Lib/test/test_httplib.py')
-rw-r--r--Lib/test/test_httplib.py14
1 files changed, 14 insertions, 0 deletions
diff --git a/Lib/test/test_httplib.py b/Lib/test/test_httplib.py
index 933e5c4edf..49d767dba0 100644
--- a/Lib/test/test_httplib.py
+++ b/Lib/test/test_httplib.py
@@ -882,6 +882,7 @@ class HTTPSTest(TestCase):
server = self.make_server(CERT_fakehostname)
context = ssl.SSLContext(ssl.PROTOCOL_TLSv1)
context.verify_mode = ssl.CERT_REQUIRED
+ context.check_hostname = True
context.load_verify_locations(CERT_fakehostname)
h = client.HTTPSConnection('localhost', server.port, context=context)
with self.assertRaises(ssl.CertificateError):
@@ -892,11 +893,24 @@ class HTTPSTest(TestCase):
with self.assertRaises(ssl.CertificateError):
h.request('GET', '/')
# With check_hostname=False, the mismatching is ignored
+ context.check_hostname = False
h = client.HTTPSConnection('localhost', server.port, context=context,
check_hostname=False)
h.request('GET', '/nonexistent')
resp = h.getresponse()
self.assertEqual(resp.status, 404)
+ # The context's check_hostname setting is used if one isn't passed to
+ # HTTPSConnection.
+ context.check_hostname = False
+ h = client.HTTPSConnection('localhost', server.port, context=context)
+ h.request('GET', '/nonexistent')
+ self.assertEqual(h.getresponse().status, 404)
+ # Passing check_hostname to HTTPSConnection should override the
+ # context's setting.
+ h = client.HTTPSConnection('localhost', server.port, context=context,
+ check_hostname=True)
+ with self.assertRaises(ssl.CertificateError):
+ h.request('GET', '/')
@unittest.skipIf(not hasattr(client, 'HTTPSConnection'),
'http.client.HTTPSConnection not available')