@@ -117,6 +117,44 @@ async fn test_send_encrypted_to_device() {
117
117
) ;
118
118
}
119
119
120
+ /// Test what happens when the sending device is deleted before the to-device
121
+ /// event arrives. (It should still be successfully decrypted.)
122
+ ///
123
+ /// Regression test for https://github.com/matrix-org/matrix-rust-sdk/issues/5768.
124
+ #[ async_test]
125
+ async fn test_encrypted_to_device_from_deleted_device ( ) {
126
+ let ( alice, bob) =
127
+ get_machine_pair_with_session ( tests:: alice_id ( ) , tests:: user_id ( ) , false ) . await ;
128
+
129
+ // Tell Bob that Alice's device has been deleted
130
+ let mut keys_query_response = ruma:: api:: client:: keys:: get_keys:: v3:: Response :: default ( ) ;
131
+ keys_query_response. device_keys . insert ( alice. user_id ( ) . to_owned ( ) , Default :: default ( ) ) ;
132
+ bob. receive_keys_query_response ( & TransactionId :: new ( ) , & keys_query_response) . await . unwrap ( ) ;
133
+
134
+ let custom_event_type = "m.new_device" ;
135
+ let custom_content = json ! ( { "a" : "b" } ) ;
136
+
137
+ let decryption_settings =
138
+ DecryptionSettings { sender_device_trust_requirement : TrustRequirement :: Untrusted } ;
139
+
140
+ let processed_event = send_and_receive_encrypted_to_device_test_helper (
141
+ & alice,
142
+ & bob,
143
+ custom_event_type,
144
+ & custom_content,
145
+ & decryption_settings,
146
+ )
147
+ . await ;
148
+
149
+ assert_let ! ( ProcessedToDeviceEvent :: Decrypted { raw, encryption_info } = processed_event) ;
150
+
151
+ let decrypted_event = raw. deserialize ( ) . unwrap ( ) ;
152
+ assert_eq ! ( decrypted_event. event_type( ) . to_string( ) , custom_event_type. to_owned( ) ) ;
153
+
154
+ assert_eq ! ( encryption_info. sender, alice. user_id( ) . to_owned( ) ) ;
155
+ assert_matches ! ( & encryption_info. sender_device, Some ( sender_device) ) ;
156
+ assert_eq ! ( sender_device. to_owned( ) , alice. device_id( ) . to_owned( ) ) ;
157
+ }
120
158
121
159
/// If the sender device is genuinely unknown (it is not in the store, nor does
122
160
/// the to-device message contain `sender_device_keys`), decryption will fail,
0 commit comments