-
Notifications
You must be signed in to change notification settings - Fork 144
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
Add more Secure Session tests #376
Merged
Merged
Conversation
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
Move the required method get_public_key_for_id() first in the trait definition. This has no semantic meaning but it's important for IDE autocomplete or example, rustdoc also uses this order, and this is the order which is most likely to be used by users when defining transport implementations.
Every public struct or enum should have a Debug implementation for logging whatnot, so add it. It is also sometimes useful to copy the state in the state reporting callback, so add Clone and Copy impls. This enum is likely to stay simple so copying is cheap.
Rust does not have an established popular mocking framework, and mock objects are generally frowned upon in tests. However, sometimes they are useful, and the current practice is to roll out your own mocks. Introduce a simple implementation of SecureSessionTransport based on closures. This allows to reimplement and change behavior at run-time.
Its functionality can be easily reimplemented with a simple utility that sets the get_public_key_for_id callback to recognize a single peer and return its public key. Drop the comments about RSA keys. It is now impossible to pass RSA keys instead of ECDSA to Secure Session.
Again, we can easily reimplement ad-hoc ChannelTransport with a similar ad-hoc function that sets up the same communication channel between two Secure Sessions. The test code is now a bit easier to follow with this change.
Check that state changes are reported at correct moment. We use channels to transport state reports out of a closure. It's a bit tricky to do otherwise to satisfy the borrow checker.
Both Secure Sessions should fail at connection negotiation stage with ErrorKind::SessionGetPublicKeyForIdError if any of them does not recognize its peer by an ID.
Check that errors reported from send_data and receive_data callbacks are correctly forwarded to the user (and that they actually cause connection failure). We use yet another tricky setup with channels to override the behavior of MockTransport. The channels are used to pass one-shot closures that describe the behavior of the next call to callback. The callbacks then revert to their previous behavior if there are no pending 'behavior overrides'. This can be used to test multiple failures in the future.
Secure Session cannot send or receive empty messages for security reasons because empty message does not contain any authentication information. Verify that Secure Session reports errors when the user tries to send and empty message or when the transport layer returns an empty message.
vixentael
approved these changes
Feb 12, 2019
Lagovas
approved these changes
Feb 12, 2019
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
This PR updates the tests for Secure Session with new cases.
Now we check more happy and failure paths in Secure Session. We verify that errors are correctly forwarded from transport callbacks, and that this causes the whole session to fail. We also test the session change callback. Finally, we test a couple of edge cases with empty messages.
We also make a couple of other tweaks. There are more details in individual commit messages.
Unfortunately it is not possible to write tests for buffer size overflow handling as that will require the current implementation to actually allocate a buffer of 4 GB or larger which usually segfaults. Buffer sizes are completely under control of Secure Session user though.