Skip to content

Commit 778660a

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 6e55f0c commit 778660a

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
@@ -770,10 +770,20 @@ mod tests {
770770
use crate::stock_str::chat_protection_enabled;
771771
use crate::test_utils::get_chat_msg;
772772
use crate::test_utils::{TestContext, TestContextManager};
773-
use crate::tools::EmailAddress;
773+
use crate::tools::{EmailAddress, SystemTime};
774+
use std::time::Duration;
774775

775776
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
776777
async fn test_setup_contact() {
778+
test_setup_contact_ex(false).await
779+
}
780+
781+
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
782+
async fn test_setup_contact_protection_timestamp() {
783+
test_setup_contact_ex(true).await
784+
}
785+
786+
async fn test_setup_contact_ex(check_protection_timestamp: bool) {
777787
let mut tcm = TestContextManager::new();
778788
let alice = tcm.alice().await;
779789
let bob = tcm.bob().await;
@@ -862,6 +872,10 @@ mod tests {
862872
// Check Bob sent the right message.
863873
let sent = bob.pop_sent_msg().await;
864874
let msg = alice.parse_msg(&sent).await;
875+
let vc_request_with_auth_ts_sent = msg
876+
.get_header(HeaderDef::Date)
877+
.and_then(|value| mailparse::dateparse(value).ok())
878+
.unwrap();
865879
assert!(msg.was_encrypted());
866880
assert_eq!(
867881
msg.get_header(HeaderDef::SecureJoin).unwrap(),
@@ -885,6 +899,10 @@ mod tests {
885899
.unwrap();
886900
assert_eq!(contact_bob.is_verified(&alice.ctx).await.unwrap(), false);
887901

902+
if check_protection_timestamp {
903+
SystemTime::shift(Duration::from_secs(3600));
904+
}
905+
888906
// Step 5+6: Alice receives vc-request-with-auth, sends vc-contact-confirm
889907
alice.recv_msg(&sent).await;
890908
assert_eq!(contact_bob.is_verified(&alice.ctx).await.unwrap(), true);
@@ -910,6 +928,9 @@ mod tests {
910928
assert!(msg.is_info());
911929
let expected_text = chat_protection_enabled(&alice).await;
912930
assert_eq!(msg.get_text(), expected_text);
931+
if check_protection_timestamp {
932+
assert_eq!(msg.timestamp_sort, vc_request_with_auth_ts_sent);
933+
}
913934
}
914935

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

0 commit comments

Comments
 (0)