Skip to content

Commit ef61c0c

Browse files
committed
test: test_remove_member_bcc: Test unencrypted group as it was initially
1 parent dc5f939 commit ef61c0c

File tree

2 files changed

+27
-14
lines changed

2 files changed

+27
-14
lines changed

src/chat.rs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3730,10 +3730,16 @@ pub(crate) async fn add_contact_to_chat_ex(
37303730
chat.typ != Chattype::OutBroadcast || contact_id != ContactId::SELF,
37313731
"Cannot add SELF to broadcast channel."
37323732
);
3733-
ensure!(
3734-
chat.is_encrypted(context).await? == contact.is_key_contact(),
3735-
"Only key-contacts can be added to encrypted chats"
3736-
);
3733+
match chat.is_encrypted(context).await? {
3734+
true => ensure!(
3735+
contact.is_key_contact(),
3736+
"Only key-contacts can be added to encrypted chats"
3737+
),
3738+
false => ensure!(
3739+
!contact.is_key_contact(),
3740+
"Only address-contacts can be added to unencrypted chats"
3741+
),
3742+
}
37373743

37383744
if !chat.is_self_in_chat(context).await? {
37393745
context.emit_event(EventType::ErrorSelfNotInGroup(

src/mimefactory/mimefactory_tests.rs

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ use std::time::Duration;
66

77
use super::*;
88
use crate::chat::{
9-
self, ChatId, add_contact_to_chat, create_group, remove_contact_from_chat, send_text_msg,
9+
self, ChatId, add_contact_to_chat, create_group, create_group_unencrypted,
10+
remove_contact_from_chat, send_text_msg,
1011
};
1112
use crate::chatlist::Chatlist;
1213
use crate::constants;
@@ -351,7 +352,7 @@ async fn test_subject_in_group() -> Result<()> {
351352
let mut tcm = TestContextManager::new();
352353
let t = tcm.alice().await;
353354
let bob = tcm.bob().await;
354-
let group_id = chat::create_group(&t, "groupname").await.unwrap();
355+
let group_id = create_group(&t, "groupname").await.unwrap();
355356
let bob_contact_id = t.add_or_lookup_contact_id(&bob).await;
356357
chat::add_contact_to_chat(&t, group_id, bob_contact_id).await?;
357358

@@ -671,15 +672,20 @@ async fn test_selfavatar_unencrypted_signed() {
671672
async fn test_remove_member_bcc() -> Result<()> {
672673
let mut tcm = TestContextManager::new();
673674

674-
// Alice creates a group with Bob and Claire and then removes Bob.
675+
// Alice creates a group with Bob and Charlie and then removes Charlie.
676+
675677
let alice = &tcm.alice().await;
676678
let bob = &tcm.bob().await;
677679
let charlie = &tcm.charlie().await;
678680

679-
let bob_id = alice.add_or_lookup_contact_id(bob).await;
680-
let charlie_id = alice.add_or_lookup_contact_id(charlie).await;
681+
let alice_addr = alice.get_config(Config::Addr).await?.unwrap();
682+
let bob_addr = bob.get_config(Config::Addr).await?.unwrap();
683+
let charlie_addr = charlie.get_config(Config::Addr).await?.unwrap();
684+
685+
let bob_id = alice.add_or_lookup_address_contact_id(bob).await;
686+
let charlie_id = alice.add_or_lookup_address_contact_id(charlie).await;
681687

682-
let alice_chat_id = create_group(alice, "foo").await?;
688+
let alice_chat_id = create_group_unencrypted(alice, "foo").await?;
683689
add_contact_to_chat(alice, alice_chat_id, bob_id).await?;
684690
add_contact_to_chat(alice, alice_chat_id, charlie_id).await?;
685691
send_text_msg(alice, alice_chat_id, "Creating a group".to_string()).await?;
@@ -696,11 +702,12 @@ async fn test_remove_member_bcc() -> Result<()> {
696702
for to_addr in to.iter() {
697703
match to_addr {
698704
mailparse::MailAddr::Single(info) => {
699-
panic!("Single addresses are not expected here: {info:?}");
705+
// Addresses should be of existing members and not Charlie.
706+
assert_ne!(info.addr, charlie_addr);
707+
assert!(info.addr == alice_addr || info.addr == bob_addr);
700708
}
701-
mailparse::MailAddr::Group(info) => {
702-
assert_eq!(info.group_name, "hidden-recipients");
703-
assert_eq!(info.addrs, []);
709+
mailparse::MailAddr::Group(_) => {
710+
panic!("Group addresses are not expected here");
704711
}
705712
}
706713
}

0 commit comments

Comments
 (0)