mod common; pub use common::*; use indymilter_test::*; use spf_milter::*; #[tokio::test] async fn delete_auth_results() { let opts = configure_logging(CliOptions::builder()) .config_file(to_config_file_name(file!())) .build(); let lookup = MockLookup::new() .with_lookup_txt(|_| Ok(vec!["v=spf1 ~all".into()])); let config = Config::read_with_lookup(opts, lookup).await.unwrap(); let milter = SpfMilter::spawn(config).await.unwrap(); let mut conn = TestConnection::open(milter.addr()).await.unwrap(); conn.macros(MacroStage::Connect, [("j", "mail.gluet.ch")]).await.unwrap(); let status = conn.connect("client.example.org", [123, 123, 123, 123]).await.unwrap(); assert_eq!(status, Status::Continue); let status = conn.helo("mail.example.org").await.unwrap(); assert_eq!(status, Status::Continue); let status = conn.mail([""]).await.unwrap(); assert_eq!(status, Status::Continue); conn.macros(MacroStage::Data, [("i", "1234567ABC")]).await.unwrap(); let status = conn.header("Authentication-Results", "\ (different authserv-id:) myhost.org 1; spf=pass smtp.mailfrom=example.org").await.unwrap(); assert_eq!(status, Status::Continue); let status = conn.header("Authentication-Results", "\ (invalid authserv-id:) mail.gluet.ch/1234; spf=pass smtp.mailfrom=example.org").await.unwrap(); assert_eq!(status, Status::Continue); let status = conn.header("Authentication-Results", "\ (unusual but legal comment) \"mail.G\\luet.ch\" (<- attempt to bypass deletion!); spf=pass smtp.mailfrom=example.org").await.unwrap(); assert_eq!(status, Status::Continue); let (actions, status) = conn.eom().await.unwrap(); assert_eq!(status, Status::Continue); assert!(actions.has_delete_header("Authentication-Results", 3)); assert!(actions.has_insert_header( 0, "Authentication-Results", "mail.gluet.ch; spf=softfail smtp.mailfrom=example.org" )); conn.close().await.unwrap(); milter.shutdown().await.unwrap(); }