Skip to content

Commit 474f832

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 a288c19 commit 474f832

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
@@ -783,10 +783,20 @@ mod tests {
783783
use crate::stock_str::chat_protection_enabled;
784784
use crate::test_utils::get_chat_msg;
785785
use crate::test_utils::{TestContext, TestContextManager};
786-
use crate::tools::EmailAddress;
786+
use crate::tools::{EmailAddress, SystemTime};
787+
use std::time::Duration;
787788

788789
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
789790
async fn test_setup_contact() {
791+
test_setup_contact_ex(false).await
792+
}
793+
794+
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
795+
async fn test_setup_contact_protection_timestamp() {
796+
test_setup_contact_ex(true).await
797+
}
798+
799+
async fn test_setup_contact_ex(check_protection_timestamp: bool) {
790800
let mut tcm = TestContextManager::new();
791801
let alice = tcm.alice().await;
792802
let bob = tcm.bob().await;
@@ -875,6 +885,10 @@ mod tests {
875885
// Check Bob sent the right message.
876886
let sent = bob.pop_sent_msg().await;
877887
let msg = alice.parse_msg(&sent).await;
888+
let vc_request_with_auth_ts_sent = msg
889+
.get_header(HeaderDef::Date)
890+
.and_then(|value| mailparse::dateparse(value).ok())
891+
.unwrap();
878892
assert!(msg.was_encrypted());
879893
assert_eq!(
880894
msg.get_header(HeaderDef::SecureJoin).unwrap(),
@@ -898,6 +912,10 @@ mod tests {
898912
.unwrap();
899913
assert_eq!(contact_bob.is_verified(&alice.ctx).await.unwrap(), false);
900914

915+
if check_protection_timestamp {
916+
SystemTime::shift(Duration::from_secs(3600));
917+
}
918+
901919
// Step 5+6: Alice receives vc-request-with-auth, sends vc-contact-confirm
902920
alice.recv_msg(&sent).await;
903921
assert_eq!(contact_bob.is_verified(&alice.ctx).await.unwrap(), true);
@@ -923,6 +941,9 @@ mod tests {
923941
assert!(msg.is_info());
924942
let expected_text = chat_protection_enabled(&alice).await;
925943
assert_eq!(msg.get_text(), expected_text);
944+
if check_protection_timestamp {
945+
assert_eq!(msg.timestamp_sort, vc_request_with_auth_ts_sent);
946+
}
926947
}
927948

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

0 commit comments

Comments
 (0)