From 980bab30403b13012ec647b6c07da6ef2127e4da Mon Sep 17 00:00:00 2001 From: iequidoo Date: Thu, 30 May 2024 13:20:30 -0300 Subject: [PATCH] test: Don't leave protected group if some member's key is missing (#5508) The "I left the group" message can't be sent to a protected group if some member's key is missing, in this case we should remain in the group. The problem should be fixed first, then the user may retry to leave the group. --- src/receive_imf/tests.rs | 36 +++++++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/src/receive_imf/tests.rs b/src/receive_imf/tests.rs index 33dcec546..97e1040b9 100644 --- a/src/receive_imf/tests.rs +++ b/src/receive_imf/tests.rs @@ -13,7 +13,7 @@ use crate::constants::{DC_GCL_FOR_FORWARDING, DC_GCL_NO_SPECIALS}; use crate::download::MIN_DOWNLOAD_LIMIT; use crate::imap::prefetch_should_download; use crate::imex::{imex, ImexMode}; -use crate::test_utils::{get_chat_msg, TestContext, TestContextManager}; +use crate::test_utils::{get_chat_msg, mark_as_verified, TestContext, TestContextManager}; use crate::tools::SystemTime; #[tokio::test(flavor = "multi_thread", worker_threads = 2)] @@ -4464,6 +4464,40 @@ Chat-Group-Member-Added: charlie@example.com", Ok(()) } +#[tokio::test(flavor = "multi_thread", worker_threads = 2)] +async fn test_leave_protected_group_missing_member_key() -> Result<()> { + let mut tcm = TestContextManager::new(); + let alice = &tcm.alice().await; + let bob = &tcm.bob().await; + mark_as_verified(alice, bob).await; + let alice_bob_id = alice.add_or_lookup_contact(bob).await.id; + let group_id = create_group_chat(alice, ProtectionStatus::Protected, "Group").await?; + add_contact_to_chat(alice, group_id, alice_bob_id).await?; + alice.send_text(group_id, "Hello!").await; + alice + .sql + .execute( + "UPDATE acpeerstates SET addr=? WHERE addr=?", + ("b@b", "bob@example.net"), + ) + .await?; + assert!(remove_contact_from_chat(alice, group_id, ContactId::SELF) + .await + .is_err()); + assert!(is_contact_in_chat(alice, group_id, ContactId::SELF).await?); + alice + .sql + .execute( + "UPDATE acpeerstates SET addr=? WHERE addr=?", + ("bob@example.net", "b@b"), + ) + .await?; + remove_contact_from_chat(alice, group_id, ContactId::SELF).await?; + alice.pop_sent_msg().await; + assert!(!is_contact_in_chat(alice, group_id, ContactId::SELF).await?); + Ok(()) +} + #[tokio::test(flavor = "multi_thread", worker_threads = 2)] async fn test_forged_from() -> Result<()> { let mut tcm = TestContextManager::new();