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

Method test_sni_callback

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

Source from the content-addressed store, hash-verified

4220 self.assertIn((('commonName', name),), cert['subject'])
4221
4222 def test_sni_callback(self):
4223 calls = []
4224 server_context, other_context, client_context = self.sni_contexts()
4225
4226 client_context.check_hostname = False
4227
4228 def servername_cb(ssl_sock, server_name, initial_context):
4229 calls.append((server_name, initial_context))
4230 if server_name is not None:
4231 ssl_sock.context = other_context
4232 server_context.set_servername_callback(servername_cb)
4233
4234 stats = server_params_test(client_context, server_context,
4235 chatty=True,
4236 sni_name='supermessage')
4237 # The hostname was fetched properly, and the certificate was
4238 # changed for the connection.
4239 self.assertEqual(calls, [("supermessage", server_context)])
4240 # CERTFILE4 was selected
4241 self.check_common_name(stats, 'fakehostname')
4242
4243 calls = []
4244 # The callback is called with server_name=None
4245 stats = server_params_test(client_context, server_context,
4246 chatty=True,
4247 sni_name=None)
4248 self.assertEqual(calls, [(None, server_context)])
4249 self.check_common_name(stats, SIGNED_CERTFILE_HOSTNAME)
4250
4251 # Check disabling the callback
4252 calls = []
4253 server_context.set_servername_callback(None)
4254
4255 stats = server_params_test(client_context, server_context,
4256 chatty=True,
4257 sni_name='notfunny')
4258 # Certificate didn't change
4259 self.check_common_name(stats, SIGNED_CERTFILE_HOSTNAME)
4260 self.assertEqual(calls, [])
4261
4262 @unittest.expectedFailure # TODO: RUSTPYTHON; + TLSV1_ALERT_ACCESS_DENIED
4263 def test_sni_callback_alert(self):

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