Skip to content

Commit 30bba9a

Browse files
committed
test: Extra IMF header removal if message has standard Header Protection (#7130)
1 parent 489fc81 commit 30bba9a

File tree

1 file changed

+18
-12
lines changed

1 file changed

+18
-12
lines changed

src/mimeparser/mimeparser_tests.rs

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1401,22 +1401,28 @@ async fn test_x_microsoft_original_message_id_precedence() -> Result<()> {
14011401
}
14021402

14031403
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
1404-
async fn test_extra_imf_chat_header() -> Result<()> {
1404+
async fn test_extra_imf_headers() -> Result<()> {
14051405
let mut tcm = TestContextManager::new();
14061406
let t = &tcm.alice().await;
14071407
let chat_id = t.get_self_chat().await.id;
14081408

1409-
chat::send_text_msg(t, chat_id, "hi!".to_string()).await?;
1410-
let sent_msg = t.pop_sent_msg().await;
1411-
// Check removal of some nonexistent "Chat-*" header to protect the code from future breakages.
1412-
let payload = sent_msg
1413-
.payload
1414-
.replace("Message-ID:", "Chat-Forty-Two: 42\r\nMessage-ID:");
1415-
let msg = MimeMessage::from_bytes(t, payload.as_bytes(), None)
1416-
.await
1417-
.unwrap();
1418-
assert!(msg.headers.contains_key("chat-version"));
1419-
assert!(!msg.headers.contains_key("chat-forty-two"));
1409+
for std_hp_composing in [false, true] {
1410+
t.set_config_bool(Config::StdHeaderProtectionComposing, std_hp_composing)
1411+
.await?;
1412+
chat::send_text_msg(t, chat_id, "hi!".to_string()).await?;
1413+
let sent_msg = t.pop_sent_msg().await;
1414+
// Check removal of some nonexistent "Chat-*" header to protect the code from future
1415+
// breakages. But headers not prefixed with "Chat-" remain unless a message has standard
1416+
// Header Protection.
1417+
let payload = sent_msg.payload.replace(
1418+
"Message-ID:",
1419+
"Chat-Forty-Two: 42\r\nForty-Two: 42\r\nMessage-ID:",
1420+
);
1421+
let msg = MimeMessage::from_bytes(t, payload.as_bytes(), None).await?;
1422+
assert!(msg.headers.contains_key("chat-version"));
1423+
assert!(!msg.headers.contains_key("chat-forty-two"));
1424+
assert_ne!(msg.headers.contains_key("forty-two"), std_hp_composing);
1425+
}
14201426
Ok(())
14211427
}
14221428

0 commit comments

Comments
 (0)