|
| 1 | +use std::time::Duration; |
| 2 | + |
1 | 3 | use deltachat_contact_tools::EmailAddress;
|
2 | 4 |
|
3 | 5 | use super::*;
|
4 | 6 | use crate::chat::{CantSendReason, remove_contact_from_chat};
|
5 | 7 | use crate::chatlist::Chatlist;
|
6 | 8 | use crate::constants::Chattype;
|
7 | 9 | use crate::key::self_fingerprint;
|
8 |
| -use crate::mimeparser::GossipedKey; |
| 10 | +use crate::mimeparser::{GossipedKey, SystemMessage}; |
9 | 11 | use crate::receive_imf::receive_imf;
|
10 | 12 | use crate::stock_str::{self, messages_e2e_encrypted};
|
11 | 13 | use crate::test_utils::{
|
12 | 14 | TestContext, TestContextManager, TimeShiftFalsePositiveNote, get_chat_msg,
|
13 | 15 | };
|
| 16 | +use crate::tools::SystemTime; |
14 | 17 |
|
15 | 18 | #[derive(PartialEq)]
|
16 | 19 | enum SetupContactCase {
|
@@ -800,3 +803,80 @@ async fn test_wrong_auth_token() -> Result<()> {
|
800 | 803 |
|
801 | 804 | Ok(())
|
802 | 805 | }
|
| 806 | + |
| 807 | +/// Tests that scanning a QR code week later |
| 808 | +/// allows Bob to establish a contact with Alice, |
| 809 | +/// but does not mark Bob as verified for Alice. |
| 810 | +#[tokio::test(flavor = "multi_thread", worker_threads = 2)] |
| 811 | +async fn test_expired_contact_auth_token() -> Result<()> { |
| 812 | + let mut tcm = TestContextManager::new(); |
| 813 | + let alice = &tcm.alice().await; |
| 814 | + let bob = &tcm.bob().await; |
| 815 | + |
| 816 | + // Alice creates a QR code. |
| 817 | + let qr = get_securejoin_qr(alice, None).await?; |
| 818 | + |
| 819 | + // One week passes, QR code expires. |
| 820 | + SystemTime::shift(Duration::from_secs(7 * 24 * 3600)); |
| 821 | + |
| 822 | + // Bob scans the QR code. |
| 823 | + join_securejoin(bob, &qr).await?; |
| 824 | + |
| 825 | + // vc-request |
| 826 | + alice.recv_msg_trash(&bob.pop_sent_msg().await).await; |
| 827 | + |
| 828 | + // vc-auth-requried |
| 829 | + bob.recv_msg_trash(&alice.pop_sent_msg().await).await; |
| 830 | + |
| 831 | + // vc-request-with-auth |
| 832 | + alice.recv_msg_trash(&bob.pop_sent_msg().await).await; |
| 833 | + |
| 834 | + // Bob should not be verified for Alice. |
| 835 | + let contact_bob = alice.add_or_lookup_contact_no_key(bob).await; |
| 836 | + assert_eq!(contact_bob.is_verified(alice).await.unwrap(), false); |
| 837 | + |
| 838 | + Ok(()) |
| 839 | +} |
| 840 | + |
| 841 | +#[tokio::test(flavor = "multi_thread", worker_threads = 2)] |
| 842 | +async fn test_expired_group_auth_token() -> Result<()> { |
| 843 | + let mut tcm = TestContextManager::new(); |
| 844 | + let alice = &tcm.alice().await; |
| 845 | + let bob = &tcm.bob().await; |
| 846 | + |
| 847 | + let alice_chat_id = chat::create_group_chat(alice, "Group").await?; |
| 848 | + |
| 849 | + // Alice creates a group QR code. |
| 850 | + let qr = get_securejoin_qr(&alice, Some(alice_chat_id)) |
| 851 | + .await |
| 852 | + .unwrap(); |
| 853 | + |
| 854 | + // One week passes, QR code expires. |
| 855 | + SystemTime::shift(Duration::from_secs(7 * 24 * 3600)); |
| 856 | + |
| 857 | + // Bob scans the QR code. |
| 858 | + join_securejoin(bob, &qr).await?; |
| 859 | + |
| 860 | + // vg-request |
| 861 | + alice.recv_msg_trash(&bob.pop_sent_msg().await).await; |
| 862 | + |
| 863 | + // vg-auth-requried |
| 864 | + bob.recv_msg_trash(&alice.pop_sent_msg().await).await; |
| 865 | + |
| 866 | + // vg-request-with-auth |
| 867 | + alice.recv_msg_trash(&bob.pop_sent_msg().await).await; |
| 868 | + |
| 869 | + // vg-member-added |
| 870 | + let bob_member_added_msg = bob.recv_msg(&alice.pop_sent_msg().await).await; |
| 871 | + assert!(bob_member_added_msg.is_info()); |
| 872 | + assert_eq!( |
| 873 | + bob_member_added_msg.get_info_type(), |
| 874 | + SystemMessage::MemberAddedToGroup |
| 875 | + ); |
| 876 | + |
| 877 | + // Bob should not be verified for Alice. |
| 878 | + let contact_bob = alice.add_or_lookup_contact_no_key(bob).await; |
| 879 | + assert_eq!(contact_bob.is_verified(alice).await.unwrap(), false); |
| 880 | + |
| 881 | + Ok(()) |
| 882 | +} |
0 commit comments