From b5ad9ce0ddb0e1fa0f1dce99040619f1651f5a4a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20B=C3=BCrgin?= Date: Tue, 21 Dec 2021 18:40:01 +0100 Subject: [PATCH] Complete eom with Status::Continue, cosmetics --- CHANGELOG.md | 2 ++ README.md | 2 +- src/client.rs | 6 +++--- tests/authenticated_sender.lua | 2 +- tests/authenticated_sender.rs | 2 +- tests/ham_message.lua | 4 ++-- tests/ham_message.rs | 3 ++- tests/live.lua | 4 ++-- tests/live.rs | 2 +- tests/loopback_connection.lua | 4 ++-- tests/loopback_connection.rs | 2 +- tests/reject_spam.lua | 4 ++-- tests/reject_spam.rs | 3 ++- tests/skip_oversized.lua | 4 ++-- tests/skip_oversized.rs | 2 +- tests/spam_message.lua | 4 ++-- tests/spam_message.rs | 3 ++- tests/spamc_connection_error.lua | 2 +- tests/spamc_connection_error.rs | 2 +- tests/trusted_network_connection.lua | 2 +- tests/trusted_network_connection.rs | 2 +- 21 files changed, 33 insertions(+), 28 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f68ca4a..8ef1ced 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ ## 0.2.1 (unreleased) +* Various cosmetic improvements in code and tests, and updates to + documentation. * Update dependencies. ## 0.2.0 (2021-08-26) diff --git a/README.md b/README.md index 83c7711..30060f8 100644 --- a/README.md +++ b/README.md @@ -55,7 +55,7 @@ provided `milter.pc` file. Put this file on the pkg-config path when running any Cargo command: ``` -PKG_CONFIG_PATH=. cargo build +PKG_CONFIG_PATH=/path/to/milter.pc cargo build ``` SpamAssassin Milter uses the `spamc` program for communication with SpamAssassin diff --git a/src/client.rs b/src/client.rs index a5414f0..7c39589 100644 --- a/src/client.rs +++ b/src/client.rs @@ -292,7 +292,7 @@ impl Client { } } - Ok(Status::Accept) + Ok(Status::Continue) } } @@ -562,7 +562,7 @@ mod tests { let status = client.process("id", &actions, &config).unwrap(); - assert_eq!(status, Status::Accept); + assert_eq!(status, Status::Continue); assert_eq!( actions.called.borrow().as_slice(), [ @@ -588,7 +588,7 @@ mod tests { let status = client.process("id", &actions, &config).unwrap(); - assert_eq!(status, Status::Accept); + assert_eq!(status, Status::Continue); let called = actions.called.borrow(); assert!(called.contains(&Action::InsertHeader(0, "X-Spam-Level".into(), " *****".into()))); diff --git a/tests/authenticated_sender.lua b/tests/authenticated_sender.lua index 8fdf570..f5d482e 100644 --- a/tests/authenticated_sender.lua +++ b/tests/authenticated_sender.lua @@ -1,6 +1,6 @@ -- An authenticated sender is accepted, the message is not processed. -conn = mt.connect("inet:3333@localhost") +local conn = mt.connect("inet:3333@localhost") assert(conn, "could not open connection") local err = mt.conninfo(conn, "client.gluet.ch", "123.123.123.123") diff --git a/tests/authenticated_sender.rs b/tests/authenticated_sender.rs index ff2478c..a7ff5b5 100644 --- a/tests/authenticated_sender.rs +++ b/tests/authenticated_sender.rs @@ -1,6 +1,6 @@ mod common; -pub use common::*; // `pub` only to silence unused code warnings +pub use common::*; use spamassassin_milter::*; #[test] diff --git a/tests/ham_message.lua b/tests/ham_message.lua index 520730c..3d0b73d 100644 --- a/tests/ham_message.lua +++ b/tests/ham_message.lua @@ -1,6 +1,6 @@ -- ‘Happy path’ processing of an ordinary ham (not spam) message. -conn = mt.connect("inet:3333@localhost") +local conn = mt.connect("inet:3333@localhost") assert(conn, "could not open connection") local err = mt.conninfo(conn, "client.gluet.ch", "123.123.123.123") @@ -65,7 +65,7 @@ assert(mt.getreply(conn) == SMFIR_CONTINUE) local err = mt.eom(conn) assert(err == nil, err) -assert(mt.getreply(conn) == SMFIR_ACCEPT) +assert(mt.getreply(conn) == SMFIR_CONTINUE) assert(mt.eom_check(conn, MT_HDRINSERT, "X-Spam-Custom", " Custom-Value")) assert(mt.eom_check(conn, MT_HDRDELETE, "X-Spam-Checker-Version")) diff --git a/tests/ham_message.rs b/tests/ham_message.rs index 355533b..5954693 100644 --- a/tests/ham_message.rs +++ b/tests/ham_message.rs @@ -1,6 +1,6 @@ mod common; -pub use common::*; // `pub` only to silence unused code warnings +pub use common::*; use spamassassin_milter::*; #[test] @@ -23,6 +23,7 @@ fn ham_message() { Ok(ham) }); + let miltertest = spawn_miltertest_runner(file!()); run("inet:3333@localhost", config).expect("milter execution failed"); diff --git a/tests/live.lua b/tests/live.lua index ec7a61e..9300849 100644 --- a/tests/live.lua +++ b/tests/live.lua @@ -1,6 +1,6 @@ -- Live test against a real SpamAssassin server. -conn = mt.connect("inet:3333@localhost") +local conn = mt.connect("inet:3333@localhost") assert(conn, "could not open connection") local err = mt.conninfo(conn, "client.gluet.ch", "123.123.123.123") @@ -65,7 +65,7 @@ assert(mt.getreply(conn) == SMFIR_CONTINUE) local err = mt.eom(conn) assert(err == nil, err) -assert(mt.getreply(conn) == SMFIR_ACCEPT) +assert(mt.getreply(conn) == SMFIR_CONTINUE) local err = mt.disconnect(conn) assert(err == nil, err) diff --git a/tests/live.rs b/tests/live.rs index aa79698..c75b05f 100644 --- a/tests/live.rs +++ b/tests/live.rs @@ -1,6 +1,6 @@ mod common; -pub use common::*; // `pub` only to silence unused code warnings +pub use common::*; use spamassassin_milter::*; /// Runs a ‘live’ test against a real SpamAssassin server instance. This test is diff --git a/tests/loopback_connection.lua b/tests/loopback_connection.lua index f7e4652..6d88aa5 100644 --- a/tests/loopback_connection.lua +++ b/tests/loopback_connection.lua @@ -1,6 +1,6 @@ -- 1) A connection from the loopback IP address is accepted. -conn = mt.connect("inet:3333@localhost") +local conn = mt.connect("inet:3333@localhost") assert(conn, "could not open connection") local err = mt.conninfo(conn, nil, "127.0.0.1") @@ -13,7 +13,7 @@ assert(err == nil, err) -- 2) A connection from an ‘unknown’ IP address (for example, from a UNIX -- domain socket) is also accepted. -conn = mt.connect("inet:3333@localhost") +local conn = mt.connect("inet:3333@localhost") assert(conn, "could not open connection") local err = mt.conninfo(conn, nil, "unspec") diff --git a/tests/loopback_connection.rs b/tests/loopback_connection.rs index 156f9ac..c1fa4a7 100644 --- a/tests/loopback_connection.rs +++ b/tests/loopback_connection.rs @@ -1,6 +1,6 @@ mod common; -pub use common::*; // `pub` only to silence unused code warnings +pub use common::*; use spamassassin_milter::*; #[test] diff --git a/tests/reject_spam.lua b/tests/reject_spam.lua index 8272dad..fce5d54 100644 --- a/tests/reject_spam.lua +++ b/tests/reject_spam.lua @@ -1,6 +1,6 @@ -- A spam message is rejected with an SMTP error reply. -conn = mt.connect("inet:3333@localhost") +local conn = mt.connect("inet:3333@localhost") assert(conn, "could not open connection") local err = mt.conninfo(conn, "client.gluet.ch", "123.123.123.123") @@ -56,7 +56,7 @@ local err = mt.bodystring(conn, "Test message body") assert(err == nil, err) assert(mt.getreply(conn) == SMFIR_CONTINUE) --- A `miltertest` (or milter protocol?) pitfall: Even though we return the +-- A `miltertest` (or milter protocol) pitfall: Even though we return the -- `SMFIR_REJECT` status in the application code, because we use a custom error -- reply, we must check for `SMFIR_REPLYCODE` instead. local err = mt.eom(conn) diff --git a/tests/reject_spam.rs b/tests/reject_spam.rs index 94f6208..2be7d4e 100644 --- a/tests/reject_spam.rs +++ b/tests/reject_spam.rs @@ -1,6 +1,6 @@ mod common; -pub use common::*; // `pub` only to silence unused code warnings +pub use common::*; use spamassassin_milter::*; #[test] @@ -16,6 +16,7 @@ fn reject_spam() { let server = spawn_mock_spamd_server(SPAMD_PORT, |spam| { Err(spam.replacen("\r\n\r\n", "\r\nX-Spam-Flag: YES\r\n\r\n", 1)) }); + let miltertest = spawn_miltertest_runner(file!()); run("inet:3333@localhost", config).expect("milter execution failed"); diff --git a/tests/skip_oversized.lua b/tests/skip_oversized.lua index d31b926..acf7fa9 100644 --- a/tests/skip_oversized.lua +++ b/tests/skip_oversized.lua @@ -2,7 +2,7 @@ -- reached, the rest is skipped (oversized messages are not processed by -- SpamAssassin, so it is futile to send the whole message in this case). -conn = mt.connect("inet:3333@localhost") +local conn = mt.connect("inet:3333@localhost") assert(conn, "could not open connection") local err = mt.conninfo(conn, "client.gluet.ch", "123.123.123.123") @@ -72,7 +72,7 @@ assert(mt.getreply(conn) == SMFIR_SKIP) local err = mt.eom(conn) assert(err == nil, err) -assert(mt.getreply(conn) == SMFIR_ACCEPT) +assert(mt.getreply(conn) == SMFIR_CONTINUE) local err = mt.disconnect(conn) assert(err == nil, err) diff --git a/tests/skip_oversized.rs b/tests/skip_oversized.rs index f14534e..f5f917c 100644 --- a/tests/skip_oversized.rs +++ b/tests/skip_oversized.rs @@ -1,6 +1,6 @@ mod common; -pub use common::*; // `pub` only to silence unused code warnings +pub use common::*; use spamassassin_milter::*; #[test] diff --git a/tests/spam_message.lua b/tests/spam_message.lua index 935ecbc..121c42a 100644 --- a/tests/spam_message.lua +++ b/tests/spam_message.lua @@ -1,6 +1,6 @@ -- ‘Happy path’ processing of a spam message. -conn = mt.connect("inet:3333@localhost") +local conn = mt.connect("inet:3333@localhost") assert(conn, "could not open connection") local err = mt.conninfo(conn, "client.gluet.ch", "123.123.123.123") @@ -65,7 +65,7 @@ assert(mt.getreply(conn) == SMFIR_CONTINUE) local err = mt.eom(conn) assert(err == nil, err) -assert(mt.getreply(conn) == SMFIR_ACCEPT) +assert(mt.getreply(conn) == SMFIR_CONTINUE) assert(mt.eom_check(conn, MT_HDRDELETE, "X-Spam-Checker-Version")) assert(mt.eom_check(conn, MT_HDRADD, "X-Spam-Checker-Version", " MyChecker 1.0.0")) diff --git a/tests/spam_message.rs b/tests/spam_message.rs index d42b69d..5927402 100644 --- a/tests/spam_message.rs +++ b/tests/spam_message.rs @@ -1,6 +1,6 @@ mod common; -pub use common::*; // `pub` only to silence unused code warnings +pub use common::*; use spamassassin_milter::*; #[test] @@ -37,6 +37,7 @@ fn spam_message() { Err(spam) }); + let miltertest = spawn_miltertest_runner(file!()); run("inet:3333@localhost", config).expect("milter execution failed"); diff --git a/tests/spamc_connection_error.lua b/tests/spamc_connection_error.lua index 3aa7cd7..69dc945 100644 --- a/tests/spamc_connection_error.lua +++ b/tests/spamc_connection_error.lua @@ -1,6 +1,6 @@ -- When no `spamd` server is available, `spamc` fails to connect. -conn = mt.connect("inet:3333@localhost") +local conn = mt.connect("inet:3333@localhost") assert(conn, "could not open connection") local err = mt.conninfo(conn, "client.gluet.ch", "123.123.123.123") diff --git a/tests/spamc_connection_error.rs b/tests/spamc_connection_error.rs index 8ce0e37..a4b2d5c 100644 --- a/tests/spamc_connection_error.rs +++ b/tests/spamc_connection_error.rs @@ -1,6 +1,6 @@ mod common; -pub use common::*; // `pub` only to silence unused code warnings +pub use common::*; use spamassassin_milter::*; #[test] diff --git a/tests/trusted_network_connection.lua b/tests/trusted_network_connection.lua index 62edda5..5c9d4b0 100644 --- a/tests/trusted_network_connection.lua +++ b/tests/trusted_network_connection.lua @@ -1,6 +1,6 @@ -- A connection from a trusted network is accepted. -conn = mt.connect("inet:3333@localhost") +local conn = mt.connect("inet:3333@localhost") assert(conn, "could not open connection") local err = mt.conninfo(conn, "client.gluet.ch", "123.123.123.123") diff --git a/tests/trusted_network_connection.rs b/tests/trusted_network_connection.rs index 4b0e162..575d7a8 100644 --- a/tests/trusted_network_connection.rs +++ b/tests/trusted_network_connection.rs @@ -1,6 +1,6 @@ mod common; -pub use common::*; // `pub` only to silence unused code warnings +pub use common::*; use spamassassin_milter::*; #[test]