MCPcopy Index your code
hub / github.com/python/cpython / test_local_bad_hostname

Method test_local_bad_hostname

Lib/test/test_httplib.py:2170–2193  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

2168 self.assertEqual(resp.status, 404)
2169
2170 def test_local_bad_hostname(self):
2171 # The (valid) cert doesn't validate the HTTPS hostname
2172 import ssl
2173 server = self.make_server(CERT_fakehostname)
2174 context = ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT)
2175 context.load_verify_locations(CERT_fakehostname)
2176 h = client.HTTPSConnection('localhost', server.port, context=context)
2177 with self.assertRaises(ssl.CertificateError):
2178 h.request('GET', '/')
2179
2180 # Same with explicit context.check_hostname=True
2181 context.check_hostname = True
2182 h = client.HTTPSConnection('localhost', server.port, context=context)
2183 with self.assertRaises(ssl.CertificateError):
2184 h.request('GET', '/')
2185
2186 # With context.check_hostname=False, the mismatching is ignored
2187 context.check_hostname = False
2188 h = client.HTTPSConnection('localhost', server.port, context=context)
2189 h.request('GET', '/nonexistent')
2190 resp = h.getresponse()
2191 resp.close()
2192 h.close()
2193 self.assertEqual(resp.status, 404)
2194
2195 @unittest.skipIf(not hasattr(client, 'HTTPSConnection'),
2196 'http.client.HTTPSConnection not available')

Callers

nothing calls this directly

Calls 6

make_serverMethod · 0.95
assertRaisesMethod · 0.45
requestMethod · 0.45
getresponseMethod · 0.45
closeMethod · 0.45
assertEqualMethod · 0.45

Tested by

no test coverage detected