Skip to content

Commit e97fe7a

Browse files
committed
test: test_remove_member_bcc: Test unencrypted group as it was initially
1 parent 2c00927 commit e97fe7a

File tree

2 files changed

+25
-15
lines changed

2 files changed

+25
-15
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: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,7 @@ use std::str;
55
use std::time::Duration;
66

77
use super::*;
8-
use crate::chat::{
9-
self, ChatId, add_contact_to_chat, create_group, remove_contact_from_chat, send_text_msg,
10-
};
8+
use crate::chat::{self, ChatId, add_contact_to_chat, remove_contact_from_chat, send_text_msg};
119
use crate::chatlist::Chatlist;
1210
use crate::constants;
1311
use crate::contact::Origin;
@@ -671,15 +669,20 @@ async fn test_selfavatar_unencrypted_signed() {
671669
async fn test_remove_member_bcc() -> Result<()> {
672670
let mut tcm = TestContextManager::new();
673671

674-
// Alice creates a group with Bob and Claire and then removes Bob.
672+
// Alice creates a group with Bob and Charlie and then removes Charlie.
673+
675674
let alice = &tcm.alice().await;
676675
let bob = &tcm.bob().await;
677676
let charlie = &tcm.charlie().await;
678677

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

682-
let alice_chat_id = create_group(alice, "foo").await?;
685+
let alice_chat_id = chat::create_group_unencrypted(alice, "foo").await?;
683686
add_contact_to_chat(alice, alice_chat_id, bob_id).await?;
684687
add_contact_to_chat(alice, alice_chat_id, charlie_id).await?;
685688
send_text_msg(alice, alice_chat_id, "Creating a group".to_string()).await?;
@@ -696,11 +699,12 @@ async fn test_remove_member_bcc() -> Result<()> {
696699
for to_addr in to.iter() {
697700
match to_addr {
698701
mailparse::MailAddr::Single(info) => {
699-
panic!("Single addresses are not expected here: {info:?}");
702+
// Addresses should be of existing members and not Charlie.
703+
assert_ne!(info.addr, charlie_addr);
704+
assert!(info.addr == alice_addr || info.addr == bob_addr);
700705
}
701-
mailparse::MailAddr::Group(info) => {
702-
assert_eq!(info.group_name, "hidden-recipients");
703-
assert_eq!(info.addrs, []);
706+
mailparse::MailAddr::Group(_) => {
707+
panic!("Group addresses are not expected here");
704708
}
705709
}
706710
}

0 commit comments

Comments
 (0)