@@ -110,6 +110,29 @@ impl MatrixMockServer {
110
110
known_otks. entry ( user_id) . or_default ( ) . entry ( device_id) . or_default ( ) . clear ( ) ;
111
111
}
112
112
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
+
113
136
/// Utility to properly setup two clients. These two clients will know about
114
137
/// each others (alice will have downloaded bob device keys).
115
138
pub async fn set_up_alice_and_bob_for_encryption ( & self ) -> ( Client , Client ) {
@@ -126,21 +149,7 @@ impl MatrixMockServer {
126
149
let bob =
127
150
self . client_builder_for_crypto_end_to_end ( & bob_user_id, & bob_device_id) . build ( ) . await ;
128
151
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 ;
144
153
145
154
( alice, bob)
146
155
}
0 commit comments