Skip to content

Commit b1d1267

Browse files
committed
test: Add a test on protection message sort timestamp (#5088)
Even if `vc-request-with-auth` is received with a delay, the protection message must have the sort timestamp equal to the Sent timestamp of `vc-request-with-auth`, otherwise subsequent chat messages would also have greater sort timestamps and while it doesn't affect the chat itself (because Sent timestamps are shown to a user), it affects the chat position in the chatlist because chats there are sorted by sort timestamps of the last messages, so the user sees chats sorted out of order. That's what happened in #5088 where a user restores the backup made before setting up a verified chat with their contact and fetches new messages, including `vc-request-with-auth` and also messages from other chats, after that.
1 parent c4a2f58 commit b1d1267

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

src/securejoin.rs

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -775,10 +775,20 @@ mod tests {
775775
use crate::stock_str::chat_protection_enabled;
776776
use crate::test_utils::get_chat_msg;
777777
use crate::test_utils::{TestContext, TestContextManager};
778-
use crate::tools::EmailAddress;
778+
use crate::tools::{EmailAddress, SystemTime};
779+
use std::time::Duration;
779780

780781
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
781782
async fn test_setup_contact() {
783+
test_setup_contact_ex(false).await
784+
}
785+
786+
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
787+
async fn test_setup_contact_protection_timestamp() {
788+
test_setup_contact_ex(true).await
789+
}
790+
791+
async fn test_setup_contact_ex(check_protection_timestamp: bool) {
782792
let mut tcm = TestContextManager::new();
783793
let alice = tcm.alice().await;
784794
let bob = tcm.bob().await;
@@ -867,6 +877,10 @@ mod tests {
867877
// Check Bob sent the right message.
868878
let sent = bob.pop_sent_msg().await;
869879
let msg = alice.parse_msg(&sent).await;
880+
let vc_request_with_auth_ts_sent = msg
881+
.get_header(HeaderDef::Date)
882+
.and_then(|value| mailparse::dateparse(value).ok())
883+
.unwrap();
870884
assert!(msg.was_encrypted());
871885
assert_eq!(
872886
msg.get_header(HeaderDef::SecureJoin).unwrap(),
@@ -890,6 +904,10 @@ mod tests {
890904
.unwrap();
891905
assert_eq!(contact_bob.is_verified(&alice.ctx).await.unwrap(), false);
892906

907+
if check_protection_timestamp {
908+
SystemTime::shift(Duration::from_secs(3600));
909+
}
910+
893911
// Step 5+6: Alice receives vc-request-with-auth, sends vc-contact-confirm
894912
alice.recv_msg(&sent).await;
895913
assert_eq!(contact_bob.is_verified(&alice.ctx).await.unwrap(), true);
@@ -915,6 +933,9 @@ mod tests {
915933
assert!(msg.is_info());
916934
let expected_text = chat_protection_enabled(&alice).await;
917935
assert_eq!(msg.get_text(), expected_text);
936+
if check_protection_timestamp {
937+
assert_eq!(msg.timestamp_sort, vc_request_with_auth_ts_sent);
938+
}
918939
}
919940

920941
// Check Alice sent the right message to Bob.

0 commit comments

Comments
 (0)