|
| 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 {
|
@@ -846,3 +849,120 @@ async fn test_wrong_auth_token() -> Result<()> {
|
846 | 849 |
|
847 | 850 | Ok(())
|
848 | 851 | }
|
| 852 | + |
| 853 | +/// Tests that scanning a QR code week later |
| 854 | +/// allows Bob to establish a contact with Alice, |
| 855 | +/// but does not mark Bob as verified for Alice. |
| 856 | +#[tokio::test(flavor = "multi_thread", worker_threads = 2)] |
| 857 | +async fn test_expired_contact_auth_token() -> Result<()> { |
| 858 | + let mut tcm = TestContextManager::new(); |
| 859 | + let alice = &tcm.alice().await; |
| 860 | + let bob = &tcm.bob().await; |
| 861 | + |
| 862 | + // Alice creates a QR code. |
| 863 | + let qr = get_securejoin_qr(alice, None).await?; |
| 864 | + |
| 865 | + // One week passes, QR code expires. |
| 866 | + SystemTime::shift(Duration::from_secs(7 * 24 * 3600)); |
| 867 | + |
| 868 | + // Bob scans the QR code. |
| 869 | + join_securejoin(bob, &qr).await?; |
| 870 | + |
| 871 | + // vc-request |
| 872 | + alice.recv_msg_trash(&bob.pop_sent_msg().await).await; |
| 873 | + |
| 874 | + // vc-auth-requried |
| 875 | + bob.recv_msg_trash(&alice.pop_sent_msg().await).await; |
| 876 | + |
| 877 | + // vc-request-with-auth |
| 878 | + alice.recv_msg_trash(&bob.pop_sent_msg().await).await; |
| 879 | + |
| 880 | + // Bob should not be verified for Alice. |
| 881 | + let contact_bob = alice.add_or_lookup_contact_no_key(bob).await; |
| 882 | + assert_eq!(contact_bob.is_verified(alice).await.unwrap(), false); |
| 883 | + |
| 884 | + Ok(()) |
| 885 | +} |
| 886 | + |
| 887 | +#[tokio::test(flavor = "multi_thread", worker_threads = 2)] |
| 888 | +async fn test_expired_group_auth_token() -> Result<()> { |
| 889 | + let mut tcm = TestContextManager::new(); |
| 890 | + let alice = &tcm.alice().await; |
| 891 | + let bob = &tcm.bob().await; |
| 892 | + |
| 893 | + let alice_chat_id = chat::create_group_chat(alice, "Group").await?; |
| 894 | + |
| 895 | + // Alice creates a group QR code. |
| 896 | + let qr = get_securejoin_qr(alice, Some(alice_chat_id)).await.unwrap(); |
| 897 | + |
| 898 | + // One week passes, QR code expires. |
| 899 | + SystemTime::shift(Duration::from_secs(7 * 24 * 3600)); |
| 900 | + |
| 901 | + // Bob scans the QR code. |
| 902 | + join_securejoin(bob, &qr).await?; |
| 903 | + |
| 904 | + // vg-request |
| 905 | + alice.recv_msg_trash(&bob.pop_sent_msg().await).await; |
| 906 | + |
| 907 | + // vg-auth-requried |
| 908 | + bob.recv_msg_trash(&alice.pop_sent_msg().await).await; |
| 909 | + |
| 910 | + // vg-request-with-auth |
| 911 | + alice.recv_msg_trash(&bob.pop_sent_msg().await).await; |
| 912 | + |
| 913 | + // vg-member-added |
| 914 | + let bob_member_added_msg = bob.recv_msg(&alice.pop_sent_msg().await).await; |
| 915 | + assert!(bob_member_added_msg.is_info()); |
| 916 | + assert_eq!( |
| 917 | + bob_member_added_msg.get_info_type(), |
| 918 | + SystemMessage::MemberAddedToGroup |
| 919 | + ); |
| 920 | + |
| 921 | + // Bob should not be verified for Alice. |
| 922 | + let contact_bob = alice.add_or_lookup_contact_no_key(bob).await; |
| 923 | + assert_eq!(contact_bob.is_verified(alice).await.unwrap(), false); |
| 924 | + |
| 925 | + Ok(()) |
| 926 | +} |
| 927 | + |
| 928 | +/// Tests that old token is considered expired |
| 929 | +/// even if sync message just arrived. |
| 930 | +#[tokio::test(flavor = "multi_thread", worker_threads = 2)] |
| 931 | +async fn test_expired_synced_auth_token() -> Result<()> { |
| 932 | + let mut tcm = TestContextManager::new(); |
| 933 | + let alice = &tcm.alice().await; |
| 934 | + let alice2 = &tcm.alice().await; |
| 935 | + let bob = &tcm.bob().await; |
| 936 | + |
| 937 | + alice.set_config_bool(Config::SyncMsgs, true).await?; |
| 938 | + alice2.set_config_bool(Config::SyncMsgs, true).await?; |
| 939 | + |
| 940 | + // Alice creates a QR code on the second device. |
| 941 | + let qr = get_securejoin_qr(alice2, None).await?; |
| 942 | + |
| 943 | + alice2.send_sync_msg().await.unwrap(); |
| 944 | + let sync_msg = alice2.pop_sent_sync_msg().await; |
| 945 | + |
| 946 | + // One week passes, QR code expires. |
| 947 | + SystemTime::shift(Duration::from_secs(7 * 24 * 3600)); |
| 948 | + |
| 949 | + alice.recv_msg_trash(&sync_msg).await; |
| 950 | + |
| 951 | + // Bob scans the QR code. |
| 952 | + join_securejoin(bob, &qr).await?; |
| 953 | + |
| 954 | + // vc-request |
| 955 | + alice.recv_msg_trash(&bob.pop_sent_msg().await).await; |
| 956 | + |
| 957 | + // vc-auth-requried |
| 958 | + bob.recv_msg_trash(&alice.pop_sent_msg().await).await; |
| 959 | + |
| 960 | + // vc-request-with-auth |
| 961 | + alice.recv_msg_trash(&bob.pop_sent_msg().await).await; |
| 962 | + |
| 963 | + // Bob should not be verified for Alice. |
| 964 | + let contact_bob = alice.add_or_lookup_contact_no_key(bob).await; |
| 965 | + assert_eq!(contact_bob.is_verified(alice).await.unwrap(), false); |
| 966 | + |
| 967 | + Ok(()) |
| 968 | +} |
0 commit comments