Skip to content

Commit 27be8e5

Browse files
committed
test: Add another test for pinned timelines
This time we're testing the redecryption of pinned events that were not part of the main timeline, more importantly we never backpaginated enough for them to be part of the main timeline and thus never got put into the event cache. This test expectedly fails for now.
1 parent 5f81739 commit 27be8e5

File tree

1 file changed

+37
-13
lines changed
  • testing/matrix-sdk-integration-testing/src/tests

1 file changed

+37
-13
lines changed

testing/matrix-sdk-integration-testing/src/tests/timeline.rs

Lines changed: 37 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1086,6 +1086,7 @@ async fn test_local_echo_to_send_event_has_encryption_info() -> TestResult {
10861086
async fn prepare_room_with_pinned_events(
10871087
alice: &Client,
10881088
recovery_passphrase: &str,
1089+
number_of_normal_events: usize,
10891090
) -> Result<(OwnedRoomId, OwnedEventId), TestError> {
10901091
let sync_service = SyncService::builder(alice.clone()).build().await?;
10911092
sync_service.start().await;
@@ -1113,22 +1114,20 @@ async fn prepare_room_with_pinned_events(
11131114
let timeline = room.timeline().await?;
11141115
timeline.pin_event(&event_id).await?;
11151116

1117+
// Now send a bunch of normal events, this ensures that our pinned event isn't
1118+
// in the main timeline when we restore things.
1119+
for i in 0..number_of_normal_events {
1120+
room.send(RoomMessageEventContent::text_plain(format!("Normal event {i}"))).await?;
1121+
}
1122+
11161123
sync_service.stop().await;
11171124

11181125
Ok((room_id, event_id))
11191126
}
11201127

1121-
/// Test that pinned UTD events, once decrypted by R2D2 (the redecryptor), get
1122-
/// replaced in the timeline with the decrypted variant.
1123-
///
1124-
/// We do this by first creating the pinned events on one Client, called
1125-
/// `alice`. Then another client object is created, called `another_alice`.
1126-
/// `another_alice` initially doesn't have access to the room history.
1127-
///
1128-
/// Only once `another_alice` recovers things and gets access to the backup can
1129-
/// she download the room key to decrypt the pinned event.
1130-
#[tokio::test(flavor = "multi_thread", worker_threads = 4)]
1131-
async fn test_pinned_events_are_decrypted_after_recovering() -> TestResult {
1128+
async fn test_pinned_events_are_decrypted_after_recovering_with_event_count(
1129+
event_count: usize,
1130+
) -> TestResult {
11321131
const RECOVERY_PASSPHRASE: &str = "I am error";
11331132

11341133
let encryption_settings = EncryptionSettings {
@@ -1145,7 +1144,8 @@ async fn test_pinned_events_are_decrypted_after_recovering() -> TestResult {
11451144
.await?;
11461145
let user_id = alice.user_id().expect("We should have a user ID by now");
11471146

1148-
let (room_id, event_id) = prepare_room_with_pinned_events(&alice, RECOVERY_PASSPHRASE).await?;
1147+
let (room_id, event_id) =
1148+
prepare_room_with_pinned_events(&alice, RECOVERY_PASSPHRASE, event_count).await?;
11491149

11501150
// Now `another_alice` comes into play.
11511151
let another_alice = TestClientBuilder::with_exact_username(user_id.localpart().to_owned())
@@ -1241,5 +1241,29 @@ async fn test_pinned_events_are_decrypted_after_recovering() -> TestResult {
12411241
Ok(())
12421242
}
12431243

1244-
Ok(())
1244+
/// Test that pinned UTD events, once decrypted by R2D2 (the redecryptor), get
1245+
/// replaced in the timeline with the decrypted variant.
1246+
///
1247+
/// We do this by first creating the pinned events on one Client, called
1248+
/// `alice`. Then another client object is created, called `another_alice`.
1249+
/// `another_alice` initially doesn't have access to the room history.
1250+
///
1251+
/// Only once `another_alice` recovers things and gets access to the backup can
1252+
/// she download the room key to decrypt the pinned event.
1253+
#[tokio::test(flavor = "multi_thread", worker_threads = 4)]
1254+
async fn test_pinned_events_are_decrypted_after_recovering_with_event_in_timeline() -> TestResult {
1255+
test_pinned_events_are_decrypted_after_recovering_with_event_count(0).await
1256+
}
1257+
1258+
/// Test that pinned UTD events, once decrypted by R2D2 (the redecryptor), get
1259+
/// replaced in the timeline with the decrypted variant even if the pinened UTD
1260+
/// event isn't part of the main timeline and thus wasn't put into the event
1261+
/// cache by the main timeline backpaginating.
1262+
#[tokio::test(flavor = "multi_thread", worker_threads = 4)]
1263+
// FIXME: This test is ignored because R2D2 can't decrypt this pinned event as it's never put into
1264+
// the event cache.
1265+
#[ignore]
1266+
async fn test_pinned_events_are_decrypted_after_recovering_with_event_not_in_timeline() -> TestResult
1267+
{
1268+
test_pinned_events_are_decrypted_after_recovering_with_event_count(30).await
12451269
}

0 commit comments

Comments
 (0)