@@ -625,6 +625,7 @@ mod tests {
625
625
use ruma:: { device_id, room_id, user_id, CanonicalJsonValue , DeviceId , RoomId , UserId } ;
626
626
use serde_json:: json;
627
627
628
+ use super :: BackupMachine ;
628
629
use crate :: {
629
630
olm:: BackedUpRoomKey , store:: BackupDecryptionKey , types:: RoomKeyBackupInfo , OlmError ,
630
631
OlmMachine ,
@@ -664,19 +665,19 @@ mod tests {
664
665
665
666
async fn backup_flow ( machine : OlmMachine ) -> Result < ( ) , OlmError > {
666
667
let backup_machine = machine. backup_machine ( ) ;
667
- let backup_version =
668
- backup_machine. backup_key . read ( ) . await . as_ref ( ) . and_then ( |k| k. backup_version ( ) ) ;
669
- let backup_version = backup_version. as_deref ( ) ;
668
+ let backup_version = current_backup_version ( backup_machine) . await ;
670
669
671
- let counts = backup_machine. store . inbound_group_session_counts ( backup_version) . await ?;
670
+ let counts =
671
+ backup_machine. store . inbound_group_session_counts ( backup_version. as_deref ( ) ) . await ?;
672
672
673
673
assert_eq ! ( counts. total, 0 , "Initially no keys exist" ) ;
674
674
assert_eq ! ( counts. backed_up, 0 , "Initially no backed up keys exist" ) ;
675
675
676
676
machine. create_outbound_group_session_with_defaults_test_helper ( room_id ( ) ) . await ?;
677
677
machine. create_outbound_group_session_with_defaults_test_helper ( room_id2 ( ) ) . await ?;
678
678
679
- let counts = backup_machine. store . inbound_group_session_counts ( backup_version) . await ?;
679
+ let counts =
680
+ backup_machine. store . inbound_group_session_counts ( backup_version. as_deref ( ) ) . await ?;
680
681
assert_eq ! ( counts. total, 2 , "Two room keys need to exist in the store" ) ;
681
682
assert_eq ! ( counts. backed_up, 0 , "No room keys have been backed up yet" ) ;
682
683
@@ -695,8 +696,10 @@ mod tests {
695
696
) ;
696
697
697
698
backup_machine. mark_request_as_sent ( & request_id) . await ?;
699
+ let backup_version = current_backup_version ( backup_machine) . await ;
698
700
699
- let counts = backup_machine. store . inbound_group_session_counts ( backup_version) . await ?;
701
+ let counts =
702
+ backup_machine. store . inbound_group_session_counts ( backup_version. as_deref ( ) ) . await ?;
700
703
assert_eq ! ( counts. total, 2 ) ;
701
704
assert_eq ! ( counts. backed_up, 2 , "All room keys have been backed up" ) ;
702
705
@@ -706,8 +709,10 @@ mod tests {
706
709
) ;
707
710
708
711
backup_machine. disable_backup ( ) . await ?;
712
+ let backup_version = current_backup_version ( backup_machine) . await ;
709
713
710
- let counts = backup_machine. store . inbound_group_session_counts ( backup_version) . await ?;
714
+ let counts =
715
+ backup_machine. store . inbound_group_session_counts ( backup_version. as_deref ( ) ) . await ?;
711
716
assert_eq ! ( counts. total, 2 ) ;
712
717
assert_eq ! (
713
718
counts. backed_up, 0 ,
@@ -717,6 +722,10 @@ mod tests {
717
722
Ok ( ( ) )
718
723
}
719
724
725
+ async fn current_backup_version ( backup_machine : & BackupMachine ) -> Option < String > {
726
+ backup_machine. backup_key . read ( ) . await . as_ref ( ) . and_then ( |k| k. backup_version ( ) )
727
+ }
728
+
720
729
#[ async_test]
721
730
async fn memory_store_backups ( ) -> Result < ( ) , OlmError > {
722
731
let machine = OlmMachine :: new ( alice_id ( ) , alice_device_id ( ) ) . await ;
0 commit comments