()
| 653 | |
| 654 | #[tokio::test(flavor = "multi_thread", worker_threads = 2)] |
| 655 | async fn test_send_sync_msg() -> Result<()> { |
| 656 | let alice = TestContext::new_alice().await; |
| 657 | alice.set_config_bool(Config::SyncMsgs, true).await?; |
| 658 | alice |
| 659 | .add_sync_item(SyncData::AddQrToken(QrTokenData { |
| 660 | invitenumber: "in".to_string(), |
| 661 | auth: "testtoken".to_string(), |
| 662 | grpid: None, |
| 663 | })) |
| 664 | .await?; |
| 665 | let msg_id = alice.send_sync_msg().await?.unwrap(); |
| 666 | let msg = Message::load_from_db(&alice, msg_id).await?; |
| 667 | let chat = Chat::load_from_db(&alice, msg.chat_id).await?; |
| 668 | assert!(chat.is_self_talk()); |
| 669 | |
| 670 | // check that the used self-talk is not visible to the user |
| 671 | // but that creation will still work (in this case, the chat is empty) |
| 672 | assert_eq!(Chatlist::try_load(&alice, 0, None, None).await?.len(), 0); |
| 673 | let chat_id = ChatId::create_for_contact(&alice, ContactId::SELF).await?; |
| 674 | let chat = Chat::load_from_db(&alice, chat_id).await?; |
| 675 | assert!(chat.is_self_talk()); |
| 676 | assert_eq!(Chatlist::try_load(&alice, 0, None, None).await?.len(), 1); |
| 677 | let msgs = chat::get_chat_msgs(&alice, chat_id).await?; |
| 678 | assert_eq!(msgs.len(), 0); |
| 679 | |
| 680 | // let alice's other device receive and execute the sync message, |
| 681 | // also here, self-talk should stay hidden |
| 682 | let sent_msg = alice.pop_sent_msg().await; |
| 683 | let alice2 = TestContext::new_alice().await; |
| 684 | alice2.set_config_bool(Config::SyncMsgs, true).await?; |
| 685 | alice2.recv_msg_trash(&sent_msg).await; |
| 686 | assert!(token::exists(&alice2, token::Namespace::Auth, "testtoken").await?); |
| 687 | assert_eq!(Chatlist::try_load(&alice2, 0, None, None).await?.len(), 0); |
| 688 | |
| 689 | // Sync messages are "auto-generated", but they mustn't make the self-contact a bot. |
| 690 | let self_contact = alice2.add_or_lookup_contact(&alice2).await; |
| 691 | assert!(!self_contact.is_bot()); |
| 692 | |
| 693 | // the same sync message sent to bob must not be executed |
| 694 | let bob = TestContext::new_bob().await; |
| 695 | bob.recv_msg_trash(&sent_msg).await; |
| 696 | assert!(!token::exists(&bob, token::Namespace::Auth, "testtoken").await?); |
| 697 | |
| 698 | Ok(()) |
| 699 | } |
| 700 | |
| 701 | #[tokio::test(flavor = "multi_thread", worker_threads = 2)] |
| 702 | async fn test_send_sync_msg_enables_bccself() -> Result<()> { |
nothing calls this directly
no test coverage detected