MCPcopy Index your code
hub / github.com/RustPython/RustPython / test_local_bad_hostname

Method test_local_bad_hostname

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

Source from the content-addressed store, hash-verified

2123
2124 @unittest.skip("TODO: RUSTPYTHON; Flaky on CI")
2125 def test_local_bad_hostname(self):
2126 # The (valid) cert doesn't validate the HTTPS hostname
2127 import ssl
2128 server = self.make_server(CERT_fakehostname)
2129 context = ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT)
2130 context.load_verify_locations(CERT_fakehostname)
2131 h = client.HTTPSConnection('localhost', server.port, context=context)
2132 with self.assertRaises(ssl.CertificateError):
2133 h.request('GET', '/')
2134
2135 # Same with explicit context.check_hostname=True
2136 context.check_hostname = True
2137 h = client.HTTPSConnection('localhost', server.port, context=context)
2138 with self.assertRaises(ssl.CertificateError):
2139 h.request('GET', '/')
2140
2141 # With context.check_hostname=False, the mismatching is ignored
2142 context.check_hostname = False
2143 h = client.HTTPSConnection('localhost', server.port, context=context)
2144 h.request('GET', '/nonexistent')
2145 resp = h.getresponse()
2146 resp.close()
2147 h.close()
2148 self.assertEqual(resp.status, 404)
2149
2150 @unittest.skipIf(not hasattr(client, 'HTTPSConnection'),
2151 'http.client.HTTPSConnection not available')

Callers

nothing calls this directly

Calls 7

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

Tested by

no test coverage detected