From 58b96b6b85645fb72579ffc3f1dd751164ee15f4 Mon Sep 17 00:00:00 2001 From: iequidoo Date: Sat, 19 Oct 2024 17:23:32 -0300 Subject: [PATCH] test: Message from old setup preserves contact verification, but breaks 1:1 protection If a message from an old contact's setup is received, the outdated Autocrypt header isn't applied, so the contact verification preserves. But the chat protection breaks because the old message is sorted to the bottom as it mustn't be sorted over the protection info message (which is `InNoticed` moreover). Would be nice to preserve the chat protection too e.g. add a "protection broken" message, then the old message and then a new "protection enabled" message, but let's record the current behaviour first. --- src/tests/verified_chats.rs | 40 +++++++++++++++++++ .../verified_chats_message_from_old_dc_setup | 7 ++++ 2 files changed, 47 insertions(+) create mode 100644 test-data/golden/verified_chats_message_from_old_dc_setup diff --git a/src/tests/verified_chats.rs b/src/tests/verified_chats.rs index 757158e344..c37d8569a8 100644 --- a/src/tests/verified_chats.rs +++ b/src/tests/verified_chats.rs @@ -730,6 +730,46 @@ async fn test_break_protection_then_verify_again() -> Result<()> { Ok(()) } +#[tokio::test(flavor = "multi_thread", worker_threads = 2)] +async fn test_message_from_old_dc_setup() -> Result<()> { + let mut tcm = TestContextManager::new(); + let alice = &tcm.alice().await; + let bob_old = &tcm.unconfigured().await; + enable_verified_oneonone_chats(&[alice, bob_old]).await; + mark_as_verified(bob_old, alice).await; + bob_old.configure_addr("bob@example.net").await; + let chat = bob_old.create_chat(alice).await; + let sent_old = bob_old + .send_text(chat.id, "Soon i'll have a new device") + .await; + SystemTime::shift(std::time::Duration::from_secs(3600)); + + tcm.section("Bob reinstalls DC"); + let bob = &tcm.bob().await; + enable_verified_oneonone_chats(&[bob]).await; + + mark_as_verified(alice, bob).await; + mark_as_verified(bob, alice).await; + + tcm.send_recv(bob, alice, "Now i have it!").await; + assert_verified(alice, bob, ProtectionStatus::Protected).await; + + let msg = alice.recv_msg(&sent_old).await; + assert!(!msg.get_showpadlock()); + let contact = alice.add_or_lookup_contact(bob).await; + // The outdated Bob's Autocrypt header isn't applied, so the verification preserves. + assert!(contact.is_verified(alice).await.unwrap()); + let chat = alice.get_chat(bob).await; + // But the chat protection is broken because the old message is sorted to the bottom as it + // mustn't be sorted over the protection info message (which is `InNoticed` moreover). + assert_eq!(chat.is_protected(), false); + assert_eq!(chat.is_protection_broken(), true); + alice + .golden_test_chat(msg.chat_id, "verified_chats_message_from_old_dc_setup") + .await; + Ok(()) +} + /// Regression test for the following bug: /// /// - Scan your chat partner's QR Code diff --git a/test-data/golden/verified_chats_message_from_old_dc_setup b/test-data/golden/verified_chats_message_from_old_dc_setup new file mode 100644 index 0000000000..8c026deb52 --- /dev/null +++ b/test-data/golden/verified_chats_message_from_old_dc_setup @@ -0,0 +1,7 @@ +Single#Chat#10: bob@example.net [bob@example.net] +-------------------------------------------------------------------------------- +Msg#10: info (Contact#Contact#Info): Messages are guaranteed to be end-to-end encrypted from now on. [NOTICED][INFO 🛡️] +Msg#11🔒: (Contact#Contact#10): Now i have it! [FRESH] +Msg#12: info (Contact#Contact#Info): bob@example.net sent a message from another device. [NOTICED][INFO 🛡️❌] +Msg#13: (Contact#Contact#10): Soon i'll have a new device [FRESH] +--------------------------------------------------------------------------------