|
1 | 1 | use anyhow::Result;
|
2 | 2 |
|
3 |
| -use crate::chat; |
4 |
| -use crate::chat::ChatId; |
| 3 | +use crate::chat::{self, Chat, ChatId, ProtectionStatus}; |
5 | 4 | use crate::contact;
|
6 | 5 | use crate::contact::Contact;
|
7 | 6 | use crate::contact::ContactId;
|
8 | 7 | use crate::message::Message;
|
9 | 8 | use crate::peerstate::Peerstate;
|
10 | 9 | use crate::receive_imf::receive_imf;
|
| 10 | +use crate::securejoin::get_securejoin_qr; |
11 | 11 | use crate::stock_str;
|
12 | 12 | use crate::test_utils::mark_as_verified;
|
13 | 13 | use crate::test_utils::TestContext;
|
@@ -394,3 +394,40 @@ async fn test_aeap_replay_attack() -> Result<()> {
|
394 | 394 |
|
395 | 395 | Ok(())
|
396 | 396 | }
|
| 397 | + |
| 398 | +#[tokio::test(flavor = "multi_thread", worker_threads = 2)] |
| 399 | +async fn test_write_to_alice_after_aeap() -> Result<()> { |
| 400 | + let mut tcm = TestContextManager::new(); |
| 401 | + let alice = &tcm.alice().await; |
| 402 | + let bob = &tcm.bob().await; |
| 403 | + let alice_grp_id = chat::create_group_chat(alice, ProtectionStatus::Protected, "Group").await?; |
| 404 | + let qr = get_securejoin_qr(alice, Some(alice_grp_id)).await?; |
| 405 | + tcm.exec_securejoin_qr(bob, alice, &qr).await; |
| 406 | + let bob_alice_contact = bob.add_or_lookup_contact(alice).await; |
| 407 | + assert!(bob_alice_contact.is_verified(bob).await?); |
| 408 | + let bob_alice_chat = bob.create_chat(alice).await; |
| 409 | + assert!(bob_alice_chat.is_protected()); |
| 410 | + let bob_unprotected_grp_id = bob |
| 411 | + .create_group_with_members(ProtectionStatus::Unprotected, "Group", &[alice]) |
| 412 | + .await; |
| 413 | + |
| 414 | + tcm.change_addr(alice, "alice@someotherdomain.xyz").await; |
| 415 | + let sent = alice.send_text(alice_grp_id, "Hello!").await; |
| 416 | + bob.recv_msg(&sent).await; |
| 417 | + |
| 418 | + assert!(!bob_alice_contact.is_verified(bob).await?); |
| 419 | + let bob_alice_chat = Chat::load_from_db(bob, bob_alice_chat.id).await?; |
| 420 | + assert!(bob_alice_chat.is_protected()); |
| 421 | + let mut msg = Message::new_text("hi".to_string()); |
| 422 | + assert!(chat::send_msg(bob, bob_alice_chat.id, &mut msg) |
| 423 | + .await |
| 424 | + .is_err()); |
| 425 | + |
| 426 | + // But encrypted communication is still possible in unprotected groups with old Alice. |
| 427 | + let sent = bob |
| 428 | + .send_text(bob_unprotected_grp_id, "Alice, how is your address change?") |
| 429 | + .await; |
| 430 | + let msg = Message::load_from_db(bob, sent.sender_msg_id).await?; |
| 431 | + assert!(msg.get_showpadlock()); |
| 432 | + Ok(()) |
| 433 | +} |
0 commit comments