Skip to content

Commit c63dc8f

Browse files
committed
test(sdk): Test the conditions under which we accept a historic room key bundle
1 parent 754d946 commit c63dc8f

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
@@ -454,13 +454,13 @@ impl BundleReceiverTask {
454454

455455
#[cfg(all(test, not(target_family = "wasm")))]
456456
mod test {
457-
use matrix_sdk_test::async_test;
458-
use ruma::{event_id, room_id};
457+
use matrix_sdk_test::{async_test, InvitedRoomBuilder, JoinedRoomBuilder};
458+
use ruma::{event_id, room_id, user_id};
459459
use serde_json::json;
460460
use wiremock::MockServer;
461461

462462
use super::*;
463-
use crate::test_utils::logged_in_client;
463+
use crate::test_utils::{logged_in_client, mocks::MatrixMockServer};
464464

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

0 commit comments

Comments
 (0)