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

Method test_check_hostname

Lib/test/test_ssl.py:2990–3025  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

2988 self.assertTrue(cert, "Can't get peer certificate.")
2989
2990 def test_check_hostname(self):
2991 if support.verbose:
2992 sys.stdout.write("\n")
2993
2994 client_context, server_context, hostname = testing_context()
2995
2996 # correct hostname should verify
2997 server = ThreadedEchoServer(context=server_context, chatty=True)
2998 with server:
2999 with client_context.wrap_socket(socket.socket(),
3000 server_hostname=hostname) as s:
3001 s.connect((HOST, server.port))
3002 cert = s.getpeercert()
3003 self.assertTrue(cert, "Can't get peer certificate.")
3004
3005 # incorrect hostname should raise an exception
3006 server = ThreadedEchoServer(context=server_context, chatty=True)
3007 # Allow for flexible libssl error messages.
3008 regex = re.compile(r"""(
3009 certificate verify failed # OpenSSL
3010 |
3011 CERTIFICATE_VERIFY_FAILED # AWS-LC
3012 )""", re.X)
3013 with server:
3014 with client_context.wrap_socket(socket.socket(),
3015 server_hostname="invalid") as s:
3016 with self.assertRaisesRegex(ssl.CertificateError, regex):
3017 s.connect((HOST, server.port))
3018
3019 # missing server_hostname arg should cause an exception, too
3020 server = ThreadedEchoServer(context=server_context, chatty=True)
3021 with server:
3022 with socket.socket() as s:
3023 with self.assertRaisesRegex(ValueError,
3024 "check_hostname requires server_hostname"):
3025 client_context.wrap_socket(s)
3026
3027 @unittest.skipUnless(
3028 ssl.HAS_NEVER_CHECK_COMMON_NAME, "test requires hostname_checks_common_name"

Callers

nothing calls this directly

Calls 10

testing_contextFunction · 0.85
ThreadedEchoServerClass · 0.85
wrap_socketMethod · 0.80
socketMethod · 0.80
assertTrueMethod · 0.80
assertRaisesRegexMethod · 0.80
writeMethod · 0.45
connectMethod · 0.45
getpeercertMethod · 0.45
compileMethod · 0.45

Tested by

no test coverage detected