From 269bd5b1561793b14d7545457fb4a18a3d547971 Mon Sep 17 00:00:00 2001 From: iequidoo Date: Mon, 1 Sep 2025 08:48:50 -0300 Subject: [PATCH] test: Contact shalln't be verified by another having unknown verifier It must be verified by "unknown verifier" instead. But if the verifier has known verifier in turn, it must reverify contacts having unknown verifier. Add a check for this also. --- src/receive_imf/receive_imf_tests.rs | 38 ++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/src/receive_imf/receive_imf_tests.rs b/src/receive_imf/receive_imf_tests.rs index 861bb984f3..82ba90f462 100644 --- a/src/receive_imf/receive_imf_tests.rs +++ b/src/receive_imf/receive_imf_tests.rs @@ -5180,6 +5180,44 @@ async fn test_dont_reverify_by_self_on_outgoing_msg() -> Result<()> { Ok(()) } +#[tokio::test(flavor = "multi_thread", worker_threads = 2)] +async fn test_dont_verify_by_verified_by_unknown() -> Result<()> { + let mut tcm = TestContextManager::new(); + let a0 = &tcm.alice().await; + let a1 = &tcm.alice().await; + let bob = &tcm.bob().await; + let fiona = &tcm.fiona().await; + + let bob_chat_id = chat::create_group_chat(bob, ProtectionStatus::Protected, "Group").await?; + let qr = get_securejoin_qr(bob, Some(bob_chat_id)).await?; + tcm.exec_securejoin_qr(a0, bob, &qr).await; + tcm.exec_securejoin_qr(fiona, bob, &qr).await; + // Bob verifies Fiona for Alice#0. + a0.recv_msg(&bob.send_text(bob_chat_id, "Hi").await).await; + + let chat_id = a0 + .create_group_with_members(ProtectionStatus::Protected, "", &[fiona]) + .await; + a1.recv_msg(&a0.send_text(chat_id, "Hi").await).await; + let a1_fiona = a1.add_or_lookup_contact(fiona).await; + assert_eq!(a1_fiona.get_verifier_id(a1).await?, Some(None)); + + let fiona_chat_id = fiona.get_last_msg().await.chat_id; + a1.recv_msg(&fiona.send_text(fiona_chat_id, "Hi").await) + .await; + let a1_bob = a1.add_or_lookup_contact(bob).await; + // There was a bug that Bob is verified by Fiona on Alice's other device. + assert_eq!(a1_bob.get_verifier_id(a1).await?, Some(None)); + + tcm.execute_securejoin(a1, fiona).await; + a1.recv_msg(&fiona.send_text(fiona_chat_id, "Hi").await) + .await; + // But now Bob's verifier id must be updated because Fiona is verified by a known verifier + // (moreover, directly), so Alice has reverse verification chains on her devices. + assert_eq!(a1_bob.get_verifier_id(a1).await?, Some(Some(a1_fiona.id))); + Ok(()) +} + #[tokio::test(flavor = "multi_thread", worker_threads = 2)] async fn test_sanitize_filename_in_received() -> Result<()> { let alice = &TestContext::new_alice().await;