Skip to content

Commit dff6227

Browse files
committed
test(sdk): Test the conditions under which we accept a historic room key bundle
1 parent 3f2e506 commit dff6227

File tree

1 file changed

+43
-3
lines changed
  • crates/matrix-sdk/src/encryption

1 file changed

+43
-3
lines changed

crates/matrix-sdk/src/encryption/tasks.rs

Lines changed: 43 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -458,13 +458,13 @@ impl BundleReceiverTask {
458458

459459
#[cfg(all(test, not(target_family = "wasm")))]
460460
mod test {
461-
use matrix_sdk_test::async_test;
462-
use ruma::{event_id, room_id};
461+
use matrix_sdk_test::{async_test, InvitedRoomBuilder, JoinedRoomBuilder};
462+
use ruma::{event_id, room_id, user_id};
463463
use serde_json::json;
464464
use wiremock::MockServer;
465465

466466
use super::*;
467-
use crate::test_utils::logged_in_client;
467+
use crate::test_utils::{logged_in_client, mocks::MatrixMockServer};
468468

469469
// Test that, if backups are not enabled, we don't incorrectly mark a room key
470470
// as downloaded.
@@ -522,4 +522,44 @@ mod test {
522522
)
523523
}
524524
}
525+
526+
/// Test that ensures that we only accept a bundle if a certain set of
527+
/// conditions is met.
528+
#[async_test]
529+
async fn test_should_accept_bundle() {
530+
let server = MatrixMockServer::new().await;
531+
let client = server.client_builder().logged_in_with_oauth().build().await;
532+
533+
let user_id = user_id!("@alice:localhost");
534+
let joined_room_id = room_id!("!joined:localhost");
535+
let invited_rom_id = room_id!("!invited:localhost");
536+
537+
server
538+
.mock_sync()
539+
.ok_and_run(&client, |builder| {
540+
builder
541+
.add_joined_room(JoinedRoomBuilder::new(&joined_room_id))
542+
.add_invited_room(InvitedRoomBuilder::new(&invited_rom_id));
543+
})
544+
.await;
545+
546+
let room =
547+
client.get_room(&joined_room_id).expect("We should have access to our joined room now");
548+
549+
let bundle_info =
550+
RoomKeyBundleInfo { sender: user_id.to_owned(), room_id: joined_room_id.to_owned() };
551+
552+
assert!(BundleReceiverTask::should_accept_bundle(&room, &bundle_info));
553+
554+
let invited_room =
555+
client.get_room(invited_rom_id).expect("We should have access to our invited room now");
556+
557+
assert!(
558+
!BundleReceiverTask::should_accept_bundle(&invited_room, &bundle_info),
559+
"We should not accept a bundle if we didn't join the room."
560+
);
561+
562+
// TODO: Add more cases here once we figure out the correct acceptance
563+
// rules.
564+
}
525565
}

0 commit comments

Comments
 (0)