Skip to content

Commit

Permalink
fix: Create a group unblocked for bot even if 1:1 chat is blocked (#5514
Browse files Browse the repository at this point in the history
)
  • Loading branch information
iequidoo committed May 30, 2024
1 parent ef70e49 commit 956d805
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/receive_imf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -826,7 +826,7 @@ async fn add_parts(
// 1:1 chat is blocked, but the contact is not.
// This happens when 1:1 chat is hidden
// during scanning of a group invitation code.
Blocked::Request
create_blocked_default
}
}
}
Expand Down
31 changes: 30 additions & 1 deletion src/securejoin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1186,11 +1186,29 @@ mod tests {
Ok(())
}

#[derive(PartialEq)]
enum SecurejoinCase {
Normal,
BobIsBot,
}

#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn test_secure_join() -> Result<()> {
async fn test_securejoin() -> Result<()> {
test_securejoin_ex(SecurejoinCase::Normal).await
}

#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn test_securejoin_bob_is_bot() -> Result<()> {
test_securejoin_ex(SecurejoinCase::BobIsBot).await
}

async fn test_securejoin_ex(case: SecurejoinCase) -> Result<()> {
let mut tcm = TestContextManager::new();
let alice = tcm.alice().await;
let bob = tcm.bob().await;
if case == SecurejoinCase::BobIsBot {
bob.set_config(Config::Bot, Some("1")).await?;
}

// We start with empty chatlists.
assert_eq!(Chatlist::try_load(&alice, 0, None, None).await?.len(), 0);
Expand Down Expand Up @@ -1343,6 +1361,17 @@ mod tests {
}
}
}
if case == SecurejoinCase::BobIsBot {
let alice_gid =
chat::create_group_chat(&alice, ProtectionStatus::Unprotected, "Group").await?;
chat::add_to_chat_contacts_table(&alice, alice_gid, &[contact_bob_id]).await?;
let sent = alice.send_text(alice_gid, "Hello!").await;
let msg = bob.recv_msg(&sent).await;
let bob_chat = chat::Chat::load_from_db(&bob, msg.chat_id).await?;
assert!(!bob_chat.is_contact_request());
alice_gid.delete(&alice).await?;
bob_chat.id.delete(&bob).await?;
}

let bob_chat = Chat::load_from_db(&bob.ctx, bob_chatid).await?;
assert!(bob_chat.is_protected());
Expand Down

0 comments on commit 956d805

Please sign in to comment.