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

Method test_sni_callback

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

Source from the content-addressed store, hash-verified

4607 self.assertIn((('commonName', name),), cert['subject'])
4608
4609 def test_sni_callback(self):
4610 calls = []
4611 server_context, other_context, client_context = self.sni_contexts()
4612
4613 client_context.check_hostname = False
4614
4615 def servername_cb(ssl_sock, server_name, initial_context):
4616 calls.append((server_name, initial_context))
4617 if server_name is not None:
4618 ssl_sock.context = other_context
4619 server_context.set_servername_callback(servername_cb)
4620
4621 stats = server_params_test(client_context, server_context,
4622 chatty=True,
4623 sni_name='supermessage')
4624 # The hostname was fetched properly, and the certificate was
4625 # changed for the connection.
4626 self.assertEqual(calls, [("supermessage", server_context)])
4627 # CERTFILE4 was selected
4628 self.check_common_name(stats, 'fakehostname')
4629
4630 calls = []
4631 # The callback is called with server_name=None
4632 stats = server_params_test(client_context, server_context,
4633 chatty=True,
4634 sni_name=None)
4635 self.assertEqual(calls, [(None, server_context)])
4636 self.check_common_name(stats, SIGNED_CERTFILE_HOSTNAME)
4637
4638 # Check disabling the callback
4639 calls = []
4640 server_context.set_servername_callback(None)
4641
4642 stats = server_params_test(client_context, server_context,
4643 chatty=True,
4644 sni_name='notfunny')
4645 # Certificate didn't change
4646 self.check_common_name(stats, SIGNED_CERTFILE_HOSTNAME)
4647 self.assertEqual(calls, [])
4648
4649 def test_sni_callback_alert(self):
4650 # Returning a TLS alert is reflected to the connecting client

Callers

nothing calls this directly

Calls 5

sni_contextsMethod · 0.95
check_common_nameMethod · 0.95
server_params_testFunction · 0.85
assertEqualMethod · 0.45

Tested by

no test coverage detected