Skip to content

Commit 72614b0

Browse files
committed
test: add failing test where email contacts are added to PGP-chat
1 parent c2a2035 commit 72614b0

File tree

2 files changed

+66
-0
lines changed

2 files changed

+66
-0
lines changed

src/receive_imf.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2089,6 +2089,11 @@ async fn lookup_chat_by_reply(
20892089
}
20902090
}
20912091

2092+
// Do not assign unencrypted messages to encrypted chats.
2093+
if parent_chat.is_encrypted(context).await? && !mime_parser.was_encrypted() {
2094+
return Ok(None);
2095+
}
2096+
20922097
info!(
20932098
context,
20942099
"Assigning message to {} as it's a reply to {}.", parent_chat.id, parent.rfc724_mid

src/receive_imf/receive_imf_tests.rs

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5087,3 +5087,64 @@ PGh0bWw+PGJvZHk+dGV4dDwvYm9keT5kYXRh
50875087

50885088
Ok(())
50895089
}
5090+
5091+
/// Tests that email contacts are not added into a group
5092+
/// with PGP-contacts by a plaintext reply.
5093+
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
5094+
async fn test_no_email_contact_added_into_group() -> Result<()> {
5095+
let mut tcm = TestContextManager::new();
5096+
let alice = &tcm.alice().await;
5097+
let bob = &tcm.bob().await;
5098+
5099+
let alice_chat_id = alice
5100+
.create_group_with_members(ProtectionStatus::Unprotected, "Group", &[bob])
5101+
.await;
5102+
let bob_received_msg = bob
5103+
.recv_msg(&alice.send_text(alice_chat_id, "Message").await)
5104+
.await;
5105+
let rfc724_mid = bob_received_msg.rfc724_mid;
5106+
5107+
// Alice leaves the group so message from email address contact bob@example.com
5108+
// does not fail the test for being non-member and is allowed to
5109+
// modify the chat.
5110+
remove_contact_from_chat(alice, alice_chat_id, ContactId::SELF).await?;
5111+
5112+
// Wait 60 days so chatlist is stale.
5113+
SystemTime::shift(Duration::from_secs(60 * 24 * 60 * 60 + 1));
5114+
5115+
// Only Bob is the chat member.
5116+
assert_eq!(
5117+
chat::get_chat_contacts(alice, alice_chat_id).await?.len(),
5118+
1
5119+
);
5120+
5121+
let msg = receive_imf(
5122+
alice,
5123+
format!(
5124+
"From: bob@example.com\n\
5125+
To: alice@example.net, charlie@example.net, fiona@example.net\n\
5126+
Subject: foo\n\
5127+
Message-ID: <something@example.com>\n\
5128+
Chat-Version: 1.0\n\
5129+
In-Reply-To: {rfc724_mid}\n\
5130+
Date: Sun, 22 Mar 2020 22:37:57 +0000\n\
5131+
\n\
5132+
Hello\n"
5133+
)
5134+
.as_bytes(),
5135+
false,
5136+
)
5137+
.await?
5138+
.unwrap();
5139+
5140+
// Unencrypted message should not modify the chat member list.
5141+
assert_eq!(
5142+
chat::get_chat_contacts(alice, alice_chat_id).await?.len(),
5143+
1
5144+
);
5145+
5146+
// Unencrypted message should not even be assigned to encrypted chat.
5147+
assert_eq!(msg.chat_id, alice_chat_id);
5148+
5149+
Ok(())
5150+
}

0 commit comments

Comments
 (0)