(self)
| 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') |
nothing calls this directly
no test coverage detected