diff --git a/src/chat/chat_tests.rs b/src/chat/chat_tests.rs index 66c076d02..891c3407d 100644 --- a/src/chat/chat_tests.rs +++ b/src/chat/chat_tests.rs @@ -483,7 +483,7 @@ async fn test_msg_with_implicit_member_removed() -> Result<()> { // If Bob sends a message to Alice now, Fiona is removed. assert_eq!(get_chat_contacts(&alice, alice_chat_id).await?.len(), 3); let sent_msg = bob - .send_text(alice_chat_id, "I have removed Fiona some time ago.") + .send_text(bob_chat_id, "I have removed Fiona some time ago.") .await; alice.recv_msg(&sent_msg).await; assert_eq!(get_chat_contacts(&alice, alice_chat_id).await?.len(), 2); @@ -2412,14 +2412,14 @@ async fn test_forward_from_saved_to_saved() -> Result<()> { let bob = TestContext::new_bob().await; let sent = alice.send_text(alice.create_chat(&bob).await.id, "k").await; - bob.recv_msg(&sent).await; + let received_message = bob.recv_msg(&sent).await; let orig = bob.get_last_msg().await; let self_chat = bob.get_self_chat().await; save_msgs(&bob, &[orig.id]).await?; let saved1 = bob.get_last_msg().await; assert_eq!( saved1.get_original_msg_id(&bob).await?.unwrap(), - sent.sender_msg_id + received_message.id ); assert_ne!(saved1.from_id, ContactId::SELF); @@ -2644,7 +2644,7 @@ async fn test_broadcast() -> Result<()> { add_contact_to_chat( &alice, broadcast_id, - get_chat_contacts(&alice, chat_bob.id).await?.pop().unwrap(), + get_chat_contacts(&alice, msg.chat_id).await?.pop().unwrap(), ) .await?; let fiona_contact_id = alice.add_or_lookup_contact_id(&fiona).await; @@ -4013,26 +4013,27 @@ async fn test_info_contact_id() -> Result<()> { ) .await?; - let fiona_id = alice.add_or_lookup_contact_id(&tcm.fiona().await).await; // contexts are in sync, fiona_id is same everywhere - add_contact_to_chat(alice, alice_chat_id, fiona_id).await?; + let alice_fiona_id = alice.add_or_lookup_contact_id(&tcm.fiona().await).await; + let bob_fiona_id = bob.add_or_lookup_contact_id(&tcm.fiona().await).await; + add_contact_to_chat(alice, alice_chat_id, alice_fiona_id).await?; pop_recv_and_check( alice, alice2, bob, SystemMessage::MemberAddedToGroup, - fiona_id, - fiona_id, + alice_fiona_id, + bob_fiona_id, ) .await?; - remove_contact_from_chat(alice, alice_chat_id, fiona_id).await?; + remove_contact_from_chat(alice, alice_chat_id, alice_fiona_id).await?; pop_recv_and_check( alice, alice2, bob, SystemMessage::MemberRemovedFromGroup, - fiona_id, - fiona_id, + alice_fiona_id, + bob_fiona_id, ) .await?; @@ -4040,11 +4041,12 @@ async fn test_info_contact_id() -> Result<()> { // We raw delete in db as Contact::delete() leaves a tombstone (which is great as the tap works longer then) alice .sql - .execute("DELETE FROM contacts WHERE id=?", (fiona_id,)) + .execute("DELETE FROM contacts WHERE id=?", (alice_fiona_id,)) .await?; let msg = alice.get_last_msg().await; assert_eq!(msg.get_info_type(), SystemMessage::MemberRemovedFromGroup); assert!(msg.get_info_contact_id(alice).await?.is_none()); + assert!(msg.get_info_contact_id(bob).await?.is_none()); Ok(()) } diff --git a/src/peer_channels.rs b/src/peer_channels.rs index 1f1c158ef..7e19202b0 100644 --- a/src/peer_channels.rs +++ b/src/peer_channels.rs @@ -616,7 +616,7 @@ mod tests { loop { let event = bob.evtracker.recv().await.unwrap(); if let EventType::WebxdcRealtimeAdvertisementReceived { msg_id } = event.typ { - assert!(msg_id == alice_webxdc.id); + assert!(msg_id == bob_webxdc.id); break; } } diff --git a/src/receive_imf/receive_imf_tests.rs b/src/receive_imf/receive_imf_tests.rs index af428153c..8978f7e85 100644 --- a/src/receive_imf/receive_imf_tests.rs +++ b/src/receive_imf/receive_imf_tests.rs @@ -2901,9 +2901,9 @@ async fn test_accept_outgoing() -> Result<()> { let bob1_chat = bob1.create_chat(&alice1).await; let sent = bob1.send_text(bob1_chat.id, "Hello!").await; - alice1.recv_msg(&sent).await; + let alice1_msg = alice1.recv_msg(&sent).await; alice2.recv_msg(&sent).await; - let alice1_msg = bob2.recv_msg(&sent).await; + bob2.recv_msg(&sent).await; assert_eq!(alice1_msg.text, "Hello!"); let alice1_chat = chat::Chat::load_from_db(&alice1, alice1_msg.chat_id).await?; assert!(alice1_chat.is_contact_request()); diff --git a/src/sql/migrations/migrations_tests.rs b/src/sql/migrations/migrations_tests.rs index 85ef9966a..0517f12e5 100644 --- a/src/sql/migrations/migrations_tests.rs +++ b/src/sql/migrations/migrations_tests.rs @@ -122,7 +122,7 @@ async fn test_key_contacts_migration_email2() -> Result<()> { .await? .is_empty() ); - let pgp_bob = Contact::get_by_id(&t, ContactId::new(11)).await?; + let pgp_bob = Contact::get_by_id(&t, ContactId::new(11001)).await?; assert_eq!(pgp_bob.is_key_contact(), true); assert_eq!(pgp_bob.origin, Origin::Hidden); diff --git a/src/test_utils.rs b/src/test_utils.rs index 5b68de1a5..e92fc658c 100644 --- a/src/test_utils.rs +++ b/src/test_utils.rs @@ -84,6 +84,7 @@ impl TestContextManager { pub async fn alice(&mut self) -> TestContext { TestContext::builder() .configure_alice() + .with_id_offset(1000) .with_log_sink(self.log_sink.clone()) .build(Some(&mut self.used_names)) .await @@ -92,6 +93,7 @@ impl TestContextManager { pub async fn bob(&mut self) -> TestContext { TestContext::builder() .configure_bob() + .with_id_offset(2000) .with_log_sink(self.log_sink.clone()) .build(Some(&mut self.used_names)) .await @@ -100,6 +102,7 @@ impl TestContextManager { pub async fn charlie(&mut self) -> TestContext { TestContext::builder() .configure_charlie() + .with_id_offset(3000) .with_log_sink(self.log_sink.clone()) .build(Some(&mut self.used_names)) .await @@ -108,6 +111,7 @@ impl TestContextManager { pub async fn dom(&mut self) -> TestContext { TestContext::builder() .configure_dom() + .with_id_offset(4000) .with_log_sink(self.log_sink.clone()) .build(Some(&mut self.used_names)) .await @@ -116,6 +120,7 @@ impl TestContextManager { pub async fn elena(&mut self) -> TestContext { TestContext::builder() .configure_elena() + .with_id_offset(5000) .with_log_sink(self.log_sink.clone()) .build(Some(&mut self.used_names)) .await @@ -124,6 +129,7 @@ impl TestContextManager { pub async fn fiona(&mut self) -> TestContext { TestContext::builder() .configure_fiona() + .with_id_offset(6000) .with_log_sink(self.log_sink.clone()) .build(Some(&mut self.used_names)) .await @@ -263,6 +269,11 @@ pub struct TestContextBuilder { /// so the caller should store the LogSink elsewhere to /// prevent it from being dropped immediately. log_sink: Option, + + /// Offset for chat-,message-,contact ids. + /// + /// This makes tests fail where ids from different accounts were mixed up. + id_offset: Option, } impl TestContextBuilder { @@ -328,6 +339,14 @@ impl TestContextBuilder { self } + /// Adds an offset for chat-, message-, contact IDs. + /// + /// This makes it harder to accidentally mix up IDs from different accounts. + pub fn with_id_offset(mut self, offset: u32) -> Self { + self.id_offset = Some(offset); + self + } + /// Builds the [`TestContext`]. pub async fn build(self, used_names: Option<&mut BTreeSet>) -> TestContext { if let Some(key_pair) = self.key_pair { @@ -360,6 +379,22 @@ impl TestContextBuilder { key::store_self_keypair(&test_context, &key_pair) .await .expect("Failed to save key"); + + if let Some(offset) = self.id_offset { + test_context + .ctx + .sql + .execute( + "UPDATE sqlite_sequence SET seq = ? + WHERE name = 'contacts' + OR name = 'chats' + OR name = 'msgs'", + (offset,), + ) + .await + .expect("Failed set id offset"); + } + test_context } else { TestContext::new_internal(None, self.log_sink).await @@ -409,21 +444,33 @@ impl TestContext { /// /// This is a shortcut which configures alice@example.org with a fixed key. pub async fn new_alice() -> Self { - Self::builder().configure_alice().build(None).await + Self::builder() + .configure_alice() + .with_id_offset(11000) + .build(None) + .await } /// Creates a new configured [`TestContext`]. /// /// This is a shortcut which configures bob@example.net with a fixed key. pub async fn new_bob() -> Self { - Self::builder().configure_bob().build(None).await + Self::builder() + .configure_bob() + .with_id_offset(12000) + .build(None) + .await } /// Creates a new configured [`TestContext`]. /// /// This is a shortcut which configures fiona@example.net with a fixed key. pub async fn new_fiona() -> Self { - Self::builder().configure_fiona().build(None).await + Self::builder() + .configure_fiona() + .with_id_offset(13000) + .build(None) + .await } /// Print current chat state. @@ -1624,4 +1671,32 @@ mod tests { let runtime = tokio::runtime::Runtime::new().expect("unable to create tokio runtime"); runtime.block_on(TestContext::new()); } + + #[tokio::test(flavor = "multi_thread", worker_threads = 2)] + async fn test_id_offset() { + let mut tcm = TestContextManager::new(); + let alice = tcm.alice().await; + let bob = tcm.bob().await; + let fiona = tcm.fiona().await; + + // chat ids + let alice_bob_chat = alice.create_chat(&bob).await; + let bob_alice_chat = bob.create_chat(&alice).await; + assert_ne!(alice_bob_chat.id, bob_alice_chat.id); + + // contact ids + let alice_fiona_contact_id = alice.add_or_lookup_contact_id(&fiona).await; + let fiona_fiona_contact_id = bob.add_or_lookup_contact_id(&fiona).await; + assert_ne!(alice_fiona_contact_id, fiona_fiona_contact_id); + + // message ids + let alice_group_id = alice + .create_group_with_members("test group", &[&bob, &fiona]) + .await; + let alice_sent_msg = alice.send_text(alice_group_id, "testing").await; + let bob_received_id = bob.recv_msg(&alice_sent_msg).await; + assert_ne!(alice_sent_msg.sender_msg_id, bob_received_id.id); + let fiona_received_id = fiona.recv_msg(&alice_sent_msg).await; + assert_ne!(bob_received_id.id, fiona_received_id.id); + } } diff --git a/test-data/golden/chat_test_parallel_member_remove b/test-data/golden/chat_test_parallel_member_remove index 1e4e17d3d..894f275de 100644 --- a/test-data/golden/chat_test_parallel_member_remove +++ b/test-data/golden/chat_test_parallel_member_remove @@ -1,8 +1,8 @@ -Group#Chat#10: Group chat [3 member(s)] +Group#Chat#2001: Group chat [3 member(s)] -------------------------------------------------------------------------------- -Msg#10: info (Contact#Contact#Info): Messages are end-to-end encrypted. [NOTICED][INFO] -Msg#11πŸ”’: (Contact#Contact#10): Hi! I created a group. [FRESH] -Msg#12πŸ”’: Me (Contact#Contact#Self): You left the group. [INFO] √ -Msg#13πŸ”’: (Contact#Contact#10): Member charlie@example.net added by alice@example.org. [FRESH][INFO] -Msg#14πŸ”’: (Contact#Contact#10): What a silence! [FRESH] +Msg#2001: info (Contact#Contact#Info): Messages are end-to-end encrypted. [NOTICED][INFO] +Msg#2002πŸ”’: (Contact#Contact#2001): Hi! I created a group. [FRESH] +Msg#2003πŸ”’: Me (Contact#Contact#Self): You left the group. [INFO] √ +Msg#2004πŸ”’: (Contact#Contact#2001): Member charlie@example.net added by alice@example.org. [FRESH][INFO] +Msg#2005πŸ”’: (Contact#Contact#2001): What a silence! [FRESH] -------------------------------------------------------------------------------- diff --git a/test-data/golden/receive_imf_delayed_removal_is_ignored b/test-data/golden/receive_imf_delayed_removal_is_ignored index 1e8363ba7..3333fb833 100644 --- a/test-data/golden/receive_imf_delayed_removal_is_ignored +++ b/test-data/golden/receive_imf_delayed_removal_is_ignored @@ -1,10 +1,10 @@ -Group#Chat#10: Group [5 member(s)] +Group#Chat#1001: Group [5 member(s)] -------------------------------------------------------------------------------- -Msg#10: info (Contact#Contact#Info): Messages are end-to-end encrypted. [NOTICED][INFO] -Msg#11πŸ”’: Me (Contact#Contact#Self): populate √ -Msg#12: info (Contact#Contact#Info): Member dom@example.net added. [NOTICED][INFO] -Msg#13: info (Contact#Contact#Info): Member fiona@example.net removed. [NOTICED][INFO] -Msg#14πŸ”’: (Contact#Contact#10): Member elena@example.net added by bob@example.net. [FRESH][INFO] -Msg#15πŸ”’: Me (Contact#Contact#Self): You added member fiona@example.net. [INFO] o -Msg#16πŸ”’: (Contact#Contact#10): Member fiona@example.net removed by bob@example.net. [FRESH][INFO] +Msg#1001: info (Contact#Contact#Info): Messages are end-to-end encrypted. [NOTICED][INFO] +Msg#1002πŸ”’: Me (Contact#Contact#Self): populate √ +Msg#1003: info (Contact#Contact#Info): Member dom@example.net added. [NOTICED][INFO] +Msg#1004: info (Contact#Contact#Info): Member fiona@example.net removed. [NOTICED][INFO] +Msg#1005πŸ”’: (Contact#Contact#1001): Member elena@example.net added by bob@example.net. [FRESH][INFO] +Msg#1006πŸ”’: Me (Contact#Contact#Self): You added member fiona@example.net. [INFO] o +Msg#1007πŸ”’: (Contact#Contact#1001): Member fiona@example.net removed by bob@example.net. [FRESH][INFO] -------------------------------------------------------------------------------- diff --git a/test-data/golden/receive_imf_older_message_from_2nd_device b/test-data/golden/receive_imf_older_message_from_2nd_device index 4d036f98e..b83343287 100644 --- a/test-data/golden/receive_imf_older_message_from_2nd_device +++ b/test-data/golden/receive_imf_older_message_from_2nd_device @@ -1,5 +1,5 @@ -Single#Chat#10: bob@example.net [bob@example.net] Icon: 4138c52e5bc1c576cda7dd44d088c07.png +Single#Chat#1001: bob@example.net [bob@example.net] Icon: 4138c52e5bc1c576cda7dd44d088c07.png -------------------------------------------------------------------------------- -Msg#10: Me (Contact#Contact#Self): We share this account √ -Msg#11: Me (Contact#Contact#Self): I'm Alice too √ +Msg#1001: Me (Contact#Contact#Self): We share this account √ +Msg#1002: Me (Contact#Contact#Self): I'm Alice too √ -------------------------------------------------------------------------------- diff --git a/test-data/golden/test_old_message_5 b/test-data/golden/test_old_message_5 index 9a847dce0..92bd8ac86 100644 --- a/test-data/golden/test_old_message_5 +++ b/test-data/golden/test_old_message_5 @@ -1,5 +1,5 @@ -Single#Chat#10: Bob [bob@example.net] Icon: 4138c52e5bc1c576cda7dd44d088c07.png +Single#Chat#11001: Bob [bob@example.net] Icon: 4138c52e5bc1c576cda7dd44d088c07.png -------------------------------------------------------------------------------- -Msg#10: Me (Contact#Contact#Self): Happy birthday, Bob! √ -Msg#11: (Contact#Contact#10): Happy birthday to me, Alice! [FRESH] +Msg#11001: Me (Contact#Contact#Self): Happy birthday, Bob! √ +Msg#11002: (Contact#Contact#11001): Happy birthday to me, Alice! [FRESH] -------------------------------------------------------------------------------- diff --git a/test-data/golden/test_outgoing_encrypted_msg b/test-data/golden/test_outgoing_encrypted_msg index cf7625803..4b26297c2 100644 --- a/test-data/golden/test_outgoing_encrypted_msg +++ b/test-data/golden/test_outgoing_encrypted_msg @@ -1,5 +1,5 @@ -Single#Chat#10: bob@example.net [KEY bob@example.net] +Single#Chat#1001: bob@example.net [KEY bob@example.net] -------------------------------------------------------------------------------- -Msg#10: info (Contact#Contact#Info): Messages are end-to-end encrypted. [NOTICED][INFO] -Msg#11πŸ”’: Me (Contact#Contact#Self): Test – This is encrypted, signed, and has an Autocrypt Header without prefer-encrypt=mutual. √ +Msg#1001: info (Contact#Contact#Info): Messages are end-to-end encrypted. [NOTICED][INFO] +Msg#1002πŸ”’: Me (Contact#Contact#Self): Test – This is encrypted, signed, and has an Autocrypt Header without prefer-encrypt=mutual. √ -------------------------------------------------------------------------------- diff --git a/test-data/golden/test_outgoing_mua_msg b/test-data/golden/test_outgoing_mua_msg index db73265bb..5940262b1 100644 --- a/test-data/golden/test_outgoing_mua_msg +++ b/test-data/golden/test_outgoing_mua_msg @@ -1,4 +1,4 @@ -Single#Chat#11: bob@example.net [bob@example.net] Icon: 4138c52e5bc1c576cda7dd44d088c07.png +Single#Chat#1002: bob@example.net [bob@example.net] Icon: 4138c52e5bc1c576cda7dd44d088c07.png -------------------------------------------------------------------------------- -Msg#12: Me (Contact#Contact#Self): One classical MUA message √ +Msg#1003: Me (Contact#Contact#Self): One classical MUA message √ -------------------------------------------------------------------------------- diff --git a/test-data/golden/test_outgoing_mua_msg_pgp b/test-data/golden/test_outgoing_mua_msg_pgp index b71ee0873..3c4c163f4 100644 --- a/test-data/golden/test_outgoing_mua_msg_pgp +++ b/test-data/golden/test_outgoing_mua_msg_pgp @@ -1,6 +1,6 @@ -Single#Chat#10: bob@example.net [KEY bob@example.net] +Single#Chat#1001: bob@example.net [KEY bob@example.net] -------------------------------------------------------------------------------- -Msg#10: info (Contact#Contact#Info): Messages are end-to-end encrypted. [NOTICED][INFO] -Msg#11πŸ”’: (Contact#Contact#10): Heyho from DC [FRESH] -Msg#13πŸ”’: Me (Contact#Contact#Self): Sending with DC again √ +Msg#1001: info (Contact#Contact#Info): Messages are end-to-end encrypted. [NOTICED][INFO] +Msg#1002πŸ”’: (Contact#Contact#1001): Heyho from DC [FRESH] +Msg#1004πŸ”’: Me (Contact#Contact#Self): Sending with DC again √ -------------------------------------------------------------------------------- diff --git a/test-data/golden/two_group_securejoins b/test-data/golden/two_group_securejoins index fe3f5efc1..5e20c36b6 100644 --- a/test-data/golden/two_group_securejoins +++ b/test-data/golden/two_group_securejoins @@ -1,9 +1,9 @@ -Group#Chat#11: Group [3 member(s)] +Group#Chat#6002: Group [3 member(s)] -------------------------------------------------------------------------------- -Msg#13: info (Contact#Contact#Info): alice@example.org invited you to join this group. +Msg#6004: info (Contact#Contact#Info): alice@example.org invited you to join this group. Waiting for the device of alice@example.org to reply… [NOTICED][INFO] -Msg#15: info (Contact#Contact#Info): alice@example.org replied, waiting for being added to the group… [NOTICED][INFO] -Msg#12: info (Contact#Contact#Info): Messages are end-to-end encrypted. [NOTICED][INFO] -Msg#17πŸ”’: (Contact#Contact#10): Member Me added by alice@example.org. [FRESH][INFO] +Msg#6006: info (Contact#Contact#Info): alice@example.org replied, waiting for being added to the group… [NOTICED][INFO] +Msg#6003: info (Contact#Contact#Info): Messages are end-to-end encrypted. [NOTICED][INFO] +Msg#6008πŸ”’: (Contact#Contact#6001): Member Me added by alice@example.org. [FRESH][INFO] -------------------------------------------------------------------------------- diff --git a/test-data/golden/verified_chats_editor_reordering b/test-data/golden/verified_chats_editor_reordering index 15f88d602..3bf488c00 100644 --- a/test-data/golden/verified_chats_editor_reordering +++ b/test-data/golden/verified_chats_editor_reordering @@ -1,11 +1,11 @@ -Group#Chat#11: Group [3 member(s)] +Group#Chat#3002: Group [3 member(s)] -------------------------------------------------------------------------------- -Msg#13: info (Contact#Contact#Info): alice@example.org invited you to join this group. +Msg#3004: info (Contact#Contact#Info): alice@example.org invited you to join this group. Waiting for the device of alice@example.org to reply… [NOTICED][INFO] -Msg#15: info (Contact#Contact#Info): alice@example.org replied, waiting for being added to the group… [NOTICED][INFO] -Msg#12: info (Contact#Contact#Info): Messages are end-to-end encrypted. [NOTICED][INFO] -Msg#17πŸ”’: (Contact#Contact#11): [FRESH] -Msg#18: info (Contact#Contact#Info): Member bob@example.net added. [NOTICED][INFO] -Msg#19πŸ”’: (Contact#Contact#10): Member Me added by alice@example.org. [FRESH][INFO] +Msg#3006: info (Contact#Contact#Info): alice@example.org replied, waiting for being added to the group… [NOTICED][INFO] +Msg#3003: info (Contact#Contact#Info): Messages are end-to-end encrypted. [NOTICED][INFO] +Msg#3008πŸ”’: (Contact#Contact#3002): [FRESH] +Msg#3009: info (Contact#Contact#Info): Member bob@example.net added. [NOTICED][INFO] +Msg#3010πŸ”’: (Contact#Contact#3001): Member Me added by alice@example.org. [FRESH][INFO] --------------------------------------------------------------------------------