test: use encrypted messages in more tests

This change is a preparation for ignoring
unencrypted messages by default.

New test_utils::encrypt_raw_message and
test_utils::receive_encrypted_imf are
used to encrypt the messages before
"receiving" them with receive_imf.
This commit is contained in:
link2xt
2026-05-09 19:19:32 +02:00
parent 4bdc3c29ed
commit 1adf87997c
22 changed files with 988 additions and 888 deletions

View File

@@ -9,6 +9,7 @@ use crate::download::DownloadState;
use crate::location;
use crate::message::markseen_msgs;
use crate::receive_imf::receive_imf;
use crate::test_utils;
use crate::test_utils::{TestContext, TestContextManager};
use crate::timesmearing::MAX_SECONDS_TO_LEND_FROM_FUTURE;
use crate::{
@@ -557,50 +558,54 @@ async fn test_delete_expired_imap_messages() -> Result<()> {
// Regression test for a bug in the timer rollback protection.
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn test_ephemeral_timer_references() -> Result<()> {
let alice = TestContext::new_alice().await;
let mut tcm = TestContextManager::new();
let alice = &tcm.alice().await;
let bob = &tcm.bob().await;
// Message with Message-ID <first@example.com> and no timer is received.
receive_imf(
&alice,
b"From: Bob <bob@example.com>\n\
To: Alice <alice@example.org>\n\
Chat-Version: 1.0\n\
Subject: Subject\n\
Message-ID: <first@example.com>\n\
Date: Sun, 22 Mar 2020 00:10:00 +0000\n\
\n\
hello\n",
false,
let encrypted_msg = test_utils::encrypt_raw_message(
bob,
&[alice],
b"From: Bob <bob@example.net>\r\n\
To: Alice <alice@example.org>\r\n\
Chat-Version: 1.0\r\n\
Subject: Subject\r\n\
Message-ID: <first@example.com>\r\n\
Date: Sun, 22 Mar 2020 00:10:00 +0000\r\n\
\r\n\
hello\r\n",
)
.await?;
receive_imf(alice, encrypted_msg.as_bytes(), false).await?;
let msg = alice.get_last_msg().await;
let chat_id = msg.chat_id;
assert_eq!(chat_id.get_ephemeral_timer(&alice).await?, Timer::Disabled);
assert_eq!(chat_id.get_ephemeral_timer(alice).await?, Timer::Disabled);
// Message with Message-ID <second@example.com> is received.
receive_imf(
&alice,
b"From: Bob <bob@example.com>\n\
To: Alice <alice@example.org>\n\
Chat-Version: 1.0\n\
Subject: Subject\n\
Message-ID: <second@example.com>\n\
Date: Sun, 22 Mar 2020 00:11:00 +0000\n\
Ephemeral-Timer: 60\n\
\n\
second message\n",
false,
let encrypted_msg = test_utils::encrypt_raw_message(
bob,
&[alice],
b"From: Bob <bob@example.net>\r\n\
To: Alice <alice@example.org>\r\n\
Chat-Version: 1.0\r\n\
Subject: Subject\r\n\
Message-ID: <second@example.com>\r\n\
Date: Sun, 22 Mar 2020 00:11:00 +0000\r\n\
Ephemeral-Timer: 60\r\n\
\r\n\
second message\r\n",
)
.await?;
receive_imf(alice, encrypted_msg.as_bytes(), false).await?;
assert_eq!(
chat_id.get_ephemeral_timer(&alice).await?,
chat_id.get_ephemeral_timer(alice).await?,
Timer::Enabled { duration: 60 }
);
let msg = alice.get_last_msg().await;
// Message is deleted when its timer expires.
msg.id.trash(&alice, false).await?;
msg.id.trash(alice, false).await?;
// Message with Message-ID <third@example.com>, referencing <first@example.com> and
// <second@example.com>, is received. The message <second@example.come> is not in the
@@ -614,25 +619,26 @@ async fn test_ephemeral_timer_references() -> Result<()> {
//
// The message also contains a quote of the first message to test that only References:
// header and not In-Reply-To: is consulted by the rollback protection.
receive_imf(
&alice,
b"From: Bob <bob@example.com>\n\
To: Alice <alice@example.org>\n\
Chat-Version: 1.0\n\
Subject: Subject\n\
Message-ID: <third@example.com>\n\
Date: Sun, 22 Mar 2020 00:12:00 +0000\n\
References: <first@example.com> <second@example.com>\n\
In-Reply-To: <first@example.com>\n\
\n\
> hello\n",
false,
let encrypted_msg = test_utils::encrypt_raw_message(
bob,
&[alice],
b"From: Bob <bob@example.net>\r\n\
To: Alice <alice@example.org>\r\n\
Chat-Version: 1.0\r\n\
Subject: Subject\r\n\
Message-ID: <third@example.com>\r\n\
Date: Sun, 22 Mar 2020 00:12:00 +0000\r\n\
References: <first@example.com> <second@example.com>\r\n\
In-Reply-To: <first@example.com>\r\n\
\r\n\
> hello\r\n",
)
.await?;
receive_imf(alice, encrypted_msg.as_bytes(), false).await?;
let msg = alice.get_last_msg().await;
assert_eq!(
msg.chat_id.get_ephemeral_timer(&alice).await?,
msg.chat_id.get_ephemeral_timer(alice).await?,
Timer::Disabled
);