Skip to content

Commit b2f4756

Browse files
committed
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 3325270. 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.
1 parent 448c0d2 commit b2f4756

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

src/receive_imf/receive_imf_tests.rs

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5117,6 +5117,7 @@ async fn test_recv_outgoing_msg_before_securejoin() -> Result<()> {
51175117
tcm.execute_securejoin(bob, a0).await;
51185118
let chat_id_a0_bob = a0.create_chat_id(bob).await;
51195119
let sent_msg = a0.send_text(chat_id_a0_bob, "Hi").await;
5120+
bob.recv_msg(&sent_msg).await;
51205121
let msg_a1 = a1.recv_msg(&sent_msg).await;
51215122
assert!(msg_a1.get_showpadlock());
51225123
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<()> {
51325133
);
51335134

51345135
let sent_msg = a0.send_text(chat_id_a0_bob, "Hi again").await;
5136+
bob.recv_msg(&sent_msg).await;
51355137
let msg_a1 = a1.recv_msg(&sent_msg).await;
51365138
assert!(msg_a1.get_showpadlock());
51375139
assert_eq!(msg_a1.chat_id, chat_a1.id);
@@ -5140,6 +5142,45 @@ async fn test_recv_outgoing_msg_before_securejoin() -> Result<()> {
51405142
chat_a1.why_cant_send(a1).await?,
51415143
Some(CantSendReason::NotAMember)
51425144
);
5145+
5146+
let msg_a1 = tcm.send_recv(bob, a1, "Hi back").await;
5147+
assert!(msg_a1.get_showpadlock());
5148+
let chat_a1 = Chat::load_from_db(a1, msg_a1.chat_id).await?;
5149+
assert_eq!(chat_a1.typ, Chattype::Single);
5150+
assert!(chat_a1.is_encrypted(a1).await?);
5151+
// Weird, but fine, anyway the bigger problem is the conversation split into two chats.
5152+
assert_eq!(
5153+
chat_a1.why_cant_send(a1).await?,
5154+
Some(CantSendReason::ContactRequest)
5155+
);
5156+
Ok(())
5157+
}
5158+
5159+
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
5160+
async fn test_recv_outgoing_msg_before_having_key_and_after() -> Result<()> {
5161+
let mut tcm = TestContextManager::new();
5162+
let a0 = &tcm.alice().await;
5163+
let a1 = &tcm.alice().await;
5164+
let bob = &tcm.bob().await;
5165+
5166+
tcm.execute_securejoin(bob, a0).await;
5167+
let chat_id_a0_bob = a0.create_chat_id(bob).await;
5168+
let sent_msg = a0.send_text(chat_id_a0_bob, "Hi").await;
5169+
let msg_a1 = a1.recv_msg(&sent_msg).await;
5170+
assert!(msg_a1.get_showpadlock());
5171+
let chat_a1 = Chat::load_from_db(a1, msg_a1.chat_id).await?;
5172+
assert_eq!(chat_a1.typ, Chattype::Group);
5173+
assert!(!chat_a1.is_encrypted(a1).await?);
5174+
5175+
// Device a1 somehow learns Bob's key and creates the corresponding chat. However, this doesn't
5176+
// help currently because we only look up key contacts by address in a particular chat and the
5177+
// new chat isn't referenced by the received message. This should be fixed by sending and
5178+
// receiving Intended Recipient Fingerprint subpackets.
5179+
a1.create_chat_id(bob).await;
5180+
let sent_msg = a0.send_text(chat_id_a0_bob, "Hi again").await;
5181+
let msg_a1 = a1.recv_msg(&sent_msg).await;
5182+
assert!(msg_a1.get_showpadlock());
5183+
assert_eq!(msg_a1.chat_id, chat_a1.id);
51435184
Ok(())
51445185
}
51455186

0 commit comments

Comments
 (0)