test: test_remove_member_bcc: Test unencrypted group as it was initially

This commit is contained in:
iequidoo
2025-11-29 15:53:37 -03:00
committed by iequidoo
parent dc5f939ac6
commit ef61c0c408
2 changed files with 27 additions and 14 deletions

View File

@@ -3730,10 +3730,16 @@ pub(crate) async fn add_contact_to_chat_ex(
chat.typ != Chattype::OutBroadcast || contact_id != ContactId::SELF, chat.typ != Chattype::OutBroadcast || contact_id != ContactId::SELF,
"Cannot add SELF to broadcast channel." "Cannot add SELF to broadcast channel."
); );
ensure!( match chat.is_encrypted(context).await? {
chat.is_encrypted(context).await? == contact.is_key_contact(), true => ensure!(
"Only key-contacts can be added to encrypted chats" contact.is_key_contact(),
); "Only key-contacts can be added to encrypted chats"
),
false => ensure!(
!contact.is_key_contact(),
"Only address-contacts can be added to unencrypted chats"
),
}
if !chat.is_self_in_chat(context).await? { if !chat.is_self_in_chat(context).await? {
context.emit_event(EventType::ErrorSelfNotInGroup( context.emit_event(EventType::ErrorSelfNotInGroup(

View File

@@ -6,7 +6,8 @@ use std::time::Duration;
use super::*; use super::*;
use crate::chat::{ use crate::chat::{
self, ChatId, add_contact_to_chat, create_group, remove_contact_from_chat, send_text_msg, self, ChatId, add_contact_to_chat, create_group, create_group_unencrypted,
remove_contact_from_chat, send_text_msg,
}; };
use crate::chatlist::Chatlist; use crate::chatlist::Chatlist;
use crate::constants; use crate::constants;
@@ -351,7 +352,7 @@ async fn test_subject_in_group() -> Result<()> {
let mut tcm = TestContextManager::new(); let mut tcm = TestContextManager::new();
let t = tcm.alice().await; let t = tcm.alice().await;
let bob = tcm.bob().await; let bob = tcm.bob().await;
let group_id = chat::create_group(&t, "groupname").await.unwrap(); let group_id = create_group(&t, "groupname").await.unwrap();
let bob_contact_id = t.add_or_lookup_contact_id(&bob).await; let bob_contact_id = t.add_or_lookup_contact_id(&bob).await;
chat::add_contact_to_chat(&t, group_id, bob_contact_id).await?; chat::add_contact_to_chat(&t, group_id, bob_contact_id).await?;
@@ -671,15 +672,20 @@ async fn test_selfavatar_unencrypted_signed() {
async fn test_remove_member_bcc() -> Result<()> { async fn test_remove_member_bcc() -> Result<()> {
let mut tcm = TestContextManager::new(); let mut tcm = TestContextManager::new();
// Alice creates a group with Bob and Claire and then removes Bob. // Alice creates a group with Bob and Charlie and then removes Charlie.
let alice = &tcm.alice().await; let alice = &tcm.alice().await;
let bob = &tcm.bob().await; let bob = &tcm.bob().await;
let charlie = &tcm.charlie().await; let charlie = &tcm.charlie().await;
let bob_id = alice.add_or_lookup_contact_id(bob).await; let alice_addr = alice.get_config(Config::Addr).await?.unwrap();
let charlie_id = alice.add_or_lookup_contact_id(charlie).await; let bob_addr = bob.get_config(Config::Addr).await?.unwrap();
let charlie_addr = charlie.get_config(Config::Addr).await?.unwrap();
let alice_chat_id = create_group(alice, "foo").await?; let bob_id = alice.add_or_lookup_address_contact_id(bob).await;
let charlie_id = alice.add_or_lookup_address_contact_id(charlie).await;
let alice_chat_id = create_group_unencrypted(alice, "foo").await?;
add_contact_to_chat(alice, alice_chat_id, bob_id).await?; add_contact_to_chat(alice, alice_chat_id, bob_id).await?;
add_contact_to_chat(alice, alice_chat_id, charlie_id).await?; add_contact_to_chat(alice, alice_chat_id, charlie_id).await?;
send_text_msg(alice, alice_chat_id, "Creating a group".to_string()).await?; send_text_msg(alice, alice_chat_id, "Creating a group".to_string()).await?;
@@ -696,11 +702,12 @@ async fn test_remove_member_bcc() -> Result<()> {
for to_addr in to.iter() { for to_addr in to.iter() {
match to_addr { match to_addr {
mailparse::MailAddr::Single(info) => { mailparse::MailAddr::Single(info) => {
panic!("Single addresses are not expected here: {info:?}"); // Addresses should be of existing members and not Charlie.
assert_ne!(info.addr, charlie_addr);
assert!(info.addr == alice_addr || info.addr == bob_addr);
} }
mailparse::MailAddr::Group(info) => { mailparse::MailAddr::Group(_) => {
assert_eq!(info.group_name, "hidden-recipients"); panic!("Group addresses are not expected here");
assert_eq!(info.addrs, []);
} }
} }
} }