Skip to content

Commit a187251

Browse files
committed
test: HP-Outer headers are added to messages with standard Header Protection (#7130)
1 parent 30bba9a commit a187251

File tree

3 files changed

+35
-0
lines changed

3 files changed

+35
-0
lines changed

src/headerdef.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,9 @@ pub enum HeaderDef {
129129
/// Advertised gossip topic for one webxdc.
130130
IrohGossipTopic,
131131

132+
/// See <https://www.rfc-editor.org/rfc/rfc9788.html#name-hp-outer-header-field>.
133+
HpOuter,
134+
132135
#[cfg(test)]
133136
TestHeader,
134137
}

src/mimefactory/mimefactory_tests.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -837,6 +837,30 @@ async fn test_protected_headers_directive() -> Result<()> {
837837
Ok(())
838838
}
839839

840+
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
841+
async fn test_hp_outer_headers() -> Result<()> {
842+
let mut tcm = TestContextManager::new();
843+
let t = &tcm.alice().await;
844+
let chat_id = t.get_self_chat().await.id;
845+
846+
for std_hp_composing in [false, true] {
847+
t.set_config_bool(Config::StdHeaderProtectionComposing, std_hp_composing)
848+
.await?;
849+
chat::send_text_msg(t, chat_id, "hi!".to_string()).await?;
850+
let sent_msg = t.pop_sent_msg().await;
851+
let msg = MimeMessage::from_bytes(t, sent_msg.payload.as_bytes(), None).await?;
852+
assert_eq!(msg.header_exists(HeaderDef::HpOuter), std_hp_composing);
853+
for hdr in ["Date", "From", "Message-ID"] {
854+
assert_eq!(
855+
msg.decoded_data_contains(&format!("HP-Outer: {hdr}:")),
856+
std_hp_composing,
857+
);
858+
}
859+
assert!(!msg.decoded_data_contains("HP-Outer: Content-Type"));
860+
}
861+
Ok(())
862+
}
863+
840864
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
841865
async fn test_dont_remove_self() -> Result<()> {
842866
let mut tcm = TestContextManager::new();

src/mimeparser.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1001,6 +1001,14 @@ impl MimeMessage {
10011001
self.headers.contains_key(hname) || self.headers_removed.contains(hname)
10021002
}
10031003

1004+
#[cfg(test)]
1005+
/// Returns whether the decrypted data contains the given `&str`.
1006+
pub(crate) fn decoded_data_contains(&self, s: &str) -> bool {
1007+
assert!(!self.decrypting_failed);
1008+
let decoded_str = str::from_utf8(&self.decoded_data).unwrap();
1009+
decoded_str.contains(s)
1010+
}
1011+
10041012
/// Returns `Chat-Group-ID` header value if it is a valid group ID.
10051013
pub fn get_chat_group_id(&self) -> Option<&str> {
10061014
self.get_header(HeaderDef::ChatGroupId)

0 commit comments

Comments
 (0)