test: add function to manually create encrypted messages

This commit is contained in:
link2xt
2026-05-09 19:19:32 +02:00
parent 6fb2f27831
commit 84bc3f8bae
3 changed files with 79 additions and 13 deletions

View File

@@ -871,6 +871,7 @@ mod tests {
use crate::config::Config;
use crate::message::MessageState;
use crate::receive_imf::receive_imf;
use crate::test_utils;
use crate::test_utils::{ExpectedEvents, TestContext, TestContextManager};
use crate::tools::SystemTime;
@@ -939,12 +940,15 @@ mod tests {
/// Tests that location.kml is hidden.
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn receive_location_kml() -> Result<()> {
let alice = TestContext::new_alice().await;
let mut tcm = TestContextManager::new();
let alice = &tcm.alice().await;
let bob = &tcm.bob().await;
receive_imf(
&alice,
let encrypted_message = test_utils::encrypt_raw_message(
bob,
&[alice],
br#"Subject: Hello
Message-ID: hello@example.net
Message-ID: <hello@example.net>
To: Alice <alice@example.org>
From: Bob <bob@example.net>
Date: Mon, 20 Dec 2021 00:00:00 +0000
@@ -952,14 +956,15 @@ Chat-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed; delsp=no
Text message."#,
false,
)
.await?;
receive_imf(alice, encrypted_message.as_bytes(), false).await?;
let received_msg = alice.get_last_msg().await;
assert_eq!(received_msg.text, "Text message.");
receive_imf(
&alice,
let encrypted_message = test_utils::encrypt_raw_message(
bob,
&[alice],
br#"Subject: locations
MIME-Version: 1.0
To: <alice@example.org>
@@ -986,10 +991,8 @@ Content-Disposition: attachment; filename="location.kml"
</Document>
</kml>
--U8BOG8qNXfB0GgLiQ3PKUjlvdIuLRF--"#,
false,
)
.await?;
--U8BOG8qNXfB0GgLiQ3PKUjlvdIuLRF--"#).await?;
receive_imf(alice, encrypted_message.as_bytes(), false).await?;
// Received location message is not visible, last message stays the same.
let received_msg2 = alice.get_last_msg().await;