From 28cb9169cc6598bd2a3a82c17ccf3dc8e7b8aa26 Mon Sep 17 00:00:00 2001 From: Alberto Bertogli Date: Sun, 1 Dec 2019 22:11:57 +0000 Subject: [PATCH] test: Add SPF integration test This patch adds a new integration test to cover SPF checks. The main goal is not to cover the SPF parsing, since that's handled by the library already, but the higher level aspects: that the mails are indeed rejected, that the DSN looks reasonable, etc. --- .gitignore | 1 + test/t-14-tls_tracking/run.sh | 2 +- test/t-16-spf/A/chasquid.conf | 10 +++++ test/t-16-spf/B/chasquid.conf | 10 +++++ test/t-16-spf/config/chasquid.conf | 10 +++++ test/t-16-spf/content | 4 ++ test/t-16-spf/expected_dsn | 65 ++++++++++++++++++++++++++++ test/t-16-spf/hosts | 2 + test/t-16-spf/msmtprc | 14 ++++++ test/t-16-spf/run.sh | 68 ++++++++++++++++++++++++++++++ test/t-16-spf/zones.t0 | 11 +++++ test/t-16-spf/zones.t1 | 13 ++++++ test/util/lib.sh | 6 ++- 13 files changed, 213 insertions(+), 3 deletions(-) create mode 100644 test/t-16-spf/A/chasquid.conf create mode 100644 test/t-16-spf/B/chasquid.conf create mode 100644 test/t-16-spf/config/chasquid.conf create mode 100644 test/t-16-spf/content create mode 100644 test/t-16-spf/expected_dsn create mode 100644 test/t-16-spf/hosts create mode 100644 test/t-16-spf/msmtprc create mode 100755 test/t-16-spf/run.sh create mode 100644 test/t-16-spf/zones.t0 create mode 100644 test/t-16-spf/zones.t1 diff --git a/.gitignore b/.gitignore index fe33517..fc8151c 100644 --- a/.gitignore +++ b/.gitignore @@ -19,6 +19,7 @@ cmd/smtp-check/smtp-check cmd/spf-check/spf-check cmd/mda-lmtp/mda-lmtp cmd/dovecot-auth-cli/dovecot-auth-cli +test/util/minidns # Test binary, generated during coverage tests. chasquid.test diff --git a/test/t-14-tls_tracking/run.sh b/test/t-14-tls_tracking/run.sh index 4b6a3ac..f291cf7 100755 --- a/test/t-14-tls_tracking/run.sh +++ b/test/t-14-tls_tracking/run.sh @@ -11,7 +11,7 @@ init export GOTAGS="dnsoverride" # Launch minidns in the background using our configuration. -minidns --addr=":9053" -zones=zones >> .minidns.log 2>&1 & +minidns_bg --addr=":9053" -zones=zones >> .minidns.log 2>&1 # Two chasquid servers: diff --git a/test/t-16-spf/A/chasquid.conf b/test/t-16-spf/A/chasquid.conf new file mode 100644 index 0000000..3120200 --- /dev/null +++ b/test/t-16-spf/A/chasquid.conf @@ -0,0 +1,10 @@ +smtp_address: ":1025" +submission_address: ":1587" +submission_over_tls_address: ":1465" +monitoring_address: ":1099" + +mail_delivery_agent_bin: "test-mda" +mail_delivery_agent_args: "%to%" + +data_dir: "../.data-A" +mail_log_path: "../.logs-A/mail_log" diff --git a/test/t-16-spf/B/chasquid.conf b/test/t-16-spf/B/chasquid.conf new file mode 100644 index 0000000..7cd0d88 --- /dev/null +++ b/test/t-16-spf/B/chasquid.conf @@ -0,0 +1,10 @@ +smtp_address: ":2025" +submission_address: ":2587" +submission_over_tls_address: ":2465" +monitoring_address: ":2099" + +mail_delivery_agent_bin: "test-mda" +mail_delivery_agent_args: "%to%" + +data_dir: "../.data-B" +mail_log_path: "../.logs-B/mail_log" diff --git a/test/t-16-spf/config/chasquid.conf b/test/t-16-spf/config/chasquid.conf new file mode 100644 index 0000000..cf76e8a --- /dev/null +++ b/test/t-16-spf/config/chasquid.conf @@ -0,0 +1,10 @@ +smtp_address: ":1025" +submission_address: ":1587" +submission_over_tls_address: ":1465" +monitoring_address: ":1099" + +mail_delivery_agent_bin: "test-mda" +mail_delivery_agent_args: "%to%" + +data_dir: "../.data" +mail_log_path: "../.logs/mail_log" diff --git a/test/t-16-spf/content b/test/t-16-spf/content new file mode 100644 index 0000000..76a8b16 --- /dev/null +++ b/test/t-16-spf/content @@ -0,0 +1,4 @@ +Subject: Prueba desde el test + +Crece desde el test el futuro +Crece desde el test diff --git a/test/t-16-spf/expected_dsn b/test/t-16-spf/expected_dsn new file mode 100644 index 0000000..17a8308 --- /dev/null +++ b/test/t-16-spf/expected_dsn @@ -0,0 +1,65 @@ +From usera@srv-a +From: Mail Delivery System +To: +Subject: Mail delivery failed: returning message to sender +Message-ID: > .minidns.log 2>&1 + wait_until_ready 9053 +} + +# T0: Successful. +launch_minidns zones.t0 +run_msmtp userB@srv-B < content +wait_for_file .mail/userb@srv-b +mail_diff content .mail/userb@srv-b + +# T1: A is not permitted to send to B. +# Check that userA got a DSN about it. +rm .mail/* +launch_minidns zones.t1 +run_msmtp userB@srv-B < content +wait_for_file .mail/usera@srv-a +mail_diff expected_dsn .mail/usera@srv-a + +success diff --git a/test/t-16-spf/zones.t0 b/test/t-16-spf/zones.t0 new file mode 100644 index 0000000..76711dc --- /dev/null +++ b/test/t-16-spf/zones.t0 @@ -0,0 +1,11 @@ +# srv-a zone +srv-a A 127.0.0.1 +srv-a AAAA ::1 +srv-a MX srv-a +srv-a TXT v=spf1 a + +# srv-b zone +srv-b A 127.0.0.1 +srv-b AAAA ::1 +srv-b MX srv-b +srv-b TXT v=spf1 a diff --git a/test/t-16-spf/zones.t1 b/test/t-16-spf/zones.t1 new file mode 100644 index 0000000..5f18ca9 --- /dev/null +++ b/test/t-16-spf/zones.t1 @@ -0,0 +1,13 @@ +# srv-a is forbidden from sending mail. + +# srv-a zone +srv-a A 127.0.0.1 +srv-a AAAA ::1 +srv-a MX srv-a +srv-a TXT v=spf1 -all + +# srv-b zone +srv-b A 127.0.0.1 +srv-b AAAA ::1 +srv-b MX srv-b +srv-b TXT v=spf1 a diff --git a/test/util/lib.sh b/test/util/lib.sh index 54469e5..0deea41 100644 --- a/test/util/lib.sh +++ b/test/util/lib.sh @@ -112,8 +112,10 @@ function conngen() { go run ${UTILDIR}/conngen.go "$@" } -function minidns() { - go run ${UTILDIR}/minidns.go "$@" +function minidns_bg() { + ( cd ${UTILDIR}; go build minidns.go ) + ${UTILDIR}/minidns "$@" & + MINIDNS=$! } function success() {