From 8469cb11468e9bd8dd91b7ef713b7705bc36e595 Mon Sep 17 00:00:00 2001 From: Stefan Ceriu Date: Tue, 15 Oct 2024 17:13:27 +0300 Subject: [PATCH] fix(crypto): fix incorrect `VerificationMachine` tests - the tests used to incorrectly wrap the to-device content into an event as if it was sent by alice instead of bob --- .../src/verification/machine.rs | 17 +++++++++-------- .../matrix-sdk-crypto/src/verification/mod.rs | 2 +- .../src/verification/sas/mod.rs | 2 +- 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/crates/matrix-sdk-crypto/src/verification/machine.rs b/crates/matrix-sdk-crypto/src/verification/machine.rs index 19033209e..864800f1a 100644 --- a/crates/matrix-sdk-crypto/src/verification/machine.rs +++ b/crates/matrix-sdk-crypto/src/verification/machine.rs @@ -341,6 +341,7 @@ impl VerificationMachine { match &content { AnyVerificationContent::Request(r) => { info!( + sender = ?event.sender(), from_device = r.from_device().as_str(), "Received a new verification request", ); @@ -733,12 +734,12 @@ mod tests { let content: OutgoingContent = request.try_into().unwrap(); machine - .receive_any_event(&wrap_any_to_device_content(bob_request.other_user(), content)) + .receive_any_event(&wrap_any_to_device_content(bob_request.own_user_id(), content)) .await .unwrap(); let alice_request = - machine.get_request(bob_request.other_user(), bob_request.flow_id().as_str()).unwrap(); + machine.get_request(bob_request.own_user_id(), bob_request.flow_id().as_str()).unwrap(); // We're not yet cancelled. assert!(!alice_request.is_cancelled()); @@ -757,12 +758,12 @@ mod tests { let content: OutgoingContent = request.try_into().unwrap(); machine - .receive_any_event(&wrap_any_to_device_content(bob_request.other_user(), content)) + .receive_any_event(&wrap_any_to_device_content(bob_request.own_user_id(), content)) .await .unwrap(); let second_request = - machine.get_request(bob_request.other_user(), bob_request.flow_id().as_str()).unwrap(); + machine.get_request(bob_request.own_user_id(), bob_request.flow_id().as_str()).unwrap(); // Make sure we fetched the new one. assert_eq!(second_request.flow_id().as_str(), second_transaction_id); @@ -795,12 +796,12 @@ mod tests { let content: OutgoingContent = request.try_into().unwrap(); machine - .receive_any_event(&wrap_any_to_device_content(bob_request.other_user(), content)) + .receive_any_event(&wrap_any_to_device_content(bob_request.own_user_id(), content)) .await .unwrap(); let first_request = - machine.get_request(bob_request.other_user(), bob_request.flow_id().as_str()).unwrap(); + machine.get_request(bob_request.own_user_id(), bob_request.flow_id().as_str()).unwrap(); // We're not yet cancelled. assert!(!first_request.is_cancelled()); @@ -819,12 +820,12 @@ mod tests { let content: OutgoingContent = request.try_into().unwrap(); machine - .receive_any_event(&wrap_any_to_device_content(bob_request.other_user(), content)) + .receive_any_event(&wrap_any_to_device_content(bob_request.own_user_id(), content)) .await .unwrap(); let second_request = - machine.get_request(bob_request.other_user(), bob_request.flow_id().as_str()).unwrap(); + machine.get_request(bob_request.own_user_id(), bob_request.flow_id().as_str()).unwrap(); // None of the requests are cancelled assert!(!first_request.is_cancelled()); diff --git a/crates/matrix-sdk-crypto/src/verification/mod.rs b/crates/matrix-sdk-crypto/src/verification/mod.rs index 6d48d38e6..1598114fb 100644 --- a/crates/matrix-sdk-crypto/src/verification/mod.rs +++ b/crates/matrix-sdk-crypto/src/verification/mod.rs @@ -819,7 +819,7 @@ pub(crate) mod tests { } pub fn bob_device_id() -> &'static DeviceId { - device_id!("BOBDEVCIE") + device_id!("BOBDEVICE") } pub(crate) async fn setup_stores() -> (Account, VerificationStore, Account, VerificationStore) { diff --git a/crates/matrix-sdk-crypto/src/verification/sas/mod.rs b/crates/matrix-sdk-crypto/src/verification/sas/mod.rs index c9a3acf96..caf43a249 100644 --- a/crates/matrix-sdk-crypto/src/verification/sas/mod.rs +++ b/crates/matrix-sdk-crypto/src/verification/sas/mod.rs @@ -899,7 +899,7 @@ mod tests { } fn bob_device_id() -> &'static DeviceId { - device_id!("BOBDEVCIE") + device_id!("BOBDEVICE") } fn machine_pair_test_helper() -> (VerificationStore, DeviceData, VerificationStore, DeviceData)