Skip to content

Commit 13ee4c8

Browse files
committed
tests(crypto): Document introduced tests and helper
Signed-off-by: Skye Elliot <[email protected]>
1 parent 84ebbd9 commit 13ee4c8

File tree

1 file changed

+22
-2
lines changed
  • crates/matrix-sdk-crypto/src/machine/tests

1 file changed

+22
-2
lines changed

crates/matrix-sdk-crypto/src/machine/tests/mod.rs

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -732,6 +732,19 @@ async fn test_megolm_encryption() {
732732
}
733733
}
734734

735+
/// Helper function to set up end-to-end Megolm encryption between two devices.
736+
///
737+
/// Creates two devices, Alice and Bob, and has Alice create an outgoing Megolm
738+
/// session in the given room, whose decryption key is shared with Bob via a
739+
/// to-device message.
740+
///
741+
/// # Arguments
742+
///
743+
/// * `room_id` - The RoomId for which to set up Megolm encryption.
744+
///
745+
/// # Returns
746+
///
747+
/// A tuple containing the alice and bob OlmMachine instances.
735748
#[cfg(feature = "experimental-encrypted-state-events")]
736749
async fn megolm_encryption_setup_helper(room_id: &RoomId) -> (OlmMachine, OlmMachine) {
737750
let (alice, bob) =
@@ -773,6 +786,9 @@ async fn megolm_encryption_setup_helper(room_id: &RoomId) -> (OlmMachine, OlmMac
773786
(alice, bob)
774787
}
775788

789+
/// Verifies that Megolm-encrypted state events can be encrypted and decrypted
790+
/// correctly, and that the decrypted event matches the expected type and
791+
/// content.
776792
#[cfg(feature = "experimental-encrypted-state-events")]
777793
#[async_test]
778794
async fn test_megolm_state_encryption() {
@@ -818,6 +834,9 @@ async fn test_megolm_state_encryption() {
818834
}
819835
}
820836

837+
/// Verifies that decryption fails with StateKeyVerificationFailed
838+
/// when unpacking the state_key of the decrypted event yields an event type
839+
/// that does not exist or does not match the type in the decrypted ciphertext.
821840
#[cfg(feature = "experimental-encrypted-state-events")]
822841
#[async_test]
823842
async fn test_megolm_state_encryption_bad_type() {
@@ -831,7 +850,6 @@ async fn test_megolm_state_encryption_bad_type() {
831850
let encrypted_content =
832851
alice.encrypt_state_event(room_id, content, EmptyStateKey).await.unwrap();
833852

834-
// Malformed events
835853
let bad_type_event = json!({
836854
"event_id": "$xxxxx:example.org",
837855
"origin_server_ts": MilliSecondsSinceUnixEpoch::now(),
@@ -858,6 +876,9 @@ async fn test_megolm_state_encryption_bad_type() {
858876
);
859877
}
860878

879+
/// Verifies that decryption fails with StateKeyVerificationFailed
880+
/// when unpacking the state_key of the decrypted event yields a state_key
881+
/// that does not match the state_key in the decrypted ciphertext.
861882
#[cfg(feature = "experimental-encrypted-state-events")]
862883
#[async_test]
863884
async fn test_megolm_state_encryption_bad_state_key() {
@@ -890,7 +911,6 @@ async fn test_megolm_state_encryption_bad_state_key() {
890911
.await
891912
.unwrap();
892913

893-
// Require malformed events fail verification
894914
assert_matches!(
895915
bad_state_key_decryption_result,
896916
RoomEventDecryptionResult::UnableToDecrypt(UnableToDecryptInfo {

0 commit comments

Comments
 (0)