Skip to content

Commit 1830f74

Browse files
committed
test: add test_no_email_contacts_in_group_chats
1 parent 689433d commit 1830f74

File tree

1 file changed

+36
-3
lines changed

1 file changed

+36
-3
lines changed

src/chat/chat_tests.rs

+36-3
Original file line numberDiff line numberDiff line change
@@ -3039,11 +3039,17 @@ async fn test_sync_block_before_first_msg() -> Result<()> {
30393039
let rcvd_msg = alice0.recv_msg(&sent_msg).await;
30403040
let a0b_chat_id = rcvd_msg.chat_id;
30413041
let a0b_contact_id = rcvd_msg.from_id;
3042-
assert_eq!(Chat::load_from_db(alice0, a0b_chat_id).await?.blocked, Blocked::Request);
3042+
assert_eq!(
3043+
Chat::load_from_db(alice0, a0b_chat_id).await?.blocked,
3044+
Blocked::Request
3045+
);
30433046
a0b_chat_id.block(alice0).await?;
30443047
let a0b_contact = Contact::get_by_id(alice0, a0b_contact_id).await?;
30453048
assert_eq!(a0b_contact.origin, Origin::IncomingUnknownFrom);
3046-
assert_eq!(Chat::load_from_db(alice0, a0b_chat_id).await?.blocked, Blocked::Yes);
3049+
assert_eq!(
3050+
Chat::load_from_db(alice0, a0b_chat_id).await?.blocked,
3051+
Blocked::Yes
3052+
);
30473053

30483054
sync(alice0, alice1).await;
30493055
let alice1_contacts = Contact::get_all(alice1, 0, None).await?;
@@ -3053,7 +3059,12 @@ async fn test_sync_block_before_first_msg() -> Result<()> {
30533059
let a1b_contact_id = rcvd_msg.from_id;
30543060
let a1b_contact = Contact::get_by_id(alice1, a1b_contact_id).await?;
30553061
assert_eq!(a1b_contact.origin, Origin::IncomingUnknownFrom);
3056-
let ChatIdBlocked {id: a1b_chat_id, blocked: a1b_chat_blocked} = ChatIdBlocked::lookup_by_contact(alice1, a1b_contact_id).await?.unwrap();
3062+
let ChatIdBlocked {
3063+
id: a1b_chat_id,
3064+
blocked: a1b_chat_blocked,
3065+
} = ChatIdBlocked::lookup_by_contact(alice1, a1b_contact_id)
3066+
.await?
3067+
.unwrap();
30573068
assert_eq!(a1b_chat_blocked, Blocked::Yes);
30583069
assert_eq!(rcvd_msg.chat_id, a1b_chat_id);
30593070
Ok(())
@@ -4098,3 +4109,25 @@ async fn test_oneone_gossip() -> Result<()> {
40984109

40994110
Ok(())
41004111
}
4112+
4113+
/// Tests that email contacts cannot be added to encrypted group chats.
4114+
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
4115+
async fn test_no_email_contacts_in_group_chats() -> Result<()> {
4116+
let mut tcm = TestContextManager::new();
4117+
let alice = &tcm.alice().await;
4118+
let bob = &tcm.bob().await;
4119+
let charlie = &tcm.charlie().await;
4120+
4121+
let chat_id = create_group_chat(alice, ProtectionStatus::Unprotected, "Group chat").await?;
4122+
let pgp_bob_contact_id = alice.add_or_lookup_contact_id(bob).await;
4123+
let email_charlie_contact_id = alice.add_or_lookup_email_contact_id(charlie).await;
4124+
4125+
// PGP-contact should be added successfully.
4126+
add_contact_to_chat(alice, chat_id, pgp_bob_contact_id).await?;
4127+
4128+
// Adding email-contact should fail.
4129+
let res = add_contact_to_chat(alice, chat_id, email_charlie_contact_id).await;
4130+
assert!(res.is_err());
4131+
4132+
Ok(())
4133+
}

0 commit comments

Comments
 (0)