diff --git a/README.md b/README.md index 93c1159..c93de28 100644 --- a/README.md +++ b/README.md @@ -99,7 +99,8 @@ spamassassin-milter -h ``` More detailed information can be found in the provided man page -*spamassassin-milter*(8). +*spamassassin-milter*(8). (You can view the man page without installing by +passing the file’s path to `man`: `man ./spamassassin-milter.8`) Setting up SpamAssassin Milter as a system service is easiest by using the provided systemd service file: Edit `spamassassin-milter.service` with the diff --git a/tests/common/mod.rs b/tests/common/mod.rs index ee7b124..8ab33fb 100644 --- a/tests/common/mod.rs +++ b/tests/common/mod.rs @@ -9,13 +9,15 @@ use std::{ time::{Duration, Instant}, }; -// A file `/etc/spamassassin/spamc.conf` present on the host is read by `spamc` -// by default and may break the integration tests. Isolate `spamc` by overriding -// the configuration file location. -pub fn isolate_from_spamc_conf(mut builder: ConfigBuilder) -> ConfigBuilder { - // Must use `-F` instead of `--config` due to a bug in `spamc`. - // Additionally, `--log-to-stderr` avoids polluting syslog with test output. - builder.spamc_args(vec!["-F", "/dev/null", "--log-to-stderr"]); +/// Configures the builder for integration testing with `spamc`. Most +/// importantly, this isolates `spamc` from any configuration file +/// `/etc/spamassassin/spamc.conf` present on the host, as this configuration is +/// read by default and may break the integration tests. +pub fn configure_spamc(mut builder: ConfigBuilder) -> ConfigBuilder { + // Note: Must use `-F` instead of `--config` due to a bug in `spamc`. + // `--no-safe-fallback` prevents connection attempts from failing silently, + // and `--log-to-stderr` avoids polluting syslog with test output. + builder.spamc_args(&["-F", "/dev/null", "--no-safe-fallback", "--log-to-stderr"]); builder } diff --git a/tests/ham_message.rs b/tests/ham_message.rs index abdb9c6..626cf33 100644 --- a/tests/ham_message.rs +++ b/tests/ham_message.rs @@ -5,8 +5,8 @@ use spamassassin_milter::*; #[test] fn ham_message() { - let mut builder = isolate_from_spamc_conf(Config::builder()); - builder.spamc_args(vec![format!("--port={}", SPAMD_PORT)]); + let mut builder = configure_spamc(Config::builder()); + builder.spamc_args(&[format!("--port={}", SPAMD_PORT)]); let config = builder.build(); let server = spawn_mock_spamd_server(SPAMD_PORT, |ham| { diff --git a/tests/live.rs b/tests/live.rs index 5c1f99c..aa79698 100644 --- a/tests/live.rs +++ b/tests/live.rs @@ -7,11 +7,11 @@ use spamassassin_milter::*; /// run on demand, as SpamAssassin will actually analyse the input, and do DNS /// queries etc. #[test] -#[ignore] // use option `--include-ignored` to run +#[ignore] fn live() { - // Without `spamc_args` set, `spamc` will try to connect to the default + // When no port is specified, `spamc` will try to connect to the default // `spamd` port 783 (see also `/etc/services`). - let config = isolate_from_spamc_conf(Config::builder()).build(); + let config = configure_spamc(Config::builder()).build(); let miltertest = spawn_miltertest_runner(file!()); diff --git a/tests/reject_spam.rs b/tests/reject_spam.rs index da2fffd..94f6208 100644 --- a/tests/reject_spam.rs +++ b/tests/reject_spam.rs @@ -5,12 +5,12 @@ use spamassassin_milter::*; #[test] fn reject_spam() { - let mut builder = isolate_from_spamc_conf(Config::builder()); + let mut builder = configure_spamc(Config::builder()); builder .reject_spam(true) .reply_code("554".into()) .reply_text("Not allowed!".into()) - .spamc_args(vec![format!("--port={}", SPAMD_PORT)]); + .spamc_args(&[format!("--port={}", SPAMD_PORT)]); let config = builder.build(); let server = spawn_mock_spamd_server(SPAMD_PORT, |spam| { diff --git a/tests/skip_oversized.rs b/tests/skip_oversized.rs index bf77bbc..f14534e 100644 --- a/tests/skip_oversized.rs +++ b/tests/skip_oversized.rs @@ -5,9 +5,10 @@ use spamassassin_milter::*; #[test] fn skip_oversized() { - let mut builder = isolate_from_spamc_conf(Config::builder()); - builder.max_message_size(512); - builder.spamc_args(vec![format!("--port={}", SPAMD_PORT)]); + let mut builder = configure_spamc(Config::builder()); + builder + .max_message_size(512) + .spamc_args(&[format!("--port={}", SPAMD_PORT)]); let config = builder.build(); let server = spawn_mock_spamd_server(SPAMD_PORT, Ok); diff --git a/tests/spam_message.rs b/tests/spam_message.rs index 5cefc15..bb30344 100644 --- a/tests/spam_message.rs +++ b/tests/spam_message.rs @@ -5,8 +5,8 @@ use spamassassin_milter::*; #[test] fn spam_message() { - let mut builder = isolate_from_spamc_conf(Config::builder()); - builder.spamc_args(vec![format!("--port={}", SPAMD_PORT)]); + let mut builder = configure_spamc(Config::builder()); + builder.spamc_args(&[format!("--port={}", SPAMD_PORT)]); let config = builder.build(); let server = spawn_mock_spamd_server(SPAMD_PORT, |spam| { diff --git a/tests/spamc_connection_error.rs b/tests/spamc_connection_error.rs index 45168e8..8ce0e37 100644 --- a/tests/spamc_connection_error.rs +++ b/tests/spamc_connection_error.rs @@ -5,13 +5,8 @@ use spamassassin_milter::*; #[test] fn spamc_connection_error() { - let mut builder = isolate_from_spamc_conf(Config::builder()); - // `spamc` always ‘works’ even if it cannot actually reach `spamd`! - // `--no-safe-fallback` prevents this masking of connection errors. - builder.spamc_args(vec![ - String::from("--no-safe-fallback"), - format!("--port={}", SPAMD_PORT), - ]); + let mut builder = configure_spamc(Config::builder()); + builder.spamc_args(&[format!("--port={}", SPAMD_PORT)]); let config = builder.build(); let miltertest = spawn_miltertest_runner(file!());