@@ -53,7 +53,7 @@ use super::TestTimeline;
53
53
use crate :: {
54
54
timeline:: {
55
55
EncryptedMessage , MsgLikeContent , MsgLikeKind , TimelineDetails , TimelineItemContent ,
56
- tests:: { TestRoomDataProvider , TestTimelineBuilder } ,
56
+ tests:: { TestDecryptor , TestRoomDataProvider , TestTimelineBuilder } ,
57
57
} ,
58
58
unable_to_decrypt_hook:: { UnableToDecryptHook , UnableToDecryptInfo , UtdHookManager } ,
59
59
} ;
@@ -90,7 +90,16 @@ async fn test_retry_message_decryption() {
90
90
let client = test_client_builder ( None ) . build ( ) . await . unwrap ( ) ;
91
91
let utd_hook = Arc :: new ( UtdHookManager :: new ( hook. clone ( ) , client) ) ;
92
92
93
- let timeline = TestTimelineBuilder :: new ( ) . unable_to_decrypt_hook ( utd_hook. clone ( ) ) . build ( ) ;
93
+ let own_user_id = user_id ! ( "@example:morheus.localhost" ) ;
94
+ let olm_machine = OlmMachine :: new ( own_user_id, "SomeDeviceId" . into ( ) ) . await ;
95
+
96
+ let timeline = TestTimelineBuilder :: new ( )
97
+ . unable_to_decrypt_hook ( utd_hook. clone ( ) )
98
+ . decryptor ( TestDecryptor :: new (
99
+ room_id ! ( "!DovneieKSTkdHKpIXy:morpheus.localhost" ) ,
100
+ & olm_machine,
101
+ ) )
102
+ . build ( ) ;
94
103
let mut stream = timeline. subscribe ( ) . await ;
95
104
96
105
let f = & timeline. factory ;
@@ -146,19 +155,13 @@ async fn test_retry_message_decryption() {
146
155
assert ! ( utds[ 0 ] . time_to_decrypt. is_none( ) ) ;
147
156
}
148
157
149
- let own_user_id = user_id ! ( "@example:morheus.localhost" ) ;
150
158
let exported_keys = decrypt_room_key_export ( Cursor :: new ( SESSION_KEY ) , "1234" ) . unwrap ( ) ;
151
159
152
- let olm_machine = OlmMachine :: new ( own_user_id, "SomeDeviceId" . into ( ) ) . await ;
153
160
olm_machine. store ( ) . import_exported_room_keys ( exported_keys, |_, _| { } ) . await . unwrap ( ) ;
154
161
155
162
timeline
156
163
. controller
157
- . retry_event_decryption_test (
158
- room_id ! ( "!DovneieKSTkdHKpIXy:morpheus.localhost" ) ,
159
- olm_machine,
160
- Some ( iter:: once ( SESSION_ID . to_owned ( ) ) . collect ( ) ) ,
161
- )
164
+ . retry_event_decryption_test ( Some ( iter:: once ( SESSION_ID . to_owned ( ) ) . collect ( ) ) )
162
165
. await ;
163
166
164
167
assert_eq ! ( timeline. controller. items( ) . await . len( ) , 2 ) ;
@@ -198,7 +201,16 @@ async fn test_false_positive_late_decryption_regression() {
198
201
UtdHookManager :: new ( hook. clone ( ) , client) . with_max_delay ( Duration :: from_millis ( 500 ) ) ,
199
202
) ;
200
203
201
- let timeline = TestTimelineBuilder :: new ( ) . unable_to_decrypt_hook ( utd_hook. clone ( ) ) . build ( ) ;
204
+ let own_user_id = user_id ! ( "@example:morheus.localhost" ) ;
205
+ let olm_machine = OlmMachine :: new ( own_user_id, "SomeDeviceId" . into ( ) ) . await ;
206
+
207
+ let timeline = TestTimelineBuilder :: new ( )
208
+ . unable_to_decrypt_hook ( utd_hook. clone ( ) )
209
+ . decryptor ( TestDecryptor :: new (
210
+ room_id ! ( "!DovneieKSTkdHKpIXy:morpheus.localhost" ) ,
211
+ & olm_machine,
212
+ ) )
213
+ . build ( ) ;
202
214
203
215
let f = & timeline. factory ;
204
216
timeline
@@ -227,21 +239,14 @@ async fn test_false_positive_late_decryption_regression() {
227
239
)
228
240
. await ;
229
241
230
- let own_user_id = user_id ! ( "@example:morheus.localhost" ) ;
231
- let olm_machine = OlmMachine :: new ( own_user_id, "SomeDeviceId" . into ( ) ) . await ;
232
-
233
242
sleep ( Duration :: from_millis ( 200 ) ) . await ;
234
243
235
244
// Simulate a retry decryption.
236
245
// Due to the regression this was marking the event as successfully decrypted on
237
246
// retry
238
247
timeline
239
248
. controller
240
- . retry_event_decryption_test (
241
- room_id ! ( "!DovneieKSTkdHKpIXy:morpheus.localhost" ) ,
242
- olm_machine,
243
- Some ( iter:: once ( SESSION_ID . to_owned ( ) ) . collect ( ) ) ,
244
- )
249
+ . retry_event_decryption_test ( Some ( iter:: once ( SESSION_ID . to_owned ( ) ) . collect ( ) ) )
245
250
. await ;
246
251
assert_eq ! ( timeline. controller. items( ) . await . len( ) , 2 ) ;
247
252
@@ -287,7 +292,16 @@ async fn test_retry_edit_decryption() {
287
292
rHCyB4ElRjU\n \
288
293
-----END MEGOLM SESSION DATA-----";
289
294
290
- let timeline = TestTimeline :: new ( ) ;
295
+ let own_user_id = user_id ! ( "@example:morheus.localhost" ) ;
296
+ let olm_machine = OlmMachine :: new ( own_user_id, "SomeDeviceId" . into ( ) ) . await ;
297
+
298
+ let timeline = TestTimelineBuilder :: new ( )
299
+ . decryptor ( TestDecryptor :: new (
300
+ room_id ! ( "!bdsREiCPHyZAPkpXer:morpheus.localhost" ) ,
301
+ & olm_machine,
302
+ ) )
303
+ . build ( ) ;
304
+
291
305
let f = & timeline. factory ;
292
306
let mut stream = timeline. subscribe_events ( ) . await ;
293
307
@@ -353,18 +367,9 @@ async fn test_retry_edit_decryption() {
353
367
let mut keys = decrypt_room_key_export ( Cursor :: new ( SESSION1_KEY ) , "1234" ) . unwrap ( ) ;
354
368
keys. extend ( decrypt_room_key_export ( Cursor :: new ( SESSION2_KEY ) , "1234" ) . unwrap ( ) ) ;
355
369
356
- let own_user_id = user_id ! ( "@example:morheus.localhost" ) ;
357
- let olm_machine = OlmMachine :: new ( own_user_id, "SomeDeviceId" . into ( ) ) . await ;
358
370
olm_machine. store ( ) . import_exported_room_keys ( keys, |_, _| { } ) . await . unwrap ( ) ;
359
371
360
- timeline
361
- . controller
362
- . retry_event_decryption_test (
363
- room_id ! ( "!bdsREiCPHyZAPkpXer:morpheus.localhost" ) ,
364
- olm_machine,
365
- None ,
366
- )
367
- . await ;
372
+ timeline. controller . retry_event_decryption_test ( None ) . await ;
368
373
369
374
// Then first, the first item gets decrypted on its own
370
375
assert_next_matches_with_timeout ! ( stream, VectorDiff :: Set { index: 0 , .. } ) ;
@@ -419,7 +424,12 @@ async fn test_retry_edit_and_more() {
419
424
)
420
425
}
421
426
422
- let timeline = TestTimeline :: new ( ) ;
427
+ let olm_machine = OlmMachine :: new ( user_id ! ( "@jptest:matrix.org" ) , DEVICE_ID . into ( ) ) . await ;
428
+
429
+ let timeline = TestTimelineBuilder :: new ( )
430
+ . decryptor ( TestDecryptor :: new ( room_id ! ( "!wFnAUSQbxMcfIMgvNX:flipdot.org" ) , & olm_machine) )
431
+ . build ( ) ;
432
+
423
433
let f = & timeline. factory ;
424
434
let mut stream = timeline. subscribe ( ) . await ;
425
435
@@ -480,17 +490,12 @@ async fn test_retry_edit_and_more() {
480
490
assert_next_matches_with_timeout ! ( stream, VectorDiff :: PushBack { .. } ) ;
481
491
assert_next_matches_with_timeout ! ( stream, VectorDiff :: PushBack { .. } ) ;
482
492
483
- let olm_machine = OlmMachine :: new ( user_id ! ( "@jptest:matrix.org" ) , DEVICE_ID . into ( ) ) . await ;
484
493
let keys = decrypt_room_key_export ( Cursor :: new ( SESSION_KEY ) , "testing" ) . unwrap ( ) ;
485
494
olm_machine. store ( ) . import_exported_room_keys ( keys, |_, _| { } ) . await . unwrap ( ) ;
486
495
487
496
timeline
488
497
. controller
489
- . retry_event_decryption_test (
490
- room_id ! ( "!wFnAUSQbxMcfIMgvNX:flipdot.org" ) ,
491
- olm_machine,
492
- Some ( iter:: once ( SESSION_ID . to_owned ( ) ) . collect ( ) ) ,
493
- )
498
+ . retry_event_decryption_test ( Some ( iter:: once ( SESSION_ID . to_owned ( ) ) . collect ( ) ) )
494
499
. await ;
495
500
496
501
// Then first, the original item got decrypted
@@ -536,7 +541,13 @@ async fn test_retry_message_decryption_highlighted() {
536
541
FM8H2PpVkKgrA+tx8LNQD+FWDfp6MyhmEJEvk9r5vU9LtTXtZl4toYvNY0UHUBbZj2xF9U9Z9A\n \
537
542
-----END MEGOLM SESSION DATA-----";
538
543
539
- let timeline = TestTimeline :: new ( ) ;
544
+ let own_user_id = user_id ! ( "@example:matrix.org" ) ;
545
+ let olm_machine = OlmMachine :: new ( own_user_id, "SomeDeviceId" . into ( ) ) . await ;
546
+
547
+ let timeline = TestTimelineBuilder :: new ( )
548
+ . decryptor ( TestDecryptor :: new ( room_id ! ( "!rYtFvMGENJleNQVJzb:matrix.org" ) , & olm_machine) )
549
+ . build ( ) ;
550
+
540
551
let f = & timeline. factory ;
541
552
let mut stream = timeline. subscribe ( ) . await ;
542
553
@@ -583,19 +594,13 @@ async fn test_retry_message_decryption_highlighted() {
583
594
let date_divider = assert_next_matches ! ( stream, VectorDiff :: PushFront { value } => value) ;
584
595
assert ! ( date_divider. is_date_divider( ) ) ;
585
596
586
- let own_user_id = user_id ! ( "@example:matrix.org" ) ;
587
597
let exported_keys = decrypt_room_key_export ( Cursor :: new ( SESSION_KEY ) , "1234" ) . unwrap ( ) ;
588
598
589
- let olm_machine = OlmMachine :: new ( own_user_id, "SomeDeviceId" . into ( ) ) . await ;
590
599
olm_machine. store ( ) . import_exported_room_keys ( exported_keys, |_, _| { } ) . await . unwrap ( ) ;
591
600
592
601
timeline
593
602
. controller
594
- . retry_event_decryption_test (
595
- room_id ! ( "!rYtFvMGENJleNQVJzb:matrix.org" ) ,
596
- olm_machine,
597
- Some ( iter:: once ( SESSION_ID . to_owned ( ) ) . collect ( ) ) ,
598
- )
603
+ . retry_event_decryption_test ( Some ( iter:: once ( SESSION_ID . to_owned ( ) ) . collect ( ) ) )
599
604
. await ;
600
605
601
606
assert_eq ! ( timeline. controller. items( ) . await . len( ) , 2 ) ;
@@ -615,12 +620,20 @@ async fn test_retry_fetching_encryption_info() {
615
620
let sender = user_id ! ( "@sender:s.co" ) ;
616
621
let room_id = room_id ! ( "!room:s.co" ) ;
617
622
623
+ let own_user_id = user_id ! ( "@me:s.co" ) ;
624
+ let olm_machine = OlmMachine :: new ( own_user_id, "SomeDeviceId" . into ( ) ) . await ;
625
+
618
626
// Given when I ask the room for new encryption info for any session, it will
619
627
// say "verified"
620
628
let verified_encryption_info = make_encryption_info ( SESSION_ID , VerificationState :: Verified ) ;
621
629
let provider =
622
630
TestRoomDataProvider :: default ( ) . with_encryption_info ( SESSION_ID , verified_encryption_info) ;
623
- let timeline = TestTimelineBuilder :: new ( ) . provider ( provider) . build ( ) ;
631
+
632
+ let timeline = TestTimelineBuilder :: new ( )
633
+ . provider ( provider)
634
+ . decryptor ( TestDecryptor :: new ( room_id, & olm_machine) )
635
+ . build ( ) ;
636
+
624
637
let f = & timeline. factory ;
625
638
let mut stream = timeline. subscribe_events ( ) . await ;
626
639
@@ -671,15 +684,9 @@ async fn test_retry_fetching_encryption_info() {
671
684
}
672
685
673
686
// When we retry the session with ID SESSION_ID
674
- let own_user_id = user_id ! ( "@me:s.co" ) ;
675
- let olm_machine = OlmMachine :: new ( own_user_id, "SomeDeviceId" . into ( ) ) . await ;
676
687
timeline
677
688
. controller
678
- . retry_event_decryption_test (
679
- room_id,
680
- olm_machine,
681
- Some ( iter:: once ( SESSION_ID . to_owned ( ) ) . collect ( ) ) ,
682
- )
689
+ . retry_event_decryption_test ( Some ( iter:: once ( SESSION_ID . to_owned ( ) ) . collect ( ) ) )
683
690
. await ;
684
691
685
692
// Then the event in that session has been updated to be verified
@@ -817,7 +824,16 @@ async fn test_retry_decryption_updates_response() {
817
824
HztoSJUr/2Y\n \
818
825
-----END MEGOLM SESSION DATA-----";
819
826
820
- let timeline = TestTimeline :: new ( ) ;
827
+ let own_user_id = user_id ! ( "@example:morheus.localhost" ) ;
828
+ let olm_machine = OlmMachine :: new ( own_user_id, "SomeDeviceId" . into ( ) ) . await ;
829
+
830
+ let timeline = TestTimelineBuilder :: new ( )
831
+ . decryptor ( TestDecryptor :: new (
832
+ room_id ! ( "!DovneieKSTkdHKpIXy:morpheus.localhost" ) ,
833
+ & olm_machine,
834
+ ) )
835
+ . build ( ) ;
836
+
821
837
let mut stream = timeline. subscribe_events ( ) . await ;
822
838
823
839
let original_event_id = event_id ! ( "$original" ) ;
@@ -883,20 +899,14 @@ async fn test_retry_decryption_updates_response() {
883
899
}
884
900
885
901
// Import a room key backup.
886
- let own_user_id = user_id ! ( "@example:morheus.localhost" ) ;
887
902
let exported_keys = decrypt_room_key_export ( Cursor :: new ( SESSION_KEY ) , "1234" ) . unwrap ( ) ;
888
903
889
- let olm_machine = OlmMachine :: new ( own_user_id, "SomeDeviceId" . into ( ) ) . await ;
890
904
olm_machine. store ( ) . import_exported_room_keys ( exported_keys, |_, _| { } ) . await . unwrap ( ) ;
891
905
892
906
// Retry decrypting the UTD.
893
907
timeline
894
908
. controller
895
- . retry_event_decryption_test (
896
- room_id ! ( "!DovneieKSTkdHKpIXy:morpheus.localhost" ) ,
897
- olm_machine,
898
- Some ( iter:: once ( SESSION_ID . to_owned ( ) ) . collect ( ) ) ,
899
- )
909
+ . retry_event_decryption_test ( Some ( iter:: once ( SESSION_ID . to_owned ( ) ) . collect ( ) ) )
900
910
. await ;
901
911
902
912
// The response is updated.
0 commit comments