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
*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
provided systemd service file: Edit `spamassassin-milter.service` with the

View file

@ -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
}

View file

@ -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| {

View file

@ -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!());

View file

@ -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| {

View file

@ -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);

View file

@ -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| {

View file

@ -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!());