Skip to content

Commit

Permalink
test: test that reordering of Member added message results in square …
Browse files Browse the repository at this point in the history
…bracket error

This is a test reproducing the problem
in <#5339>.
Fix would be to avoid reordering on the server side,
so the test checks that the unverified message
is replaced with a square bracket error
as expected if messages arrive in the wrong order.
  • Loading branch information
link2xt committed Mar 17, 2024
1 parent b95d582 commit d86ebc3
Showing 1 changed file with 44 additions and 1 deletion.
45 changes: 44 additions & 1 deletion src/tests/verified_chats.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use anyhow::Result;
use pretty_assertions::assert_eq;

use crate::chat::{self, Chat, ProtectionStatus};
use crate::chat::{self, add_contact_to_chat, Chat, ProtectionStatus};
use crate::chatlist::Chatlist;
use crate::config::Config;
use crate::constants::{Chattype, DC_GCL_FOR_FORWARDING};
Expand Down Expand Up @@ -815,6 +815,49 @@ async fn test_create_protected_grp_multidev() -> Result<()> {
Ok(())
}

#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn test_verified_member_added_reordering() -> Result<()> {
let mut tcm = TestContextManager::new();
let alice = &tcm.alice().await;
let bob = &tcm.bob().await;
let fiona = &tcm.fiona().await;
enable_verified_oneonone_chats(&[alice, bob, fiona]).await;

let alice_fiona_contact_id = Contact::create(&alice, "Fiona", "fiona@example.net").await?;

// Bob and Fiona scan Alice's QR code.
tcm.execute_securejoin(bob, alice).await;
tcm.execute_securejoin(fiona, alice).await;

// Alice creates protected group with Bob.
let alice_chat_id = alice
.create_group_with_members(ProtectionStatus::Protected, "Group", &[bob])
.await;
let alice_sent_group_promotion = alice.send_text(alice_chat_id, "I created a group").await;
let msg = bob.recv_msg(&alice_sent_group_promotion).await;
let bob_chat_id = msg.chat_id;

// Alice adds Fiona.
add_contact_to_chat(&alice, alice_chat_id, alice_fiona_contact_id).await?;
let alice_sent_member_added = alice.pop_sent_msg().await;

// Bob receives "Alice added Fiona" message.
bob.recv_msg(&alice_sent_member_added).await;

// Bob sends a message to the group.
let bob_sent_message = bob.send_text(bob_chat_id, "Hi").await;

// Fiona receives message from Bob before receiving
// "Member added" message.
let fiona_received_message = fiona.recv_msg(&bob_sent_message).await;
assert_eq!(
fiona_received_message.get_text(),
"[The message was sent with non-verified encryption. See 'Info' for more details]"
);

Ok(())
}

// ============== Helper Functions ==============

async fn assert_verified(this: &TestContext, other: &TestContext, protected: ProtectionStatus) {
Expand Down

0 comments on commit d86ebc3

Please sign in to comment.