Skip to content

Commit a843125

Browse files
committed
crypto: Share code to get backup_version in tests
1 parent f11aeaf commit a843125

File tree

2 files changed

+17
-8
lines changed

2 files changed

+17
-8
lines changed

crates/matrix-sdk-crypto/src/backups/mod.rs

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -625,6 +625,7 @@ mod tests {
625625
use ruma::{device_id, room_id, user_id, CanonicalJsonValue, DeviceId, RoomId, UserId};
626626
use serde_json::json;
627627

628+
use super::BackupMachine;
628629
use crate::{
629630
olm::BackedUpRoomKey, store::BackupDecryptionKey, types::RoomKeyBackupInfo, OlmError,
630631
OlmMachine,
@@ -664,19 +665,19 @@ mod tests {
664665

665666
async fn backup_flow(machine: OlmMachine) -> Result<(), OlmError> {
666667
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;
670669

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?;
672672

673673
assert_eq!(counts.total, 0, "Initially no keys exist");
674674
assert_eq!(counts.backed_up, 0, "Initially no backed up keys exist");
675675

676676
machine.create_outbound_group_session_with_defaults_test_helper(room_id()).await?;
677677
machine.create_outbound_group_session_with_defaults_test_helper(room_id2()).await?;
678678

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?;
680681
assert_eq!(counts.total, 2, "Two room keys need to exist in the store");
681682
assert_eq!(counts.backed_up, 0, "No room keys have been backed up yet");
682683

@@ -695,8 +696,10 @@ mod tests {
695696
);
696697

697698
backup_machine.mark_request_as_sent(&request_id).await?;
699+
let backup_version = current_backup_version(backup_machine).await;
698700

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?;
700703
assert_eq!(counts.total, 2);
701704
assert_eq!(counts.backed_up, 2, "All room keys have been backed up");
702705

@@ -706,8 +709,10 @@ mod tests {
706709
);
707710

708711
backup_machine.disable_backup().await?;
712+
let backup_version = current_backup_version(backup_machine).await;
709713

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?;
711716
assert_eq!(counts.total, 2);
712717
assert_eq!(
713718
counts.backed_up, 0,
@@ -717,6 +722,10 @@ mod tests {
717722
Ok(())
718723
}
719724

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+
720729
#[async_test]
721730
async fn memory_store_backups() -> Result<(), OlmError> {
722731
let machine = OlmMachine::new(alice_id(), alice_device_id()).await;

crates/matrix-sdk-crypto/src/store/integration_tests.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -442,7 +442,7 @@ macro_rules! cryptostore_integration_tests {
442442
loaded_session.export().await;
443443

444444
assert_eq!(store.get_inbound_group_sessions().await.unwrap().len(), 1);
445-
assert_eq!(store.inbound_group_session_counts(Some("bkpver1")).await.unwrap().total, 1);
445+
assert_eq!(store.inbound_group_session_counts(None).await.unwrap().total, 1);
446446
}
447447

448448
#[async_test]

0 commit comments

Comments
 (0)