mirror of
https://github.com/chatmail/core.git
synced 2026-05-08 17:36:29 +03:00
test: HP-Outer headers are added to messages with standard Header Protection (#7130)
This commit is contained in:
@@ -2632,12 +2632,6 @@ async fn test_can_send_group() -> Result<()> {
|
|||||||
/// the recipients can't see the identity of their fellow recipients.
|
/// the recipients can't see the identity of their fellow recipients.
|
||||||
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
|
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
|
||||||
async fn test_broadcast_members_cant_see_each_other() -> Result<()> {
|
async fn test_broadcast_members_cant_see_each_other() -> Result<()> {
|
||||||
fn contains(parsed: &MimeMessage, s: &str) -> bool {
|
|
||||||
assert_eq!(parsed.decrypting_failed, false);
|
|
||||||
let decoded_str = std::str::from_utf8(&parsed.decoded_data).unwrap();
|
|
||||||
decoded_str.contains(s)
|
|
||||||
}
|
|
||||||
|
|
||||||
let mut tcm = TestContextManager::new();
|
let mut tcm = TestContextManager::new();
|
||||||
let alice = &tcm.alice().await;
|
let alice = &tcm.alice().await;
|
||||||
let bob = &tcm.bob().await;
|
let bob = &tcm.bob().await;
|
||||||
@@ -2669,8 +2663,8 @@ async fn test_broadcast_members_cant_see_each_other() -> Result<()> {
|
|||||||
);
|
);
|
||||||
let parsed = charlie.parse_msg(&auth_required).await;
|
let parsed = charlie.parse_msg(&auth_required).await;
|
||||||
assert!(parsed.get_header(HeaderDef::AutocryptGossip).is_some());
|
assert!(parsed.get_header(HeaderDef::AutocryptGossip).is_some());
|
||||||
assert!(contains(&parsed, "charlie@example.net"));
|
assert!(parsed.decoded_data_contains("charlie@example.net"));
|
||||||
assert_eq!(contains(&parsed, "bob@example.net"), false);
|
assert_eq!(parsed.decoded_data_contains("bob@example.net"), false);
|
||||||
|
|
||||||
let parsed_by_bob = bob.parse_msg(&auth_required).await;
|
let parsed_by_bob = bob.parse_msg(&auth_required).await;
|
||||||
assert!(parsed_by_bob.decrypting_failed);
|
assert!(parsed_by_bob.decrypting_failed);
|
||||||
@@ -2698,8 +2692,8 @@ async fn test_broadcast_members_cant_see_each_other() -> Result<()> {
|
|||||||
);
|
);
|
||||||
let parsed = charlie.parse_msg(&member_added).await;
|
let parsed = charlie.parse_msg(&member_added).await;
|
||||||
assert!(parsed.get_header(HeaderDef::AutocryptGossip).is_some());
|
assert!(parsed.get_header(HeaderDef::AutocryptGossip).is_some());
|
||||||
assert!(contains(&parsed, "charlie@example.net"));
|
assert!(parsed.decoded_data_contains("charlie@example.net"));
|
||||||
assert_eq!(contains(&parsed, "bob@example.net"), false);
|
assert_eq!(parsed.decoded_data_contains("bob@example.net"), false);
|
||||||
|
|
||||||
let parsed_by_bob = bob.parse_msg(&member_added).await;
|
let parsed_by_bob = bob.parse_msg(&member_added).await;
|
||||||
assert!(parsed_by_bob.decrypting_failed);
|
assert!(parsed_by_bob.decrypting_failed);
|
||||||
@@ -2713,8 +2707,8 @@ async fn test_broadcast_members_cant_see_each_other() -> Result<()> {
|
|||||||
let hi_msg = alice.send_text(alice_broadcast_id, "hi").await;
|
let hi_msg = alice.send_text(alice_broadcast_id, "hi").await;
|
||||||
let parsed = charlie.parse_msg(&hi_msg).await;
|
let parsed = charlie.parse_msg(&hi_msg).await;
|
||||||
assert_eq!(parsed.header_exists(HeaderDef::AutocryptGossip), false);
|
assert_eq!(parsed.header_exists(HeaderDef::AutocryptGossip), false);
|
||||||
assert_eq!(contains(&parsed, "charlie@example.net"), false);
|
assert_eq!(parsed.decoded_data_contains("charlie@example.net"), false);
|
||||||
assert_eq!(contains(&parsed, "bob@example.net"), false);
|
assert_eq!(parsed.decoded_data_contains("bob@example.net"), false);
|
||||||
|
|
||||||
let parsed_by_bob = bob.parse_msg(&hi_msg).await;
|
let parsed_by_bob = bob.parse_msg(&hi_msg).await;
|
||||||
assert_eq!(parsed_by_bob.decrypting_failed, false);
|
assert_eq!(parsed_by_bob.decrypting_failed, false);
|
||||||
@@ -2730,8 +2724,8 @@ async fn test_broadcast_members_cant_see_each_other() -> Result<()> {
|
|||||||
"charlie@example.net alice@example.org"
|
"charlie@example.net alice@example.org"
|
||||||
);
|
);
|
||||||
let parsed = charlie.parse_msg(&member_removed).await;
|
let parsed = charlie.parse_msg(&member_removed).await;
|
||||||
assert!(contains(&parsed, "charlie@example.net"));
|
assert!(parsed.decoded_data_contains("charlie@example.net"));
|
||||||
assert_eq!(contains(&parsed, "bob@example.net"), false);
|
assert_eq!(parsed.decoded_data_contains("bob@example.net"), false);
|
||||||
|
|
||||||
let parsed_by_bob = bob.parse_msg(&member_removed).await;
|
let parsed_by_bob = bob.parse_msg(&member_removed).await;
|
||||||
assert!(parsed_by_bob.decrypting_failed);
|
assert!(parsed_by_bob.decrypting_failed);
|
||||||
|
|||||||
@@ -138,6 +138,9 @@ pub enum HeaderDef {
|
|||||||
/// Advertised gossip topic for one webxdc.
|
/// Advertised gossip topic for one webxdc.
|
||||||
IrohGossipTopic,
|
IrohGossipTopic,
|
||||||
|
|
||||||
|
/// See <https://www.rfc-editor.org/rfc/rfc9788.html#name-hp-outer-header-field>.
|
||||||
|
HpOuter,
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
TestHeader,
|
TestHeader,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -837,6 +837,30 @@ async fn test_protected_headers_directive() -> Result<()> {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
|
||||||
|
async fn test_hp_outer_headers() -> Result<()> {
|
||||||
|
let mut tcm = TestContextManager::new();
|
||||||
|
let t = &tcm.alice().await;
|
||||||
|
let chat_id = t.get_self_chat().await.id;
|
||||||
|
|
||||||
|
for std_hp_composing in [false, true] {
|
||||||
|
t.set_config_bool(Config::StdHeaderProtectionComposing, std_hp_composing)
|
||||||
|
.await?;
|
||||||
|
chat::send_text_msg(t, chat_id, "hi!".to_string()).await?;
|
||||||
|
let sent_msg = t.pop_sent_msg().await;
|
||||||
|
let msg = MimeMessage::from_bytes(t, sent_msg.payload.as_bytes(), None).await?;
|
||||||
|
assert_eq!(msg.header_exists(HeaderDef::HpOuter), std_hp_composing);
|
||||||
|
for hdr in ["Date", "From", "Message-ID"] {
|
||||||
|
assert_eq!(
|
||||||
|
msg.decoded_data_contains(&format!("HP-Outer: {hdr}:")),
|
||||||
|
std_hp_composing,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
assert!(!msg.decoded_data_contains("HP-Outer: Content-Type"));
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
|
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
|
||||||
async fn test_dont_remove_self() -> Result<()> {
|
async fn test_dont_remove_self() -> Result<()> {
|
||||||
let mut tcm = TestContextManager::new();
|
let mut tcm = TestContextManager::new();
|
||||||
|
|||||||
@@ -1007,6 +1007,14 @@ impl MimeMessage {
|
|||||||
self.headers.contains_key(hname) || self.headers_removed.contains(hname)
|
self.headers.contains_key(hname) || self.headers_removed.contains(hname)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
/// Returns whether the decrypted data contains the given `&str`.
|
||||||
|
pub(crate) fn decoded_data_contains(&self, s: &str) -> bool {
|
||||||
|
assert!(!self.decrypting_failed);
|
||||||
|
let decoded_str = str::from_utf8(&self.decoded_data).unwrap();
|
||||||
|
decoded_str.contains(s)
|
||||||
|
}
|
||||||
|
|
||||||
/// Returns `Chat-Group-ID` header value if it is a valid group ID.
|
/// Returns `Chat-Group-ID` header value if it is a valid group ID.
|
||||||
pub fn get_chat_group_id(&self) -> Option<&str> {
|
pub fn get_chat_group_id(&self) -> Option<&str> {
|
||||||
self.get_header(HeaderDef::ChatGroupId)
|
self.get_header(HeaderDef::ChatGroupId)
|
||||||
|
|||||||
Reference in New Issue
Block a user