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

Method test_alpn_protocols

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

Source from the content-addressed store, hash-verified

4557 self.assertIs(stats['client_alpn_protocol'], None)
4558
4559 def test_alpn_protocols(self):
4560 server_protocols = ['foo', 'bar', 'milkshake']
4561 protocol_tests = [
4562 (['foo', 'bar'], 'foo'),
4563 (['bar', 'foo'], 'foo'),
4564 (['milkshake'], 'milkshake'),
4565 (['http/3.0', 'http/4.0'], None)
4566 ]
4567 for client_protocols, expected in protocol_tests:
4568 client_context, server_context, hostname = testing_context()
4569 server_context.set_alpn_protocols(server_protocols)
4570 client_context.set_alpn_protocols(client_protocols)
4571
4572 try:
4573 stats = server_params_test(client_context,
4574 server_context,
4575 chatty=True,
4576 connectionchatty=True,
4577 sni_name=hostname)
4578 except ssl.SSLError as e:
4579 stats = e
4580
4581 msg = "failed trying %s (s) and %s (c).\n" \
4582 "was expecting %s, but got %%s from the %%s" \
4583 % (str(server_protocols), str(client_protocols),
4584 str(expected))
4585 client_result = stats['client_alpn_protocol']
4586 self.assertEqual(client_result, expected,
4587 msg % (client_result, "client"))
4588 server_result = stats['server_alpn_protocols'][-1] \
4589 if len(stats['server_alpn_protocols']) else 'nothing'
4590 self.assertEqual(server_result, expected,
4591 msg % (server_result, "server"))
4592
4593 def test_npn_protocols(self):
4594 assert not ssl.HAS_NPN

Callers

nothing calls this directly

Calls 5

testing_contextFunction · 0.85
server_params_testFunction · 0.85
strFunction · 0.85
set_alpn_protocolsMethod · 0.80
assertEqualMethod · 0.45

Tested by

no test coverage detected