Skip to content

Commit 3a41d3a

Browse files
committed
test: Add regression test for verification-gossiping crash
1 parent c28dabb commit 3a41d3a

File tree

2 files changed

+44
-3
lines changed

2 files changed

+44
-3
lines changed

src/mimefactory.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ pub struct MimeFactory {
100100
/// e.g. if members are hidden for broadcast channels
101101
/// or if the keys for some recipients are missing
102102
/// and encrypted message cannot be sent to them.
103-
to: Vec<(String, String)>,
103+
pub(crate) to: Vec<(String, String)>,
104104

105105
/// Vector of pairs of past group member names and addresses.
106106
past_members: Vec<(String, String)>,
@@ -110,14 +110,14 @@ pub struct MimeFactory {
110110
///
111111
/// If this is not empty, its length
112112
/// should be the sum of `to` and `past_members` length.
113-
member_fingerprints: Vec<String>,
113+
pub(crate) member_fingerprints: Vec<String>,
114114

115115
/// Timestamps of the members in the same order as in the `to`
116116
/// followed by `past_members`.
117117
///
118118
/// If this is not empty, its length
119119
/// should be the sum of `to` and `past_members` length.
120-
member_timestamps: Vec<i64>,
120+
pub(crate) member_timestamps: Vec<i64>,
121121

122122
timestamp: i64,
123123
loaded: Loaded,

src/receive_imf/receive_imf_tests.rs

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ use crate::contact;
1414
use crate::download::MIN_DOWNLOAD_LIMIT;
1515
use crate::imap::prefetch_should_download;
1616
use crate::imex::{ImexMode, imex};
17+
use crate::mimefactory::MimeFactory;
1718
use crate::securejoin::get_securejoin_qr;
1819
use crate::test_utils::{
1920
E2EE_INFO_MSGS, TestContext, TestContextManager, get_chat_msg, mark_as_verified,
@@ -3050,6 +3051,46 @@ async fn test_auto_accept_protected_group_for_bots() -> Result<()> {
30503051
Ok(())
30513052
}
30523053

3054+
/// Regression test for a bug where receive_imf() failed
3055+
/// if the sender of a message also put itself into the recipients list.
3056+
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
3057+
async fn test_verification_gossip() -> Result<()> {
3058+
let mut tcm = TestContextManager::new();
3059+
let alice = &tcm.alice().await;
3060+
let bob = &tcm.bob().await;
3061+
let fiona = &tcm.fiona().await;
3062+
3063+
mark_as_verified(alice, bob).await;
3064+
mark_as_verified(bob, alice).await;
3065+
3066+
mark_as_verified(alice, fiona).await;
3067+
mark_as_verified(fiona, alice).await;
3068+
3069+
let group_id = alice
3070+
.create_group_with_members(ProtectionStatus::Protected, "Group", &[bob, fiona])
3071+
.await;
3072+
3073+
let mut msg = Message::new_text("Hello!".to_string());
3074+
msg.chat_id = group_id;
3075+
msg.from_id = ContactId::SELF;
3076+
msg.rfc724_mid = "rfc724_mid".to_string();
3077+
msg.id = MsgId::new(10);
3078+
let mut mime_factory = MimeFactory::from_msg(alice, msg).await?;
3079+
mime_factory
3080+
.to
3081+
.push(("Alice".to_string(), "[email protected]".to_string()));
3082+
mime_factory
3083+
.member_fingerprints
3084+
.push(crate::key::self_fingerprint(alice).await?.to_string());
3085+
mime_factory.member_timestamps.push(0);
3086+
let rendered = mime_factory.render(alice).await?;
3087+
let imf_raw = rendered.message.as_bytes();
3088+
3089+
let _msg = receive_imf(bob, imf_raw, false).await?;
3090+
3091+
Ok(())
3092+
}
3093+
30533094
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
30543095
async fn test_bot_accepts_another_group_after_qr_scan() -> Result<()> {
30553096
let mut tcm = TestContextManager::new();

0 commit comments

Comments
 (0)