From 44b07362163d08acee5f119d38e872f9b94b7031 Mon Sep 17 00:00:00 2001 From: iequidoo Date: Sat, 24 Jan 2026 11:16:35 -0300 Subject: [PATCH] test: Encrypted incoming message goes to encrypted 1:1 chat even if references messages in ad-hoc group This is an important thing forgotten to be checked in 332527089. Also there's another test which currently doesn't work as we want: outgoing encrypted messages continue to arrive to ad-hoc group even if we already have contact's key. This should be fixed by sending and receiving Intended Recipient Fingerprint subpackets. The good thing is that apparently there are no scenarios requiring the contact to update their software, the user should just update own devices. --- src/receive_imf/receive_imf_tests.rs | 41 ++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/src/receive_imf/receive_imf_tests.rs b/src/receive_imf/receive_imf_tests.rs index 855600396..9c83ae2ab 100644 --- a/src/receive_imf/receive_imf_tests.rs +++ b/src/receive_imf/receive_imf_tests.rs @@ -5117,6 +5117,7 @@ async fn test_recv_outgoing_msg_before_securejoin() -> Result<()> { tcm.execute_securejoin(bob, a0).await; let chat_id_a0_bob = a0.create_chat_id(bob).await; let sent_msg = a0.send_text(chat_id_a0_bob, "Hi").await; + bob.recv_msg(&sent_msg).await; let msg_a1 = a1.recv_msg(&sent_msg).await; assert!(msg_a1.get_showpadlock()); let chat_a1 = Chat::load_from_db(a1, msg_a1.chat_id).await?; @@ -5132,6 +5133,7 @@ async fn test_recv_outgoing_msg_before_securejoin() -> Result<()> { ); let sent_msg = a0.send_text(chat_id_a0_bob, "Hi again").await; + bob.recv_msg(&sent_msg).await; let msg_a1 = a1.recv_msg(&sent_msg).await; assert!(msg_a1.get_showpadlock()); assert_eq!(msg_a1.chat_id, chat_a1.id); @@ -5140,6 +5142,45 @@ async fn test_recv_outgoing_msg_before_securejoin() -> Result<()> { chat_a1.why_cant_send(a1).await?, Some(CantSendReason::NotAMember) ); + + let msg_a1 = tcm.send_recv(bob, a1, "Hi back").await; + assert!(msg_a1.get_showpadlock()); + let chat_a1 = Chat::load_from_db(a1, msg_a1.chat_id).await?; + assert_eq!(chat_a1.typ, Chattype::Single); + assert!(chat_a1.is_encrypted(a1).await?); + // Weird, but fine, anyway the bigger problem is the conversation split into two chats. + assert_eq!( + chat_a1.why_cant_send(a1).await?, + Some(CantSendReason::ContactRequest) + ); + Ok(()) +} + +#[tokio::test(flavor = "multi_thread", worker_threads = 2)] +async fn test_recv_outgoing_msg_before_having_key_and_after() -> Result<()> { + let mut tcm = TestContextManager::new(); + let a0 = &tcm.alice().await; + let a1 = &tcm.alice().await; + let bob = &tcm.bob().await; + + tcm.execute_securejoin(bob, a0).await; + let chat_id_a0_bob = a0.create_chat_id(bob).await; + let sent_msg = a0.send_text(chat_id_a0_bob, "Hi").await; + let msg_a1 = a1.recv_msg(&sent_msg).await; + assert!(msg_a1.get_showpadlock()); + let chat_a1 = Chat::load_from_db(a1, msg_a1.chat_id).await?; + assert_eq!(chat_a1.typ, Chattype::Group); + assert!(!chat_a1.is_encrypted(a1).await?); + + // Device a1 somehow learns Bob's key and creates the corresponding chat. However, this doesn't + // help currently because we only look up key contacts by address in a particular chat and the + // new chat isn't referenced by the received message. This should be fixed by sending and + // receiving Intended Recipient Fingerprint subpackets. + a1.create_chat_id(bob).await; + let sent_msg = a0.send_text(chat_id_a0_bob, "Hi again").await; + let msg_a1 = a1.recv_msg(&sent_msg).await; + assert!(msg_a1.get_showpadlock()); + assert_eq!(msg_a1.chat_id, chat_a1.id); Ok(()) }