-
Notifications
You must be signed in to change notification settings - Fork 708
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
test: backwards compatibility test for the serialization feature #4548
Merged
Merged
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
eb870b2
new integ test
maddeleine 482d886
pep8
maddeleine 1f27f34
PR feedback
maddeleine 8d41cc6
Whoops
maddeleine a6d081d
PR feedback
maddeleine 216d314
code scanning
maddeleine fc382b2
name change
maddeleine eda97a7
common method
maddeleine 9c4f92f
pep8
maddeleine 3fb8b58
PR feedback
maddeleine a83faa1
Extra import
maddeleine 8b81724
enum
maddeleine 40a102a
pep 8
maddeleine 8fde08c
PR feedback
maddeleine 8190ae0
Merge branch 'main' into serialize_integ_test
maddeleine 2f12a96
Merge branch 'main' into serialize_integ_test
maddeleine 9a2db9e
Merge branch 'main' into serialize_integ_test
maddeleine File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
import pytest | ||
import copy | ||
import os | ||
from enum import Enum, auto | ||
|
||
from configuration import available_ports | ||
from common import ProviderOptions, Protocols, random_str | ||
from fixtures import managed_process # lgtm [py/unused-import] | ||
from providers import Provider, S2N | ||
from utils import invalid_test_parameters, get_parameter_name, to_bytes | ||
|
||
SERVER_STATE_FILE = 'server_state' | ||
CLIENT_STATE_FILE = 'client_state' | ||
|
||
SERVER_DATA = f"Some random data from the server:" + random_str(10) | ||
CLIENT_DATA = f"Some random data from the client:" + random_str(10) | ||
|
||
|
||
class MainlineRole(Enum): | ||
Serialize = auto() | ||
Deserialize = auto() | ||
|
||
|
||
class Mode(Enum): | ||
Server = auto() | ||
Client = auto() | ||
|
||
|
||
""" | ||
This test file checks that a serialized connection can be deserialized by an older version of | ||
s2n-tls and vice versa. This ensures that any future changes we make to the handshake are backwards-compatible | ||
with an older version of s2n-tls. | ||
|
||
This feature requires an uninterrupted TCP connection with the peer in-between serialization and | ||
deserialization. Our integration test setup can't easily provide that while also using two different | ||
s2n-tls versions. To get around that we do a hack and serialize/deserialize both peers in the TLS connection. | ||
This prevents one peer from receiving a TCP FIN message and shutting the connection down early. | ||
""" | ||
|
||
|
||
@pytest.mark.uncollect_if(func=invalid_test_parameters) | ||
@pytest.mark.parametrize("protocol", [Protocols.TLS13, Protocols.TLS12], ids=get_parameter_name) | ||
@pytest.mark.parametrize("mainline_role", [MainlineRole.Serialize, MainlineRole.Deserialize], ids=get_parameter_name) | ||
@pytest.mark.parametrize("version_change", [Mode.Server, Mode.Client], ids=get_parameter_name) | ||
def test_server_serialization_backwards_compat(managed_process, tmp_path, protocol, mainline_role, version_change): | ||
server_state_file = str(tmp_path / SERVER_STATE_FILE) | ||
client_state_file = str(tmp_path / CLIENT_STATE_FILE) | ||
assert not os.path.exists(server_state_file) | ||
assert not os.path.exists(client_state_file) | ||
|
||
options = ProviderOptions( | ||
port=next(available_ports), | ||
protocol=protocol, | ||
insecure=True, | ||
) | ||
|
||
client_options = copy.copy(options) | ||
client_options.mode = Provider.ClientMode | ||
client_options.extra_flags = ['--serialize-out', client_state_file] | ||
|
||
server_options = copy.copy(options) | ||
server_options.mode = Provider.ServerMode | ||
server_options.extra_flags = ['--serialize-out', server_state_file] | ||
|
||
if mainline_role is MainlineRole.Serialize: | ||
if version_change == Mode.Server: | ||
server_options.use_mainline_version = True | ||
else: | ||
client_options.use_mainline_version = True | ||
|
||
server = managed_process( | ||
S2N, server_options, send_marker=S2N.get_send_marker()) | ||
client = managed_process(S2N, client_options, send_marker=S2N.get_send_marker()) | ||
|
||
for results in client.get_results(): | ||
results.assert_success() | ||
assert to_bytes("Actual protocol version: {}".format(protocol.value)) in results.stdout | ||
|
||
for results in server.get_results(): | ||
results.assert_success() | ||
assert to_bytes("Actual protocol version: {}".format(protocol.value)) in results.stdout | ||
|
||
assert os.path.exists(server_state_file) | ||
assert os.path.exists(client_state_file) | ||
|
||
client_options.extra_flags = ['--deserialize-in', client_state_file] | ||
server_options.extra_flags = ['--deserialize-in', server_state_file] | ||
if mainline_role is MainlineRole.Deserialize: | ||
if version_change == Mode.Server: | ||
server_options.use_mainline_version = True | ||
else: | ||
client_options.use_mainline_version = True | ||
|
||
server_options.data_to_send = SERVER_DATA.encode() | ||
client_options.data_to_send = CLIENT_DATA.encode() | ||
|
||
server = managed_process(S2N, server_options, send_marker=CLIENT_DATA) | ||
client = managed_process(S2N, client_options, send_marker="Connected to localhost", close_marker=SERVER_DATA) | ||
|
||
for results in server.get_results(): | ||
results.assert_success() | ||
# No protocol version printout since deserialization means skipping the handshake | ||
assert to_bytes("Actual protocol version:") not in results.stdout | ||
assert CLIENT_DATA.encode() in results.stdout | ||
|
||
for results in client.get_results(): | ||
results.assert_success() | ||
assert to_bytes("Actual protocol version:") not in results.stdout | ||
assert SERVER_DATA.encode() in results.stdout |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Check notice
Code scanning / CodeQL
Unused import Note test