Repair getting x-failed-recipients header, all tests passing now

This commit is contained in:
Hocuri
2020-06-10 15:27:20 +02:00
parent 777df24c75
commit bde97b20e9
3 changed files with 12 additions and 36 deletions

View File

@@ -1779,7 +1779,7 @@ mod tests {
use crate::chat::ChatVisibility; use crate::chat::ChatVisibility;
use crate::chatlist::Chatlist; use crate::chatlist::Chatlist;
use crate::message::Message; use crate::message::Message;
use crate::test_utils::{configured_offline_context, dummy_context}; use crate::test_utils::*;
#[test] #[test]
fn test_hex_hash() { fn test_hex_hash() {
@@ -2380,19 +2380,7 @@ mod tests {
raw_ndn: &[u8], raw_ndn: &[u8],
error_msg: &str, error_msg: &str,
) { ) {
let t = dummy_context().await; let t = configured_offline_context_with_addr(self_addr).await;
t.ctx
.set_config(Config::Addr, Some(self_addr))
.await
.unwrap();
t.ctx
.set_config(Config::ConfiguredAddr, Some(self_addr))
.await
.unwrap();
t.ctx
.set_config(Config::Configured, Some("1"))
.await
.unwrap();
dc_receive_imf( dc_receive_imf(
&t.ctx, &t.ctx,
@@ -2429,26 +2417,14 @@ mod tests {
#[async_std::test] #[async_std::test]
async fn test_parse_ndn_group_msg() { async fn test_parse_ndn_group_msg() {
let t = dummy_context().await; let t = configured_offline_context_with_addr("alice@gmail.com").await;
t.ctx
.set_config(Config::Addr, Some("alice@gmail.com"))
.await
.unwrap();
t.ctx
.set_config(Config::ConfiguredAddr, Some("alice@gmail.com"))
.await
.unwrap();
t.ctx
.set_config(Config::Configured, Some("1"))
.await
.unwrap();
dc_receive_imf( dc_receive_imf(
&t.ctx, &t.ctx,
b"From: alice@gmail.com\n\ b"From: alice@gmail.com\n\
To: bob@example.org, assidhfaaspocwaeofi@gmail.com\n\ To: bob@example.org, assidhfaaspocwaeofi@gmail.com\n\
Subject: foo\n\ Subject: foo\n\
Message-ID: <CABXKi8zruXJc_6e4Dr087H5wE7sLp+u250o0N2q5DdjF_r-8wg@mail.gmail.com>\n\ Message-ID: <CADWx9Cs32Wa7Gy-gM0bvbq54P_FEHe7UcsAV=yW7sVVW=fiMYQ@mail.gmail.com>\n\
Chat-Version: 1.0\n\ Chat-Version: 1.0\n\
Chat-Group-ID: abcde\n\ Chat-Group-ID: abcde\n\
Chat-Group-Name: foo\n\ Chat-Group-Name: foo\n\
@@ -2477,12 +2453,10 @@ mod tests {
assert_eq!(msg.state, MessageState::OutFailed); assert_eq!(msg.state, MessageState::OutFailed);
let msgs = chat::get_chat_msgs(&t.ctx, msg.chat_id, 0, None).await; let msgs = chat::get_chat_msgs(&t.ctx, msg.chat_id, 0, None).await;
println!("Loading {}", msg.chat_id);
let last_msg = Message::load_from_db(&t.ctx, *msgs.last().unwrap()) let last_msg = Message::load_from_db(&t.ctx, *msgs.last().unwrap())
.await .await
.unwrap(); .unwrap();
assert_eq!(last_msg.from_id, DC_CONTACT_ID_INFO);
assert_eq!( assert_eq!(
last_msg.text, last_msg.text,
Some( Some(
@@ -2494,5 +2468,6 @@ mod tests {
.await, .await,
) )
); );
assert_eq!(last_msg.from_id, DC_CONTACT_ID_INFO);
} }
} }

View File

@@ -876,7 +876,7 @@ impl MimeMessage {
.and_then(|v| parse_message_id(&v).ok()) .and_then(|v| parse_message_id(&v).ok())
{ {
let mut to_list = get_all_addresses_from_header(&report.headers, |header_key| { let mut to_list = get_all_addresses_from_header(&report.headers, |header_key| {
header_key == "X-Failed-Recipients" header_key == "x-failed-recipients"
}); });
let to = if to_list.len() == 1 { let to = if to_list.len() == 1 {
Some(to_list.pop().unwrap()) Some(to_list.pop().unwrap())

View File

@@ -41,13 +41,14 @@ pub(crate) async fn dummy_context() -> TestContext {
} }
pub(crate) async fn configured_offline_context() -> TestContext { pub(crate) async fn configured_offline_context() -> TestContext {
configured_offline_context_with_addr("alice@example.org").await
}
pub(crate) async fn configured_offline_context_with_addr(addr: &str) -> TestContext {
let t = dummy_context().await; let t = dummy_context().await;
t.ctx.set_config(Config::Addr, Some(addr)).await.unwrap();
t.ctx t.ctx
.set_config(Config::Addr, Some("alice@example.org")) .set_config(Config::ConfiguredAddr, Some(addr))
.await
.unwrap();
t.ctx
.set_config(Config::ConfiguredAddr, Some("alice@example.org"))
.await .await
.unwrap(); .unwrap();
t.ctx t.ctx