| 1 |
|
| 2 |
|
| 3 |
import copy |
| 4 |
import pytest |
| 5 |
|
| 6 |
from configuration import ( |
| 7 |
available_ports, |
| 8 |
ALL_TEST_CIPHERS, |
| 9 |
ALL_TEST_CURVES, |
| 10 |
ALL_TEST_CERTS, |
| 11 |
PROTOCOLS, |
| 12 |
) |
| 13 |
from common import ProviderOptions, data_bytes |
| 14 |
from fixtures import managed_process |
| 15 |
from providers import Provider, S2N, OpenSSL, JavaSSL, GnuTLS, SSLv3Provider |
| 16 |
from utils import ( |
| 17 |
invalid_test_parameters, |
| 18 |
get_parameter_name, |
| 19 |
get_expected_s2n_version, |
| 20 |
to_bytes, |
| 21 |
) |
| 22 |
|
| 23 |
|
| 24 |
@pytest.mark.flaky(reruns=5, reruns_delay=2) |
| 25 |
@pytest.mark.uncollect_if(func=invalid_test_parameters) |
| 26 |
@pytest.mark.parametrize("cipher", ALL_TEST_CIPHERS, ids=get_parameter_name) |
| 27 |
@pytest.mark.parametrize("provider", [S2N, OpenSSL, GnuTLS, JavaSSL, SSLv3Provider]) |
| 28 |
@pytest.mark.parametrize("curve", ALL_TEST_CURVES, ids=get_parameter_name) |
| 29 |
@pytest.mark.parametrize("protocol", PROTOCOLS, ids=get_parameter_name) |
| 30 |
@pytest.mark.parametrize("certificate", ALL_TEST_CERTS, ids=get_parameter_name) |
| 31 |
def test_s2n_server_happy_path( |
| 32 |
managed_process, |
| 33 |
cipher, |
| 34 |
provider, |
| 35 |
curve, |
| 36 |
protocol, |
| 37 |
certificate, |
| 38 |
): |
| 39 |
port = next(available_ports) |
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
random_bytes = data_bytes(65519) |
| 47 |
client_options = ProviderOptions( |
| 48 |
mode=Provider.ClientMode, |
| 49 |
port=port, |
| 50 |
cipher=cipher, |
| 51 |
cert=certificate.cert, |
| 52 |
curve=curve, |
| 53 |
data_to_send=random_bytes, |
| 54 |
insecure=True, |
| 55 |
protocol=protocol, |
| 56 |
) |
| 57 |
|
| 58 |
server_options = copy.copy(client_options) |
| 59 |
server_options.data_to_send = None |
| 60 |
server_options.mode = Provider.ServerMode |
| 61 |
server_options.key = certificate.key |
| 62 |
server_options.cert = certificate.cert |
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
server = managed_process(S2N, server_options, timeout=5) |
| 67 |
client = managed_process(provider, client_options, timeout=5) |
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
for client_results in client.get_results(): |
| 73 |
client_results.assert_success() |
| 74 |
|
| 75 |
expected_version = get_expected_s2n_version(protocol, provider) |
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
for server_results in server.get_results(): |
| 80 |
server_results.assert_success() |
| 81 |
assert ( |
| 82 |
to_bytes("Actual protocol version: {}".format(expected_version)) |
| 83 |
in server_results.stdout |
| 84 |
) |
| 85 |
assert random_bytes in server_results.stdout |
| 86 |
|
| 87 |
if provider is not S2N: |
| 88 |
assert ( |
| 89 |
to_bytes("Cipher negotiated: {}".format(cipher.name)) |
| 90 |
in server_results.stdout |
| 91 |
) |
| 92 |
|
| 93 |
|
| 94 |
@pytest.mark.flaky(reruns=5, reruns_delay=2) |
| 95 |
@pytest.mark.uncollect_if(func=invalid_test_parameters) |
| 96 |
@pytest.mark.parametrize("cipher", ALL_TEST_CIPHERS, ids=get_parameter_name) |
| 97 |
@pytest.mark.parametrize("provider", [S2N, OpenSSL, GnuTLS, SSLv3Provider]) |
| 98 |
@pytest.mark.parametrize("curve", ALL_TEST_CURVES, ids=get_parameter_name) |
| 99 |
@pytest.mark.parametrize("protocol", PROTOCOLS, ids=get_parameter_name) |
| 100 |
@pytest.mark.parametrize("certificate", ALL_TEST_CERTS, ids=get_parameter_name) |
| 101 |
def test_s2n_client_happy_path( |
| 102 |
managed_process, |
| 103 |
cipher, |
| 104 |
provider, |
| 105 |
curve, |
| 106 |
protocol, |
| 107 |
certificate, |
| 108 |
): |
| 109 |
port = next(available_ports) |
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
random_bytes = data_bytes(4095) |
| 118 |
client_options = ProviderOptions( |
| 119 |
mode=Provider.ClientMode, |
| 120 |
port=port, |
| 121 |
cipher=cipher, |
| 122 |
curve=curve, |
| 123 |
data_to_send=random_bytes, |
| 124 |
insecure=True, |
| 125 |
protocol=protocol, |
| 126 |
) |
| 127 |
|
| 128 |
server_options = copy.copy(client_options) |
| 129 |
server_options.data_to_send = None |
| 130 |
server_options.mode = Provider.ServerMode |
| 131 |
server_options.key = certificate.key |
| 132 |
server_options.cert = certificate.cert |
| 133 |
|
| 134 |
kill_marker = None |
| 135 |
if provider == GnuTLS: |
| 136 |
kill_marker = random_bytes |
| 137 |
|
| 138 |
|
| 139 |
|
| 140 |
server = managed_process( |
| 141 |
provider, server_options, timeout=5, kill_marker=kill_marker |
| 142 |
) |
| 143 |
client = managed_process(S2N, client_options, timeout=5) |
| 144 |
|
| 145 |
expected_version = get_expected_s2n_version(protocol, provider) |
| 146 |
|
| 147 |
|
| 148 |
|
| 149 |
for client_results in client.get_results(): |
| 150 |
client_results.assert_success() |
| 151 |
assert ( |
| 152 |
to_bytes("Actual protocol version: {}".format(expected_version)) |
| 153 |
in client_results.stdout |
| 154 |
) |
| 155 |
|
| 156 |
|
| 157 |
|
| 158 |
|
| 159 |
for server_results in server.get_results(): |
| 160 |
server_results.assert_success() |
| 161 |
|
| 162 |
assert any( |
| 163 |
[random_bytes[1:] in stream for stream in server_results.output_streams()] |
| 164 |
) |