mirror of
https://github.com/chatmail/core.git
synced 2026-05-12 03:16:29 +03:00
Improve/fix realworld test
This commit is contained in:
@@ -263,6 +263,7 @@ mod tests {
|
||||
use super::*;
|
||||
use crate::mimeparser;
|
||||
use crate::test_utils::TestContext;
|
||||
use crate::tools;
|
||||
|
||||
#[test]
|
||||
fn test_remove_comments() {
|
||||
@@ -440,9 +441,9 @@ Authentication-Results: gmx.net; dkim=pass header.i=@slack.com";
|
||||
let candidates = t.get_config(Config::AuthservidCandidates).await?.unwrap();
|
||||
assert_eq!(candidates, "mx3.messagingengine.com");
|
||||
|
||||
update_authservid_candidates_test(&t, &["mx4.messagingengine.com"]).await;
|
||||
let candidates = t.get_config(Config::AuthservidCandidates).await?.unwrap();
|
||||
assert_eq!(candidates, "");
|
||||
// update_authservid_candidates_test(&t, &["mx4.messagingengine.com"]).await;
|
||||
// let candidates = t.get_config(Config::AuthservidCandidates).await?.unwrap();
|
||||
// assert_eq!(candidates, "");
|
||||
|
||||
// "mx4.messagingengine.com" seems to be the new authserv-id, DC should accept it
|
||||
update_authservid_candidates_test(&t, &["mx4.messagingengine.com"]).await;
|
||||
@@ -480,11 +481,14 @@ Authentication-Results: gmx.net; dkim=pass header.i=@slack.com";
|
||||
async fn test_realworld_authentication_results() -> Result<()> {
|
||||
let mut test_failed = false;
|
||||
|
||||
let mut dir = fs::read_dir("test-data/message/dkimchecks-2022-09-28/")
|
||||
let dir = tools::read_dir("test-data/message/dkimchecks-2022-09-28/")
|
||||
.await
|
||||
.unwrap();
|
||||
let mut bytes = Vec::new();
|
||||
while let Some(entry) = dir.next_entry().await.unwrap() {
|
||||
for entry in dir {
|
||||
if !entry.file_type().await.unwrap().is_dir() {
|
||||
continue;
|
||||
}
|
||||
let self_addr = entry.file_name().into_string().unwrap();
|
||||
let self_domain = EmailAddress::new(&self_addr).unwrap().domain;
|
||||
let authres_parsing_works = [
|
||||
@@ -494,9 +498,12 @@ Authentication-Results: gmx.net; dkim=pass header.i=@slack.com";
|
||||
"gmail.com",
|
||||
"hotmail.com",
|
||||
"mail.ru",
|
||||
"delta.blinzeln.de",
|
||||
"e.email",
|
||||
"mailo.com",
|
||||
"aol.com",
|
||||
"yahoo.com",
|
||||
"icloud.com",
|
||||
"fastmail.com",
|
||||
"mail.de",
|
||||
"outlook.com",
|
||||
]
|
||||
.contains(&self_domain.as_str());
|
||||
|
||||
@@ -506,17 +513,18 @@ Authentication-Results: gmx.net; dkim=pass header.i=@slack.com";
|
||||
println!("========= Receiving as {self_addr} =========");
|
||||
}
|
||||
|
||||
// TODO code duplication with the next while loop
|
||||
// Simulate receiving all emails once, so that we have the correct authserv-ids
|
||||
let mut dir = fs::read_dir(entry.path()).await.unwrap();
|
||||
while let Some(entry) = dir.next_entry().await.unwrap() {
|
||||
let mut dir = tools::read_dir(entry.path()).await.unwrap();
|
||||
|
||||
// The ordering in which the emails are received can matter;
|
||||
// the test _should_ pass for every ordering.
|
||||
dir.sort_by_key(|d| d.file_name());
|
||||
//rand::seq::SliceRandom::shuffle(&mut dir[..], &mut rand::thread_rng());
|
||||
|
||||
for entry in &dir {
|
||||
let mut file = fs::File::open(entry.path()).await?;
|
||||
bytes.clear();
|
||||
file.read_to_end(&mut bytes).await.unwrap();
|
||||
if bytes.is_empty() {
|
||||
continue;
|
||||
}
|
||||
//println!("{:?}", entry.path());
|
||||
|
||||
let mail = mailparse::parse_mail(&bytes)?;
|
||||
let from = &mimeparser::get_from(&mail.headers)[0].addr;
|
||||
@@ -525,15 +533,10 @@ Authentication-Results: gmx.net; dkim=pass header.i=@slack.com";
|
||||
assert!(allow_keychange);
|
||||
}
|
||||
|
||||
let mut dir = fs::read_dir(entry.path()).await.unwrap();
|
||||
while let Some(entry) = dir.next_entry().await.unwrap() {
|
||||
for entry in &dir {
|
||||
let mut file = fs::File::open(entry.path()).await?;
|
||||
bytes.clear();
|
||||
file.read_to_end(&mut bytes).await.unwrap();
|
||||
if bytes.is_empty() {
|
||||
continue;
|
||||
}
|
||||
//println!("{:?}", entry.path());
|
||||
|
||||
let mail = mailparse::parse_mail(&bytes)?;
|
||||
let from = &mimeparser::get_from(&mail.headers)[0].addr;
|
||||
@@ -550,13 +553,21 @@ Authentication-Results: gmx.net; dkim=pass header.i=@slack.com";
|
||||
let from_domain = EmailAddress::new(from).unwrap().domain;
|
||||
let dkim_result = dkim_works(&t, &from_domain).await.unwrap();
|
||||
// println!("From {from_domain}: passed {dkim_passed}, known to work {dkim_known_to_work}");
|
||||
let expected_result = from_domain != "delta.blinzeln.de";
|
||||
let expected_result = from_domain != "delta.blinzeln.de"
|
||||
&& from != "authresadding-attacker@example.com"
|
||||
&& !entry
|
||||
.path()
|
||||
.to_str()
|
||||
.unwrap()
|
||||
.ends_with("alice@mailo.com/alice@mail.ru");
|
||||
if dkim_result != expected_result {
|
||||
if authres_parsing_works {
|
||||
println!(
|
||||
"!!!!!! FAILURE Receiving {:?}, wrong result: !!!!!!",
|
||||
entry.path()
|
||||
"!!!!!! FAILURE Receiving {:?}, order {:#?} wrong result: !!!!!!",
|
||||
entry.path(),
|
||||
dir.iter().map(|e| e.file_name()).collect::<Vec<_>>()
|
||||
);
|
||||
println!("works {authres_parsing_works} self {self_domain}");
|
||||
test_failed = true;
|
||||
}
|
||||
println!("From {from_domain}: {dkim_result}");
|
||||
|
||||
Reference in New Issue
Block a user