mod common; pub use common::*; use indymilter_test::*; use spf_milter::*; #[tokio::test] async fn trusted_clients() { let opts = configure_logging(CliOptions::builder()) .config_file(to_config_file_name(file!())) .build(); let lookup = MockLookup::default(); let config = Config::read_with_lookup(opts, lookup).await.unwrap(); let milter = SpfMilter::spawn(config).await.unwrap(); let addr = milter.addr(); // Test 1: Accept connection from loopback address let mut conn = TestConnection::open(addr).await.unwrap(); let status = conn.connect("client.example.org", [127, 0, 0, 2]).await.unwrap(); assert_eq!(status, Status::Accept); conn.close().await.unwrap(); // Test 2: Accept connection from trusted IPv4 address let mut conn = TestConnection::open(addr).await.unwrap(); let status = conn.connect("client.example.org", [123, 123, 123, 123]).await.unwrap(); assert_eq!(status, Status::Accept); conn.close().await.unwrap(); // Test 3: Accept connection from trusted IPv6 address let mut conn = TestConnection::open(addr).await.unwrap(); let status = conn.connect("client.example.org", [0x123, 0, 0, 0, 0, 0, 0x123, 0x123]).await.unwrap(); assert_eq!(status, Status::Accept); conn.close().await.unwrap(); // Test 4: Accept message from authenticated sender let mut conn = TestConnection::open(addr).await.unwrap(); conn.macros(MacroStage::Connect, [("j", "mail.gluet.ch")]).await.unwrap(); let status = conn.connect("client.example.org", [7, 6, 5, 4]).await.unwrap(); assert_eq!(status, Status::Continue); let status = conn.helo("mail.example.org").await.unwrap(); assert_eq!(status, Status::Continue); conn.macros(MacroStage::Mail, [("{auth_authen}", "from@example.org")]).await.unwrap(); let status = conn.mail([""]).await.unwrap(); assert_eq!(status, Status::Accept); conn.close().await.unwrap(); milter.shutdown().await.unwrap(); }