test: Assert log warnings and errors (#8457)

Adds `assert_warn`, `assert_error` and `assert_warns_or_errors`
methods to `TestContext`, that let us assert that
a certain warning or error is logged during the test.
Also asserts test logs should not contain any other
errors or warnings.

Adjusts tests accordingly.

Signed-off-by: Jagoda Ślązak <jslazak@jslazak.com>
This commit is contained in:
Jagoda Estera Ślązak
2026-08-10 15:36:09 +02:00
committed by GitHub
parent 97932fda07
commit fd8c56894a
36 changed files with 554 additions and 219 deletions

View File

@@ -218,6 +218,11 @@ async fn test_aeap_replay_attack() -> Result<()> {
assert!(chat::is_contact_in_chat(&bob, group, bob_alice_contact).await?);
assert!(!chat::is_contact_in_chat(&bob, group, bob_fiona_contact).await?);
bob.assert_warn(r#"Autocrypt header address "alice@example.org" is not "fiona@example.net""#)
.await;
bob.assert_warn("From header in encrypted part doesn't match the outer one")
.await;
Ok(())
}

View File

@@ -93,7 +93,7 @@ async fn test_receive_both() -> Result<()> {
let mut tcm = TestContextManager::new();
let alice = &tcm.alice().await;
let bob = &tcm.bob().await;
let alice_chat_id = alice.create_group_with_members("", &[bob]).await;
let alice_chat_id = alice.create_group_with_members("group", &[bob]).await;
let (pre_message, post_message, alice_msg_id) =
send_large_file_message(alice, alice_chat_id, Viewtype::File, &vec![0u8; 200_000]).await?;

View File

@@ -52,6 +52,6 @@ async fn test_download_stub_message() -> Result<()> {
assert_eq!(msg.download_state(), DownloadState::Available);
assert_eq!(msg.get_subject(), "foo");
assert!(msg.get_text().contains("[97.66 KiB message]"));
t.assert_warn("unencrypted message").await;
Ok(())
}

View File

@@ -138,7 +138,7 @@ async fn test_receive_webxdc() -> Result<()> {
let mut tcm = TestContextManager::new();
let alice = &tcm.alice().await;
let bob = &tcm.bob().await;
let alice_group_id = alice.create_group_with_members("", &[bob]).await;
let alice_group_id = alice.create_group_with_members("group", &[bob]).await;
let (pre_msg, post_msg, _) = send_large_file_message(
alice,
@@ -310,7 +310,7 @@ async fn pre_msg_mdn_before_sending_full(text: &str) -> Result<()> {
let mut tcm = TestContextManager::new();
let alice = &tcm.alice().await;
let bob = &tcm.bob().await;
let alice_chat_id = alice.create_group_with_members("", &[bob]).await;
let alice_chat_id = alice.create_group_with_members("group", &[bob]).await;
let file_bytes = include_bytes!("../../../test-data/image/screenshot.gif");
let mut msg = Message::new(Viewtype::Image);
@@ -357,7 +357,9 @@ async fn test_post_msg_bad_sender() -> Result<()> {
let alice = &tcm.alice().await;
let bob = &tcm.bob().await;
let fiona = &tcm.fiona().await;
let chat_id_alice = alice.create_group_with_members("", &[bob, fiona]).await;
let chat_id_alice = alice
.create_group_with_members("group", &[bob, fiona])
.await;
let file_bytes = include_bytes!("../../../test-data/image/screenshot.gif");
let mut msg_alice = Message::new(Viewtype::Image);
@@ -383,6 +385,8 @@ async fn test_post_msg_bad_sender() -> Result<()> {
bob.recv_msg_trash(&post_msg_alice).await;
let msg_bob = Message::load_from_db(bob, msg_bob.id).await?;
assert_eq!(msg_bob.download_state, DownloadState::Done);
bob.assert_warn("Bad sender").await;
Ok(())
}
@@ -392,7 +396,9 @@ async fn test_lost_pre_msg_vs_new_member() -> Result<()> {
let alice = &tcm.alice().await;
let bob = &tcm.bob().await;
let fiona = &tcm.fiona().await;
let chat_id_alice = alice.create_group_with_members("", &[bob, fiona]).await;
let chat_id_alice = alice
.create_group_with_members("group", &[bob, fiona])
.await;
let file_bytes = include_bytes!("../../../test-data/image/screenshot.gif");
let mut msg_alice = Message::new(Viewtype::Image);
@@ -406,8 +412,11 @@ async fn test_lost_pre_msg_vs_new_member() -> Result<()> {
chat_id_bob.accept(bob).await?;
let sent = bob.send_text(chat_id_bob, "Hi all").await;
bob.assert_warn("Missing key for fiona@example.net").await;
alice.recv_msg(&sent).await;
fiona.recv_msg_trash(&sent).await; // Undecryptable message
fiona.assert_warn("decryption failed").await;
fiona.assert_warn("unencrypted message").await;
Ok(())
}
@@ -565,6 +574,9 @@ async fn test_full_download_after_trashed() -> Result<()> {
let msg = Message::load_from_db_optional(bob, alice_msg.id).await?;
assert!(msg.is_none());
alice
.assert_warn("Pre-message was not downloaded yet so treat as normal message")
.await;
Ok(())
}
@@ -755,6 +767,11 @@ async fn test_webxdc_updates_in_post_message_after_deleted_pre_message() -> Resu
.is_none()
);
bob.assert_warn("Pre-message was not downloaded yet so treat as normal message")
.await;
bob.assert_warn("Received webxdc update, but cannot assign it to message")
.await;
Ok(())
}

View File

@@ -57,6 +57,7 @@ async fn check_verified_single_chat_protection_not_broken(by_classical_email: bo
.await
.unwrap()
.unwrap();
alice.assert_warn("unencrypted message").await;
let contact = alice.add_or_lookup_contact(&bob).await;
assert_eq!(contact.is_verified(&alice).await.unwrap(), true);
assert_verified(&alice, &bob).await;
@@ -598,6 +599,13 @@ async fn test_verified_lost_member_added() -> Result<()> {
let result = send_msg(bob, bob_chat_id, &mut msg).await;
assert!(result.is_err());
bob.assert_warn("Missing key for fiona@example.net").await;
fiona.assert_warn("missing key").await;
fiona.assert_warn("unencrypted message").await;
bob.assert_warn("Missing key for fiona@example.net").await;
bob.assert_warn(r#"No recipient keys are available, cannot encrypt to ["fiona@example.net"]"#)
.await;
Ok(())
}