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