Skip to content

Commit c4fa348

Browse files
committed
test: test recovery from lost vc-contact-confirm
1 parent f742242 commit c4fa348

File tree

1 file changed

+66
-0
lines changed

1 file changed

+66
-0
lines changed

src/securejoin.rs

+66
Original file line numberDiff line numberDiff line change
@@ -1310,4 +1310,70 @@ First thread."#;
13101310

13111311
Ok(())
13121312
}
1313+
1314+
/// Tests that Bob gets Alice as verified
1315+
/// if `vc-contact-confirm` is lost but Alice then sends
1316+
/// a message to Bob in a verified 1:1 chat with a `Chat-Verified` header.
1317+
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
1318+
async fn test_lost_contact_confirm() {
1319+
let mut tcm = TestContextManager::new();
1320+
let alice = tcm.alice().await;
1321+
let bob = tcm.bob().await;
1322+
alice
1323+
.set_config(Config::VerifiedOneOnOneChats, Some("1"))
1324+
.await
1325+
.unwrap();
1326+
bob.set_config(Config::VerifiedOneOnOneChats, Some("1"))
1327+
.await
1328+
.unwrap();
1329+
1330+
let qr = get_securejoin_qr(&alice.ctx, None).await.unwrap();
1331+
join_securejoin(&bob.ctx, &qr).await.unwrap();
1332+
1333+
// vc-request
1334+
let sent = bob.pop_sent_msg().await;
1335+
alice.recv_msg(&sent).await;
1336+
1337+
// vc-auth-required
1338+
let sent = alice.pop_sent_msg().await;
1339+
bob.recv_msg(&sent).await;
1340+
1341+
// vc-request-with-auth
1342+
let sent = bob.pop_sent_msg().await;
1343+
alice.recv_msg(&sent).await;
1344+
1345+
// Alice has Bob verified now.
1346+
let contact_bob_id =
1347+
Contact::lookup_id_by_addr(&alice.ctx, "[email protected]", Origin::Unknown)
1348+
.await
1349+
.expect("Error looking up contact")
1350+
.expect("Contact not found");
1351+
let contact_bob = Contact::get_by_id(&alice.ctx, contact_bob_id)
1352+
.await
1353+
.unwrap();
1354+
assert_eq!(contact_bob.is_verified(&alice.ctx).await.unwrap(), true);
1355+
1356+
// Alice sends vc-contact-confirm, but it gets lost.
1357+
let _sent_vc_contact_confirm = alice.pop_sent_msg().await;
1358+
1359+
// Bob should not yet have Alice verified
1360+
let contact_alice_id =
1361+
Contact::lookup_id_by_addr(&bob, "[email protected]", Origin::Unknown)
1362+
.await
1363+
.expect("Error looking up contact")
1364+
.expect("Contact not found");
1365+
let contact_alice = Contact::get_by_id(&bob, contact_alice_id).await.unwrap();
1366+
assert_eq!(contact_alice.is_verified(&bob).await.unwrap(), false);
1367+
1368+
// Alice sends a text message to Bob.
1369+
let received_hello = tcm.send_recv(&alice, &bob, "Hello!").await;
1370+
let chat_id = received_hello.chat_id;
1371+
let chat = Chat::load_from_db(&bob, chat_id).await.unwrap();
1372+
assert_eq!(chat.is_protected(), true);
1373+
1374+
// Received text message in a verified 1:1 chat results in backward verification
1375+
// and Bob now marks alice as verified.
1376+
let contact_alice = Contact::get_by_id(&bob, contact_alice_id).await.unwrap();
1377+
assert_eq!(contact_alice.is_verified(&bob).await.unwrap(), true);
1378+
}
13131379
}

0 commit comments

Comments
 (0)