summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_httplib.py
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/test/test_httplib.py')
-rw-r--r--Lib/test/test_httplib.py43
1 files changed, 12 insertions, 31 deletions
diff --git a/Lib/test/test_httplib.py b/Lib/test/test_httplib.py
index b3d94e0..620a5b1 100644
--- a/Lib/test/test_httplib.py
+++ b/Lib/test/test_httplib.py
@@ -1978,7 +1978,7 @@ class HTTPSTest(TestCase):
self.assertEqual(exc_info.exception.reason, 'CERTIFICATE_VERIFY_FAILED')
def test_local_good_hostname(self):
- # The (valid) cert validates the HTTP hostname
+ # The (valid) cert validates the HTTPS hostname
import ssl
server = self.make_server(CERT_localhost)
context = ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT)
@@ -1991,7 +1991,7 @@ class HTTPSTest(TestCase):
self.assertEqual(resp.status, 404)
def test_local_bad_hostname(self):
- # The (valid) cert doesn't validate the HTTP hostname
+ # The (valid) cert doesn't validate the HTTPS hostname
import ssl
server = self.make_server(CERT_fakehostname)
context = ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT)
@@ -1999,38 +1999,21 @@ class HTTPSTest(TestCase):
h = client.HTTPSConnection('localhost', server.port, context=context)
with self.assertRaises(ssl.CertificateError):
h.request('GET', '/')
- # Same with explicit check_hostname=True
- with warnings_helper.check_warnings(('', DeprecationWarning)):
- h = client.HTTPSConnection('localhost', server.port,
- context=context, check_hostname=True)
+
+ # Same with explicit context.check_hostname=True
+ context.check_hostname = True
+ h = client.HTTPSConnection('localhost', server.port, context=context)
with self.assertRaises(ssl.CertificateError):
h.request('GET', '/')
- # With check_hostname=False, the mismatching is ignored
- context.check_hostname = False
- with warnings_helper.check_warnings(('', DeprecationWarning)):
- h = client.HTTPSConnection('localhost', server.port,
- context=context, check_hostname=False)
- h.request('GET', '/nonexistent')
- resp = h.getresponse()
- resp.close()
- h.close()
- self.assertEqual(resp.status, 404)
- # The context's check_hostname setting is used if one isn't passed to
- # HTTPSConnection.
+
+ # With context.check_hostname=False, the mismatching is ignored
context.check_hostname = False
h = client.HTTPSConnection('localhost', server.port, context=context)
h.request('GET', '/nonexistent')
resp = h.getresponse()
- self.assertEqual(resp.status, 404)
resp.close()
h.close()
- # Passing check_hostname to HTTPSConnection should override the
- # context's setting.
- with warnings_helper.check_warnings(('', DeprecationWarning)):
- h = client.HTTPSConnection('localhost', server.port,
- context=context, check_hostname=True)
- with self.assertRaises(ssl.CertificateError):
- h.request('GET', '/')
+ self.assertEqual(resp.status, 404)
@unittest.skipIf(not hasattr(client, 'HTTPSConnection'),
'http.client.HTTPSConnection not available')
@@ -2066,11 +2049,9 @@ class HTTPSTest(TestCase):
self.assertIs(h._context, context)
self.assertFalse(h._context.post_handshake_auth)
- with warnings.catch_warnings():
- warnings.filterwarnings('ignore', 'key_file, cert_file and check_hostname are deprecated',
- DeprecationWarning)
- h = client.HTTPSConnection('localhost', 443, context=context,
- cert_file=CERT_localhost)
+ context = ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT, cert_file=CERT_localhost)
+ context.post_handshake_auth = True
+ h = client.HTTPSConnection('localhost', 443, context=context)
self.assertTrue(h._context.post_handshake_auth)