|
1 | 1 | use super::*;
|
2 |
| -use crate::chat::{marknoticed_chat, set_muted, ChatVisibility, MuteDuration}; |
| 2 | +use crate::chat::{ |
| 3 | + add_contact_to_chat, marknoticed_chat, remove_contact_from_chat, set_muted, ChatVisibility, |
| 4 | + MuteDuration, |
| 5 | +}; |
3 | 6 | use crate::config::Config;
|
4 | 7 | use crate::constants::DC_CHAT_ID_ARCHIVED_LINK;
|
| 8 | +use crate::contact::Contact; |
5 | 9 | use crate::download::DownloadState;
|
6 | 10 | use crate::location;
|
7 | 11 | use crate::message::markseen_msgs;
|
@@ -779,3 +783,39 @@ async fn test_archived_ephemeral_timer() -> Result<()> {
|
779 | 783 |
|
780 | 784 | Ok(())
|
781 | 785 | }
|
| 786 | + |
| 787 | +/// Tests that non-members cannot change ephemeral timer settings. |
| 788 | +#[tokio::test(flavor = "multi_thread", worker_threads = 2)] |
| 789 | +async fn test_ephemeral_timer_non_member() -> Result<()> { |
| 790 | + let mut tcm = TestContextManager::new(); |
| 791 | + let alice = &tcm.alice().await; |
| 792 | + let bob = &tcm.bob().await; |
| 793 | + |
| 794 | + let alice_bob_contact_id = Contact::create(alice, "Bob", "bob@example.net").await?; |
| 795 | + let alice_chat_id = |
| 796 | + create_group_chat(alice, ProtectionStatus::Unprotected, "Group name").await?; |
| 797 | + add_contact_to_chat(alice, alice_chat_id, alice_bob_contact_id).await?; |
| 798 | + send_text_msg(alice, alice_chat_id, "Hi!".to_string()).await?; |
| 799 | + |
| 800 | + let sent = alice.pop_sent_msg().await; |
| 801 | + let bob_chat_id = bob.recv_msg(&sent).await.chat_id; |
| 802 | + |
| 803 | + // Bob wants to modify the timer. |
| 804 | + bob_chat_id.accept(bob).await?; |
| 805 | + bob_chat_id |
| 806 | + .set_ephemeral_timer(bob, Timer::Enabled { duration: 60 }) |
| 807 | + .await?; |
| 808 | + let sent_ephemeral_timer_change = bob.pop_sent_msg().await; |
| 809 | + |
| 810 | + // Alice removes Bob before receiving the timer change. |
| 811 | + remove_contact_from_chat(alice, alice_chat_id, alice_bob_contact_id).await?; |
| 812 | + alice.recv_msg(&sent_ephemeral_timer_change).await; |
| 813 | + |
| 814 | + // Timer is not changed because Bob is not a member. |
| 815 | + assert_eq!( |
| 816 | + alice_chat_id.get_ephemeral_timer(alice).await?, |
| 817 | + Timer::Disabled |
| 818 | + ); |
| 819 | + |
| 820 | + Ok(()) |
| 821 | +} |
0 commit comments