Debian Codegraph @

crt/s2n/tests/integrationv2/test_sni_match.py

raw symbols SCIP
1 # Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2 # SPDX-License-Identifier: Apache-2.0
3 import pytest
4
5 from configuration import available_ports, MULTI_CERT_TEST_CASES
6 from common import ProviderOptions, Protocols
7 from fixtures import managed_process # noqa: F401
8 from providers import Provider, S2N, OpenSSL
9 from utils import (
10 invalid_test_parameters,
11 get_parameter_name,
12 get_expected_s2n_version,
13 to_bytes,
14 )
15
16
17 def filter_cipher_list(*args, **kwargs):
18 """
19 The framework normally filters out ciphers that are not supported by the chosen
20 protocol. That doesn't happen in this test because of the unique way ciphers are
21 grouped for the multi certificate tests.
22
23 This function handles that unique grouping.
24 """
25 protocol = kwargs.get("protocol")
26 cert_test_case = kwargs.get("cert_test_case")
27
28 lowest_protocol_cipher = min(
29 cert_test_case.client_ciphers, key=lambda x: x.min_version
30 )
31 if protocol < lowest_protocol_cipher.min_version:
32 return True
33
34 return invalid_test_parameters(*args, **kwargs)
35
36
37 @pytest.mark.uncollect_if(func=filter_cipher_list)
38 @pytest.mark.parametrize("provider", [OpenSSL], ids=get_parameter_name)
39 @pytest.mark.parametrize("other_provider", [S2N], ids=get_parameter_name)
40 @pytest.mark.parametrize(
41 "protocol", [Protocols.TLS13, Protocols.TLS12], ids=get_parameter_name
42 )
43 @pytest.mark.parametrize("cert_test_case", MULTI_CERT_TEST_CASES)
44 def test_sni_match(managed_process, provider, other_provider, protocol, cert_test_case): # noqa: F811
45 port = next(available_ports)
46
47 client_options = ProviderOptions(
48 mode=Provider.ClientMode,
49 port=port,
50 insecure=False,
51 verify_hostname=True,
52 server_name=cert_test_case.client_sni,
53 cipher=cert_test_case.client_ciphers,
54 protocol=protocol,
55 )
56
57 server_options = ProviderOptions(
58 mode=Provider.ServerMode, port=port, extra_flags=[], protocol=protocol
59 )
60
61 # Setup the certificate chain for S2ND based on the multicert test case
62 cert_key_list = [(cert[0], cert[1]) for cert in cert_test_case.server_certs]
63 for cert_key_path in cert_key_list:
64 server_options.extra_flags.extend(["--cert", cert_key_path[0]])
65 server_options.extra_flags.extend(["--key", cert_key_path[1]])
66
67 server = managed_process(S2N, server_options, timeout=5)
68 client = managed_process(provider, client_options, timeout=5)
69
70 for results in client.get_results():
71 results.assert_success()
72
73 expected_version = get_expected_s2n_version(protocol, provider)
74
75 for results in server.get_results():
76 results.assert_success()
77 assert (
78 to_bytes("Actual protocol version: {}".format(expected_version))
79 in results.stdout
80 )
81 if cert_test_case.client_sni is not None:
82 assert (
83 to_bytes("Server name: {}".format(cert_test_case.client_sni))
84 in results.stdout
85 )