Pass --no-safe-fallback to spamc in tests

This commit is contained in:
David Bürgin 2020-11-28 15:46:08 +01:00
parent 8c1c9f4692
commit 4e36c3058b
8 changed files with 26 additions and 27 deletions

View file

@ -99,7 +99,8 @@ spamassassin-milter -h
``` ```
More detailed information can be found in the provided man page 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 files path to `man`: `man ./spamassassin-milter.8`)
Setting up SpamAssassin Milter as a system service is easiest by using the Setting up SpamAssassin Milter as a system service is easiest by using the
provided systemd service file: Edit `spamassassin-milter.service` with the provided systemd service file: Edit `spamassassin-milter.service` with the

View file

@ -9,13 +9,15 @@ use std::{
time::{Duration, Instant}, time::{Duration, Instant},
}; };
// A file `/etc/spamassassin/spamc.conf` present on the host is read by `spamc` /// Configures the builder for integration testing with `spamc`. Most
// by default and may break the integration tests. Isolate `spamc` by overriding /// importantly, this isolates `spamc` from any configuration file
// the configuration file location. /// `/etc/spamassassin/spamc.conf` present on the host, as this configuration is
pub fn isolate_from_spamc_conf(mut builder: ConfigBuilder) -> ConfigBuilder { /// read by default and may break the integration tests.
// Must use `-F` instead of `--config` due to a bug in `spamc`. pub fn configure_spamc(mut builder: ConfigBuilder) -> ConfigBuilder {
// Additionally, `--log-to-stderr` avoids polluting syslog with test output. // Note: Must use `-F` instead of `--config` due to a bug in `spamc`.
builder.spamc_args(vec!["-F", "/dev/null", "--log-to-stderr"]); // `--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 builder
} }

View file

@ -5,8 +5,8 @@ use spamassassin_milter::*;
#[test] #[test]
fn ham_message() { fn ham_message() {
let mut builder = isolate_from_spamc_conf(Config::builder()); let mut builder = configure_spamc(Config::builder());
builder.spamc_args(vec![format!("--port={}", SPAMD_PORT)]); builder.spamc_args(&[format!("--port={}", SPAMD_PORT)]);
let config = builder.build(); let config = builder.build();
let server = spawn_mock_spamd_server(SPAMD_PORT, |ham| { let server = spawn_mock_spamd_server(SPAMD_PORT, |ham| {

View file

@ -7,11 +7,11 @@ use spamassassin_milter::*;
/// run on demand, as SpamAssassin will actually analyse the input, and do DNS /// run on demand, as SpamAssassin will actually analyse the input, and do DNS
/// queries etc. /// queries etc.
#[test] #[test]
#[ignore] // use option `--include-ignored` to run #[ignore]
fn live() { 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`). // `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!()); let miltertest = spawn_miltertest_runner(file!());

View file

@ -5,12 +5,12 @@ use spamassassin_milter::*;
#[test] #[test]
fn reject_spam() { fn reject_spam() {
let mut builder = isolate_from_spamc_conf(Config::builder()); let mut builder = configure_spamc(Config::builder());
builder builder
.reject_spam(true) .reject_spam(true)
.reply_code("554".into()) .reply_code("554".into())
.reply_text("Not allowed!".into()) .reply_text("Not allowed!".into())
.spamc_args(vec![format!("--port={}", SPAMD_PORT)]); .spamc_args(&[format!("--port={}", SPAMD_PORT)]);
let config = builder.build(); let config = builder.build();
let server = spawn_mock_spamd_server(SPAMD_PORT, |spam| { let server = spawn_mock_spamd_server(SPAMD_PORT, |spam| {

View file

@ -5,9 +5,10 @@ use spamassassin_milter::*;
#[test] #[test]
fn skip_oversized() { fn skip_oversized() {
let mut builder = isolate_from_spamc_conf(Config::builder()); let mut builder = configure_spamc(Config::builder());
builder.max_message_size(512); builder
builder.spamc_args(vec![format!("--port={}", SPAMD_PORT)]); .max_message_size(512)
.spamc_args(&[format!("--port={}", SPAMD_PORT)]);
let config = builder.build(); let config = builder.build();
let server = spawn_mock_spamd_server(SPAMD_PORT, Ok); let server = spawn_mock_spamd_server(SPAMD_PORT, Ok);

View file

@ -5,8 +5,8 @@ use spamassassin_milter::*;
#[test] #[test]
fn spam_message() { fn spam_message() {
let mut builder = isolate_from_spamc_conf(Config::builder()); let mut builder = configure_spamc(Config::builder());
builder.spamc_args(vec![format!("--port={}", SPAMD_PORT)]); builder.spamc_args(&[format!("--port={}", SPAMD_PORT)]);
let config = builder.build(); let config = builder.build();
let server = spawn_mock_spamd_server(SPAMD_PORT, |spam| { let server = spawn_mock_spamd_server(SPAMD_PORT, |spam| {

View file

@ -5,13 +5,8 @@ use spamassassin_milter::*;
#[test] #[test]
fn spamc_connection_error() { fn spamc_connection_error() {
let mut builder = isolate_from_spamc_conf(Config::builder()); let mut builder = configure_spamc(Config::builder());
// `spamc` always works even if it cannot actually reach `spamd`! builder.spamc_args(&[format!("--port={}", SPAMD_PORT)]);
// `--no-safe-fallback` prevents this masking of connection errors.
builder.spamc_args(vec![
String::from("--no-safe-fallback"),
format!("--port={}", SPAMD_PORT),
]);
let config = builder.build(); let config = builder.build();
let miltertest = spawn_miltertest_runner(file!()); let miltertest = spawn_miltertest_runner(file!());