Skip to content

Commit 65aec7e

Browse files
committed
test(sdk): Add a method for two test clients to exchange E2EE identities
1 parent a686838 commit 65aec7e

File tree

1 file changed

+24
-15
lines changed

1 file changed

+24
-15
lines changed

crates/matrix-sdk/src/test_utils/mocks/encryption.rs

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,29 @@ impl MatrixMockServer {
110110
known_otks.entry(user_id).or_default().entry(device_id).or_default().clear();
111111
}
112112

113+
/// Ensure that the given clients are aware of each others public
114+
/// identities.
115+
pub async fn exchange_e2ee_identities(&self, alice: &Client, bob: &Client) {
116+
let alice_user_id = alice.user_id().expect("Alice should have a user ID configured");
117+
let bob_user_id = bob.user_id().expect("Bob should have a user ID configured");
118+
119+
// Have Alice track Bob, so she queries his keys later.
120+
alice.update_tracked_users_for_testing([bob_user_id]).await;
121+
122+
// let bob be aware of Alice keys in order to be able to decrypt custom
123+
// to-device (the device keys check are deferred for `m.room.key` so this is not
124+
// needed for sending room messages for example).
125+
bob.update_tracked_users_for_testing([alice_user_id]).await;
126+
127+
// Have Alice and Bob upload their signed device keys.
128+
self.mock_sync().ok_and_run(alice, |_x| {}).await;
129+
self.mock_sync().ok_and_run(bob, |_x| {}).await;
130+
131+
// Run a sync so we do send outgoing requests, including the /keys/query for
132+
// getting bob's identity.
133+
self.mock_sync().ok_and_run(alice, |_x| {}).await;
134+
}
135+
113136
/// Utility to properly setup two clients. These two clients will know about
114137
/// each others (alice will have downloaded bob device keys).
115138
pub async fn set_up_alice_and_bob_for_encryption(&self) -> (Client, Client) {
@@ -126,21 +149,7 @@ impl MatrixMockServer {
126149
let bob =
127150
self.client_builder_for_crypto_end_to_end(&bob_user_id, &bob_device_id).build().await;
128151

129-
// Have Alice track Bob, so she queries his keys later.
130-
alice.update_tracked_users_for_testing([bob_user_id.as_ref()]).await;
131-
132-
// let bob be aware of Alice keys in order to be able to decrypt custom
133-
// to-device (the device keys check are deferred for `m.room.key` so this is not
134-
// needed for sending room messages for example).
135-
bob.update_tracked_users_for_testing([alice_user_id.as_ref()]).await;
136-
137-
// Have Alice and Bob upload their signed device keys.
138-
self.mock_sync().ok_and_run(&alice, |_x| {}).await;
139-
self.mock_sync().ok_and_run(&bob, |_x| {}).await;
140-
141-
// Run a sync so we do send outgoing requests, including the /keys/query for
142-
// getting bob's identity.
143-
self.mock_sync().ok_and_run(&alice, |_x| {}).await;
152+
self.exchange_e2ee_identities(&alice, &bob).await;
144153

145154
(alice, bob)
146155
}

0 commit comments

Comments
 (0)