From d38ff4c122c0a62d8d31490c7dd1dd8dc2d26587 Mon Sep 17 00:00:00 2001 From: Martin Schulze Date: Thu, 17 Sep 2020 23:40:39 +0200 Subject: [PATCH 01/50] Extrract disabled clamav tests into own file --- Makefile | 9 ---- test/mail_disabled_clamav_spamassassin.bats | 60 +++++++++++++++++++++ test/test_helper/common.bash | 20 ++++++- test/tests.bats | 25 --------- 4 files changed, 78 insertions(+), 36 deletions(-) create mode 100644 test/mail_disabled_clamav_spamassassin.bats diff --git a/Makefile b/Makefile index 6833a4bb..68f9c4a7 100644 --- a/Makefile +++ b/Makefile @@ -92,14 +92,6 @@ run: -h unknown.domain.tld \ -t $(NAME) -@ sleep $(SLEEP) - docker run --rm -d --name mail_disabled_clamav_spamassassin \ - -v "`pwd`/test/config":/tmp/docker-mailserver \ - -v "`pwd`/test/test-files":/tmp/docker-mailserver-test:ro \ - -e ENABLE_CLAMAV=0 \ - -e ENABLE_SPAMASSASSIN=0 \ - -e DMS_DEBUG=0 \ - -h mail.my-domain.com -t $(NAME) - -@ sleep $(SLEEP) generate-accounts-after-run: @ docker run --rm -e MAIL_USER=added@localhost.localdomain -e MAIL_PASS=mypassword -t $(NAME) /bin/sh -c 'echo "$$MAIL_USER|$$(doveadm pw -s SHA512-CRYPT -u $$MAIL_USER -p $$MAIL_PASS)"' >> test/config/postfix-accounts.cf @@ -127,7 +119,6 @@ fixtures: docker exec mail /bin/sh -c "nc 0.0.0.0 25 < /tmp/docker-mailserver-test/email-templates/sieve-spam-folder.txt" docker exec mail /bin/sh -c "nc 0.0.0.0 25 < /tmp/docker-mailserver-test/email-templates/sieve-pipe.txt" docker exec mail /bin/sh -c "nc 0.0.0.0 25 < /tmp/docker-mailserver-test/email-templates/non-existing-user.txt" - docker exec mail_disabled_clamav_spamassassin /bin/sh -c "nc 0.0.0.0 25 < /tmp/docker-mailserver-test/email-templates/existing-user1.txt" docker exec mail /bin/sh -c "sendmail root < /tmp/docker-mailserver-test/email-templates/root-email.txt" # postfix virtual transport lmtp docker exec mail_override_hostname /bin/sh -c "nc 0.0.0.0 25 < /tmp/docker-mailserver-test/email-templates/existing-user1.txt" diff --git a/test/mail_disabled_clamav_spamassassin.bats b/test/mail_disabled_clamav_spamassassin.bats new file mode 100644 index 00000000..269a53c2 --- /dev/null +++ b/test/mail_disabled_clamav_spamassassin.bats @@ -0,0 +1,60 @@ +load 'test_helper/common' + +setup() { + run_setup_file_if_necessary +} + +teardown() { + run_teardown_file_if_necessary +} + +setup_file() { + docker run --rm -d --name mail_disabled_clamav_spamassassin \ + -v "`pwd`/test/config":/tmp/docker-mailserver \ + -v "`pwd`/test/test-files":/tmp/docker-mailserver-test:ro \ + -e ENABLE_CLAMAV=0 \ + -e ENABLE_SPAMASSASSIN=0 \ + -e DMS_DEBUG=0 \ + -h mail.my-domain.com -t ${NAME} + # TODO: find a better way to know when we have waited long enough + # for clamav to should have come up, if it were enabled + wait_for_smtp_port_in_container mail_disabled_clamav_spamassassin + docker exec mail_disabled_clamav_spamassassin /bin/sh -c "nc 0.0.0.0 25 < /tmp/docker-mailserver-test/email-templates/existing-user1.txt" +} + +teardown_file() { + docker rm -f mail_disabled_clamav_spamassassin +} + +@test "first" { + skip 'only used to call setup_file from setup' +} + +@test "checking process: clamav (clamav disabled by ENABLED_CLAMAV=0)" { + run docker exec mail_disabled_clamav_spamassassin /bin/bash -c "ps aux --forest | grep -v grep | grep '/usr/sbin/clamd'" + assert_failure +} + +@test "checking spamassassin: should not be listed in amavis when disabled" { + run docker exec mail_disabled_clamav_spamassassin /bin/sh -c "grep -i 'ANTI-SPAM-SA code' /var/log/mail/mail.log | grep 'NOT loaded'" + assert_success +} + +@test "checking clamav: should not be listed in amavis when disabled" { + run docker exec mail_disabled_clamav_spamassassin grep -i 'Found secondary av scanner ClamAV-clamscan' /var/log/mail/mail.log + assert_failure +} + +@test "checking clamav: should not be called when disabled" { + run docker exec mail_disabled_clamav_spamassassin grep -i 'connect to /var/run/clamav/clamd.ctl failed' /var/log/mail/mail.log + assert_failure +} + +@test "checking restart of process: clamav (clamav disabled by ENABLED_CLAMAV=0)" { + run docker exec mail_disabled_clamav_spamassassin /bin/bash -c "pkill -f clamd && sleep 10 && ps aux --forest | grep -v grep | grep '/usr/sbin/clamd'" + assert_failure +} + +@test "last" { + skip 'only used to call teardown_file from teardown' +} diff --git a/test/test_helper/common.bash b/test/test_helper/common.bash index eeb27a13..f81de298 100644 --- a/test/test_helper/common.bash +++ b/test/test_helper/common.bash @@ -7,6 +7,9 @@ NAME=tvial/docker-mailserver:testing TEST_TIMEOUT_IN_SECONDS=${TEST_TIMEOUT_IN_SECONDS-120} NUMBER_OF_LOG_LINES=${NUMBER_OF_LOG_LINES-10} +# @param $1 timeout +# @param --fatal-test additional test whose failure aborts immediately +# @param ... test to run function repeat_until_success_or_timeout { if ! [[ "$1" =~ ^[0-9]+$ ]]; then echo "First parameter for timeout must be an integer, recieved \"$1\"" @@ -15,20 +18,33 @@ function repeat_until_success_or_timeout { TIMEOUT=$1 STARTTIME=$SECONDS shift 1 + local fatal_failure_test_command + if [[ "$1" == "--fatal-test" ]]; then + fatal_failure_test_command="$2" + shift 2 + fi until "$@" do + if [[ -n "$fatal_failure_test_command" ]] && ! eval "$fatal_failure_test_command"; then + echo "\`$fatal_failure_test_command\` failed, early aborting repeat_until_success of \`$*\`" >&2 + exit 1 + fi sleep 5 if [[ $(($SECONDS - $STARTTIME )) -gt $TIMEOUT ]]; then - echo "Timed out on command: $@" + echo "Timed out on command: $@" >&2 return 1 fi done } +function container_is_running() { + [[ "$(docker inspect -f '{{.State.Running}}' "$1")" == "true" ]] +} + # @param $1 port # @param $2 container name function wait_for_tcp_port_in_container() { - repeat_until_success_or_timeout $TEST_TIMEOUT_IN_SECONDS docker exec $2 /bin/sh -c "nc -z 0.0.0.0 $1" + repeat_until_success_or_timeout $TEST_TIMEOUT_IN_SECONDS --fatal-test "container_is_running $2" docker exec $2 /bin/sh -c "nc -z 0.0.0.0 $1" } # @param $1 name of the postfix container diff --git a/test/tests.bats b/test/tests.bats index 5635fecc..fa4a4752 100644 --- a/test/tests.bats +++ b/test/tests.bats @@ -114,11 +114,6 @@ function count_processed_changes() { assert_failure } -@test "checking process: clamav (clamav disabled by ENABLED_CLAMAV=0)" { - run docker exec mail_disabled_clamav_spamassassin /bin/bash -c "ps aux --forest | grep -v grep | grep '/usr/sbin/clamd'" - assert_failure -} - # # imap # @@ -384,11 +379,6 @@ EOF assert_failure } -@test "checking spamassassin: should not be listed in amavis when disabled" { - run docker exec mail_disabled_clamav_spamassassin /bin/sh -c "grep -i 'ANTI-SPAM-SA code' /var/log/mail/mail.log | grep 'NOT loaded'" - assert_success -} - @test "checking spamassassin: all registered domains should see spam headers" { run docker exec mail /bin/sh -c "grep -ir 'X-Spam-' /var/mail/localhost.localdomain/user1/new" assert_success @@ -406,16 +396,6 @@ EOF assert_success } -@test "checking clamav: should not be listed in amavis when disabled" { - run docker exec mail_disabled_clamav_spamassassin grep -i 'Found secondary av scanner ClamAV-clamscan' /var/log/mail/mail.log - assert_failure -} - -@test "checking clamav: should not be called when disabled" { - run docker exec mail_disabled_clamav_spamassassin grep -i 'connect to /var/run/clamav/clamd.ctl failed' /var/log/mail/mail.log - assert_failure -} - # # opendkim # @@ -1604,11 +1584,6 @@ EOF assert_success } -@test "checking restart of process: clamav (clamav disabled by ENABLED_CLAMAV=0)" { - run docker exec mail_disabled_clamav_spamassassin /bin/bash -c "pkill -f clamd && sleep 10 && ps aux --forest | grep -v grep | grep '/usr/sbin/clamd'" - assert_failure -} - # # root mail delivery # From ad0be553d8546c7f1be2b7b9d66e8c1f9adb81a0 Mon Sep 17 00:00:00 2001 From: Martin Schulze Date: Thu, 17 Sep 2020 23:46:31 +0200 Subject: [PATCH 02/50] Extract SRS DOMAINNAME tests/container into own file --- Makefile | 21 --------------------- test/mail_srs_domainname.bats | 34 ++++++++++++++++++++++++++++++++++ test/tests.bats | 10 +--------- 3 files changed, 35 insertions(+), 30 deletions(-) create mode 100644 test/mail_srs_domainname.bats diff --git a/Makefile b/Makefile index 68f9c4a7..50d2e492 100644 --- a/Makefile +++ b/Makefile @@ -71,27 +71,6 @@ run: -h unknown.domain.tld \ -t $(NAME) -@ sleep $(SLEEP) - docker run --rm -d --name mail_domainname \ - -v "`pwd`/test/config":/tmp/docker-mailserver \ - -v "`pwd`/test/test-files":/tmp/docker-mailserver-test:ro \ - -e PERMIT_DOCKER=network \ - -e DMS_DEBUG=0 \ - -e ENABLE_SRS=1 \ - -e DOMAINNAME=my-domain.com \ - -h unknown.domain.tld \ - -t $(NAME) - -@ sleep $(SLEEP) - docker run --rm -d --name mail_srs_domainname \ - -v "`pwd`/test/config":/tmp/docker-mailserver \ - -v "`pwd`/test/test-files":/tmp/docker-mailserver-test:ro \ - -e PERMIT_DOCKER=network \ - -e DMS_DEBUG=0 \ - -e ENABLE_SRS=1 \ - -e SRS_DOMAINNAME=srs.my-domain.com \ - -e DOMAINNAME=my-domain.com \ - -h unknown.domain.tld \ - -t $(NAME) - -@ sleep $(SLEEP) generate-accounts-after-run: @ docker run --rm -e MAIL_USER=added@localhost.localdomain -e MAIL_PASS=mypassword -t $(NAME) /bin/sh -c 'echo "$$MAIL_USER|$$(doveadm pw -s SHA512-CRYPT -u $$MAIL_USER -p $$MAIL_PASS)"' >> test/config/postfix-accounts.cf diff --git a/test/mail_srs_domainname.bats b/test/mail_srs_domainname.bats new file mode 100644 index 00000000..8047df79 --- /dev/null +++ b/test/mail_srs_domainname.bats @@ -0,0 +1,34 @@ +load 'test_helper/common' + +@test "checking SRS: SRS_DOMAINNAME is used correctly" { + docker run --rm -d --name mail_srs_domainname \ + -v "`pwd`/test/config":/tmp/docker-mailserver \ + -v "`pwd`/test/test-files":/tmp/docker-mailserver-test:ro \ + -e PERMIT_DOCKER=network \ + -e DMS_DEBUG=0 \ + -e ENABLE_SRS=1 \ + -e SRS_DOMAINNAME=srs.my-domain.com \ + -e DOMAINNAME=my-domain.com \ + -h unknown.domain.tld \ + -t ${NAME} + + teardown() { docker rm -f mail_srs_domainname; } + + repeat_until_success_or_timeout 15 docker exec mail_srs_domainname grep "SRS_DOMAIN=srs.my-domain.com" /etc/default/postsrsd +} + +@test "checking SRS: DOMAINNAME is handled correctly" { + docker run --rm -d --name mail_domainname \ + -v "`pwd`/test/config":/tmp/docker-mailserver \ + -v "`pwd`/test/test-files":/tmp/docker-mailserver-test:ro \ + -e PERMIT_DOCKER=network \ + -e DMS_DEBUG=0 \ + -e ENABLE_SRS=1 \ + -e DOMAINNAME=my-domain.com \ + -h unknown.domain.tld \ + -t ${NAME} + + teardown() { docker rm -f mail_domainname; } + + repeat_until_success_or_timeout 15 docker exec mail_domainname grep "SRS_DOMAIN=my-domain.com" /etc/default/postsrsd +} \ No newline at end of file diff --git a/test/tests.bats b/test/tests.bats index fa4a4752..e582add6 100644 --- a/test/tests.bats +++ b/test/tests.bats @@ -667,20 +667,12 @@ EOF assert_success } -@test "checking SRS: SRS_DOMAINNAME is used correctly" { - run docker exec mail_srs_domainname grep "SRS_DOMAIN=srs.my-domain.com" /etc/default/postsrsd - assert_success -} - @test "checking SRS: OVERRIDE_HOSTNAME is handled correctly" { run docker exec mail_override_hostname grep "SRS_DOMAIN=my-domain.com" /etc/default/postsrsd assert_success } -@test "checking SRS: DOMAINNAME is handled correctly" { - run docker exec mail_domainname grep "SRS_DOMAIN=my-domain.com" /etc/default/postsrsd - assert_success -} + @test "checking SRS: fallback to hostname is handled correctly" { run docker exec mail grep "SRS_DOMAIN=my-domain.com" /etc/default/postsrsd assert_success From 06b137e5a8bf1c8f5d3ad54f3c73b833382a8271 Mon Sep 17 00:00:00 2001 From: Martin Schulze Date: Fri, 18 Sep 2020 00:02:38 +0200 Subject: [PATCH 03/50] Extract container mail_smtponly_without_config into test --- Makefile | 7 ------- test/test_helper/common.bash | 10 ++++++++++ test/tests.bats | 11 ++++++++++- 3 files changed, 20 insertions(+), 8 deletions(-) diff --git a/Makefile b/Makefile index 50d2e492..81c61643 100644 --- a/Makefile +++ b/Makefile @@ -54,13 +54,6 @@ run: -e DMS_DEBUG=0 \ -h mail.my-domain.com -t $(NAME) -@ sleep $(SLEEP) - docker run --rm -d --name mail_smtponly_without_config \ - -e SMTP_ONLY=1 \ - -e ENABLE_LDAP=1 \ - -e PERMIT_DOCKER=network \ - -e OVERRIDE_HOSTNAME=mail.mydomain.com \ - -t $(NAME) - -@ sleep $(SLEEP) docker run --rm -d --name mail_override_hostname \ -v "`pwd`/test/config":/tmp/docker-mailserver \ -v "`pwd`/test/test-files":/tmp/docker-mailserver-test:ro \ diff --git a/test/test_helper/common.bash b/test/test_helper/common.bash index f81de298..f537d95c 100644 --- a/test/test_helper/common.bash +++ b/test/test_helper/common.bash @@ -37,6 +37,16 @@ function repeat_until_success_or_timeout { done } +# @param $1 timeout +# @param $2 container name +# @param ... test command for container +function repeat_in_container_until_success_or_timeout() { + timeout="$1" + container_name="$2" + shift 2 + repeat_until_success_or_timeout "$timeout" --fatal-test "container_is_running $container_name" docker exec "$container_name" "$@" +} + function container_is_running() { [[ "$(docker inspect -f '{{.State.Running}}' "$1")" == "true" ]] } diff --git a/test/tests.bats b/test/tests.bats index e582add6..e52a426e 100644 --- a/test/tests.bats +++ b/test/tests.bats @@ -407,7 +407,16 @@ EOF } @test "checking opendkim: /etc/opendkim/KeyTable dummy file generated without keys provided" { - run docker exec mail_smtponly_without_config /bin/bash -c "cat /etc/opendkim/KeyTable" + docker run --rm -d --name mail_smtponly_without_config \ + -e SMTP_ONLY=1 \ + -e ENABLE_LDAP=1 \ + -e PERMIT_DOCKER=network \ + -e OVERRIDE_HOSTNAME=mail.mydomain.com \ + -t ${NAME} + + teardown() { docker rm -f mail_smtponly_without_config; } + + run repeat_in_container_until_success_or_timeout 15 mail_smtponly_without_config /bin/bash -c "cat /etc/opendkim/KeyTable" assert_success } From 9c285db52039b70994627a30d678dbb1172520e3 Mon Sep 17 00:00:00 2001 From: Martin Schulze Date: Fri, 18 Sep 2020 00:09:43 +0200 Subject: [PATCH 04/50] Extract mail_override_hostname into own test file --- Makefile | 12 ----- test/mail_override_hostname.bats | 86 ++++++++++++++++++++++++++++++++ test/tests.bats | 55 -------------------- 3 files changed, 86 insertions(+), 67 deletions(-) create mode 100644 test/mail_override_hostname.bats diff --git a/Makefile b/Makefile index 81c61643..eaaa2d8c 100644 --- a/Makefile +++ b/Makefile @@ -54,16 +54,6 @@ run: -e DMS_DEBUG=0 \ -h mail.my-domain.com -t $(NAME) -@ sleep $(SLEEP) - docker run --rm -d --name mail_override_hostname \ - -v "`pwd`/test/config":/tmp/docker-mailserver \ - -v "`pwd`/test/test-files":/tmp/docker-mailserver-test:ro \ - -e PERMIT_DOCKER=network \ - -e DMS_DEBUG=0 \ - -e ENABLE_SRS=1 \ - -e OVERRIDE_HOSTNAME=mail.my-domain.com \ - -h unknown.domain.tld \ - -t $(NAME) - -@ sleep $(SLEEP) generate-accounts-after-run: @ docker run --rm -e MAIL_USER=added@localhost.localdomain -e MAIL_PASS=mypassword -t $(NAME) /bin/sh -c 'echo "$$MAIL_USER|$$(doveadm pw -s SHA512-CRYPT -u $$MAIL_USER -p $$MAIL_PASS)"' >> test/config/postfix-accounts.cf @@ -92,8 +82,6 @@ fixtures: docker exec mail /bin/sh -c "nc 0.0.0.0 25 < /tmp/docker-mailserver-test/email-templates/sieve-pipe.txt" docker exec mail /bin/sh -c "nc 0.0.0.0 25 < /tmp/docker-mailserver-test/email-templates/non-existing-user.txt" docker exec mail /bin/sh -c "sendmail root < /tmp/docker-mailserver-test/email-templates/root-email.txt" -# postfix virtual transport lmtp - docker exec mail_override_hostname /bin/sh -c "nc 0.0.0.0 25 < /tmp/docker-mailserver-test/email-templates/existing-user1.txt" # wait for mails to be analyzed sleep 80 diff --git a/test/mail_override_hostname.bats b/test/mail_override_hostname.bats new file mode 100644 index 00000000..dbc6a9ca --- /dev/null +++ b/test/mail_override_hostname.bats @@ -0,0 +1,86 @@ +load 'test_helper/common' + +function setup() { + run_setup_file_if_necessary +} + +function setup_file() { + docker run --rm -d --name mail_override_hostname \ + -v "`pwd`/test/config":/tmp/docker-mailserver \ + -v "`pwd`/test/test-files":/tmp/docker-mailserver-test:ro \ + -e PERMIT_DOCKER=network \ + -e DMS_DEBUG=0 \ + -e ENABLE_SRS=1 \ + -e OVERRIDE_HOSTNAME=mail.my-domain.com \ + -h unknown.domain.tld \ + -t ${NAME} + + wait_for_smtp_port_in_container mail_override_hostname + # postfix virtual transport lmtp + docker exec mail_override_hostname /bin/sh -c "nc 0.0.0.0 25 < /tmp/docker-mailserver-test/email-templates/existing-user1.txt" +} + +@test "first" { + skip 'only used to call setup_file from setup' +} + +@test "checking configuration: hostname/domainname override: check container hostname is applied correctly" { + run docker exec mail_override_hostname /bin/bash -c "hostname | grep unknown.domain.tld" + assert_success +} + +@test "checking configuration: hostname/domainname override: check overriden hostname is applied to all configs" { + run docker exec mail_override_hostname /bin/bash -c "cat /etc/mailname | grep my-domain.com" + assert_success + run docker exec mail_override_hostname /bin/bash -c "postconf -n | grep mydomain | grep my-domain.com" + assert_success + run docker exec mail_override_hostname /bin/bash -c "postconf -n | grep myhostname | grep mail.my-domain.com" + assert_success + run docker exec mail_override_hostname /bin/bash -c "doveconf | grep hostname | grep mail.my-domain.com" + assert_success + run docker exec mail_override_hostname /bin/bash -c "cat /etc/opendmarc.conf | grep AuthservID | grep mail.my-domain.com" + assert_success + run docker exec mail_override_hostname /bin/bash -c "cat /etc/opendmarc.conf | grep TrustedAuthservIDs | grep mail.my-domain.com" + assert_success + run docker exec mail_override_hostname /bin/bash -c "cat /etc/amavis/conf.d/05-node_id | grep myhostname | grep mail.my-domain.com" + assert_success +} + +@test "checking configuration: hostname/domainname override: check hostname in postfix HELO message" { + run docker exec mail_override_hostname /bin/bash -c "nc -w 1 0.0.0.0 25 | grep mail.my-domain.com" + assert_success +} + +@test "checking configuration: hostname/domainname override: check headers of received mail" { + run docker exec mail_override_hostname /bin/sh -c "ls -A /var/mail/localhost.localdomain/user1/new | wc -l | grep 1" + assert_success + run docker exec mail_override_hostname /bin/sh -c "cat /var/mail/localhost.localdomain/user1/new/* | grep mail.my-domain.com" + assert_success + + # test whether the container hostname is not found in received mail + run docker exec mail_override_hostname /bin/sh -c "cat /var/mail/localhost.localdomain/user1/new/* | grep unknown.domain.tld" + assert_failure +} + +@test "checking SRS: OVERRIDE_HOSTNAME is handled correctly" { + run docker exec mail_override_hostname grep "SRS_DOMAIN=my-domain.com" /etc/default/postsrsd + assert_success +} + +@test "checking dovecot: postmaster address" { + run docker exec mail_override_hostname /bin/sh -c "grep 'postmaster_address = postmaster@my-domain.com' /etc/dovecot/conf.d/15-lda.conf" + assert_success +} + +# +# clean exit +# + +@test "checking that the container stops cleanly" { + run docker stop -t 60 mail_override_hostname + assert_success +} + +@test "last" { + skip 'only used to call teardown_file from teardown' +} diff --git a/test/tests.bats b/test/tests.bats index e52a426e..933d454c 100644 --- a/test/tests.bats +++ b/test/tests.bats @@ -37,44 +37,6 @@ function count_processed_changes() { assert_success } -@test "checking configuration: hostname/domainname override: check container hostname is applied correctly" { - run docker exec mail_override_hostname /bin/bash -c "hostname | grep unknown.domain.tld" - assert_success -} - -@test "checking configuration: hostname/domainname override: check overriden hostname is applied to all configs" { - run docker exec mail_override_hostname /bin/bash -c "cat /etc/mailname | grep my-domain.com" - assert_success - run docker exec mail_override_hostname /bin/bash -c "postconf -n | grep mydomain | grep my-domain.com" - assert_success - run docker exec mail_override_hostname /bin/bash -c "postconf -n | grep myhostname | grep mail.my-domain.com" - assert_success - run docker exec mail_override_hostname /bin/bash -c "doveconf | grep hostname | grep mail.my-domain.com" - assert_success - run docker exec mail_override_hostname /bin/bash -c "cat /etc/opendmarc.conf | grep AuthservID | grep mail.my-domain.com" - assert_success - run docker exec mail_override_hostname /bin/bash -c "cat /etc/opendmarc.conf | grep TrustedAuthservIDs | grep mail.my-domain.com" - assert_success - run docker exec mail_override_hostname /bin/bash -c "cat /etc/amavis/conf.d/05-node_id | grep myhostname | grep mail.my-domain.com" - assert_success -} - -@test "checking configuration: hostname/domainname override: check hostname in postfix HELO message" { - run docker exec mail_override_hostname /bin/bash -c "nc -w 1 0.0.0.0 25 | grep mail.my-domain.com" - assert_success -} - -@test "checking configuration: hostname/domainname override: check headers of received mail" { - run docker exec mail_override_hostname /bin/sh -c "ls -A /var/mail/localhost.localdomain/user1/new | wc -l | grep 1" - assert_success - run docker exec mail_override_hostname /bin/sh -c "cat /var/mail/localhost.localdomain/user1/new/* | grep mail.my-domain.com" - assert_success - - # test whether the container hostname is not found in received mail - run docker exec mail_override_hostname /bin/sh -c "cat /var/mail/localhost.localdomain/user1/new/* | grep unknown.domain.tld" - assert_failure -} - # # processes # @@ -676,11 +638,6 @@ EOF assert_success } -@test "checking SRS: OVERRIDE_HOSTNAME is handled correctly" { - run docker exec mail_override_hostname grep "SRS_DOMAIN=my-domain.com" /etc/default/postsrsd - assert_success -} - @test "checking SRS: fallback to hostname is handled correctly" { run docker exec mail grep "SRS_DOMAIN=my-domain.com" /etc/default/postsrsd @@ -1467,9 +1424,6 @@ EOF @test "checking dovecot: postmaster address" { run docker exec mail /bin/sh -c "grep 'postmaster_address = postmaster@my-domain.com' /etc/dovecot/conf.d/15-lda.conf" assert_success - - run docker exec mail_override_hostname /bin/sh -c "grep 'postmaster_address = postmaster@my-domain.com' /etc/dovecot/conf.d/15-lda.conf" - assert_success } @test "checking spoofing: rejects sender forging" { @@ -1593,12 +1547,3 @@ EOF run docker exec mail grep "Subject: Root Test Message" /var/mail/localhost.localdomain/user1/new/ -R assert_success } - -# -# clean exit -# - -@test "checking that the container stops cleanly" { - run docker stop -t 60 mail_override_hostname - assert_success -} From 190f4961c048bf07fc6e61c465e23165d13d8a31 Mon Sep 17 00:00:00 2001 From: Martin Schulze Date: Fri, 18 Sep 2020 00:39:32 +0200 Subject: [PATCH 05/50] Move mail container creation into tests file --- Makefile | 54 +------------------------------------------ test/tests.bats | 61 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 62 insertions(+), 53 deletions(-) diff --git a/Makefile b/Makefile index eaaa2d8c..a68804b6 100644 --- a/Makefile +++ b/Makefile @@ -28,63 +28,11 @@ generate-accounts: @ echo "# this is a test comment, please don't delete me :'(" >> test/config/postfix-accounts.cf @ echo " # this is also a test comment, :O" >> test/config/postfix-accounts.cf -run: -# run containers - -@ echo "Sleeping $(SLEEP) after each container" - docker run --rm -d --name mail \ - -v "`pwd`/test/config":/tmp/docker-mailserver \ - -v "`pwd`/test/test-files":/tmp/docker-mailserver-test:ro \ - -v "`pwd`/test/onedir":/var/mail-state \ - -v "`pwd`/test/config/user-patches/user-patches.sh":/tmp/docker-mailserver/user-patches.sh \ - -e ENABLE_CLAMAV=1 \ - -e SPOOF_PROTECTION=1 \ - -e ENABLE_SPAMASSASSIN=1 \ - -e REPORT_RECIPIENT=user1@localhost.localdomain \ - -e REPORT_SENDER=report1@mail.my-domain.com \ - -e SA_TAG=-5.0 \ - -e SA_TAG2=2.0 \ - -e SA_KILL=3.0 \ - -e SA_SPAM_SUBJECT="SPAM: " \ - -e VIRUSMAILS_DELETE_DELAY=7 \ - -e ENABLE_SRS=1 \ - -e SASL_PASSWD="external-domain.com username:password" \ - -e ENABLE_MANAGESIEVE=1 \ - --cap-add=SYS_PTRACE \ - -e PERMIT_DOCKER=host \ - -e DMS_DEBUG=0 \ - -h mail.my-domain.com -t $(NAME) - -@ sleep $(SLEEP) - +# TODO: ensure this is run per container after each container started! generate-accounts-after-run: @ docker run --rm -e MAIL_USER=added@localhost.localdomain -e MAIL_PASS=mypassword -t $(NAME) /bin/sh -c 'echo "$$MAIL_USER|$$(doveadm pw -s SHA512-CRYPT -u $$MAIL_USER -p $$MAIL_PASS)"' >> test/config/postfix-accounts.cf - @ docker exec mail addmailuser pass@localhost.localdomain 'may be \a `p^a.*ssword' @ sleep $(SLEEP) -fixtures: -# setup sieve - docker cp "`pwd`/test/config/sieve/dovecot.sieve" mail:/var/mail/localhost.localdomain/user1/.dovecot.sieve - sleep $(SLEEP) - sleep $(SLEEP) -# sending test mails - docker exec mail /bin/sh -c "nc 0.0.0.0 25 < /tmp/docker-mailserver-test/email-templates/amavis-spam.txt" - docker exec mail /bin/sh -c "nc 0.0.0.0 25 < /tmp/docker-mailserver-test/email-templates/amavis-virus.txt" - docker exec mail /bin/sh -c "nc 0.0.0.0 25 < /tmp/docker-mailserver-test/email-templates/existing-alias-external.txt" - docker exec mail /bin/sh -c "nc 0.0.0.0 25 < /tmp/docker-mailserver-test/email-templates/existing-alias-local.txt" - docker exec mail /bin/sh -c "nc 0.0.0.0 25 < /tmp/docker-mailserver-test/email-templates/existing-alias-recipient-delimiter.txt" - docker exec mail /bin/sh -c "nc 0.0.0.0 25 < /tmp/docker-mailserver-test/email-templates/existing-user1.txt" - docker exec mail /bin/sh -c "nc 0.0.0.0 25 < /tmp/docker-mailserver-test/email-templates/existing-user2.txt" - docker exec mail /bin/sh -c "nc 0.0.0.0 25 < /tmp/docker-mailserver-test/email-templates/existing-added.txt" - docker exec mail /bin/sh -c "nc 0.0.0.0 25 < /tmp/docker-mailserver-test/email-templates/existing-user-and-cc-local-alias.txt" - docker exec mail /bin/sh -c "nc 0.0.0.0 25 < /tmp/docker-mailserver-test/email-templates/existing-regexp-alias-external.txt" - docker exec mail /bin/sh -c "nc 0.0.0.0 25 < /tmp/docker-mailserver-test/email-templates/existing-regexp-alias-local.txt" - docker exec mail /bin/sh -c "nc 0.0.0.0 25 < /tmp/docker-mailserver-test/email-templates/existing-catchall-local.txt" - docker exec mail /bin/sh -c "nc 0.0.0.0 25 < /tmp/docker-mailserver-test/email-templates/sieve-spam-folder.txt" - docker exec mail /bin/sh -c "nc 0.0.0.0 25 < /tmp/docker-mailserver-test/email-templates/sieve-pipe.txt" - docker exec mail /bin/sh -c "nc 0.0.0.0 25 < /tmp/docker-mailserver-test/email-templates/non-existing-user.txt" - docker exec mail /bin/sh -c "sendmail root < /tmp/docker-mailserver-test/email-templates/root-email.txt" -# wait for mails to be analyzed - sleep 80 - tests: ./test/bats/bin/bats test/*.bats diff --git a/test/tests.bats b/test/tests.bats index 933d454c..fcc3841f 100644 --- a/test/tests.bats +++ b/test/tests.bats @@ -2,6 +2,67 @@ load 'test_helper/bats-support/load' load 'test_helper/bats-assert/load' load 'test_helper/common' +setup() { + run_setup_file_if_necessary +} + +setup_file() { + docker run --rm -d --name mail \ + -v "`pwd`/test/config":/tmp/docker-mailserver \ + -v "`pwd`/test/test-files":/tmp/docker-mailserver-test:ro \ + -v "`pwd`/test/onedir":/var/mail-state \ + -v "`pwd`/test/config/user-patches/user-patches.sh":/tmp/docker-mailserver/user-patches.sh \ + -e ENABLE_CLAMAV=1 \ + -e SPOOF_PROTECTION=1 \ + -e ENABLE_SPAMASSASSIN=1 \ + -e REPORT_RECIPIENT=user1@localhost.localdomain \ + -e REPORT_SENDER=report1@mail.my-domain.com \ + -e SA_TAG=-5.0 \ + -e SA_TAG2=2.0 \ + -e SA_KILL=3.0 \ + -e SA_SPAM_SUBJECT="SPAM: " \ + -e VIRUSMAILS_DELETE_DELAY=7 \ + -e ENABLE_SRS=1 \ + -e SASL_PASSWD="external-domain.com username:password" \ + -e ENABLE_MANAGESIEVE=1 \ + --cap-add=SYS_PTRACE \ + -e PERMIT_DOCKER=host \ + -e DMS_DEBUG=0 \ + -h mail.my-domain.com -t ${NAME} + # generate account after run + docker exec mail addmailuser pass@localhost.localdomain 'may be \a `p^a.*ssword' + # setup sieve + repeat_until_success_or_timeout 15 docker cp "`pwd`/test/config/sieve/dovecot.sieve" mail:/var/mail/localhost.localdomain/user1/.dovecot.sieve + wait_for_smtp_port_in_container mail + # sending test mails + docker exec mail /bin/sh -c "nc 0.0.0.0 25 < /tmp/docker-mailserver-test/email-templates/amavis-spam.txt" + docker exec mail /bin/sh -c "nc 0.0.0.0 25 < /tmp/docker-mailserver-test/email-templates/amavis-virus.txt" + docker exec mail /bin/sh -c "nc 0.0.0.0 25 < /tmp/docker-mailserver-test/email-templates/existing-alias-external.txt" + docker exec mail /bin/sh -c "nc 0.0.0.0 25 < /tmp/docker-mailserver-test/email-templates/existing-alias-local.txt" + docker exec mail /bin/sh -c "nc 0.0.0.0 25 < /tmp/docker-mailserver-test/email-templates/existing-alias-recipient-delimiter.txt" + docker exec mail /bin/sh -c "nc 0.0.0.0 25 < /tmp/docker-mailserver-test/email-templates/existing-user1.txt" + docker exec mail /bin/sh -c "nc 0.0.0.0 25 < /tmp/docker-mailserver-test/email-templates/existing-user2.txt" + docker exec mail /bin/sh -c "nc 0.0.0.0 25 < /tmp/docker-mailserver-test/email-templates/existing-added.txt" + docker exec mail /bin/sh -c "nc 0.0.0.0 25 < /tmp/docker-mailserver-test/email-templates/existing-user-and-cc-local-alias.txt" + docker exec mail /bin/sh -c "nc 0.0.0.0 25 < /tmp/docker-mailserver-test/email-templates/existing-regexp-alias-external.txt" + docker exec mail /bin/sh -c "nc 0.0.0.0 25 < /tmp/docker-mailserver-test/email-templates/existing-regexp-alias-local.txt" + docker exec mail /bin/sh -c "nc 0.0.0.0 25 < /tmp/docker-mailserver-test/email-templates/existing-catchall-local.txt" + docker exec mail /bin/sh -c "nc 0.0.0.0 25 < /tmp/docker-mailserver-test/email-templates/sieve-spam-folder.txt" + docker exec mail /bin/sh -c "nc 0.0.0.0 25 < /tmp/docker-mailserver-test/email-templates/sieve-pipe.txt" + docker exec mail /bin/sh -c "nc 0.0.0.0 25 < /tmp/docker-mailserver-test/email-templates/non-existing-user.txt" + docker exec mail /bin/sh -c "sendmail root < /tmp/docker-mailserver-test/email-templates/root-email.txt" + # wait for mails to be analyzed + #sleep 80 +} + +teardown() { + run_teardown_file_if_necessary +} + +teardown_file() { + docker rm -f mail +} + # # shared functions # From e5d04aa30d8a6297b45b13c3832e7c5a73798ab7 Mon Sep 17 00:00:00 2001 From: Martin Schulze Date: Fri, 18 Sep 2020 01:37:24 +0200 Subject: [PATCH 06/50] Remove references to unused targets --- Makefile | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index a68804b6..e54669d3 100644 --- a/Makefile +++ b/Makefile @@ -6,9 +6,9 @@ VCS_VERSION := $(shell git describe --tags --contains --always) SLEEP = 15s -all: build backup generate-accounts run generate-accounts-after-run fixtures tests clean -no-build: backup generate-accounts run generate-accounts-after-run fixtures tests clean -complete_test: lint build generate-accounts run generate-accounts-after-run fixtures tests +all: build backup generate-accounts generate-accounts-after-run tests clean +no-build: backup generate-accounts generate-accounts-after-run tests clean +complete_test: lint build generate-accounts generate-accounts-after-run tests build: docker build \ From 5fef8a5b780692f37cd5cee58cc948ca3d6f75f3 Mon Sep 17 00:00:00 2001 From: Martin Schulze Date: Fri, 18 Sep 2020 01:37:42 +0200 Subject: [PATCH 07/50] Give each container their own private config folder --- test/default_relay_host.bats | 2 +- test/mail_dhparams_default.bats | 4 +- test/mail_dhparams_manual_not_one_dir.bats | 7 +- test/mail_dhparams_manual_one_dir.bats | 2 +- test/mail_disabled_clamav_spamassassin.bats | 2 +- test/mail_fail2ban.bats | 2 +- test/mail_fetchmail.bats | 2 +- test/mail_lmtp_ip.bats | 4 +- test/mail_override_hostname.bats | 2 +- test/mail_pop3.bats | 2 +- test/mail_postfix_inet.bats | 8 +- test/mail_postscreen.bats | 2 +- test/mail_privacy.bats | 2 +- test/mail_quotas_disabled.bats | 2 +- test/mail_smtponly.bats | 2 +- test/mail_spam_bounced.bats | 4 +- test/mail_spam_junk_folder.bats | 4 +- test/mail_special_use_folders.bats | 2 +- test/mail_srs_domainname.bats | 4 +- test/mail_ssl_letsencrypt.bats | 28 +++-- test/mail_ssl_manual.bats | 2 +- test/mail_undef_spam_subject.bats | 4 +- test/mail_with_imap.bats | 2 +- test/mail_with_ldap.bats | 2 +- test/mail_with_mdbox.bats | 2 +- test/mail_with_postgrey.bats | 2 +- ...ail_with_postgrey_disabled_by_default.bats | 2 +- test/mail_with_sdbox.bats | 2 +- test/permit_docker.bats | 4 +- test/test_helper/common.bash | 16 +++ test/tests.bats | 118 ++++++++++-------- 31 files changed, 138 insertions(+), 105 deletions(-) diff --git a/test/default_relay_host.bats b/test/default_relay_host.bats index a1fa22f7..91c42ab2 100644 --- a/test/default_relay_host.bats +++ b/test/default_relay_host.bats @@ -2,7 +2,7 @@ load 'test_helper/common' function setup() { docker run -d --name mail_with_default_relay \ - -v "`pwd`/test/config/relay-hosts":/tmp/docker-mailserver \ + -v "$(duplicate_config_for_container relay-hosts/)":/tmp/docker-mailserver \ -v "`pwd`/test/test-files":/tmp/docker-mailserver-test:ro \ -e DEFAULT_RELAY_HOST=default.relay.host.invalid:25 \ --cap-add=SYS_PTRACE \ diff --git a/test/mail_dhparams_default.bats b/test/mail_dhparams_default.bats index 9fae1b16..72a789ea 100644 --- a/test/mail_dhparams_default.bats +++ b/test/mail_dhparams_default.bats @@ -22,7 +22,7 @@ function teardown() { function setup_file() { docker run -d --name mail_default_dhparams_one_dir \ - -v "`pwd`/test/config":/tmp/docker-mailserver \ + -v "$(duplicate_config_for_container . mail_default_dhparams_both_one_dir)":/tmp/docker-mailserver \ -v "`pwd`/test/test-files":/tmp/docker-mailserver-test:ro \ -e DMS_DEBUG=0 \ -e ONE_DIR=1 \ @@ -30,7 +30,7 @@ function setup_file() { wait_for_finished_setup_in_container mail_default_dhparams_one_dir docker run -d --name mail_default_dhparams_not_one_dir \ - -v "`pwd`/test/config":/tmp/docker-mailserver \ + -v "$(duplicate_config_for_container . mail_default_dhparams_both_not_one_dir)":/tmp/docker-mailserver \ -v "`pwd`/test/test-files":/tmp/docker-mailserver-test:ro \ -e DMS_DEBUG=0 \ -e ONE_DIR=0 \ diff --git a/test/mail_dhparams_manual_not_one_dir.bats b/test/mail_dhparams_manual_not_one_dir.bats index 36e2f926..2277c2f5 100644 --- a/test/mail_dhparams_manual_not_one_dir.bats +++ b/test/mail_dhparams_manual_not_one_dir.bats @@ -21,11 +21,12 @@ function teardown() { } function setup_file() { + private_config=$(duplicate_config_for_container .) # copy the custom DHE params in local config - cp "`pwd`/test/test-files/ssl/custom-dhe-params.pem" "`pwd`/test/config/dhparams.pem" + cp "`pwd`/test/test-files/ssl/custom-dhe-params.pem" "$private_config/dhparams.pem" docker run -d --name mail_manual_dhparams_not_one_dir \ - -v "`pwd`/test/config":/tmp/docker-mailserver \ + -v "$private_config":/tmp/docker-mailserver \ -v "`pwd`/test/test-files":/tmp/docker-mailserver-test:ro \ -e DMS_DEBUG=0 \ -e ONE_DIR=0 \ @@ -34,8 +35,6 @@ function setup_file() { } function teardown_file() { - # remove custom dhe file - rm "`pwd`/test/config/dhparams.pem" docker rm -f mail_manual_dhparams_not_one_dir } diff --git a/test/mail_dhparams_manual_one_dir.bats b/test/mail_dhparams_manual_one_dir.bats index 1ce23adc..69091d83 100644 --- a/test/mail_dhparams_manual_one_dir.bats +++ b/test/mail_dhparams_manual_one_dir.bats @@ -21,7 +21,7 @@ function teardown() { function setup_file() { docker run -d --name mail_manual_dhparams_one_dir \ - -v "`pwd`/test/config":/tmp/docker-mailserver \ + -v "$(duplicate_config_for_container .)":/tmp/docker-mailserver \ -v "`pwd`/test/test-files":/tmp/docker-mailserver-test:ro \ -v "`pwd`/test/test-files/ssl/custom-dhe-params.pem":/var/mail-state/lib-shared/dhparams.pem:ro \ -e DMS_DEBUG=0 \ diff --git a/test/mail_disabled_clamav_spamassassin.bats b/test/mail_disabled_clamav_spamassassin.bats index 269a53c2..a85cd712 100644 --- a/test/mail_disabled_clamav_spamassassin.bats +++ b/test/mail_disabled_clamav_spamassassin.bats @@ -10,7 +10,7 @@ teardown() { setup_file() { docker run --rm -d --name mail_disabled_clamav_spamassassin \ - -v "`pwd`/test/config":/tmp/docker-mailserver \ + -v "$(duplicate_config_for_container .)":/tmp/docker-mailserver \ -v "`pwd`/test/test-files":/tmp/docker-mailserver-test:ro \ -e ENABLE_CLAMAV=0 \ -e ENABLE_SPAMASSASSIN=0 \ diff --git a/test/mail_fail2ban.bats b/test/mail_fail2ban.bats index 7b213c24..d96b2cfa 100644 --- a/test/mail_fail2ban.bats +++ b/test/mail_fail2ban.bats @@ -10,7 +10,7 @@ function teardown() { function setup_file() { docker run --rm -d --name mail_fail2ban \ - -v "`pwd`/test/config":/tmp/docker-mailserver \ + -v "$(duplicate_config_for_container .)":/tmp/docker-mailserver \ -v "`pwd`/test/test-files":/tmp/docker-mailserver-test:ro \ -e ENABLE_FAIL2BAN=1 \ -e POSTSCREEN_ACTION=ignore \ diff --git a/test/mail_fetchmail.bats b/test/mail_fetchmail.bats index bb6d4d8b..cdafafdc 100644 --- a/test/mail_fetchmail.bats +++ b/test/mail_fetchmail.bats @@ -10,7 +10,7 @@ function teardown() { function setup_file() { docker run -d --name mail_fetchmail \ - -v "`pwd`/test/config":/tmp/docker-mailserver \ + -v "$(duplicate_config_for_container .)":/tmp/docker-mailserver \ -v "`pwd`/test/test-files":/tmp/docker-mailserver-test:ro \ -e ENABLE_FETCHMAIL=1 \ --cap-add=NET_ADMIN \ diff --git a/test/mail_lmtp_ip.bats b/test/mail_lmtp_ip.bats index 4ec82e03..02547436 100644 --- a/test/mail_lmtp_ip.bats +++ b/test/mail_lmtp_ip.bats @@ -10,8 +10,8 @@ teardown() { setup_file() { docker run -d --name mail_lmtp_ip \ - -v "`pwd`/test/config":/tmp/docker-mailserver \ - -v "`pwd`/test/config/dovecot-lmtp":/etc/dovecot \ + -v "$(duplicate_config_for_container .)":/tmp/docker-mailserver \ + -v "$(duplicate_config_for_container dovecot-lmtp/ mail_lmtp_ip_dovecot-lmtp)":/etc/dovecot \ -v "`pwd`/test/test-files":/tmp/docker-mailserver-test:ro \ -e ENABLE_POSTFIX_VIRTUAL_TRANSPORT=1 \ -e POSTFIX_DAGENT=lmtp:127.0.0.1:24 \ diff --git a/test/mail_override_hostname.bats b/test/mail_override_hostname.bats index dbc6a9ca..1a6da949 100644 --- a/test/mail_override_hostname.bats +++ b/test/mail_override_hostname.bats @@ -6,7 +6,7 @@ function setup() { function setup_file() { docker run --rm -d --name mail_override_hostname \ - -v "`pwd`/test/config":/tmp/docker-mailserver \ + -v "$(duplicate_config_for_container .)":/tmp/docker-mailserver \ -v "`pwd`/test/test-files":/tmp/docker-mailserver-test:ro \ -e PERMIT_DOCKER=network \ -e DMS_DEBUG=0 \ diff --git a/test/mail_pop3.bats b/test/mail_pop3.bats index 5f183fea..c6d429e5 100644 --- a/test/mail_pop3.bats +++ b/test/mail_pop3.bats @@ -10,7 +10,7 @@ function teardown() { function setup_file() { docker run -d --name mail_pop3 \ - -v "`pwd`/test/config":/tmp/docker-mailserver \ + -v "$(duplicate_config_for_container .)":/tmp/docker-mailserver \ -v "`pwd`/test/test-files":/tmp/docker-mailserver-test:ro \ -e ENABLE_POP3=1 \ -e DMS_DEBUG=0 \ diff --git a/test/mail_postfix_inet.bats b/test/mail_postfix_inet.bats index a42639be..94328f11 100644 --- a/test/mail_postfix_inet.bats +++ b/test/mail_postfix_inet.bats @@ -15,14 +15,14 @@ function teardown() { function setup_file() { docker run -d --name mail_postfix_inet_default \ - -v "`pwd`/test/config":/tmp/docker-mailserver \ + -v "$(duplicate_config_for_container . mail_postfix_inet_default)":/tmp/docker-mailserver \ -v "`pwd`/test/test-files":/tmp/docker-mailserver-test:ro \ -h mail.my-domain.com -t "${NAME}" wait_for_finished_setup_in_container mail_postfix_inet_default docker run -d --name mail_postfix_inet_all \ - -v "`pwd`/test/config":/tmp/docker-mailserver \ + -v "$(duplicate_config_for_container . mail_postfix_inet_all)":/tmp/docker-mailserver \ -v "`pwd`/test/test-files":/tmp/docker-mailserver-test:ro \ -e POSTFIX_INET_PROTOCOLS=all \ -h mail.my-domain.com -t "${NAME}" @@ -30,7 +30,7 @@ function setup_file() { wait_for_finished_setup_in_container mail_postfix_inet_all docker run -d --name mail_postfix_inet_ipv4 \ - -v "`pwd`/test/config":/tmp/docker-mailserver \ + -v "$(duplicate_config_for_container . mail_postfix_inet_ipv4)":/tmp/docker-mailserver \ -v "`pwd`/test/test-files":/tmp/docker-mailserver-test:ro \ -e POSTFIX_INET_PROTOCOLS=ipv4 \ -h mail.my-domain.com -t "${NAME}" @@ -38,7 +38,7 @@ function setup_file() { wait_for_finished_setup_in_container mail_postfix_inet_ipv4 docker run -d --name mail_postfix_inet_ipv6 \ - -v "`pwd`/test/config":/tmp/docker-mailserver \ + -v "$(duplicate_config_for_container . mail_postfix_inet_ipv6)":/tmp/docker-mailserver \ -v "`pwd`/test/test-files":/tmp/docker-mailserver-test:ro \ -e POSTFIX_INET_PROTOCOLS=ipv6 \ -h mail.my-domain.com -t "${NAME}" diff --git a/test/mail_postscreen.bats b/test/mail_postscreen.bats index a6f17b5c..8df044bc 100644 --- a/test/mail_postscreen.bats +++ b/test/mail_postscreen.bats @@ -13,7 +13,7 @@ teardown() { setup_file() { docker run -d --name mail_postscreen \ - -v "`pwd`/test/config":/tmp/docker-mailserver \ + -v "$(duplicate_config_for_container .)":/tmp/docker-mailserver \ -v "`pwd`/test/test-files":/tmp/docker-mailserver-test:ro \ -e POSTSCREEN_ACTION=enforce \ --cap-add=NET_ADMIN \ diff --git a/test/mail_privacy.bats b/test/mail_privacy.bats index 44af92af..a425f6b8 100644 --- a/test/mail_privacy.bats +++ b/test/mail_privacy.bats @@ -10,7 +10,7 @@ function teardown() { function setup_file() { docker run -d --name mail_privacy \ - -v "`pwd`/test/config":/tmp/docker-mailserver \ + -v "$(duplicate_config_for_container .)":/tmp/docker-mailserver \ -v "`pwd`/test/test-files":/tmp/docker-mailserver-test:ro \ -e SASL_PASSWD="external-domain.com username:password" \ -e ENABLE_MANAGESIEVE=1 \ diff --git a/test/mail_quotas_disabled.bats b/test/mail_quotas_disabled.bats index e04e5918..faefd2af 100644 --- a/test/mail_quotas_disabled.bats +++ b/test/mail_quotas_disabled.bats @@ -15,7 +15,7 @@ function teardown() { function setup_file() { docker run -d --name mail_no_quotas \ - -v "`pwd`/test/config":/tmp/docker-mailserver \ + -v "$(duplicate_config_for_container .)":/tmp/docker-mailserver \ -v "`pwd`/test/test-files":/tmp/docker-mailserver-test:ro \ -e DMS_DEBUG=0 \ -e ENABLE_QUOTAS=0 \ diff --git a/test/mail_smtponly.bats b/test/mail_smtponly.bats index e0cc8080..7b9cec5c 100644 --- a/test/mail_smtponly.bats +++ b/test/mail_smtponly.bats @@ -10,7 +10,7 @@ function teardown() { function setup_file() { docker run --rm -d --name mail_smtponly \ - -v "`pwd`/test/config":/tmp/docker-mailserver \ + -v "$(duplicate_config_for_container .)":/tmp/docker-mailserver \ -v "`pwd`/test/test-files":/tmp/docker-mailserver-test:ro \ -e SMTP_ONLY=1 \ -e PERMIT_DOCKER=network \ diff --git a/test/mail_spam_bounced.bats b/test/mail_spam_bounced.bats index 9b0880fc..f6af38ae 100644 --- a/test/mail_spam_bounced.bats +++ b/test/mail_spam_bounced.bats @@ -15,7 +15,7 @@ function teardown() { function setup_file() { docker run -d --name mail_spam_bounced_defined \ - -v "`pwd`/test/config":/tmp/docker-mailserver \ + -v "$(duplicate_config_for_container . mail_spam_bounced_defined)":/tmp/docker-mailserver \ -v "`pwd`/test/test-files":/tmp/docker-mailserver-test:ro \ -e ENABLE_SPAMASSASSIN=1 \ -e SPAMASSASSIN_SPAM_TO_INBOX=0 \ @@ -24,7 +24,7 @@ function setup_file() { wait_for_finished_setup_in_container mail_spam_bounced_defined docker run -d --name mail_spam_bounced_undefined \ - -v "`pwd`/test/config":/tmp/docker-mailserver \ + -v "$(duplicate_config_for_container . mail_spam_bounced_defined)":/tmp/docker-mailserver \ -v "`pwd`/test/test-files":/tmp/docker-mailserver-test:ro \ -e ENABLE_SPAMASSASSIN=1 \ -h mail.my-domain.com -t "${NAME}" diff --git a/test/mail_spam_junk_folder.bats b/test/mail_spam_junk_folder.bats index 3b17c92e..6e7259e2 100644 --- a/test/mail_spam_junk_folder.bats +++ b/test/mail_spam_junk_folder.bats @@ -15,7 +15,7 @@ function teardown() { function setup_file() { docker run -d --name mail_spam_moved_junk \ - -v "`pwd`/test/config":/tmp/docker-mailserver \ + -v "$(duplicate_config_for_container . mail_spam_moved_junk)":/tmp/docker-mailserver \ -v "`pwd`/test/test-files":/tmp/docker-mailserver-test:ro \ -e ENABLE_SPAMASSASSIN=1 \ -e SPAMASSASSIN_SPAM_TO_INBOX=1 \ @@ -26,7 +26,7 @@ function setup_file() { wait_for_finished_setup_in_container mail_spam_moved_junk docker run -d --name mail_spam_moved_new \ - -v "`pwd`/test/config":/tmp/docker-mailserver \ + -v "$(duplicate_config_for_container . mail_spam_moved_new)":/tmp/docker-mailserver \ -v "`pwd`/test/test-files":/tmp/docker-mailserver-test:ro \ -e ENABLE_SPAMASSASSIN=1 \ -e SPAMASSASSIN_SPAM_TO_INBOX=1 \ diff --git a/test/mail_special_use_folders.bats b/test/mail_special_use_folders.bats index bbd2cc79..cb6eb84a 100644 --- a/test/mail_special_use_folders.bats +++ b/test/mail_special_use_folders.bats @@ -10,7 +10,7 @@ teardown() { setup_file() { docker run -d --name mail_special_use_folders \ - -v "`pwd`/test/config":/tmp/docker-mailserver \ + -v "$(duplicate_config_for_container .)":/tmp/docker-mailserver \ -v "`pwd`/test/test-files":/tmp/docker-mailserver-test:ro \ -e SASL_PASSWD="external-domain.com username:password" \ -e ENABLE_CLAMAV=0 \ diff --git a/test/mail_srs_domainname.bats b/test/mail_srs_domainname.bats index 8047df79..efbc5d83 100644 --- a/test/mail_srs_domainname.bats +++ b/test/mail_srs_domainname.bats @@ -2,7 +2,7 @@ load 'test_helper/common' @test "checking SRS: SRS_DOMAINNAME is used correctly" { docker run --rm -d --name mail_srs_domainname \ - -v "`pwd`/test/config":/tmp/docker-mailserver \ + -v "$(duplicate_config_for_container . mail_srs_domainname)":/tmp/docker-mailserver \ -v "`pwd`/test/test-files":/tmp/docker-mailserver-test:ro \ -e PERMIT_DOCKER=network \ -e DMS_DEBUG=0 \ @@ -19,7 +19,7 @@ load 'test_helper/common' @test "checking SRS: DOMAINNAME is handled correctly" { docker run --rm -d --name mail_domainname \ - -v "`pwd`/test/config":/tmp/docker-mailserver \ + -v "$(duplicate_config_for_container . mail_domainname)":/tmp/docker-mailserver \ -v "`pwd`/test/test-files":/tmp/docker-mailserver-test:ro \ -e PERMIT_DOCKER=network \ -e DMS_DEBUG=0 \ diff --git a/test/mail_ssl_letsencrypt.bats b/test/mail_ssl_letsencrypt.bats index 0a8cc62b..cb826208 100644 --- a/test/mail_ssl_letsencrypt.bats +++ b/test/mail_ssl_letsencrypt.bats @@ -9,28 +9,31 @@ function teardown() { } function setup_file() { + private_config="$(duplicate_config_for_container . mail_lets_domain)" docker run -d --name mail_lets_domain \ - -v "`pwd`/test/config":/tmp/docker-mailserver \ + -v "$private_config":/tmp/docker-mailserver \ -v "`pwd`/test/test-files":/tmp/docker-mailserver-test:ro \ - -v "`pwd`/test/config/letsencrypt/my-domain.com":/etc/letsencrypt/live/my-domain.com \ + -v "$private_config/letsencrypt/my-domain.com":/etc/letsencrypt/live/my-domain.com \ -e DMS_DEBUG=0 \ -e SSL_TYPE=letsencrypt \ -h mail.my-domain.com -t ${NAME} wait_for_finished_setup_in_container mail_lets_domain + private_config="$(duplicate_config_for_container . mail_lets_hostname)" docker run -d --name mail_lets_hostname \ - -v "`pwd`/test/config":/tmp/docker-mailserver \ + -v "$private_config":/tmp/docker-mailserver \ -v "`pwd`/test/test-files":/tmp/docker-mailserver-test:ro \ - -v "`pwd`/test/config/letsencrypt/mail.my-domain.com":/etc/letsencrypt/live/mail.my-domain.com \ + -v "$private_config/letsencrypt/mail.my-domain.com":/etc/letsencrypt/live/mail.my-domain.com \ -e DMS_DEBUG=0 \ -e SSL_TYPE=letsencrypt \ -h mail.my-domain.com -t ${NAME} wait_for_finished_setup_in_container mail_lets_hostname - cp "`pwd`/test/config/letsencrypt/acme.json" "`pwd`/test/config/acme.json" + private_config="$(duplicate_config_for_container . mail_lets_acme_json)" + cp "$(private_config_path mail_lets_acme_json)/letsencrypt/acme.json" "$(private_config_path mail_lets_acme_json)/acme.json" docker run -d --name mail_lets_acme_json \ - -v "`pwd`/test/config":/tmp/docker-mailserver \ - -v "`pwd`/test/config/acme.json":/etc/letsencrypt/acme.json:ro \ + -v "$private_config":/tmp/docker-mailserver \ + -v "$private_config/acme.json":/etc/letsencrypt/acme.json:ro \ -v "`pwd`/test/test-files":/tmp/docker-mailserver-test:ro \ -e DMS_DEBUG=0 \ -e SSL_TYPE=letsencrypt \ @@ -44,7 +47,6 @@ function teardown_file() { docker rm -f mail_lets_domain docker rm -f mail_lets_hostname docker rm -f mail_lets_acme_json - rm "`pwd`/test/config/acme.json" } # this test must come first to reliably identify when to run setup_file @@ -103,16 +105,16 @@ function teardown_file() { @test "can extract certs from acme.json" { run docker exec mail_lets_acme_json /bin/bash -c "cat /etc/letsencrypt/live/mail.my-domain.com/key.pem" - assert_output "$(cat "`pwd`/test/config/letsencrypt/mail.my-domain.com/privkey.pem")" + assert_output "$(cat "$(private_config_path mail_lets_acme_json)/letsencrypt/mail.my-domain.com/privkey.pem")" assert_success run docker exec mail_lets_acme_json /bin/bash -c "cat /etc/letsencrypt/live/mail.my-domain.com/fullchain.pem" - assert_output "$(cat "`pwd`/test/config/letsencrypt/mail.my-domain.com/fullchain.pem")" + assert_output "$(cat "$(private_config_path mail_lets_acme_json)/letsencrypt/mail.my-domain.com/fullchain.pem")" assert_success } @test "can detect changes" { - cp "`pwd`/test/config/letsencrypt/acme-changed.json" "`pwd`/test/config/acme.json" + cp "$(private_config_path mail_lets_acme_json)/letsencrypt/acme-changed.json" "$(private_config_path mail_lets_acme_json)/acme.json" sleep 11 run docker exec mail_lets_acme_json /bin/bash -c "supervisorctl tail changedetector" assert_output --partial "Cert found in /etc/letsencrypt/acme.json for *.example.com" @@ -121,11 +123,11 @@ function teardown_file() { assert_output --partial "Change detected" run docker exec mail_lets_acme_json /bin/bash -c "cat /etc/letsencrypt/live/mail.my-domain.com/key.pem" - assert_output "$(cat "`pwd`/test/config/letsencrypt/changed/key.pem")" + assert_output "$(cat "$(private_config_path mail_lets_acme_json)/letsencrypt/changed/key.pem")" assert_success run docker exec mail_lets_acme_json /bin/bash -c "cat /etc/letsencrypt/live/mail.my-domain.com/fullchain.pem" - assert_output "$(cat "`pwd`/test/config/letsencrypt/changed/fullchain.pem")" + assert_output "$(cat "$(private_config_path mail_lets_acme_json)/letsencrypt/changed/fullchain.pem")" assert_success } diff --git a/test/mail_ssl_manual.bats b/test/mail_ssl_manual.bats index 00465ebd..0ce0a90c 100644 --- a/test/mail_ssl_manual.bats +++ b/test/mail_ssl_manual.bats @@ -10,7 +10,7 @@ function teardown() { function setup_file() { docker run -d --name mail_manual_ssl \ - -v "`pwd`/test/config":/tmp/docker-mailserver \ + -v "$(duplicate_config_for_container .)":/tmp/docker-mailserver \ -v "`pwd`/test/test-files":/tmp/docker-mailserver-test:ro \ -e SSL_TYPE=manual \ -e SSL_CERT_PATH=/tmp/docker-mailserver/letsencrypt/mail.my-domain.com/fullchain.pem \ diff --git a/test/mail_undef_spam_subject.bats b/test/mail_undef_spam_subject.bats index 5798f2bb..0f9b83c7 100644 --- a/test/mail_undef_spam_subject.bats +++ b/test/mail_undef_spam_subject.bats @@ -2,13 +2,13 @@ load 'test_helper/common' function setup() { docker run -d --name mail_undef_spam_subject \ - -v "`pwd`/test/config":/tmp/docker-mailserver \ + -v "$(duplicate_config_for_container .)":/tmp/docker-mailserver \ -v "`pwd`/test/test-files":/tmp/docker-mailserver-test:ro \ -e ENABLE_SPAMASSASSIN=1 \ -e SA_SPAM_SUBJECT="undef" \ -h mail.my-domain.com -t ${NAME} CONTAINER=$(docker run -d \ - -v "`pwd`/test/config":/tmp/docker-mailserver \ + -v "$(duplicate_config_for_container . mail_undef_spam_subject_2)":/tmp/docker-mailserver \ -v "`pwd`/test/test-files":/tmp/docker-mailserver-test:ro \ -v "`pwd`/test/onedir":/var/mail-state \ -e ENABLE_CLAMAV=1 \ diff --git a/test/mail_with_imap.bats b/test/mail_with_imap.bats index ae867c5f..0b23693a 100644 --- a/test/mail_with_imap.bats +++ b/test/mail_with_imap.bats @@ -11,7 +11,7 @@ teardown() { setup_file() { docker run -d --name mail_with_imap \ - -v "`pwd`/test/config":/tmp/docker-mailserver \ + -v "$(duplicate_config_for_container .)":/tmp/docker-mailserver \ -v "`pwd`/test/test-files":/tmp/docker-mailserver-test:ro \ -e ENABLE_SASLAUTHD=1 \ -e SASLAUTHD_MECHANISMS=rimap \ diff --git a/test/mail_with_ldap.bats b/test/mail_with_ldap.bats index a236035c..3b4254a8 100644 --- a/test/mail_with_ldap.bats +++ b/test/mail_with_ldap.bats @@ -18,7 +18,7 @@ function setup_file() { -h ldap.my-domain.com -t ldap docker run -d --name mail_with_ldap \ - -v "`pwd`/test/config":/tmp/docker-mailserver \ + -v "$(duplicate_config_for_container .)":/tmp/docker-mailserver \ -v "`pwd`/test/test-files":/tmp/docker-mailserver-test:ro \ -e ENABLE_LDAP=1 \ -e LDAP_SERVER_HOST=ldap \ diff --git a/test/mail_with_mdbox.bats b/test/mail_with_mdbox.bats index 535aa801..8913eff4 100644 --- a/test/mail_with_mdbox.bats +++ b/test/mail_with_mdbox.bats @@ -10,7 +10,7 @@ teardown() { setup_file() { docker run -d --name mail_with_mdbox_format \ - -v "`pwd`/test/config":/tmp/docker-mailserver \ + -v "$(duplicate_config_for_container .)":/tmp/docker-mailserver \ -v "`pwd`/test/test-files":/tmp/docker-mailserver-test:ro \ -e SASL_PASSWD="external-domain.com username:password" \ -e ENABLE_CLAMAV=0 \ diff --git a/test/mail_with_postgrey.bats b/test/mail_with_postgrey.bats index 03248295..11ce2f04 100644 --- a/test/mail_with_postgrey.bats +++ b/test/mail_with_postgrey.bats @@ -10,7 +10,7 @@ function teardown() { function setup_file() { docker run -d --name mail_with_postgrey \ - -v "`pwd`/test/config":/tmp/docker-mailserver \ + -v "$(duplicate_config_for_container .)":/tmp/docker-mailserver \ -v "`pwd`/test/test-files":/tmp/docker-mailserver-test:ro \ -e ENABLE_POSTGREY=1 \ -e POSTGREY_DELAY=15 \ diff --git a/test/mail_with_postgrey_disabled_by_default.bats b/test/mail_with_postgrey_disabled_by_default.bats index d71108b4..31b4baf5 100644 --- a/test/mail_with_postgrey_disabled_by_default.bats +++ b/test/mail_with_postgrey_disabled_by_default.bats @@ -2,7 +2,7 @@ load 'test_helper/common' function setup() { CONTAINER=$(docker run -d \ - -v "`pwd`/test/config":/tmp/docker-mailserver \ + -v "$(duplicate_config_for_container .)":/tmp/docker-mailserver \ -v "`pwd`/test/test-files":/tmp/docker-mailserver-test:ro \ -e DMS_DEBUG=0 \ -h mail.my-domain.com -t ${NAME}) diff --git a/test/mail_with_sdbox.bats b/test/mail_with_sdbox.bats index 2f3d2202..2056d480 100644 --- a/test/mail_with_sdbox.bats +++ b/test/mail_with_sdbox.bats @@ -10,7 +10,7 @@ teardown() { setup_file() { docker run -d --name mail_with_sdbox_format \ - -v "`pwd`/test/config":/tmp/docker-mailserver \ + -v "$(duplicate_config_for_container .)":/tmp/docker-mailserver \ -v "`pwd`/test/test-files":/tmp/docker-mailserver-test:ro \ -e SASL_PASSWD="external-domain.com username:password" \ -e ENABLE_CLAMAV=0 \ diff --git a/test/permit_docker.bats b/test/permit_docker.bats index 4429ab11..3edb6cdd 100644 --- a/test/permit_docker.bats +++ b/test/permit_docker.bats @@ -8,7 +8,7 @@ setup() { # currently we cannot use --network in `docker run` multiple times, it will just use the last one # instead we need to use create, network connect and start (see https://success.docker.com/article/multiple-docker-networks) docker create --name mail_smtponly_second_network \ - -v "`pwd`/test/config":/tmp/docker-mailserver \ + -v "$(duplicate_config_for_container . mail_smtponly_second_network)":/tmp/docker-mailserver \ -v "`pwd`/test/test-files":/tmp/docker-mailserver-test:ro \ -e SMTP_ONLY=1 \ -e PERMIT_DOCKER=connected-networks \ @@ -19,7 +19,7 @@ setup() { docker network connect ${NON_DEFAULT_DOCKER_MAIL_NETWORK_NAME}2 mail_smtponly_second_network docker start mail_smtponly_second_network docker run -d --name mail_smtponly_second_network_sender \ - -v "`pwd`/test/config":/tmp/docker-mailserver \ + -v "$(duplicate_config_for_container . mail_smtponly_second_network_sender)":/tmp/docker-mailserver \ -v "`pwd`/test/test-files":/tmp/docker-mailserver-test:ro \ -e SMTP_ONLY=1 \ -e PERMIT_DOCKER=connected-networks \ diff --git a/test/test_helper/common.bash b/test/test_helper/common.bash index f537d95c..929cc8cc 100644 --- a/test/test_helper/common.bash +++ b/test/test_helper/common.bash @@ -105,3 +105,19 @@ function run_teardown_file_if_necessary() { teardown_file fi } + +# get the private config path for the given container or test file, if no container name was given +function private_config_path() { + echo "$PWD/test/duplicate_configs/${1:$BATS_TEST_FILENAME}" +} + +# @param $1 relative source in test/config folder +# @param $2 (optional) container name, defaults to $BATS_TEST_FILENAME +# @return path to the folder where the config is duplicated +function duplicate_config_for_container() { + output="$(private_config_path "$2")" + rm -rf "$output" # cleanup + mkdir -p "$output" + cp -r "$PWD/test/config/$1" "$output" + echo "$output" +} \ No newline at end of file diff --git a/test/tests.bats b/test/tests.bats index fcc3841f..1193fcc4 100644 --- a/test/tests.bats +++ b/test/tests.bats @@ -7,11 +7,12 @@ setup() { } setup_file() { + private_config="$(duplicate_config_for_container . mail)" docker run --rm -d --name mail \ - -v "`pwd`/test/config":/tmp/docker-mailserver \ + -v "$private_config":/tmp/docker-mailserver \ -v "`pwd`/test/test-files":/tmp/docker-mailserver-test:ro \ -v "`pwd`/test/onedir":/var/mail-state \ - -v "`pwd`/test/config/user-patches/user-patches.sh":/tmp/docker-mailserver/user-patches.sh \ + -v "$private_config/user-patches/user-patches.sh":/tmp/docker-mailserver/user-patches.sh \ -e ENABLE_CLAMAV=1 \ -e SPOOF_PROTECTION=1 \ -e ENABLE_SPAMASSASSIN=1 \ @@ -32,7 +33,7 @@ setup_file() { # generate account after run docker exec mail addmailuser pass@localhost.localdomain 'may be \a `p^a.*ssword' # setup sieve - repeat_until_success_or_timeout 15 docker cp "`pwd`/test/config/sieve/dovecot.sieve" mail:/var/mail/localhost.localdomain/user1/.dovecot.sieve + repeat_until_success_or_timeout 15 docker cp "$private_config/sieve/dovecot.sieve" mail:/var/mail/localhost.localdomain/user1/.dovecot.sieve wait_for_smtp_port_in_container mail # sending test mails docker exec mail /bin/sh -c "nc 0.0.0.0 25 < /tmp/docker-mailserver-test/email-templates/amavis-spam.txt" @@ -460,18 +461,21 @@ EOF # Instead it tests the file-size (here 511) - which may differ with a different domain names # This test may be re-used as a global test to provide better test coverage. @test "checking opendkim: generator creates default keys size" { + private_config="$(duplicate_config_for_container . mail_default_key_size)" # Prepare default key size 2048 - rm -rf "$(pwd)/test/config/keyDefault" && mkdir -p "$(pwd)/test/config/keyDefault" + rm -rf "$private_config/keyDefault" + mkdir -p "$private_config/keyDefault" + run docker run --rm \ - -v "$(pwd)/test/config/keyDefault/":/tmp/docker-mailserver/ \ - -v "$(pwd)/test/config/postfix-accounts.cf":/tmp/docker-mailserver/postfix-accounts.cf \ - -v "$(pwd)/test/config/postfix-virtual.cf":/tmp/docker-mailserver/postfix-virtual.cf \ + -v "$private_config/keyDefault/":/tmp/docker-mailserver/ \ + -v "$private_config/postfix-accounts.cf":/tmp/docker-mailserver/postfix-accounts.cf \ + -v "$private_config/postfix-virtual.cf":/tmp/docker-mailserver/postfix-virtual.cf \ `docker inspect --format '{{ .Config.Image }}' mail` /bin/sh -c 'generate-dkim-config | wc -l' assert_success assert_output 6 run docker run --rm \ - -v "$(pwd)/test/config/keyDefault/opendkim":/etc/opendkim \ + -v "$private_config/keyDefault/opendkim":/etc/opendkim \ `docker inspect --format '{{ .Config.Image }}' mail` \ /bin/sh -c 'stat -c%s /etc/opendkim/keys/localhost.localdomain/mail.txt' @@ -483,18 +487,20 @@ EOF # Instead it tests the file-size (here 511) - which may differ with a different domain names # This test may be re-used as a global test to provide better test coverage. @test "checking opendkim: generator creates key size 2048" { + private_config="$(duplicate_config_for_container . mail_key_size_2048)" # Prepare set key size 2048 - rm -rf "$(pwd)/test/config/key2048" && mkdir -p "$(pwd)/test/config/key2048" + rm -rf "$private_config/key2048" + mkdir -p "$private_config/config/key2048" run docker run --rm \ - -v "$(pwd)/test/config/key2048/":/tmp/docker-mailserver/ \ - -v "$(pwd)/test/config/postfix-accounts.cf":/tmp/docker-mailserver/postfix-accounts.cf \ - -v "$(pwd)/test/config/postfix-virtual.cf":/tmp/docker-mailserver/postfix-virtual.cf \ + -v "$private_config/key2048/":/tmp/docker-mailserver/ \ + -v "$private_config/postfix-accounts.cf":/tmp/docker-mailserver/postfix-accounts.cf \ + -v "$private_config/postfix-virtual.cf":/tmp/docker-mailserver/postfix-virtual.cf \ `docker inspect --format '{{ .Config.Image }}' mail` /bin/sh -c 'generate-dkim-config 2048 | wc -l' assert_success assert_output 6 run docker run --rm \ - -v "$(pwd)/test/config/key2048/opendkim":/etc/opendkim \ + -v "$private_config/key2048/opendkim":/etc/opendkim \ `docker inspect --format '{{ .Config.Image }}' mail` \ /bin/sh -c 'stat -c%s /etc/opendkim/keys/localhost.localdomain/mail.txt' @@ -506,18 +512,20 @@ EOF # Instead it tests the file-size (here 329) - which may differ with a different domain names # This test may be re-used as a global test to provide better test coverage. @test "checking opendkim: generator creates key size 1024" { + private_config="$(duplicate_config_for_container . mail_key_size_1024)" # Prepare set key size 1024 - rm -rf "$(pwd)/test/config/key1024" && mkdir -p "$(pwd)/test/config/key1024" + rm -rf "$private_config/key1024" + mkdir -p "$private_config/key1024" run docker run --rm \ - -v "$(pwd)/test/config/key1024/":/tmp/docker-mailserver/ \ - -v "$(pwd)/test/config/postfix-accounts.cf":/tmp/docker-mailserver/postfix-accounts.cf \ - -v "$(pwd)/test/config/postfix-virtual.cf":/tmp/docker-mailserver/postfix-virtual.cf \ + -v "$private_config/key1024/":/tmp/docker-mailserver/ \ + -v "$private_config/postfix-accounts.cf":/tmp/docker-mailserver/postfix-accounts.cf \ + -v "$private_config/postfix-virtual.cf":/tmp/docker-mailserver/postfix-virtual.cf \ `docker inspect --format '{{ .Config.Image }}' mail` /bin/sh -c 'generate-dkim-config 1024 | wc -l' assert_success assert_output 6 run docker run --rm \ - -v "$(pwd)/test/config/key1024/opendkim":/etc/opendkim \ + -v "$private_config/key1024/opendkim":/etc/opendkim \ `docker inspect --format '{{ .Config.Image }}' mail` \ /bin/sh -c 'stat -c%s /etc/opendkim/keys/localhost.localdomain/mail.txt' @@ -526,139 +534,146 @@ EOF } @test "checking opendkim: generator creates keys, tables and TrustedHosts" { - rm -rf "$(pwd)/test/config/empty" && mkdir -p "$(pwd)/test/config/empty" + private_config="$(duplicate_config_for_container . mail_dkim_generator_creates_keys_tables_TrustedHosts)" + rm -rf "$private_config/empty" + mkdir -p "$private_config/empty" run docker run --rm \ - -v "$(pwd)/test/config/empty/":/tmp/docker-mailserver/ \ - -v "$(pwd)/test/config/postfix-accounts.cf":/tmp/docker-mailserver/postfix-accounts.cf \ - -v "$(pwd)/test/config/postfix-virtual.cf":/tmp/docker-mailserver/postfix-virtual.cf \ + -v "$private_config/empty/":/tmp/docker-mailserver/ \ + -v "$private_config/postfix-accounts.cf":/tmp/docker-mailserver/postfix-accounts.cf \ + -v "$private_config/postfix-virtual.cf":/tmp/docker-mailserver/postfix-virtual.cf \ `docker inspect --format '{{ .Config.Image }}' mail` /bin/sh -c 'generate-dkim-config | wc -l' assert_success assert_output 6 # Check keys for localhost.localdomain run docker run --rm \ - -v "$(pwd)/test/config/empty/opendkim":/etc/opendkim \ + -v "$private_config/empty/opendkim":/etc/opendkim \ `docker inspect --format '{{ .Config.Image }}' mail` /bin/sh -c 'ls -1 /etc/opendkim/keys/localhost.localdomain/ | wc -l' assert_success assert_output 2 # Check keys for otherdomain.tld run docker run --rm \ - -v "$(pwd)/test/config/empty/opendkim":/etc/opendkim \ + -v "$private_config/empty/opendkim":/etc/opendkim \ `docker inspect --format '{{ .Config.Image }}' mail` /bin/sh -c 'ls -1 /etc/opendkim/keys/otherdomain.tld | wc -l' assert_success assert_output 2 # Check presence of tables and TrustedHosts run docker run --rm \ - -v "$(pwd)/test/config/empty/opendkim":/etc/opendkim \ + -v "$private_config/empty/opendkim":/etc/opendkim \ `docker inspect --format '{{ .Config.Image }}' mail` /bin/sh -c "ls -1 /etc/opendkim | grep -E 'KeyTable|SigningTable|TrustedHosts|keys'|wc -l" assert_success assert_output 4 } @test "checking opendkim: generator creates keys, tables and TrustedHosts without postfix-accounts.cf" { - rm -rf "$(pwd)/test/config/without-accounts" && mkdir -p "$(pwd)/test/config/without-accounts" + private_config="$(duplicate_config_for_container . mail_dkim_generator_creates_keys_tables_TrustedHosts_without_postfix_accounts.cf)" + rm -rf "$private_config/without-accounts" + mkdir -p "$private_config/without-accounts" run docker run --rm \ - -v "$(pwd)/test/config/without-accounts/":/tmp/docker-mailserver/ \ - -v "$(pwd)/test/config/postfix-virtual.cf":/tmp/docker-mailserver/postfix-virtual.cf \ + -v "$private_config/without-accounts/":/tmp/docker-mailserver/ \ + -v "$private_config/postfix-virtual.cf":/tmp/docker-mailserver/postfix-virtual.cf \ `docker inspect --format '{{ .Config.Image }}' mail` /bin/sh -c 'generate-dkim-config | wc -l' assert_success assert_output 5 # Check keys for localhost.localdomain run docker run --rm \ - -v "$(pwd)/test/config/without-accounts/opendkim":/etc/opendkim \ + -v "$private_config/without-accounts/opendkim":/etc/opendkim \ `docker inspect --format '{{ .Config.Image }}' mail` /bin/sh -c 'ls -1 /etc/opendkim/keys/localhost.localdomain/ | wc -l' assert_success assert_output 2 # Check keys for otherdomain.tld # run docker run --rm \ - # -v "$(pwd)/test/config/without-accounts/opendkim":/etc/opendkim \ + # -v "$private_config/without-accounts/opendkim":/etc/opendkim \ # `docker inspect --format '{{ .Config.Image }}' mail` /bin/sh -c 'ls -1 /etc/opendkim/keys/otherdomain.tld | wc -l' # assert_success # [ "$output" -eq 0 ] # Check presence of tables and TrustedHosts run docker run --rm \ - -v "$(pwd)/test/config/without-accounts/opendkim":/etc/opendkim \ + -v "$private_config/without-accounts/opendkim":/etc/opendkim \ `docker inspect --format '{{ .Config.Image }}' mail` /bin/sh -c "ls -1 /etc/opendkim | grep -E 'KeyTable|SigningTable|TrustedHosts|keys'|wc -l" assert_success assert_output 4 } @test "checking opendkim: generator creates keys, tables and TrustedHosts without postfix-virtual.cf" { - rm -rf "$(pwd)/test/config/without-virtual" && mkdir -p "$(pwd)/test/config/without-virtual" + private_config="$(duplicate_config_for_container . mail_dkim_generator_creates_keys_tables_TrustedHosts_without_postfix_virtual.cf)" + rm -rf "$private_config/without-virtual" + mkdir -p "$private_config/without-virtual" run docker run --rm \ - -v "$(pwd)/test/config/without-virtual/":/tmp/docker-mailserver/ \ - -v "$(pwd)/test/config/postfix-accounts.cf":/tmp/docker-mailserver/postfix-accounts.cf \ + -v "$private_config/without-virtual/":/tmp/docker-mailserver/ \ + -v "$private_config/postfix-accounts.cf":/tmp/docker-mailserver/postfix-accounts.cf \ `docker inspect --format '{{ .Config.Image }}' mail` /bin/sh -c 'generate-dkim-config | wc -l' assert_success assert_output 5 # Check keys for localhost.localdomain run docker run --rm \ - -v "$(pwd)/test/config/without-virtual/opendkim":/etc/opendkim \ + -v "$private_config/without-virtual/opendkim":/etc/opendkim \ `docker inspect --format '{{ .Config.Image }}' mail` /bin/sh -c 'ls -1 /etc/opendkim/keys/localhost.localdomain/ | wc -l' assert_success assert_output 2 # Check keys for otherdomain.tld run docker run --rm \ - -v "$(pwd)/test/config/without-virtual/opendkim":/etc/opendkim \ + -v "$private_config/without-virtual/opendkim":/etc/opendkim \ `docker inspect --format '{{ .Config.Image }}' mail` /bin/sh -c 'ls -1 /etc/opendkim/keys/otherdomain.tld | wc -l' assert_success assert_output 2 # Check presence of tables and TrustedHosts run docker run --rm \ - -v "$(pwd)/test/config/without-virtual/opendkim":/etc/opendkim \ + -v "$private_config/without-virtual/opendkim":/etc/opendkim \ `docker inspect --format '{{ .Config.Image }}' mail` /bin/sh -c "ls -1 /etc/opendkim | grep -E 'KeyTable|SigningTable|TrustedHosts|keys'|wc -l" assert_success assert_output 4 } @test "checking opendkim: generator creates keys, tables and TrustedHosts using domain name" { - rm -rf "$(pwd)/test/config/with-domain" && mkdir -p "$(pwd)/test/config/with-domain" + private_config="$(duplicate_config_for_container . mail_dkim_generator_creates_keys_tables_TrustedHosts_without_postfix_virtual.cf)" + rm -rf "$private_config/with-domain" && mkdir -p "$private_config/with-domain" run docker run --rm \ - -v "$(pwd)/test/config/with-domain/":/tmp/docker-mailserver/ \ - -v "$(pwd)/test/config/postfix-accounts.cf":/tmp/docker-mailserver/postfix-accounts.cf \ - -v "$(pwd)/test/config/postfix-virtual.cf":/tmp/docker-mailserver/postfix-virtual.cf \ + -v "$private_config/with-domain/":/tmp/docker-mailserver/ \ + -v "$private_config/postfix-accounts.cf":/tmp/docker-mailserver/postfix-accounts.cf \ + -v "$private_config/postfix-virtual.cf":/tmp/docker-mailserver/postfix-virtual.cf \ `docker inspect --format '{{ .Config.Image }}' mail` /bin/sh -c 'generate-dkim-config | wc -l' assert_success assert_output 6 # Generate key using domain name run docker run --rm \ - -v "$(pwd)/test/config/with-domain/":/tmp/docker-mailserver/ \ + -v "$private_config/with-domain/":/tmp/docker-mailserver/ \ `docker inspect --format '{{ .Config.Image }}' mail` /bin/sh -c 'generate-dkim-domain testdomain.tld | wc -l' assert_success assert_output 1 # Check keys for localhost.localdomain run docker run --rm \ - -v "$(pwd)/test/config/with-domain/opendkim":/etc/opendkim \ + -v "$private_config/with-domain/opendkim":/etc/opendkim \ `docker inspect --format '{{ .Config.Image }}' mail` /bin/sh -c 'ls -1 /etc/opendkim/keys/localhost.localdomain/ | wc -l' assert_success assert_output 2 # Check keys for otherdomain.tld run docker run --rm \ - -v "$(pwd)/test/config/with-domain/opendkim":/etc/opendkim \ + -v "$private_config/with-domain/opendkim":/etc/opendkim \ `docker inspect --format '{{ .Config.Image }}' mail` /bin/sh -c 'ls -1 /etc/opendkim/keys/otherdomain.tld | wc -l' assert_success assert_output 2 # Check keys for testdomain.tld run docker run --rm \ - -v "$(pwd)/test/config/with-domain/opendkim":/etc/opendkim \ + -v "$private_config/with-domain/opendkim":/etc/opendkim \ `docker inspect --format '{{ .Config.Image }}' mail` /bin/sh -c 'ls -1 /etc/opendkim/keys/testdomain.tld | wc -l' assert_success assert_output 2 # Check presence of tables and TrustedHosts run docker run --rm \ - -v "$(pwd)/test/config/with-domain/opendkim":/etc/opendkim \ + -v "$private_config/with-domain/opendkim":/etc/opendkim \ `docker inspect --format '{{ .Config.Image }}' mail` /bin/sh -c "ls -1 /etc/opendkim | grep -E 'KeyTable|SigningTable|TrustedHosts|keys' | wc -l" assert_success assert_output 4 # Check valid entries actually present in KeyTable run docker run --rm \ - -v "$(pwd)/test/config/with-domain/opendkim":/etc/opendkim \ + -v "$private_config/with-domain/opendkim":/etc/opendkim \ `docker inspect --format '{{ .Config.Image }}' mail` /bin/sh -c \ "egrep 'localhost.localdomain|otherdomain.tld|localdomain2.com|testdomain.tld' /etc/opendkim/KeyTable | wc -l" assert_success assert_output 4 # Check valid entries actually present in SigningTable run docker run --rm \ - -v "$(pwd)/test/config/with-domain/opendkim":/etc/opendkim \ + -v "$private_config/with-domain/opendkim":/etc/opendkim \ `docker inspect --format '{{ .Config.Image }}' mail` /bin/sh -c \ "egrep 'localhost.localdomain|otherdomain.tld|localdomain2.com|testdomain.tld' /etc/opendkim/SigningTable | wc -l" assert_success @@ -915,19 +930,20 @@ EOF @test "checking accounts: no error is generated when deleting a user if /tmp/docker-mailserver/postfix-accounts.cf is missing" { run docker run --rm \ - -v "$(pwd)/test/config/without-accounts/":/tmp/docker-mailserver/ \ + -v "$(duplicate_config_for_container without-accounts/ without-accounts-deleting-user)":/tmp/docker-mailserver/ \ `docker inspect --format '{{ .Config.Image }}' mail` /bin/sh -c 'delmailuser -y user3@domain.tld' assert_success [ -z "$output" ] } @test "checking accounts: user3 should have been added to /tmp/docker-mailserver/postfix-accounts.cf even when that file does not exist" { + private_config=$(duplicate_config_for_container without-accounts/ without-accounts_file_does_not_exist) run docker run --rm \ - -v "$(pwd)/test/config/without-accounts/":/tmp/docker-mailserver/ \ + -v "$private_config/without-accounts/":/tmp/docker-mailserver/ \ `docker inspect --format '{{ .Config.Image }}' mail` /bin/sh -c 'addmailuser user3@domain.tld mypassword' assert_success run docker run --rm \ - -v "$(pwd)/test/config/without-accounts/":/tmp/docker-mailserver/ \ + -v "$private_config/without-accounts/":/tmp/docker-mailserver/ \ `docker inspect --format '{{ .Config.Image }}' mail` /bin/sh -c 'grep user3@domain.tld -i /tmp/docker-mailserver/postfix-accounts.cf' assert_success [ ! -z "$output" ] From 97806859b62421e9795c384039dd5d6033cb2ddf Mon Sep 17 00:00:00 2001 From: Martin Schulze Date: Fri, 18 Sep 2020 02:21:01 +0200 Subject: [PATCH 08/50] Fix private_config_path creating the wrong folder --- test/test_helper/common.bash | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/test_helper/common.bash b/test/test_helper/common.bash index 929cc8cc..09240710 100644 --- a/test/test_helper/common.bash +++ b/test/test_helper/common.bash @@ -108,7 +108,7 @@ function run_teardown_file_if_necessary() { # get the private config path for the given container or test file, if no container name was given function private_config_path() { - echo "$PWD/test/duplicate_configs/${1:$BATS_TEST_FILENAME}" + echo "$PWD/test/duplicate_configs/${1:-$(basename "$BATS_TEST_FILENAME")}" } # @param $1 relative source in test/config folder @@ -118,6 +118,6 @@ function duplicate_config_for_container() { output="$(private_config_path "$2")" rm -rf "$output" # cleanup mkdir -p "$output" - cp -r "$PWD/test/config/$1" "$output" + cp -r "$PWD/test/config/${1:?}/." "$output" echo "$output" } \ No newline at end of file From 0eb5bd0db9d9434839c95b7b5d2531478929da57 Mon Sep 17 00:00:00 2001 From: Martin Schulze Date: Fri, 18 Sep 2020 02:21:24 +0200 Subject: [PATCH 09/50] Add --fatal-tests for early out in container waits --- test/test_helper/common.bash | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/test/test_helper/common.bash b/test/test_helper/common.bash index 09240710..c08621c9 100644 --- a/test/test_helper/common.bash +++ b/test/test_helper/common.bash @@ -11,6 +11,11 @@ NUMBER_OF_LOG_LINES=${NUMBER_OF_LOG_LINES-10} # @param --fatal-test additional test whose failure aborts immediately # @param ... test to run function repeat_until_success_or_timeout { + local fatal_failure_test_command + if [[ "$1" == "--fatal-test" ]]; then + fatal_failure_test_command="$2" + shift 2 + fi if ! [[ "$1" =~ ^[0-9]+$ ]]; then echo "First parameter for timeout must be an integer, recieved \"$1\"" return 1 @@ -18,11 +23,6 @@ function repeat_until_success_or_timeout { TIMEOUT=$1 STARTTIME=$SECONDS shift 1 - local fatal_failure_test_command - if [[ "$1" == "--fatal-test" ]]; then - fatal_failure_test_command="$2" - shift 2 - fi until "$@" do if [[ -n "$fatal_failure_test_command" ]] && ! eval "$fatal_failure_test_command"; then @@ -44,7 +44,7 @@ function repeat_in_container_until_success_or_timeout() { timeout="$1" container_name="$2" shift 2 - repeat_until_success_or_timeout "$timeout" --fatal-test "container_is_running $container_name" docker exec "$container_name" "$@" + repeat_until_success_or_timeout --fatal-test "container_is_running $container_name" "$timeout" docker exec "$container_name" "$@" } function container_is_running() { @@ -54,23 +54,23 @@ function container_is_running() { # @param $1 port # @param $2 container name function wait_for_tcp_port_in_container() { - repeat_until_success_or_timeout $TEST_TIMEOUT_IN_SECONDS --fatal-test "container_is_running $2" docker exec $2 /bin/sh -c "nc -z 0.0.0.0 $1" + repeat_until_success_or_timeout --fatal-test "container_is_running $2" "$TEST_TIMEOUT_IN_SECONDS" docker exec $2 /bin/sh -c "nc -z 0.0.0.0 $1" } # @param $1 name of the postfix container function wait_for_smtp_port_in_container() { - wait_for_tcp_port_in_container 25 $1 + wait_for_tcp_port_in_container 25 "$1" } # @param $1 name of the postfix container function wait_for_amavis_port_in_container() { - wait_for_tcp_port_in_container 10024 $1 + wait_for_tcp_port_in_container 10024 "$1" } # @param $1 name of the postfix container function wait_for_finished_setup_in_container() { local status=0 - repeat_until_success_or_timeout $TEST_TIMEOUT_IN_SECONDS sh -c "docker logs $1 | grep 'is up and running'" || status=1 + repeat_until_success_or_timeout --fatal-test "container_is_running $1" "$TEST_TIMEOUT_IN_SECONDS" sh -c "docker logs $1 | grep 'is up and running'" || status=1 if [[ $status -eq 1 ]]; then echo "Last $NUMBER_OF_LOG_LINES lines of container \`$1\`'s log" docker logs $1 | tail -n $NUMBER_OF_LOG_LINES From b90faaeb356ce6a0c4cd74020a30edec3efd488c Mon Sep 17 00:00:00 2001 From: Martin Schulze Date: Sun, 20 Sep 2020 01:08:39 +0200 Subject: [PATCH 10/50] Ignore generated files --- .gitignore | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.gitignore b/.gitignore index e4031321..c5f8cfa6 100644 --- a/.gitignore +++ b/.gitignore @@ -38,3 +38,7 @@ test/config/without-accounts/ test/config/without-virtual/ test/config/with-domain/ test/onedir +test/duplicate_configs + +config.bak +testconfig.bak From ef80c6b2a36c80d3d29e0fb2ce07eead9f37685d Mon Sep 17 00:00:00 2001 From: Martin Schulze Date: Sun, 20 Sep 2020 01:09:10 +0200 Subject: [PATCH 11/50] Add setup/teardown marker tests --- test/tests.bats | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/test/tests.bats b/test/tests.bats index 1193fcc4..6f775111 100644 --- a/test/tests.bats +++ b/test/tests.bats @@ -85,6 +85,11 @@ function count_processed_changes() { docker exec $containerName cat /var/log/supervisor/changedetector.log | grep "Change detected" | wc -l } +# this test must come first to reliably identify when to run setup_file +@test "first" { + skip 'Starting testing of letsencrypt SSL' +} + # # configuration checks # @@ -238,7 +243,7 @@ function count_processed_changes() { @test "checking smtp: delivers mail to existing account" { run docker exec mail /bin/sh -c "grep 'postfix/lmtp' /var/log/mail/mail.log | grep 'status=sent' | grep ' Saved)' | sed 's/.* to= 6 1 , orig_to= @@ -1624,3 +1629,7 @@ EOF run docker exec mail grep "Subject: Root Test Message" /var/mail/localhost.localdomain/user1/new/ -R assert_success } + +@test "last" { + # this test is only there to reliably mark the end for the teardown_file +} From a477040abb638846bd3e513720d03c06fc83892a Mon Sep 17 00:00:00 2001 From: Martin Schulze Date: Sun, 20 Sep 2020 01:09:39 +0200 Subject: [PATCH 12/50] Allow for seamless switching between old and new bats versions --- test/test_helper/common.bash | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/test/test_helper/common.bash b/test/test_helper/common.bash index c08621c9..428ddecd 100644 --- a/test/test_helper/common.bash +++ b/test/test_helper/common.bash @@ -80,8 +80,24 @@ function wait_for_finished_setup_in_container() { SETUP_FILE_MARKER="$BATS_TMPDIR/`basename \"$BATS_TEST_FILENAME\"`.setup_file" +function native_setup_teardown_file_support() { + VERSION_REGEX='([0-9]+)\.([0-9]+)\.([0-9]+)' + # bats versions that support setup_file out of the box don't need this + if [[ "$BATS_VERSION" =~ $VERSION_REGEX ]]; then + numeric_version=$(( (BASH_REMATCH[1] * 100 + BASH_REMATCH[2]) * 100 + BASH_REMATCH[3] )) + if [[ $numeric_version -ge 10201 ]]; then + if [ "$BATS_TEST_NAME" == 'test_first' ]; then + skip 'This version natively supports setup/teardown_file' + fi + return 0 + fi + fi + return 1 +} + # use in setup() in conjunction with a `@test "first" {}` to trigger setup_file reliably function run_setup_file_if_necessary() { + native_setup_teardown_file_support && return 0 if [ "$BATS_TEST_NAME" == 'test_first' ]; then # prevent old markers from marking success or get an error if we cannot remove due to permissions rm -f "$SETUP_FILE_MARKER" @@ -99,6 +115,7 @@ function run_setup_file_if_necessary() { # use in teardown() in conjunction with a `@test "last" {}` to trigger teardown_file reliably function run_teardown_file_if_necessary() { + native_setup_teardown_file_support && return 0 if [ "$BATS_TEST_NAME" == 'test_last' ]; then # cleanup setup file marker rm -f "$SETUP_FILE_MARKER" From 40dd3ae985a672ceb8682a3a145a2ccf57ac312e Mon Sep 17 00:00:00 2001 From: Martin Schulze Date: Sun, 20 Sep 2020 01:10:05 +0200 Subject: [PATCH 13/50] Implement and use run_until_success_or_timeout --- test/mail_with_relays.bats | 12 ++---------- test/test_helper/common.bash | 21 +++++++++++++++++++++ 2 files changed, 23 insertions(+), 10 deletions(-) diff --git a/test/mail_with_relays.bats b/test/mail_with_relays.bats index 5ae3e82d..07afab7e 100644 --- a/test/mail_with_relays.bats +++ b/test/mail_with_relays.bats @@ -51,11 +51,7 @@ function teardown_file() { run docker exec mail_with_relays grep -e domainzero.tld /etc/postfix/relayhost_map assert_output '' run ./setup.sh -c mail_with_relays email add user0@domainzero.tld password123 - for i in {1..10}; do - sleep 1 - run docker exec mail_with_relays grep -e domainzero.tld /etc/postfix/relayhost_map - [[ $status == 0 ]] && break - done + run_until_success_or_timeout 10 docker exec mail_with_relays grep -e domainzero.tld /etc/postfix/relayhost_map assert_output -e '^@domainzero.tld\s+\[default.relay.com\]:2525$' } @@ -63,11 +59,7 @@ function teardown_file() { run docker exec mail_with_relays grep -e domain2.tld /etc/postfix/relayhost_map assert_output '' run ./setup.sh -c mail_with_relays alias add user2@domain2.tld user2@domaintwo.tld - for i in {1..10}; do - sleep 1 - run docker exec mail_with_relays grep -e domain2.tld /etc/postfix/relayhost_map - [[ $status == 0 ]] && break - done + run_until_success_or_timeout 10 docker exec mail_with_relays grep -e domain2.tld /etc/postfix/relayhost_map assert_output -e '^@domain2.tld\s+\[default.relay.com\]:2525$' } diff --git a/test/test_helper/common.bash b/test/test_helper/common.bash index 428ddecd..5982cb94 100644 --- a/test/test_helper/common.bash +++ b/test/test_helper/common.bash @@ -37,6 +37,27 @@ function repeat_until_success_or_timeout { done } +# like repeat_until_success_or_timeout but with wrapping the command to run into `run` for later bats consumption +# @param $1 timeout +# @param ... test command to run +function run_until_success_or_timeout { + if ! [[ "$1" =~ ^[0-9]+$ ]]; then + echo "First parameter for timeout must be an integer, recieved \"$1\"" + return 1 + fi + TIMEOUT=$1 + STARTTIME=$SECONDS + shift 1 + until run "$@" && [[ $status -eq 0 ]] + do + sleep 1 + if [[ $(($SECONDS - $STARTTIME )) -gt $TIMEOUT ]]; then + echo "Timed out on command: $@" >&2 + return 1 + fi + done +} + # @param $1 timeout # @param $2 container name # @param ... test command for container From d76493c76114edefcd271b378757ecd8a65c6ce6 Mon Sep 17 00:00:00 2001 From: Martin Schulze Date: Sun, 20 Sep 2020 02:13:05 +0200 Subject: [PATCH 14/50] Add TODOs --- Makefile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index e54669d3..a3016c1a 100644 --- a/Makefile +++ b/Makefile @@ -30,7 +30,8 @@ generate-accounts: # TODO: ensure this is run per container after each container started! generate-accounts-after-run: - @ docker run --rm -e MAIL_USER=added@localhost.localdomain -e MAIL_PASS=mypassword -t $(NAME) /bin/sh -c 'echo "$$MAIL_USER|$$(doveadm pw -s SHA512-CRYPT -u $$MAIL_USER -p $$MAIL_PASS)"' >> test/config/postfix-accounts.cf + # todo: noone seems to care about this? + #@ docker run --rm -e MAIL_USER=added@localhost.localdomain -e MAIL_PASS=mypassword -t $(NAME) /bin/sh -c 'echo "$$MAIL_USER|$$(doveadm pw -s SHA512-CRYPT -u $$MAIL_USER -p $$MAIL_PASS)"' >> test/config/postfix-accounts.cf @ sleep $(SLEEP) tests: From 969b50fb32fc32cc24db6f512499f6e9c9efb088 Mon Sep 17 00:00:00 2001 From: Martin Schulze Date: Sun, 20 Sep 2020 02:21:27 +0200 Subject: [PATCH 15/50] travis: Fix test command --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 7faa4755..d5972626 100644 --- a/.travis.yml +++ b/.travis.yml @@ -39,7 +39,7 @@ script: - make eclint - make hadolint - make shellcheck - - make generate-accounts run generate-accounts-after-run fixtures tests + - make generate-accounts tests after_script: - make clean From ca3ebc6c40aa3546e37f77e6d30fb64a66112ac4 Mon Sep 17 00:00:00 2001 From: Martin Schulze Date: Tue, 22 Sep 2020 01:08:06 +0200 Subject: [PATCH 16/50] Improve error messages on problems --- test/test_helper/common.bash | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/test_helper/common.bash b/test/test_helper/common.bash index 5982cb94..75dbff5d 100644 --- a/test/test_helper/common.bash +++ b/test/test_helper/common.bash @@ -154,7 +154,7 @@ function private_config_path() { # @return path to the folder where the config is duplicated function duplicate_config_for_container() { output="$(private_config_path "$2")" - rm -rf "$output" # cleanup + rm -r "${output:?}/" # cleanup mkdir -p "$output" cp -r "$PWD/test/config/${1:?}/." "$output" echo "$output" From 854cb2ba51c924ddffca429c6f573a2281675577 Mon Sep 17 00:00:00 2001 From: Martin Schulze Date: Tue, 22 Sep 2020 01:08:28 +0200 Subject: [PATCH 17/50] Remove duplicate_configs on cleanup --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index a3016c1a..19a3c11f 100644 --- a/Makefile +++ b/Makefile @@ -52,7 +52,7 @@ clean: sudo rm -rf test/config ;\ mv testconfig.bak test/config ;\ fi - -@ sudo rm -rf test/onedir test/alias test/quota test/relay test/config/dovecot-lmtp/userdb test/config/key* test/config/opendkim/keys/domain.tld/ test/config/opendkim/keys/example.com/ test/config/opendkim/keys/localdomain2.com/ test/config/postfix-aliases.cf test/config/postfix-receive-access.cf test/config/postfix-receive-access.cfe test/config/dovecot-quotas.cf test/config/postfix-send-access.cf test/config/postfix-send-access.cfe test/config/relay-hosts/chksum test/config/relay-hosts/postfix-aliases.cf test/config/dhparams.pem test/config/dovecot-lmtp/dh.pem test/config/relay-hosts/dovecot-quotas.cf test/config/user-patches.sh test/alias/config/postfix-virtual.cf test/quota/config/dovecot-quotas.cf test/quota/config/postfix-accounts.cf test/relay/config/postfix-relaymap.cf test/relay/config/postfix-sasl-password.cf + -@ sudo rm -rf test/onedir test/alias test/quota test/relay test/config/dovecot-lmtp/userdb test/config/key* test/config/opendkim/keys/domain.tld/ test/config/opendkim/keys/example.com/ test/config/opendkim/keys/localdomain2.com/ test/config/postfix-aliases.cf test/config/postfix-receive-access.cf test/config/postfix-receive-access.cfe test/config/dovecot-quotas.cf test/config/postfix-send-access.cf test/config/postfix-send-access.cfe test/config/relay-hosts/chksum test/config/relay-hosts/postfix-aliases.cf test/config/dhparams.pem test/config/dovecot-lmtp/dh.pem test/config/relay-hosts/dovecot-quotas.cf test/config/user-patches.sh test/alias/config/postfix-virtual.cf test/quota/config/dovecot-quotas.cf test/quota/config/postfix-accounts.cf test/relay/config/postfix-relaymap.cf test/relay/config/postfix-sasl-password.cf test/duplicate_configs/ lint: eclint hadolint shellcheck From a90e043e4574ac65fe9df245005929337303703b Mon Sep 17 00:00:00 2001 From: Martin Schulze Date: Tue, 22 Sep 2020 01:09:17 +0200 Subject: [PATCH 18/50] Fix failing tests due to old paths --- test/tests.bats | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/tests.bats b/test/tests.bats index 6f775111..8373a6db 100644 --- a/test/tests.bats +++ b/test/tests.bats @@ -1245,7 +1245,7 @@ EOF run ./setup.sh -c mail email add setup_email_add@example.com test_password assert_success - value=$(cat ./test/config/postfix-accounts.cf | grep setup_email_add@example.com | awk -F '|' '{print $1}') + value=$(cat $(private_config_path mail)/postfix-accounts.cf | grep setup_email_add@example.com | awk -F '|' '{print $1}') [ "$value" = "setup_email_add@example.com" ] assert_success @@ -1280,14 +1280,14 @@ EOF run ./setup.sh -c mail email add lorem@impsum.org test_test assert_success - initialpass=$(cat ./test/config/postfix-accounts.cf | grep lorem@impsum.org | awk -F '|' '{print $2}') + initialpass=$(cat $(private_config_path mail)/postfix-accounts.cf | grep lorem@impsum.org | awk -F '|' '{print $2}') [ "$initialpass" != "" ] assert_success run ./setup.sh -c mail email update lorem@impsum.org my password assert_success - updatepass=$(cat ./test/config/postfix-accounts.cf | grep lorem@impsum.org | awk -F '|' '{print $2}') + updatepass=$(cat $(private_config_path mail)/postfix-accounts.cf | grep lorem@impsum.org | awk -F '|' '{print $2}') [ "$updatepass" != "" ] assert_success @@ -1310,7 +1310,7 @@ EOF # # run docker exec mail ls /var/mail/impsum.org/lorem # assert_failure - run grep lorem@impsum.org ./test/config/postfix-accounts.cf + run grep lorem@impsum.org $(private_config_path mail)/postfix-accounts.cf assert_failure } From e1d0fcfe018551b5f9a6f55a5c2bc51b443c109b Mon Sep 17 00:00:00 2001 From: Martin Schulze Date: Tue, 22 Sep 2020 01:09:47 +0200 Subject: [PATCH 19/50] Improve output in failure cases --- test/tests.bats | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/test/tests.bats b/test/tests.bats index 8373a6db..c64947ec 100644 --- a/test/tests.bats +++ b/test/tests.bats @@ -206,7 +206,8 @@ function count_processed_changes() { } @test "checking smtp: authentication fails with wrong password (plain)" { - run docker exec mail /bin/sh -c "nc -w 20 0.0.0.0 25 < /tmp/docker-mailserver-test/auth/smtp-auth-plain-wrong.txt | grep 'authentication failed'" + run docker exec mail /bin/sh -c "nc -w 20 0.0.0.0 25 < /tmp/docker-mailserver-test/auth/smtp-auth-plain-wrong.txt" + assert_output --partial 'authentication failed' assert_success } @@ -216,7 +217,8 @@ function count_processed_changes() { } @test "checking smtp: authentication fails with wrong password (login)" { - run docker exec mail /bin/sh -c "nc -w 20 0.0.0.0 25 < /tmp/docker-mailserver-test/auth/smtp-auth-login-wrong.txt | grep 'authentication failed'" + run docker exec mail /bin/sh -c "nc -w 20 0.0.0.0 25 < /tmp/docker-mailserver-test/auth/smtp-auth-login-wrong.txt" + assert_output --partial 'authentication failed' assert_success } @@ -338,9 +340,9 @@ EOF @test "checking accounts: user accounts" { run docker exec mail doveadm user '*' assert_success - [ "${lines[0]}" = "user1@localhost.localdomain" ] - [ "${lines[1]}" = "user2@otherdomain.tld" ] - [ "${lines[2]}" = "added@localhost.localdomain" ] + assert_line --index 0 "user1@localhost.localdomain" + assert_line --index 1 "user2@otherdomain.tld" + assert_line --index 2 "added@localhost.localdomain" } @test "checking accounts: user mail folder for user1" { @@ -1510,8 +1512,8 @@ EOF @test "checking spoofing: rejects sender forging" { # checking rejection of spoofed sender - run docker exec mail /bin/sh -c "nc 0.0.0.0 25 < /tmp/docker-mailserver-test/auth/added-smtp-auth-spoofed.txt | grep 'Sender address rejected: not owned by user'" - assert_success + run docker exec mail /bin/sh -c "nc 0.0.0.0 25 < /tmp/docker-mailserver-test/auth/added-smtp-auth-spoofed.txt" + assert_output --partial 'Sender address rejected: not owned by user' } @test "checking spoofing: accepts sending as alias" { From 0d4eb08de887b0dded34f8c21fb52a5f8832443b Mon Sep 17 00:00:00 2001 From: Martin Schulze Date: Tue, 22 Sep 2020 01:10:00 +0200 Subject: [PATCH 20/50] Add missing accounts --- test/tests.bats | 1 + 1 file changed, 1 insertion(+) diff --git a/test/tests.bats b/test/tests.bats index c64947ec..e9c0dab4 100644 --- a/test/tests.bats +++ b/test/tests.bats @@ -31,6 +31,7 @@ setup_file() { -e DMS_DEBUG=0 \ -h mail.my-domain.com -t ${NAME} # generate account after run + docker run --rm -e MAIL_USER=added@localhost.localdomain -e MAIL_PASS=mypassword -t ${NAME} /bin/sh -c 'echo "$MAIL_USER|$(doveadm pw -s SHA512-CRYPT -u $MAIL_USER -p $MAIL_PASS)"' >> "$private_config/postfix-accounts.cf" docker exec mail addmailuser pass@localhost.localdomain 'may be \a `p^a.*ssword' # setup sieve repeat_until_success_or_timeout 15 docker cp "$private_config/sieve/dovecot.sieve" mail:/var/mail/localhost.localdomain/user1/.dovecot.sieve From 53b930448d34a22948851e89d9e315d4dc43d022 Mon Sep 17 00:00:00 2001 From: Martin Schulze Date: Thu, 1 Oct 2020 14:56:19 +0200 Subject: [PATCH 21/50] Fix shellcheck issues --- test/test_helper/common.bash | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/test/test_helper/common.bash b/test/test_helper/common.bash index 75dbff5d..b1dd9c41 100644 --- a/test/test_helper/common.bash +++ b/test/test_helper/common.bash @@ -30,8 +30,8 @@ function repeat_until_success_or_timeout { exit 1 fi sleep 5 - if [[ $(($SECONDS - $STARTTIME )) -gt $TIMEOUT ]]; then - echo "Timed out on command: $@" >&2 + if [[ $(( SECONDS - STARTTIME )) -gt $TIMEOUT ]]; then + echo "Timed out on command: $*" >&2 return 1 fi done @@ -51,8 +51,8 @@ function run_until_success_or_timeout { until run "$@" && [[ $status -eq 0 ]] do sleep 1 - if [[ $(($SECONDS - $STARTTIME )) -gt $TIMEOUT ]]; then - echo "Timed out on command: $@" >&2 + if [[ $(( SECONDS - STARTTIME )) -gt $TIMEOUT ]]; then + echo "Timed out on command: $*" >&2 return 1 fi done @@ -94,12 +94,12 @@ function wait_for_finished_setup_in_container() { repeat_until_success_or_timeout --fatal-test "container_is_running $1" "$TEST_TIMEOUT_IN_SECONDS" sh -c "docker logs $1 | grep 'is up and running'" || status=1 if [[ $status -eq 1 ]]; then echo "Last $NUMBER_OF_LOG_LINES lines of container \`$1\`'s log" - docker logs $1 | tail -n $NUMBER_OF_LOG_LINES + docker logs "$1" | tail -n "$NUMBER_OF_LOG_LINES" fi return $status } -SETUP_FILE_MARKER="$BATS_TMPDIR/`basename \"$BATS_TEST_FILENAME\"`.setup_file" +SETUP_FILE_MARKER="$BATS_TMPDIR/$(basename "$BATS_TEST_FILENAME").setup_file" function native_setup_teardown_file_support() { VERSION_REGEX='([0-9]+)\.([0-9]+)\.([0-9]+)' From 05deaa31963f7d0861ebd9a9c1c635b1c951a190 Mon Sep 17 00:00:00 2001 From: Martin Schulze Date: Thu, 1 Oct 2020 14:57:05 +0200 Subject: [PATCH 22/50] Move common functions into common.bash --- test/test_helper/common.bash | 20 +++++++++++++++++++- test/tests.bats | 21 --------------------- 2 files changed, 19 insertions(+), 22 deletions(-) diff --git a/test/test_helper/common.bash b/test/test_helper/common.bash index b1dd9c41..fd49fabb 100644 --- a/test/test_helper/common.bash +++ b/test/test_helper/common.bash @@ -158,4 +158,22 @@ function duplicate_config_for_container() { mkdir -p "$output" cp -r "$PWD/test/config/${1:?}/." "$output" echo "$output" -} \ No newline at end of file +} + +function container_has_service_running() { + containerName="$1" + serviceName="$2" + docker exec "$containerName" /usr/bin/supervisorctl status "$serviceName" | grep RUNNING >/dev/null +} + +function wait_for_service() { + containerName="$1" + serviceName="$2" + repeat_in_container_until_success_or_timeout 600 "$containerName" \ + container_has_service_running "$containerName" "$serviceName" +} + +function count_processed_changes() { + containerName=$1 + docker exec "$containerName" cat /var/log/supervisor/changedetector.log | grep "Change detected" -c +} diff --git a/test/tests.bats b/test/tests.bats index e9c0dab4..219ceb0c 100644 --- a/test/tests.bats +++ b/test/tests.bats @@ -65,27 +65,6 @@ teardown_file() { docker rm -f mail } -# -# shared functions -# - -function wait_for_service() { - containerName=$1 - serviceName=$2 - count=0 - while ! (docker exec $containerName /usr/bin/supervisorctl status $serviceName | grep RUNNING >/dev/null) - do - ((count++)) && ((count==30)) && break - sleep 5 - done - return $(docker exec $containerName /usr/bin/supervisorctl status $serviceName | grep RUNNING >/dev/null) -} - -function count_processed_changes() { - containerName=$1 - docker exec $containerName cat /var/log/supervisor/changedetector.log | grep "Change detected" | wc -l -} - # this test must come first to reliably identify when to run setup_file @test "first" { skip 'Starting testing of letsencrypt SSL' From c46edee8f9fcea219dcd737e0cead1059c378ee9 Mon Sep 17 00:00:00 2001 From: Martin Schulze Date: Fri, 2 Oct 2020 01:19:41 +0200 Subject: [PATCH 23/50] Mark the end of restarts due to changes by moving the checksum file --- target/check-for-changes.sh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/target/check-for-changes.sh b/target/check-for-changes.sh index d1808d54..fe4d2851 100755 --- a/target/check-for-changes.sh +++ b/target/check-for-changes.sh @@ -53,7 +53,6 @@ do then echo "${LOG_DATE} Change detected" CHANGED=$(grep -Fxvf "${CHKSUM_FILE}" "${CHKSUM_FILE}.new" | sed 's/^[^ ]\+ //') - mv "${CHKSUM_FILE}.new" "${CHKSUM_FILE}" # Bug alert! This overwrites the alias set by start-mailserver.sh # Take care that changes in one script are propagated to the other @@ -231,6 +230,9 @@ s/$/ regexp:\/etc\/postfix\/regexp/ # prevent restart of dovecot when smtp_only=1 [[ ${SMTP_ONLY} -ne 1 ]] && supervisorctl restart dovecot ) 200 Date: Fri, 2 Oct 2020 01:20:31 +0200 Subject: [PATCH 24/50] Avoid running tests while the services restart due to changes --- test/test_helper/common.bash | 13 +++++++++++-- test/tests.bats | 13 +++++++++++-- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/test/test_helper/common.bash b/test/test_helper/common.bash index fd49fabb..7d14c2d8 100644 --- a/test/test_helper/common.bash +++ b/test/test_helper/common.bash @@ -154,7 +154,7 @@ function private_config_path() { # @return path to the folder where the config is duplicated function duplicate_config_for_container() { output="$(private_config_path "$2")" - rm -r "${output:?}/" # cleanup + rm -rf "${output:?}/" # cleanup mkdir -p "$output" cp -r "$PWD/test/config/${1:?}/." "$output" echo "$output" @@ -175,5 +175,14 @@ function wait_for_service() { function count_processed_changes() { containerName=$1 - docker exec "$containerName" cat /var/log/supervisor/changedetector.log | grep "Change detected" -c + docker exec "$containerName" cat /var/log/supervisor/changedetector.log | grep "Change detected" -c \ + || [[ $? == 1 ]] # don't error when no matches were found } + + +function wait_for_changes_to_be_detected_in_container() { + containerName="$1" + timeout=${TEST_TIMEOUT_IN_SECONDS} + repeat_in_container_until_success_or_timeout "$timeout" "$containerName" \ + bash -c 'source /usr/local/bin/helper_functions.sh; cmp --silent -- <(_monitored_files_checksums) "$CHKSUM_FILE" >/dev/null' +} \ No newline at end of file diff --git a/test/tests.bats b/test/tests.bats index 219ceb0c..a11b93ca 100644 --- a/test/tests.bats +++ b/test/tests.bats @@ -30,12 +30,21 @@ setup_file() { -e PERMIT_DOCKER=host \ -e DMS_DEBUG=0 \ -h mail.my-domain.com -t ${NAME} - # generate account after run + + wait_for_finished_setup_in_container mail + + # generate accounts after container has been started docker run --rm -e MAIL_USER=added@localhost.localdomain -e MAIL_PASS=mypassword -t ${NAME} /bin/sh -c 'echo "$MAIL_USER|$(doveadm pw -s SHA512-CRYPT -u $MAIL_USER -p $MAIL_PASS)"' >> "$private_config/postfix-accounts.cf" docker exec mail addmailuser pass@localhost.localdomain 'may be \a `p^a.*ssword' + # setup sieve - repeat_until_success_or_timeout 15 docker cp "$private_config/sieve/dovecot.sieve" mail:/var/mail/localhost.localdomain/user1/.dovecot.sieve + docker cp "$private_config/sieve/dovecot.sieve" mail:/var/mail/localhost.localdomain/user1/.dovecot.sieve + + # this relies on the checksum file beeing updated after all changes have been applied + wait_for_changes_to_be_detected_in_container mail + wait_for_smtp_port_in_container mail + # sending test mails docker exec mail /bin/sh -c "nc 0.0.0.0 25 < /tmp/docker-mailserver-test/email-templates/amavis-spam.txt" docker exec mail /bin/sh -c "nc 0.0.0.0 25 < /tmp/docker-mailserver-test/email-templates/amavis-virus.txt" From 96b3fd726a9673663c25ed5ec8a592b10bc50876 Mon Sep 17 00:00:00 2001 From: Martin Schulze Date: Sat, 17 Oct 2020 01:03:41 +0200 Subject: [PATCH 25/50] Fix wait_for_service not working/hanging --- test/test_helper/common.bash | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/test_helper/common.bash b/test/test_helper/common.bash index 7d14c2d8..46d42519 100644 --- a/test/test_helper/common.bash +++ b/test/test_helper/common.bash @@ -169,7 +169,7 @@ function container_has_service_running() { function wait_for_service() { containerName="$1" serviceName="$2" - repeat_in_container_until_success_or_timeout 600 "$containerName" \ + repeat_until_success_or_timeout --fatal-test "container_is_running $containerName" 60 \ container_has_service_running "$containerName" "$serviceName" } From 7530aea9f56ab42e1c4729f646e363d6ecfb6b97 Mon Sep 17 00:00:00 2001 From: Martin Schulze Date: Sat, 17 Oct 2020 01:12:53 +0200 Subject: [PATCH 26/50] Don't use an extra moint for subdir --- test/tests.bats | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/tests.bats b/test/tests.bats index a11b93ca..b41e1427 100644 --- a/test/tests.bats +++ b/test/tests.bats @@ -8,11 +8,11 @@ setup() { setup_file() { private_config="$(duplicate_config_for_container . mail)" + mv "$private_config/user-patches/user-patches.sh" "$private_config/user-patches.sh" docker run --rm -d --name mail \ -v "$private_config":/tmp/docker-mailserver \ -v "`pwd`/test/test-files":/tmp/docker-mailserver-test:ro \ -v "`pwd`/test/onedir":/var/mail-state \ - -v "$private_config/user-patches/user-patches.sh":/tmp/docker-mailserver/user-patches.sh \ -e ENABLE_CLAMAV=1 \ -e SPOOF_PROTECTION=1 \ -e ENABLE_SPAMASSASSIN=1 \ From 80bfc422a22ca4d52cfe0f2a7f16699ef26ef8c4 Mon Sep 17 00:00:00 2001 From: Martin Schulze Date: Sat, 17 Oct 2020 01:15:37 +0200 Subject: [PATCH 27/50] Reduce code duplication --- test/tests.bats | 53 +++++++------------------------------------------ 1 file changed, 7 insertions(+), 46 deletions(-) diff --git a/test/tests.bats b/test/tests.bats index b41e1427..4700660d 100644 --- a/test/tests.bats +++ b/test/tests.bats @@ -1086,43 +1086,24 @@ EOF } @test "checking quota: dovecot applies user quota" { - sleep 15 # wait until any other change has finished + wait_for_changes_to_be_detected_in_container mail + run docker exec mail /bin/sh -c "doveadm quota get -u 'user1@localhost.localdomain' | grep 'User quota STORAGE'" assert_output --partial "- 0" - # set a quota - originalChangesProcessed=$(count_processed_changes mail) run docker exec mail /bin/sh -c "setquota user1@localhost.localdomain 50M" assert_success - # wait until change detector has processed the change - count=0 - while [ "${originalChangesProcessed}" = "$(count_processed_changes mail)" ] - do - ((count++)) && ((count==60)) && break - sleep 1 - done - [ "${originalChangesProcessed}" != "$(count_processed_changes mail)" ] - assert_success + wait_for_changes_to_be_detected_in_container mail # wait until quota has been updated run repeat_until_success_or_timeout 20 sh -c "docker exec mail sh -c 'doveadm quota get -u user1@localhost.localdomain | grep -oP \"(User quota STORAGE\s+[0-9]+\s+)51200(.*)\"'" assert_success - # remove the quota - originalChangesProcessed=$(count_processed_changes mail) run docker exec mail /bin/sh -c "delquota user1@localhost.localdomain" assert_success - # wait until change detector has processed the change - count=0 - while [ "${originalChangesProcessed}" = "$(count_processed_changes mail)" ] - do - ((count++)) && ((count==60)) && break - sleep 1 - done - [ "${originalChangesProcessed}" != "$(count_processed_changes mail)" ] - assert_success + wait_for_changes_to_be_detected_in_container mail # wait until quota has been updated run repeat_until_success_or_timeout 20 sh -c "docker exec mail sh -c 'doveadm quota get -u user1@localhost.localdomain | grep -oP \"(User quota STORAGE\s+[0-9]+\s+)-(.*)\"'" @@ -1130,22 +1111,13 @@ EOF } @test "checking quota: warn message received when quota exceeded" { - sleep 15 # wait until any other change has finished - - originalChangesProcessed=$(count_processed_changes mail) + wait_for_changes_to_be_detected_in_container mail # create user run docker exec mail /bin/sh -c "addmailuser quotauser@otherdomain.tld mypassword && setquota quotauser@otherdomain.tld 10k" assert_success - count=0 - while [ "${originalChangesProcessed}" = "$(count_processed_changes mail)" ] - do - ((count++)) && ((count==60)) && break - sleep 1 - done - [ "${originalChangesProcessed}" != "$(count_processed_changes mail)" ] - assert_success + wait_for_changes_to_be_detected_in_container mail # wait until quota has been updated run repeat_until_success_or_timeout 20 sh -c "docker exec mail sh -c 'doveadm quota get -u quotauser@otherdomain.tld | grep -oP \"(User quota STORAGE\s+[0-9]+\s+)10(.*)\"'" @@ -1231,8 +1203,6 @@ EOF wait_for_service mail changedetector assert_success - originalChangesProcessed=$(count_processed_changes mail) - run ./setup.sh -c mail email add setup_email_add@example.com test_password assert_success @@ -1240,16 +1210,7 @@ EOF [ "$value" = "setup_email_add@example.com" ] assert_success - # wait until change detector has processed the change - count=0 - while [ "${originalChangesProcessed}" = "$(count_processed_changes mail)" ] - do - ((count++)) && ((count==60)) && break - sleep 1 - done - - [ "${originalChangesProcessed}" != "$(count_processed_changes mail)" ] - assert_success + wait_for_changes_to_be_detected_in_container mail # Dovecot has been restarted, but this test often fails so presumably it may not be ready # Add a short sleep to see if that helps to make the test more stable From b7388d3b465401bd9a6b5a68b35076bd9cb01b36 Mon Sep 17 00:00:00 2001 From: Martin Schulze Date: Sat, 17 Oct 2020 01:17:07 +0200 Subject: [PATCH 28/50] Remove obsolete make target --- .github/CONTRIBUTING.md | 2 +- Makefile | 11 +++-------- 2 files changed, 4 insertions(+), 9 deletions(-) diff --git a/.github/CONTRIBUTING.md b/.github/CONTRIBUTING.md index 2c225fcf..aee54474 100644 --- a/.github/CONTRIBUTING.md +++ b/.github/CONTRIBUTING.md @@ -13,7 +13,7 @@ Here's a quick guide: refactoring and documentation changes require no new tests. If you are adding functionality or fixing a bug, we need tests! -4. Run the tests. `make build-no-cache generate-accounts run generate-accounts-after-run fixtures tests clean` +4. Run the tests. `make build-no-cache generate-accounts run fixtures tests clean` 5. Push to your fork and submit a pull request. If the changes will apply cleanly to the master branch, you will only need to submit one pull request. diff --git a/Makefile b/Makefile index 19a3c11f..366d2390 100644 --- a/Makefile +++ b/Makefile @@ -6,9 +6,9 @@ VCS_VERSION := $(shell git describe --tags --contains --always) SLEEP = 15s -all: build backup generate-accounts generate-accounts-after-run tests clean -no-build: backup generate-accounts generate-accounts-after-run tests clean -complete_test: lint build generate-accounts generate-accounts-after-run tests +all: build backup generate-accounts tests clean +no-build: backup generate-accounts tests clean +complete_test: lint build generate-accounts tests build: docker build \ @@ -28,11 +28,6 @@ generate-accounts: @ echo "# this is a test comment, please don't delete me :'(" >> test/config/postfix-accounts.cf @ echo " # this is also a test comment, :O" >> test/config/postfix-accounts.cf -# TODO: ensure this is run per container after each container started! -generate-accounts-after-run: - # todo: noone seems to care about this? - #@ docker run --rm -e MAIL_USER=added@localhost.localdomain -e MAIL_PASS=mypassword -t $(NAME) /bin/sh -c 'echo "$$MAIL_USER|$$(doveadm pw -s SHA512-CRYPT -u $$MAIL_USER -p $$MAIL_PASS)"' >> test/config/postfix-accounts.cf - @ sleep $(SLEEP) tests: ./test/bats/bin/bats test/*.bats From 13963747b892f46fd8d293b1593aa6af15aecb34 Mon Sep 17 00:00:00 2001 From: Martin Schulze Date: Sat, 17 Oct 2020 23:24:23 +0200 Subject: [PATCH 29/50] Fix missing newline at the end of file --- test/test_helper/common.bash | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/test_helper/common.bash b/test/test_helper/common.bash index 46d42519..e6c03ba0 100644 --- a/test/test_helper/common.bash +++ b/test/test_helper/common.bash @@ -185,4 +185,4 @@ function wait_for_changes_to_be_detected_in_container() { timeout=${TEST_TIMEOUT_IN_SECONDS} repeat_in_container_until_success_or_timeout "$timeout" "$containerName" \ bash -c 'source /usr/local/bin/helper_functions.sh; cmp --silent -- <(_monitored_files_checksums) "$CHKSUM_FILE" >/dev/null' -} \ No newline at end of file +} From f47f85598dd5a271f2b74ad8c3acbbba70a59ea8 Mon Sep 17 00:00:00 2001 From: Martin Schulze Date: Sat, 17 Oct 2020 23:24:39 +0200 Subject: [PATCH 30/50] Fix trailing slash in path --- test/default_relay_host.bats | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/default_relay_host.bats b/test/default_relay_host.bats index 91c42ab2..faa0abd5 100644 --- a/test/default_relay_host.bats +++ b/test/default_relay_host.bats @@ -2,7 +2,7 @@ load 'test_helper/common' function setup() { docker run -d --name mail_with_default_relay \ - -v "$(duplicate_config_for_container relay-hosts/)":/tmp/docker-mailserver \ + -v "$(duplicate_config_for_container relay-hosts)":/tmp/docker-mailserver \ -v "`pwd`/test/test-files":/tmp/docker-mailserver-test:ro \ -e DEFAULT_RELAY_HOST=default.relay.host.invalid:25 \ --cap-add=SYS_PTRACE \ From e2bca5f85099165e54c2104cd85389b201cef1ee Mon Sep 17 00:00:00 2001 From: Martin Schulze Date: Sun, 18 Oct 2020 02:08:11 +0200 Subject: [PATCH 31/50] Always use ${} --- test/mail_dhparams_manual_not_one_dir.bats | 4 +- test/mail_ssl_letsencrypt.bats | 12 +- test/test_helper/common.bash | 144 +++++++++--------- test/tests.bats | 164 ++++++++++----------- 4 files changed, 162 insertions(+), 162 deletions(-) diff --git a/test/mail_dhparams_manual_not_one_dir.bats b/test/mail_dhparams_manual_not_one_dir.bats index 2277c2f5..f2072a8b 100644 --- a/test/mail_dhparams_manual_not_one_dir.bats +++ b/test/mail_dhparams_manual_not_one_dir.bats @@ -23,10 +23,10 @@ function teardown() { function setup_file() { private_config=$(duplicate_config_for_container .) # copy the custom DHE params in local config - cp "`pwd`/test/test-files/ssl/custom-dhe-params.pem" "$private_config/dhparams.pem" + cp "`pwd`/test/test-files/ssl/custom-dhe-params.pem" "${private_config}/dhparams.pem" docker run -d --name mail_manual_dhparams_not_one_dir \ - -v "$private_config":/tmp/docker-mailserver \ + -v "${private_config}":/tmp/docker-mailserver \ -v "`pwd`/test/test-files":/tmp/docker-mailserver-test:ro \ -e DMS_DEBUG=0 \ -e ONE_DIR=0 \ diff --git a/test/mail_ssl_letsencrypt.bats b/test/mail_ssl_letsencrypt.bats index cb826208..c6e74a91 100644 --- a/test/mail_ssl_letsencrypt.bats +++ b/test/mail_ssl_letsencrypt.bats @@ -11,9 +11,9 @@ function teardown() { function setup_file() { private_config="$(duplicate_config_for_container . mail_lets_domain)" docker run -d --name mail_lets_domain \ - -v "$private_config":/tmp/docker-mailserver \ + -v "${private_config}":/tmp/docker-mailserver \ -v "`pwd`/test/test-files":/tmp/docker-mailserver-test:ro \ - -v "$private_config/letsencrypt/my-domain.com":/etc/letsencrypt/live/my-domain.com \ + -v "${private_config}/letsencrypt/my-domain.com":/etc/letsencrypt/live/my-domain.com \ -e DMS_DEBUG=0 \ -e SSL_TYPE=letsencrypt \ -h mail.my-domain.com -t ${NAME} @@ -21,9 +21,9 @@ function setup_file() { private_config="$(duplicate_config_for_container . mail_lets_hostname)" docker run -d --name mail_lets_hostname \ - -v "$private_config":/tmp/docker-mailserver \ + -v "${private_config}":/tmp/docker-mailserver \ -v "`pwd`/test/test-files":/tmp/docker-mailserver-test:ro \ - -v "$private_config/letsencrypt/mail.my-domain.com":/etc/letsencrypt/live/mail.my-domain.com \ + -v "${private_config}/letsencrypt/mail.my-domain.com":/etc/letsencrypt/live/mail.my-domain.com \ -e DMS_DEBUG=0 \ -e SSL_TYPE=letsencrypt \ -h mail.my-domain.com -t ${NAME} @@ -32,8 +32,8 @@ function setup_file() { private_config="$(duplicate_config_for_container . mail_lets_acme_json)" cp "$(private_config_path mail_lets_acme_json)/letsencrypt/acme.json" "$(private_config_path mail_lets_acme_json)/acme.json" docker run -d --name mail_lets_acme_json \ - -v "$private_config":/tmp/docker-mailserver \ - -v "$private_config/acme.json":/etc/letsencrypt/acme.json:ro \ + -v "${private_config}":/tmp/docker-mailserver \ + -v "${private_config}/acme.json":/etc/letsencrypt/acme.json:ro \ -v "`pwd`/test/test-files":/tmp/docker-mailserver-test:ro \ -e DMS_DEBUG=0 \ -e SSL_TYPE=letsencrypt \ diff --git a/test/test_helper/common.bash b/test/test_helper/common.bash index e6c03ba0..95800011 100644 --- a/test/test_helper/common.bash +++ b/test/test_helper/common.bash @@ -7,107 +7,107 @@ NAME=tvial/docker-mailserver:testing TEST_TIMEOUT_IN_SECONDS=${TEST_TIMEOUT_IN_SECONDS-120} NUMBER_OF_LOG_LINES=${NUMBER_OF_LOG_LINES-10} -# @param $1 timeout +# @param ${1} timeout # @param --fatal-test additional test whose failure aborts immediately # @param ... test to run function repeat_until_success_or_timeout { local fatal_failure_test_command - if [[ "$1" == "--fatal-test" ]]; then - fatal_failure_test_command="$2" + if [[ "${1}" == "--fatal-test" ]]; then + fatal_failure_test_command="${2}" shift 2 fi - if ! [[ "$1" =~ ^[0-9]+$ ]]; then - echo "First parameter for timeout must be an integer, recieved \"$1\"" + if ! [[ "${1}" =~ ^[0-9]+$ ]]; then + echo "First parameter for timeout must be an integer, recieved \"${1}\"" return 1 fi - TIMEOUT=$1 - STARTTIME=$SECONDS + local TIMEOUT=${1} + local STARTTIME=${SECONDS} shift 1 - until "$@" + until "${@}" do - if [[ -n "$fatal_failure_test_command" ]] && ! eval "$fatal_failure_test_command"; then - echo "\`$fatal_failure_test_command\` failed, early aborting repeat_until_success of \`$*\`" >&2 + if [[ -n "${fatal_failure_test_command}" ]] && ! eval "${fatal_failure_test_command}"; then + echo "\`${fatal_failure_test_command}\` failed, early aborting repeat_until_success of \`${*}\`" >&2 exit 1 fi sleep 5 - if [[ $(( SECONDS - STARTTIME )) -gt $TIMEOUT ]]; then - echo "Timed out on command: $*" >&2 + if [[ $(( SECONDS - STARTTIME )) -gt ${TIMEOUT} ]]; then + echo "Timed out on command: ${*}" >&2 return 1 fi done } # like repeat_until_success_or_timeout but with wrapping the command to run into `run` for later bats consumption -# @param $1 timeout +# @param ${1} timeout # @param ... test command to run function run_until_success_or_timeout { - if ! [[ "$1" =~ ^[0-9]+$ ]]; then - echo "First parameter for timeout must be an integer, recieved \"$1\"" + if ! [[ "${1}" =~ ^[0-9]+$ ]]; then + echo "First parameter for timeout must be an integer, recieved \"${1}\"" return 1 fi - TIMEOUT=$1 - STARTTIME=$SECONDS + local TIMEOUT=${1} + local STARTTIME=${SECONDS} shift 1 - until run "$@" && [[ $status -eq 0 ]] + until run "${@}" && [[ ${status} -eq 0 ]] do sleep 1 - if [[ $(( SECONDS - STARTTIME )) -gt $TIMEOUT ]]; then - echo "Timed out on command: $*" >&2 + if [[ $(( SECONDS - STARTTIME )) -gt ${TIMEOUT} ]]; then + echo "Timed out on command: ${*}" >&2 return 1 fi done } -# @param $1 timeout -# @param $2 container name +# @param ${1} timeout +# @param ${2} container name # @param ... test command for container function repeat_in_container_until_success_or_timeout() { - timeout="$1" - container_name="$2" + local TIMEOUT="${1}" + local CONTAINER_NAME="${2}" shift 2 - repeat_until_success_or_timeout --fatal-test "container_is_running $container_name" "$timeout" docker exec "$container_name" "$@" + repeat_until_success_or_timeout --fatal-test "container_is_running ${CONTAINER_NAME}" "${TIMEOUT}" docker exec "${CONTAINER_NAME}" "${@}" } function container_is_running() { - [[ "$(docker inspect -f '{{.State.Running}}' "$1")" == "true" ]] + [[ "$(docker inspect -f '{{.State.Running}}' "${1}")" == "true" ]] } -# @param $1 port -# @param $2 container name +# @param ${1} port +# @param ${2} container name function wait_for_tcp_port_in_container() { - repeat_until_success_or_timeout --fatal-test "container_is_running $2" "$TEST_TIMEOUT_IN_SECONDS" docker exec $2 /bin/sh -c "nc -z 0.0.0.0 $1" + repeat_until_success_or_timeout --fatal-test "container_is_running ${2}" "${TEST_TIMEOUT_IN_SECONDS}" docker exec ${2} /bin/sh -c "nc -z 0.0.0.0 ${1}" } -# @param $1 name of the postfix container +# @param ${1} name of the postfix container function wait_for_smtp_port_in_container() { - wait_for_tcp_port_in_container 25 "$1" + wait_for_tcp_port_in_container 25 "${1}" } -# @param $1 name of the postfix container +# @param ${1} name of the postfix container function wait_for_amavis_port_in_container() { - wait_for_tcp_port_in_container 10024 "$1" + wait_for_tcp_port_in_container 10024 "${1}" } -# @param $1 name of the postfix container +# @param ${1} name of the postfix container function wait_for_finished_setup_in_container() { local status=0 - repeat_until_success_or_timeout --fatal-test "container_is_running $1" "$TEST_TIMEOUT_IN_SECONDS" sh -c "docker logs $1 | grep 'is up and running'" || status=1 - if [[ $status -eq 1 ]]; then - echo "Last $NUMBER_OF_LOG_LINES lines of container \`$1\`'s log" - docker logs "$1" | tail -n "$NUMBER_OF_LOG_LINES" + repeat_until_success_or_timeout --fatal-test "container_is_running ${1}" "${TEST_TIMEOUT_IN_SECONDS}" sh -c "docker logs ${1} | grep 'is up and running'" || status=1 + if [[ ${status} -eq 1 ]]; then + echo "Last ${NUMBER_OF_LOG_LINES} lines of container \`${1}\`'s log" + docker logs "${1}" | tail -n "${NUMBER_OF_LOG_LINES}" fi - return $status + return ${status} } -SETUP_FILE_MARKER="$BATS_TMPDIR/$(basename "$BATS_TEST_FILENAME").setup_file" +SETUP_FILE_MARKER="${BATS_TMPDIR}/$(basename "${BATS_TEST_FILENAME}").setup_file" function native_setup_teardown_file_support() { - VERSION_REGEX='([0-9]+)\.([0-9]+)\.([0-9]+)' + local VERSION_REGEX='([0-9]+)\.([0-9]+)\.([0-9]+)' # bats versions that support setup_file out of the box don't need this - if [[ "$BATS_VERSION" =~ $VERSION_REGEX ]]; then + if [[ "${BATS_VERSION}" =~ ${VERSION_REGEX} ]]; then numeric_version=$(( (BASH_REMATCH[1] * 100 + BASH_REMATCH[2]) * 100 + BASH_REMATCH[3] )) - if [[ $numeric_version -ge 10201 ]]; then - if [ "$BATS_TEST_NAME" == 'test_first' ]; then + if [[ ${numeric_version} -ge 10201 ]]; then + if [ "${BATS_TEST_NAME}" == 'test_first' ]; then skip 'This version natively supports setup/teardown_file' fi return 0 @@ -119,15 +119,15 @@ function native_setup_teardown_file_support() { # use in setup() in conjunction with a `@test "first" {}` to trigger setup_file reliably function run_setup_file_if_necessary() { native_setup_teardown_file_support && return 0 - if [ "$BATS_TEST_NAME" == 'test_first' ]; then + if [ "${BATS_TEST_NAME}" == 'test_first' ]; then # prevent old markers from marking success or get an error if we cannot remove due to permissions - rm -f "$SETUP_FILE_MARKER" + rm -f "${SETUP_FILE_MARKER}" setup_file - touch "$SETUP_FILE_MARKER" + touch "${SETUP_FILE_MARKER}" else - if [ ! -f "$SETUP_FILE_MARKER" ]; then + if [ ! -f "${SETUP_FILE_MARKER}" ]; then skip "setup_file failed" return 1 fi @@ -137,52 +137,52 @@ function run_setup_file_if_necessary() { # use in teardown() in conjunction with a `@test "last" {}` to trigger teardown_file reliably function run_teardown_file_if_necessary() { native_setup_teardown_file_support && return 0 - if [ "$BATS_TEST_NAME" == 'test_last' ]; then + if [ "${BATS_TEST_NAME}" == 'test_last' ]; then # cleanup setup file marker - rm -f "$SETUP_FILE_MARKER" + rm -f "${SETUP_FILE_MARKER}" teardown_file fi } # get the private config path for the given container or test file, if no container name was given function private_config_path() { - echo "$PWD/test/duplicate_configs/${1:-$(basename "$BATS_TEST_FILENAME")}" + echo "${PWD}/test/duplicate_configs/${1:-$(basename "${BATS_TEST_FILENAME}")}" } -# @param $1 relative source in test/config folder -# @param $2 (optional) container name, defaults to $BATS_TEST_FILENAME +# @param ${1} relative source in test/config folder +# @param ${2} (optional) container name, defaults to ${BATS_TEST_FILENAME} # @return path to the folder where the config is duplicated function duplicate_config_for_container() { - output="$(private_config_path "$2")" - rm -rf "${output:?}/" # cleanup - mkdir -p "$output" - cp -r "$PWD/test/config/${1:?}/." "$output" - echo "$output" + local OUTPUT_FOLDER="$(private_config_path "${2}")" + rm -rf "${OUTPUT_FOLDER:?}/" # cleanup + mkdir -p "${OUTPUT_FOLDER}" + cp -r "${PWD}/test/config/${1:?}/." "${OUTPUT_FOLDER}" + echo "${OUTPUT_FOLDER}" } function container_has_service_running() { - containerName="$1" - serviceName="$2" - docker exec "$containerName" /usr/bin/supervisorctl status "$serviceName" | grep RUNNING >/dev/null + local CONTAINER_NAME="${1}" + local SERVICE_NAME="${2}" + docker exec "${CONTAINER_NAME}" /usr/bin/supervisorctl status "${SERVICE_NAME}" | grep RUNNING >/dev/null } function wait_for_service() { - containerName="$1" - serviceName="$2" - repeat_until_success_or_timeout --fatal-test "container_is_running $containerName" 60 \ - container_has_service_running "$containerName" "$serviceName" + local CONTAINER_NAME="${1}" + local SERVICE_NAME="${2}" + repeat_until_success_or_timeout --fatal-test "container_is_running ${CONTAINER_NAME}" 60 \ + container_has_service_running "${CONTAINER_NAME}" "${SERVICE_NAME}" } function count_processed_changes() { - containerName=$1 - docker exec "$containerName" cat /var/log/supervisor/changedetector.log | grep "Change detected" -c \ - || [[ $? == 1 ]] # don't error when no matches were found + local CONTAINER_NAME=${1} + docker exec "${CONTAINER_NAME}" cat /var/log/supervisor/changedetector.log | grep "Change detected" -c \ + || [[ ${?} == 1 ]] # don't error when no matches were found } function wait_for_changes_to_be_detected_in_container() { - containerName="$1" - timeout=${TEST_TIMEOUT_IN_SECONDS} - repeat_in_container_until_success_or_timeout "$timeout" "$containerName" \ - bash -c 'source /usr/local/bin/helper_functions.sh; cmp --silent -- <(_monitored_files_checksums) "$CHKSUM_FILE" >/dev/null' + local CONTAINER_NAME="${1}" + local TIMEOUT=${TEST_TIMEOUT_IN_SECONDS} + repeat_in_container_until_success_or_timeout "${TIMEOUT}" "${CONTAINER_NAME}" \ + bash -c 'source /usr/local/bin/helper_functions.sh; cmp --silent -- <(_monitored_files_checksums) "${CHKSUM_FILE}" >/dev/null' } diff --git a/test/tests.bats b/test/tests.bats index 4700660d..88e1793a 100644 --- a/test/tests.bats +++ b/test/tests.bats @@ -8,9 +8,9 @@ setup() { setup_file() { private_config="$(duplicate_config_for_container . mail)" - mv "$private_config/user-patches/user-patches.sh" "$private_config/user-patches.sh" + mv "${private_config}/user-patches/user-patches.sh" "${private_config}/user-patches.sh" docker run --rm -d --name mail \ - -v "$private_config":/tmp/docker-mailserver \ + -v "${private_config}":/tmp/docker-mailserver \ -v "`pwd`/test/test-files":/tmp/docker-mailserver-test:ro \ -v "`pwd`/test/onedir":/var/mail-state \ -e ENABLE_CLAMAV=1 \ @@ -34,11 +34,11 @@ setup_file() { wait_for_finished_setup_in_container mail # generate accounts after container has been started - docker run --rm -e MAIL_USER=added@localhost.localdomain -e MAIL_PASS=mypassword -t ${NAME} /bin/sh -c 'echo "$MAIL_USER|$(doveadm pw -s SHA512-CRYPT -u $MAIL_USER -p $MAIL_PASS)"' >> "$private_config/postfix-accounts.cf" + docker run --rm -e MAIL_USER=added@localhost.localdomain -e MAIL_PASS=mypassword -t ${NAME} /bin/sh -c 'echo "${MAIL_USER}|$(doveadm pw -s SHA512-CRYPT -u ${MAIL_USER} -p ${MAIL_PASS})"' >> "${private_config}/postfix-accounts.cf" docker exec mail addmailuser pass@localhost.localdomain 'may be \a `p^a.*ssword' # setup sieve - docker cp "$private_config/sieve/dovecot.sieve" mail:/var/mail/localhost.localdomain/user1/.dovecot.sieve + docker cp "${private_config}/sieve/dovecot.sieve" mail:/var/mail/localhost.localdomain/user1/.dovecot.sieve # this relies on the checksum file beeing updated after all changes have been applied wait_for_changes_to_be_detected_in_container mail @@ -459,19 +459,19 @@ EOF @test "checking opendkim: generator creates default keys size" { private_config="$(duplicate_config_for_container . mail_default_key_size)" # Prepare default key size 2048 - rm -rf "$private_config/keyDefault" - mkdir -p "$private_config/keyDefault" + rm -rf "${private_config}/keyDefault" + mkdir -p "${private_config}/keyDefault" run docker run --rm \ - -v "$private_config/keyDefault/":/tmp/docker-mailserver/ \ - -v "$private_config/postfix-accounts.cf":/tmp/docker-mailserver/postfix-accounts.cf \ - -v "$private_config/postfix-virtual.cf":/tmp/docker-mailserver/postfix-virtual.cf \ + -v "${private_config}/keyDefault/":/tmp/docker-mailserver/ \ + -v "${private_config}/postfix-accounts.cf":/tmp/docker-mailserver/postfix-accounts.cf \ + -v "${private_config}/postfix-virtual.cf":/tmp/docker-mailserver/postfix-virtual.cf \ `docker inspect --format '{{ .Config.Image }}' mail` /bin/sh -c 'generate-dkim-config | wc -l' assert_success assert_output 6 run docker run --rm \ - -v "$private_config/keyDefault/opendkim":/etc/opendkim \ + -v "${private_config}/keyDefault/opendkim":/etc/opendkim \ `docker inspect --format '{{ .Config.Image }}' mail` \ /bin/sh -c 'stat -c%s /etc/opendkim/keys/localhost.localdomain/mail.txt' @@ -485,18 +485,18 @@ EOF @test "checking opendkim: generator creates key size 2048" { private_config="$(duplicate_config_for_container . mail_key_size_2048)" # Prepare set key size 2048 - rm -rf "$private_config/key2048" - mkdir -p "$private_config/config/key2048" + rm -rf "${private_config}/key2048" + mkdir -p "${private_config}/config/key2048" run docker run --rm \ - -v "$private_config/key2048/":/tmp/docker-mailserver/ \ - -v "$private_config/postfix-accounts.cf":/tmp/docker-mailserver/postfix-accounts.cf \ - -v "$private_config/postfix-virtual.cf":/tmp/docker-mailserver/postfix-virtual.cf \ + -v "${private_config}/key2048/":/tmp/docker-mailserver/ \ + -v "${private_config}/postfix-accounts.cf":/tmp/docker-mailserver/postfix-accounts.cf \ + -v "${private_config}/postfix-virtual.cf":/tmp/docker-mailserver/postfix-virtual.cf \ `docker inspect --format '{{ .Config.Image }}' mail` /bin/sh -c 'generate-dkim-config 2048 | wc -l' assert_success assert_output 6 run docker run --rm \ - -v "$private_config/key2048/opendkim":/etc/opendkim \ + -v "${private_config}/key2048/opendkim":/etc/opendkim \ `docker inspect --format '{{ .Config.Image }}' mail` \ /bin/sh -c 'stat -c%s /etc/opendkim/keys/localhost.localdomain/mail.txt' @@ -510,18 +510,18 @@ EOF @test "checking opendkim: generator creates key size 1024" { private_config="$(duplicate_config_for_container . mail_key_size_1024)" # Prepare set key size 1024 - rm -rf "$private_config/key1024" - mkdir -p "$private_config/key1024" + rm -rf "${private_config}/key1024" + mkdir -p "${private_config}/key1024" run docker run --rm \ - -v "$private_config/key1024/":/tmp/docker-mailserver/ \ - -v "$private_config/postfix-accounts.cf":/tmp/docker-mailserver/postfix-accounts.cf \ - -v "$private_config/postfix-virtual.cf":/tmp/docker-mailserver/postfix-virtual.cf \ + -v "${private_config}/key1024/":/tmp/docker-mailserver/ \ + -v "${private_config}/postfix-accounts.cf":/tmp/docker-mailserver/postfix-accounts.cf \ + -v "${private_config}/postfix-virtual.cf":/tmp/docker-mailserver/postfix-virtual.cf \ `docker inspect --format '{{ .Config.Image }}' mail` /bin/sh -c 'generate-dkim-config 1024 | wc -l' assert_success assert_output 6 run docker run --rm \ - -v "$private_config/key1024/opendkim":/etc/opendkim \ + -v "${private_config}/key1024/opendkim":/etc/opendkim \ `docker inspect --format '{{ .Config.Image }}' mail` \ /bin/sh -c 'stat -c%s /etc/opendkim/keys/localhost.localdomain/mail.txt' @@ -531,30 +531,30 @@ EOF @test "checking opendkim: generator creates keys, tables and TrustedHosts" { private_config="$(duplicate_config_for_container . mail_dkim_generator_creates_keys_tables_TrustedHosts)" - rm -rf "$private_config/empty" - mkdir -p "$private_config/empty" + rm -rf "${private_config}/empty" + mkdir -p "${private_config}/empty" run docker run --rm \ - -v "$private_config/empty/":/tmp/docker-mailserver/ \ - -v "$private_config/postfix-accounts.cf":/tmp/docker-mailserver/postfix-accounts.cf \ - -v "$private_config/postfix-virtual.cf":/tmp/docker-mailserver/postfix-virtual.cf \ + -v "${private_config}/empty/":/tmp/docker-mailserver/ \ + -v "${private_config}/postfix-accounts.cf":/tmp/docker-mailserver/postfix-accounts.cf \ + -v "${private_config}/postfix-virtual.cf":/tmp/docker-mailserver/postfix-virtual.cf \ `docker inspect --format '{{ .Config.Image }}' mail` /bin/sh -c 'generate-dkim-config | wc -l' assert_success assert_output 6 # Check keys for localhost.localdomain run docker run --rm \ - -v "$private_config/empty/opendkim":/etc/opendkim \ + -v "${private_config}/empty/opendkim":/etc/opendkim \ `docker inspect --format '{{ .Config.Image }}' mail` /bin/sh -c 'ls -1 /etc/opendkim/keys/localhost.localdomain/ | wc -l' assert_success assert_output 2 # Check keys for otherdomain.tld run docker run --rm \ - -v "$private_config/empty/opendkim":/etc/opendkim \ + -v "${private_config}/empty/opendkim":/etc/opendkim \ `docker inspect --format '{{ .Config.Image }}' mail` /bin/sh -c 'ls -1 /etc/opendkim/keys/otherdomain.tld | wc -l' assert_success assert_output 2 # Check presence of tables and TrustedHosts run docker run --rm \ - -v "$private_config/empty/opendkim":/etc/opendkim \ + -v "${private_config}/empty/opendkim":/etc/opendkim \ `docker inspect --format '{{ .Config.Image }}' mail` /bin/sh -c "ls -1 /etc/opendkim | grep -E 'KeyTable|SigningTable|TrustedHosts|keys'|wc -l" assert_success assert_output 4 @@ -562,29 +562,29 @@ EOF @test "checking opendkim: generator creates keys, tables and TrustedHosts without postfix-accounts.cf" { private_config="$(duplicate_config_for_container . mail_dkim_generator_creates_keys_tables_TrustedHosts_without_postfix_accounts.cf)" - rm -rf "$private_config/without-accounts" - mkdir -p "$private_config/without-accounts" + rm -rf "${private_config}/without-accounts" + mkdir -p "${private_config}/without-accounts" run docker run --rm \ - -v "$private_config/without-accounts/":/tmp/docker-mailserver/ \ - -v "$private_config/postfix-virtual.cf":/tmp/docker-mailserver/postfix-virtual.cf \ + -v "${private_config}/without-accounts/":/tmp/docker-mailserver/ \ + -v "${private_config}/postfix-virtual.cf":/tmp/docker-mailserver/postfix-virtual.cf \ `docker inspect --format '{{ .Config.Image }}' mail` /bin/sh -c 'generate-dkim-config | wc -l' assert_success assert_output 5 # Check keys for localhost.localdomain run docker run --rm \ - -v "$private_config/without-accounts/opendkim":/etc/opendkim \ + -v "${private_config}/without-accounts/opendkim":/etc/opendkim \ `docker inspect --format '{{ .Config.Image }}' mail` /bin/sh -c 'ls -1 /etc/opendkim/keys/localhost.localdomain/ | wc -l' assert_success assert_output 2 # Check keys for otherdomain.tld # run docker run --rm \ - # -v "$private_config/without-accounts/opendkim":/etc/opendkim \ + # -v "${private_config}/without-accounts/opendkim":/etc/opendkim \ # `docker inspect --format '{{ .Config.Image }}' mail` /bin/sh -c 'ls -1 /etc/opendkim/keys/otherdomain.tld | wc -l' # assert_success - # [ "$output" -eq 0 ] + # [ "${output}" -eq 0 ] # Check presence of tables and TrustedHosts run docker run --rm \ - -v "$private_config/without-accounts/opendkim":/etc/opendkim \ + -v "${private_config}/without-accounts/opendkim":/etc/opendkim \ `docker inspect --format '{{ .Config.Image }}' mail` /bin/sh -c "ls -1 /etc/opendkim | grep -E 'KeyTable|SigningTable|TrustedHosts|keys'|wc -l" assert_success assert_output 4 @@ -592,29 +592,29 @@ EOF @test "checking opendkim: generator creates keys, tables and TrustedHosts without postfix-virtual.cf" { private_config="$(duplicate_config_for_container . mail_dkim_generator_creates_keys_tables_TrustedHosts_without_postfix_virtual.cf)" - rm -rf "$private_config/without-virtual" - mkdir -p "$private_config/without-virtual" + rm -rf "${private_config}/without-virtual" + mkdir -p "${private_config}/without-virtual" run docker run --rm \ - -v "$private_config/without-virtual/":/tmp/docker-mailserver/ \ - -v "$private_config/postfix-accounts.cf":/tmp/docker-mailserver/postfix-accounts.cf \ + -v "${private_config}/without-virtual/":/tmp/docker-mailserver/ \ + -v "${private_config}/postfix-accounts.cf":/tmp/docker-mailserver/postfix-accounts.cf \ `docker inspect --format '{{ .Config.Image }}' mail` /bin/sh -c 'generate-dkim-config | wc -l' assert_success assert_output 5 # Check keys for localhost.localdomain run docker run --rm \ - -v "$private_config/without-virtual/opendkim":/etc/opendkim \ + -v "${private_config}/without-virtual/opendkim":/etc/opendkim \ `docker inspect --format '{{ .Config.Image }}' mail` /bin/sh -c 'ls -1 /etc/opendkim/keys/localhost.localdomain/ | wc -l' assert_success assert_output 2 # Check keys for otherdomain.tld run docker run --rm \ - -v "$private_config/without-virtual/opendkim":/etc/opendkim \ + -v "${private_config}/without-virtual/opendkim":/etc/opendkim \ `docker inspect --format '{{ .Config.Image }}' mail` /bin/sh -c 'ls -1 /etc/opendkim/keys/otherdomain.tld | wc -l' assert_success assert_output 2 # Check presence of tables and TrustedHosts run docker run --rm \ - -v "$private_config/without-virtual/opendkim":/etc/opendkim \ + -v "${private_config}/without-virtual/opendkim":/etc/opendkim \ `docker inspect --format '{{ .Config.Image }}' mail` /bin/sh -c "ls -1 /etc/opendkim | grep -E 'KeyTable|SigningTable|TrustedHosts|keys'|wc -l" assert_success assert_output 4 @@ -622,54 +622,54 @@ EOF @test "checking opendkim: generator creates keys, tables and TrustedHosts using domain name" { private_config="$(duplicate_config_for_container . mail_dkim_generator_creates_keys_tables_TrustedHosts_without_postfix_virtual.cf)" - rm -rf "$private_config/with-domain" && mkdir -p "$private_config/with-domain" + rm -rf "${private_config}/with-domain" && mkdir -p "${private_config}/with-domain" run docker run --rm \ - -v "$private_config/with-domain/":/tmp/docker-mailserver/ \ - -v "$private_config/postfix-accounts.cf":/tmp/docker-mailserver/postfix-accounts.cf \ - -v "$private_config/postfix-virtual.cf":/tmp/docker-mailserver/postfix-virtual.cf \ + -v "${private_config}/with-domain/":/tmp/docker-mailserver/ \ + -v "${private_config}/postfix-accounts.cf":/tmp/docker-mailserver/postfix-accounts.cf \ + -v "${private_config}/postfix-virtual.cf":/tmp/docker-mailserver/postfix-virtual.cf \ `docker inspect --format '{{ .Config.Image }}' mail` /bin/sh -c 'generate-dkim-config | wc -l' assert_success assert_output 6 # Generate key using domain name run docker run --rm \ - -v "$private_config/with-domain/":/tmp/docker-mailserver/ \ + -v "${private_config}/with-domain/":/tmp/docker-mailserver/ \ `docker inspect --format '{{ .Config.Image }}' mail` /bin/sh -c 'generate-dkim-domain testdomain.tld | wc -l' assert_success assert_output 1 # Check keys for localhost.localdomain run docker run --rm \ - -v "$private_config/with-domain/opendkim":/etc/opendkim \ + -v "${private_config}/with-domain/opendkim":/etc/opendkim \ `docker inspect --format '{{ .Config.Image }}' mail` /bin/sh -c 'ls -1 /etc/opendkim/keys/localhost.localdomain/ | wc -l' assert_success assert_output 2 # Check keys for otherdomain.tld run docker run --rm \ - -v "$private_config/with-domain/opendkim":/etc/opendkim \ + -v "${private_config}/with-domain/opendkim":/etc/opendkim \ `docker inspect --format '{{ .Config.Image }}' mail` /bin/sh -c 'ls -1 /etc/opendkim/keys/otherdomain.tld | wc -l' assert_success assert_output 2 # Check keys for testdomain.tld run docker run --rm \ - -v "$private_config/with-domain/opendkim":/etc/opendkim \ + -v "${private_config}/with-domain/opendkim":/etc/opendkim \ `docker inspect --format '{{ .Config.Image }}' mail` /bin/sh -c 'ls -1 /etc/opendkim/keys/testdomain.tld | wc -l' assert_success assert_output 2 # Check presence of tables and TrustedHosts run docker run --rm \ - -v "$private_config/with-domain/opendkim":/etc/opendkim \ + -v "${private_config}/with-domain/opendkim":/etc/opendkim \ `docker inspect --format '{{ .Config.Image }}' mail` /bin/sh -c "ls -1 /etc/opendkim | grep -E 'KeyTable|SigningTable|TrustedHosts|keys' | wc -l" assert_success assert_output 4 # Check valid entries actually present in KeyTable run docker run --rm \ - -v "$private_config/with-domain/opendkim":/etc/opendkim \ + -v "${private_config}/with-domain/opendkim":/etc/opendkim \ `docker inspect --format '{{ .Config.Image }}' mail` /bin/sh -c \ "egrep 'localhost.localdomain|otherdomain.tld|localdomain2.com|testdomain.tld' /etc/opendkim/KeyTable | wc -l" assert_success assert_output 4 # Check valid entries actually present in SigningTable run docker run --rm \ - -v "$private_config/with-domain/opendkim":/etc/opendkim \ + -v "${private_config}/with-domain/opendkim":/etc/opendkim \ `docker inspect --format '{{ .Config.Image }}' mail` /bin/sh -c \ "egrep 'localhost.localdomain|otherdomain.tld|localdomain2.com|testdomain.tld' /etc/opendkim/SigningTable | wc -l" assert_success @@ -731,7 +731,7 @@ EOF } @test "checking amavis: VIRUSMAILS_DELETE_DELAY override works as expected" { - run docker run --rm -e VIRUSMAILS_DELETE_DELAY=2 `docker inspect --format '{{ .Config.Image }}' mail` /bin/bash -c 'echo $VIRUSMAILS_DELETE_DELAY | grep 2' + run docker run --rm -e VIRUSMAILS_DELETE_DELAY=2 `docker inspect --format '{{ .Config.Image }}' mail` /bin/bash -c 'echo ${VIRUSMAILS_DELETE_DELAY} | grep 2' assert_success } @@ -867,7 +867,7 @@ EOF run docker exec mail /bin/sh -c "grep '^user3@domain\.tld|' -i /tmp/docker-mailserver/postfix-accounts.cf" assert_success - [ ! -z "$output" ] + [ ! -z "${output}" ] } @test "checking accounts: auser3 should have been added to /tmp/docker-mailserver/postfix-accounts.cf" { @@ -875,7 +875,7 @@ EOF run docker exec mail /bin/sh -c "grep '^auser3@domain\.tld|' -i /tmp/docker-mailserver/postfix-accounts.cf" assert_success - [ ! -z "$output" ] + [ ! -z "${output}" ] } @test "checking accounts: a.ser3 should have been added to /tmp/docker-mailserver/postfix-accounts.cf" { @@ -883,7 +883,7 @@ EOF run docker exec mail /bin/sh -c "grep '^a\.ser3@domain\.tld|' -i /tmp/docker-mailserver/postfix-accounts.cf" assert_success - [ ! -z "$output" ] + [ ! -z "${output}" ] } @test "checking accounts: user3 should have been removed from /tmp/docker-mailserver/postfix-accounts.cf but not auser3" { @@ -891,11 +891,11 @@ EOF run docker exec mail /bin/sh -c "grep '^user3@domain\.tld' -i /tmp/docker-mailserver/postfix-accounts.cf" assert_failure - [ -z "$output" ] + [ -z "${output}" ] run docker exec mail /bin/sh -c "grep '^auser3@domain\.tld' -i /tmp/docker-mailserver/postfix-accounts.cf" assert_success - [ ! -z "$output" ] + [ ! -z "${output}" ] } @test "checking user updating password for user in /tmp/docker-mailserver/postfix-accounts.cf" { @@ -929,20 +929,20 @@ EOF -v "$(duplicate_config_for_container without-accounts/ without-accounts-deleting-user)":/tmp/docker-mailserver/ \ `docker inspect --format '{{ .Config.Image }}' mail` /bin/sh -c 'delmailuser -y user3@domain.tld' assert_success - [ -z "$output" ] + [ -z "${output}" ] } @test "checking accounts: user3 should have been added to /tmp/docker-mailserver/postfix-accounts.cf even when that file does not exist" { private_config=$(duplicate_config_for_container without-accounts/ without-accounts_file_does_not_exist) run docker run --rm \ - -v "$private_config/without-accounts/":/tmp/docker-mailserver/ \ + -v "${private_config}/without-accounts/":/tmp/docker-mailserver/ \ `docker inspect --format '{{ .Config.Image }}' mail` /bin/sh -c 'addmailuser user3@domain.tld mypassword' assert_success run docker run --rm \ - -v "$private_config/without-accounts/":/tmp/docker-mailserver/ \ + -v "${private_config}/without-accounts/":/tmp/docker-mailserver/ \ `docker inspect --format '{{ .Config.Image }}' mail` /bin/sh -c 'grep user3@domain.tld -i /tmp/docker-mailserver/postfix-accounts.cf' assert_success - [ ! -z "$output" ] + [ ! -z "${output}" ] } @@ -1037,35 +1037,35 @@ EOF @test "checking quota: dovecot mailbox max size must be equal to postfix mailbox max size" { postfix_mailbox_size=$(docker exec mail sh -c "postconf | grep -Po '(?<=mailbox_size_limit = )[0-9]+'") - run echo "$postfix_mailbox_size" + run echo "${postfix_mailbox_size}" refute_output "" # dovecot relies on virtual_mailbox_size by default postfix_virtual_mailbox_size=$(docker exec mail sh -c "postconf | grep -Po '(?<=virtual_mailbox_limit = )[0-9]+'") - assert_equal "$postfix_virtual_mailbox_size" "$postfix_mailbox_size" + assert_equal "${postfix_virtual_mailbox_size}" "${postfix_mailbox_size}" - postfix_mailbox_size_mb=$(($postfix_mailbox_size / 1000000)) + postfix_mailbox_size_mb=$(( postfix_mailbox_size / 1000000)) dovecot_mailbox_size_mb=$(docker exec mail sh -c "doveconf | grep -oP '(?<=quota_rule \= \*\:storage=)[0-9]+'") - run echo "$dovecot_mailbox_size_mb" + run echo "${dovecot_mailbox_size_mb}" refute_output "" - assert_equal "$postfix_mailbox_size_mb" "$dovecot_mailbox_size_mb" + assert_equal "${postfix_mailbox_size_mb}" "${dovecot_mailbox_size_mb}" } @test "checking quota: dovecot message max size must be equal to postfix messsage max size" { postfix_message_size=$(docker exec mail sh -c "postconf | grep -Po '(?<=message_size_limit = )[0-9]+'") - run echo "$postfix_message_size" + run echo "${postfix_message_size}" refute_output "" - postfix_message_size_mb=$(($postfix_message_size / 1000000)) + postfix_message_size_mb=$((${postfix_message_size} / 1000000)) dovecot_message_size_mb=$(docker exec mail sh -c "doveconf | grep -oP '(?<=quota_max_mail_size = )[0-9]+'") - run echo "$dovecot_message_size_mb" + run echo "${dovecot_message_size_mb}" refute_output "" - assert_equal "$postfix_message_size_mb" "$dovecot_message_size_mb" + assert_equal "${postfix_message_size_mb}" "${dovecot_message_size_mb}" } @test "checking quota: quota directive is removed when mailbox is removed" { @@ -1207,7 +1207,7 @@ EOF assert_success value=$(cat $(private_config_path mail)/postfix-accounts.cf | grep setup_email_add@example.com | awk -F '|' '{print $1}') - [ "$value" = "setup_email_add@example.com" ] + [ "${value}" = "setup_email_add@example.com" ] assert_success wait_for_changes_to_be_detected_in_container mail @@ -1233,20 +1233,20 @@ EOF assert_success initialpass=$(cat $(private_config_path mail)/postfix-accounts.cf | grep lorem@impsum.org | awk -F '|' '{print $2}') - [ "$initialpass" != "" ] + [ "${initialpass}" != "" ] assert_success run ./setup.sh -c mail email update lorem@impsum.org my password assert_success updatepass=$(cat $(private_config_path mail)/postfix-accounts.cf | grep lorem@impsum.org | awk -F '|' '{print $2}') - [ "$updatepass" != "" ] + [ "${updatepass}" != "" ] assert_success - [ "$initialpass" != "$updatepass" ] + [ "${initialpass}" != "${updatepass}" ] assert_success - docker exec mail doveadm pw -t "$updatepass" -p 'my password' | grep 'verified' + docker exec mail doveadm pw -t "${updatepass}" -p 'my password' | grep 'verified' assert_success } @@ -1395,8 +1395,8 @@ EOF # debug @test "checking setup.sh: setup.sh debug fetchmail" { run ./setup.sh -c mail debug fetchmail - [ "$status" -eq 11 ] - [[ "$output" == *"fetchmail: normal termination, status 11"* ]] + [ "${status}" -eq 11 ] + [[ "${output}" == *"fetchmail: normal termination, status 11"* ]] } @test "checking setup.sh: setup.sh debug inspect" { run ./setup.sh -c mail debug inspect From 88fbe0dbd35efee3a315dec1ac699e826631da70 Mon Sep 17 00:00:00 2001 From: Martin Schulze Date: Sun, 18 Oct 2020 02:24:26 +0200 Subject: [PATCH 32/50] Fix shellcheck errors on tests.bats --- test/tests.bats | 131 +++++++++++++++++++++++------------------------- 1 file changed, 64 insertions(+), 67 deletions(-) diff --git a/test/tests.bats b/test/tests.bats index 88e1793a..c1c721be 100644 --- a/test/tests.bats +++ b/test/tests.bats @@ -2,6 +2,9 @@ load 'test_helper/bats-support/load' load 'test_helper/bats-assert/load' load 'test_helper/common' +export IMAGE_NAME +IMAGE_NAME="${NAME}" + setup() { run_setup_file_if_necessary } @@ -11,8 +14,8 @@ setup_file() { mv "${private_config}/user-patches/user-patches.sh" "${private_config}/user-patches.sh" docker run --rm -d --name mail \ -v "${private_config}":/tmp/docker-mailserver \ - -v "`pwd`/test/test-files":/tmp/docker-mailserver-test:ro \ - -v "`pwd`/test/onedir":/var/mail-state \ + -v "$(pwd)/test/test-files":/tmp/docker-mailserver-test:ro \ + -v "$(pwd)/test/onedir":/var/mail-state \ -e ENABLE_CLAMAV=1 \ -e SPOOF_PROTECTION=1 \ -e ENABLE_SPAMASSASSIN=1 \ @@ -29,12 +32,12 @@ setup_file() { --cap-add=SYS_PTRACE \ -e PERMIT_DOCKER=host \ -e DMS_DEBUG=0 \ - -h mail.my-domain.com -t ${NAME} + -h mail.my-domain.com -t "${NAME}" wait_for_finished_setup_in_container mail # generate accounts after container has been started - docker run --rm -e MAIL_USER=added@localhost.localdomain -e MAIL_PASS=mypassword -t ${NAME} /bin/sh -c 'echo "${MAIL_USER}|$(doveadm pw -s SHA512-CRYPT -u ${MAIL_USER} -p ${MAIL_PASS})"' >> "${private_config}/postfix-accounts.cf" + docker run --rm -e MAIL_USER=added@localhost.localdomain -e MAIL_PASS=mypassword -t "${NAME}" /bin/sh -c 'echo "${MAIL_USER}|$(doveadm pw -s SHA512-CRYPT -u ${MAIL_USER} -p ${MAIL_PASS})"' >> "${private_config}/postfix-accounts.cf" docker exec mail addmailuser pass@localhost.localdomain 'may be \a `p^a.*ssword' # setup sieve @@ -84,12 +87,12 @@ teardown_file() { # @test "checking configuration: user-patches.sh executed" { - run echo -n "`docker logs mail | grep 'user\-patches\.sh'`" + run docker logs mail assert_output --partial "Default user-patches.sh successfully executed" } @test "checking configuration: hostname/domainname" { - run docker run `docker inspect --format '{{ .Config.Image }}' mail` + run docker run "${IMAGE_NAME:?}" assert_success } @@ -361,9 +364,9 @@ EOF @test "checking postfix: vhost file is correct" { run docker exec mail cat /etc/postfix/vhost assert_success - [ "${lines[0]}" = "localdomain2.com" ] - [ "${lines[1]}" = "localhost.localdomain" ] - [ "${lines[2]}" = "otherdomain.tld" ] + assert_line --index 0 "localdomain2.com" + assert_line --index 1 "localhost.localdomain" + assert_line --index 2 "otherdomain.tld" } @test "checking postfix: main.cf overrides" { @@ -432,7 +435,7 @@ EOF -e ENABLE_LDAP=1 \ -e PERMIT_DOCKER=network \ -e OVERRIDE_HOSTNAME=mail.mydomain.com \ - -t ${NAME} + -t "${NAME}" teardown() { docker rm -f mail_smtponly_without_config; } @@ -466,13 +469,13 @@ EOF -v "${private_config}/keyDefault/":/tmp/docker-mailserver/ \ -v "${private_config}/postfix-accounts.cf":/tmp/docker-mailserver/postfix-accounts.cf \ -v "${private_config}/postfix-virtual.cf":/tmp/docker-mailserver/postfix-virtual.cf \ - `docker inspect --format '{{ .Config.Image }}' mail` /bin/sh -c 'generate-dkim-config | wc -l' + "${IMAGE_NAME:?}" /bin/sh -c 'generate-dkim-config | wc -l' assert_success assert_output 6 run docker run --rm \ -v "${private_config}/keyDefault/opendkim":/etc/opendkim \ - `docker inspect --format '{{ .Config.Image }}' mail` \ + "${IMAGE_NAME:?}" \ /bin/sh -c 'stat -c%s /etc/opendkim/keys/localhost.localdomain/mail.txt' assert_success @@ -491,13 +494,13 @@ EOF -v "${private_config}/key2048/":/tmp/docker-mailserver/ \ -v "${private_config}/postfix-accounts.cf":/tmp/docker-mailserver/postfix-accounts.cf \ -v "${private_config}/postfix-virtual.cf":/tmp/docker-mailserver/postfix-virtual.cf \ - `docker inspect --format '{{ .Config.Image }}' mail` /bin/sh -c 'generate-dkim-config 2048 | wc -l' + "${IMAGE_NAME:?}" /bin/sh -c 'generate-dkim-config 2048 | wc -l' assert_success assert_output 6 run docker run --rm \ -v "${private_config}/key2048/opendkim":/etc/opendkim \ - `docker inspect --format '{{ .Config.Image }}' mail` \ + "${IMAGE_NAME:?}" \ /bin/sh -c 'stat -c%s /etc/opendkim/keys/localhost.localdomain/mail.txt' assert_success @@ -516,13 +519,13 @@ EOF -v "${private_config}/key1024/":/tmp/docker-mailserver/ \ -v "${private_config}/postfix-accounts.cf":/tmp/docker-mailserver/postfix-accounts.cf \ -v "${private_config}/postfix-virtual.cf":/tmp/docker-mailserver/postfix-virtual.cf \ - `docker inspect --format '{{ .Config.Image }}' mail` /bin/sh -c 'generate-dkim-config 1024 | wc -l' + "${IMAGE_NAME:?}" /bin/sh -c 'generate-dkim-config 1024 | wc -l' assert_success assert_output 6 run docker run --rm \ -v "${private_config}/key1024/opendkim":/etc/opendkim \ - `docker inspect --format '{{ .Config.Image }}' mail` \ + "${IMAGE_NAME:?}" \ /bin/sh -c 'stat -c%s /etc/opendkim/keys/localhost.localdomain/mail.txt' assert_success @@ -537,25 +540,25 @@ EOF -v "${private_config}/empty/":/tmp/docker-mailserver/ \ -v "${private_config}/postfix-accounts.cf":/tmp/docker-mailserver/postfix-accounts.cf \ -v "${private_config}/postfix-virtual.cf":/tmp/docker-mailserver/postfix-virtual.cf \ - `docker inspect --format '{{ .Config.Image }}' mail` /bin/sh -c 'generate-dkim-config | wc -l' + "${IMAGE_NAME:?}" /bin/sh -c 'generate-dkim-config | wc -l' assert_success assert_output 6 # Check keys for localhost.localdomain run docker run --rm \ -v "${private_config}/empty/opendkim":/etc/opendkim \ - `docker inspect --format '{{ .Config.Image }}' mail` /bin/sh -c 'ls -1 /etc/opendkim/keys/localhost.localdomain/ | wc -l' + "${IMAGE_NAME:?}" /bin/sh -c 'ls -1 /etc/opendkim/keys/localhost.localdomain/ | wc -l' assert_success assert_output 2 # Check keys for otherdomain.tld run docker run --rm \ -v "${private_config}/empty/opendkim":/etc/opendkim \ - `docker inspect --format '{{ .Config.Image }}' mail` /bin/sh -c 'ls -1 /etc/opendkim/keys/otherdomain.tld | wc -l' + "${IMAGE_NAME:?}" /bin/sh -c 'ls -1 /etc/opendkim/keys/otherdomain.tld | wc -l' assert_success assert_output 2 # Check presence of tables and TrustedHosts run docker run --rm \ -v "${private_config}/empty/opendkim":/etc/opendkim \ - `docker inspect --format '{{ .Config.Image }}' mail` /bin/sh -c "ls -1 /etc/opendkim | grep -E 'KeyTable|SigningTable|TrustedHosts|keys'|wc -l" + "${IMAGE_NAME:?}" /bin/sh -c "ls -1 /etc/opendkim | grep -E 'KeyTable|SigningTable|TrustedHosts|keys'|wc -l" assert_success assert_output 4 } @@ -567,25 +570,25 @@ EOF run docker run --rm \ -v "${private_config}/without-accounts/":/tmp/docker-mailserver/ \ -v "${private_config}/postfix-virtual.cf":/tmp/docker-mailserver/postfix-virtual.cf \ - `docker inspect --format '{{ .Config.Image }}' mail` /bin/sh -c 'generate-dkim-config | wc -l' + "${IMAGE_NAME:?}" /bin/sh -c 'generate-dkim-config | wc -l' assert_success assert_output 5 # Check keys for localhost.localdomain run docker run --rm \ -v "${private_config}/without-accounts/opendkim":/etc/opendkim \ - `docker inspect --format '{{ .Config.Image }}' mail` /bin/sh -c 'ls -1 /etc/opendkim/keys/localhost.localdomain/ | wc -l' + "${IMAGE_NAME:?}" /bin/sh -c 'ls -1 /etc/opendkim/keys/localhost.localdomain/ | wc -l' assert_success assert_output 2 # Check keys for otherdomain.tld # run docker run --rm \ # -v "${private_config}/without-accounts/opendkim":/etc/opendkim \ - # `docker inspect --format '{{ .Config.Image }}' mail` /bin/sh -c 'ls -1 /etc/opendkim/keys/otherdomain.tld | wc -l' + # "${IMAGE_NAME:?}" /bin/sh -c 'ls -1 /etc/opendkim/keys/otherdomain.tld | wc -l' # assert_success # [ "${output}" -eq 0 ] # Check presence of tables and TrustedHosts run docker run --rm \ -v "${private_config}/without-accounts/opendkim":/etc/opendkim \ - `docker inspect --format '{{ .Config.Image }}' mail` /bin/sh -c "ls -1 /etc/opendkim | grep -E 'KeyTable|SigningTable|TrustedHosts|keys'|wc -l" + "${IMAGE_NAME:?}" /bin/sh -c "ls -1 /etc/opendkim | grep -E 'KeyTable|SigningTable|TrustedHosts|keys'|wc -l" assert_success assert_output 4 } @@ -597,25 +600,25 @@ EOF run docker run --rm \ -v "${private_config}/without-virtual/":/tmp/docker-mailserver/ \ -v "${private_config}/postfix-accounts.cf":/tmp/docker-mailserver/postfix-accounts.cf \ - `docker inspect --format '{{ .Config.Image }}' mail` /bin/sh -c 'generate-dkim-config | wc -l' + "${IMAGE_NAME:?}" /bin/sh -c 'generate-dkim-config | wc -l' assert_success assert_output 5 # Check keys for localhost.localdomain run docker run --rm \ -v "${private_config}/without-virtual/opendkim":/etc/opendkim \ - `docker inspect --format '{{ .Config.Image }}' mail` /bin/sh -c 'ls -1 /etc/opendkim/keys/localhost.localdomain/ | wc -l' + "${IMAGE_NAME:?}" /bin/sh -c 'ls -1 /etc/opendkim/keys/localhost.localdomain/ | wc -l' assert_success assert_output 2 # Check keys for otherdomain.tld run docker run --rm \ -v "${private_config}/without-virtual/opendkim":/etc/opendkim \ - `docker inspect --format '{{ .Config.Image }}' mail` /bin/sh -c 'ls -1 /etc/opendkim/keys/otherdomain.tld | wc -l' + "${IMAGE_NAME:?}" /bin/sh -c 'ls -1 /etc/opendkim/keys/otherdomain.tld | wc -l' assert_success assert_output 2 # Check presence of tables and TrustedHosts run docker run --rm \ -v "${private_config}/without-virtual/opendkim":/etc/opendkim \ - `docker inspect --format '{{ .Config.Image }}' mail` /bin/sh -c "ls -1 /etc/opendkim | grep -E 'KeyTable|SigningTable|TrustedHosts|keys'|wc -l" + "${IMAGE_NAME:?}" /bin/sh -c "ls -1 /etc/opendkim | grep -E 'KeyTable|SigningTable|TrustedHosts|keys'|wc -l" assert_success assert_output 4 } @@ -627,50 +630,50 @@ EOF -v "${private_config}/with-domain/":/tmp/docker-mailserver/ \ -v "${private_config}/postfix-accounts.cf":/tmp/docker-mailserver/postfix-accounts.cf \ -v "${private_config}/postfix-virtual.cf":/tmp/docker-mailserver/postfix-virtual.cf \ - `docker inspect --format '{{ .Config.Image }}' mail` /bin/sh -c 'generate-dkim-config | wc -l' + "${IMAGE_NAME:?}" /bin/sh -c 'generate-dkim-config | wc -l' assert_success assert_output 6 # Generate key using domain name run docker run --rm \ -v "${private_config}/with-domain/":/tmp/docker-mailserver/ \ - `docker inspect --format '{{ .Config.Image }}' mail` /bin/sh -c 'generate-dkim-domain testdomain.tld | wc -l' + "${IMAGE_NAME:?}" /bin/sh -c 'generate-dkim-domain testdomain.tld | wc -l' assert_success assert_output 1 # Check keys for localhost.localdomain run docker run --rm \ -v "${private_config}/with-domain/opendkim":/etc/opendkim \ - `docker inspect --format '{{ .Config.Image }}' mail` /bin/sh -c 'ls -1 /etc/opendkim/keys/localhost.localdomain/ | wc -l' + "${IMAGE_NAME:?}" /bin/sh -c 'ls -1 /etc/opendkim/keys/localhost.localdomain/ | wc -l' assert_success assert_output 2 # Check keys for otherdomain.tld run docker run --rm \ -v "${private_config}/with-domain/opendkim":/etc/opendkim \ - `docker inspect --format '{{ .Config.Image }}' mail` /bin/sh -c 'ls -1 /etc/opendkim/keys/otherdomain.tld | wc -l' + "${IMAGE_NAME:?}" /bin/sh -c 'ls -1 /etc/opendkim/keys/otherdomain.tld | wc -l' assert_success assert_output 2 # Check keys for testdomain.tld run docker run --rm \ -v "${private_config}/with-domain/opendkim":/etc/opendkim \ - `docker inspect --format '{{ .Config.Image }}' mail` /bin/sh -c 'ls -1 /etc/opendkim/keys/testdomain.tld | wc -l' + "${IMAGE_NAME:?}" /bin/sh -c 'ls -1 /etc/opendkim/keys/testdomain.tld | wc -l' assert_success assert_output 2 # Check presence of tables and TrustedHosts run docker run --rm \ -v "${private_config}/with-domain/opendkim":/etc/opendkim \ - `docker inspect --format '{{ .Config.Image }}' mail` /bin/sh -c "ls -1 /etc/opendkim | grep -E 'KeyTable|SigningTable|TrustedHosts|keys' | wc -l" + "${IMAGE_NAME:?}" /bin/sh -c "ls -1 /etc/opendkim | grep -E 'KeyTable|SigningTable|TrustedHosts|keys' | wc -l" assert_success assert_output 4 # Check valid entries actually present in KeyTable run docker run --rm \ -v "${private_config}/with-domain/opendkim":/etc/opendkim \ - `docker inspect --format '{{ .Config.Image }}' mail` /bin/sh -c \ + "${IMAGE_NAME:?}" /bin/sh -c \ "egrep 'localhost.localdomain|otherdomain.tld|localdomain2.com|testdomain.tld' /etc/opendkim/KeyTable | wc -l" assert_success assert_output 4 # Check valid entries actually present in SigningTable run docker run --rm \ -v "${private_config}/with-domain/opendkim":/etc/opendkim \ - `docker inspect --format '{{ .Config.Image }}' mail` /bin/sh -c \ + "${IMAGE_NAME:?}" /bin/sh -c \ "egrep 'localhost.localdomain|otherdomain.tld|localdomain2.com|testdomain.tld' /etc/opendkim/SigningTable | wc -l" assert_success assert_output 4 @@ -731,8 +734,8 @@ EOF } @test "checking amavis: VIRUSMAILS_DELETE_DELAY override works as expected" { - run docker run --rm -e VIRUSMAILS_DELETE_DELAY=2 `docker inspect --format '{{ .Config.Image }}' mail` /bin/bash -c 'echo ${VIRUSMAILS_DELETE_DELAY} | grep 2' - assert_success + run docker run --rm -e VIRUSMAILS_DELETE_DELAY=2 "${IMAGE_NAME:?}" /bin/bash -c 'echo "${VIRUSMAILS_DELETE_DELAY}"' + assert_output 2 } @test "checking amavis: old virusmail is wipped by cron" { @@ -867,7 +870,7 @@ EOF run docker exec mail /bin/sh -c "grep '^user3@domain\.tld|' -i /tmp/docker-mailserver/postfix-accounts.cf" assert_success - [ ! -z "${output}" ] + [ -n "${output}" ] } @test "checking accounts: auser3 should have been added to /tmp/docker-mailserver/postfix-accounts.cf" { @@ -875,7 +878,7 @@ EOF run docker exec mail /bin/sh -c "grep '^auser3@domain\.tld|' -i /tmp/docker-mailserver/postfix-accounts.cf" assert_success - [ ! -z "${output}" ] + [ -n "${output}" ] } @test "checking accounts: a.ser3 should have been added to /tmp/docker-mailserver/postfix-accounts.cf" { @@ -883,7 +886,7 @@ EOF run docker exec mail /bin/sh -c "grep '^a\.ser3@domain\.tld|' -i /tmp/docker-mailserver/postfix-accounts.cf" assert_success - [ ! -z "${output}" ] + [ -n "${output}" ] } @test "checking accounts: user3 should have been removed from /tmp/docker-mailserver/postfix-accounts.cf but not auser3" { @@ -895,23 +898,19 @@ EOF run docker exec mail /bin/sh -c "grep '^auser3@domain\.tld' -i /tmp/docker-mailserver/postfix-accounts.cf" assert_success - [ ! -z "${output}" ] + [ -n "${output}" ] } @test "checking user updating password for user in /tmp/docker-mailserver/postfix-accounts.cf" { docker exec mail /bin/sh -c "addmailuser user4@domain.tld mypassword" - initialpass=$(run docker exec mail /bin/sh -c "grep '^user4@domain\.tld' -i /tmp/docker-mailserver/postfix-accounts.cf") + initialpass=$(docker exec mail /bin/sh -c "grep '^user4@domain\.tld' -i /tmp/docker-mailserver/postfix-accounts.cf") sleep 2 docker exec mail /bin/sh -c "updatemailuser user4@domain.tld mynewpassword" sleep 2 - changepass=$(run docker exec mail /bin/sh -c "grep '^user4@domain\.tld' -i /tmp/docker-mailserver/postfix-accounts.cf") + changepass=$(docker exec mail /bin/sh -c "grep '^user4@domain\.tld' -i /tmp/docker-mailserver/postfix-accounts.cf") - if [ initialpass != changepass ]; then - status="0" - else - status="1" - fi + [ "$initialpass" != "$changepass" ] docker exec mail /bin/sh -c "delmailuser -y auser3@domain.tld" @@ -927,7 +926,7 @@ EOF @test "checking accounts: no error is generated when deleting a user if /tmp/docker-mailserver/postfix-accounts.cf is missing" { run docker run --rm \ -v "$(duplicate_config_for_container without-accounts/ without-accounts-deleting-user)":/tmp/docker-mailserver/ \ - `docker inspect --format '{{ .Config.Image }}' mail` /bin/sh -c 'delmailuser -y user3@domain.tld' + "${IMAGE_NAME:?}" /bin/sh -c 'delmailuser -y user3@domain.tld' assert_success [ -z "${output}" ] } @@ -936,13 +935,13 @@ EOF private_config=$(duplicate_config_for_container without-accounts/ without-accounts_file_does_not_exist) run docker run --rm \ -v "${private_config}/without-accounts/":/tmp/docker-mailserver/ \ - `docker inspect --format '{{ .Config.Image }}' mail` /bin/sh -c 'addmailuser user3@domain.tld mypassword' + "${IMAGE_NAME:?}" /bin/sh -c 'addmailuser user3@domain.tld mypassword' assert_success run docker run --rm \ -v "${private_config}/without-accounts/":/tmp/docker-mailserver/ \ - `docker inspect --format '{{ .Config.Image }}' mail` /bin/sh -c 'grep user3@domain.tld -i /tmp/docker-mailserver/postfix-accounts.cf' + "${IMAGE_NAME:?}" /bin/sh -c 'grep user3@domain.tld -i /tmp/docker-mailserver/postfix-accounts.cf' assert_success - [ ! -z "${output}" ] + [ -n "${output}" ] } @@ -1059,7 +1058,7 @@ EOF run echo "${postfix_message_size}" refute_output "" - postfix_message_size_mb=$((${postfix_message_size} / 1000000)) + postfix_message_size_mb=$(( postfix_message_size / 1000000)) dovecot_message_size_mb=$(docker exec mail sh -c "doveconf | grep -oP '(?<=quota_max_mail_size = )[0-9]+'") run echo "${dovecot_message_size_mb}" @@ -1142,6 +1141,7 @@ EOF run repeat_until_success_or_timeout 20 sh -c "docker logs mail | grep 'Quota exceeded (mailbox for user is full)'" assert_success + docker exec mail ls -l '/var/mail/otherdomain.tld/quotauser/new/' # ensure only the first big message and the warn message are present (other messages are rejected: mailbox is full) run docker exec mail sh -c 'ls /var/mail/otherdomain.tld/quotauser/new/ | wc -l' assert_success @@ -1189,13 +1189,13 @@ EOF @test "checking setup.sh: Without arguments: status 1, show help text" { run ./setup.sh assert_failure - [ "${lines[1]}" = "Usage: ./setup.sh [-i IMAGE_NAME] [-c CONTAINER_NAME] [args]" ] + assert_line --index 1 "Usage: ./setup.sh [-i IMAGE_NAME] [-c CONTAINER_NAME] [args]" } @test "checking setup.sh: Wrong arguments" { run ./setup.sh lol troll assert_failure - [ "${lines[1]}" = "Usage: ./setup.sh [-i IMAGE_NAME] [-c CONTAINER_NAME] [args]" ] + assert_line --index 1 "Usage: ./setup.sh [-i IMAGE_NAME] [-c CONTAINER_NAME] [args]" } # email @@ -1206,7 +1206,7 @@ EOF run ./setup.sh -c mail email add setup_email_add@example.com test_password assert_success - value=$(cat $(private_config_path mail)/postfix-accounts.cf | grep setup_email_add@example.com | awk -F '|' '{print $1}') + value=$(grep setup_email_add@example.com "$(private_config_path mail)/postfix-accounts.cf" | awk -F '|' '{print $1}') [ "${value}" = "setup_email_add@example.com" ] assert_success @@ -1232,19 +1232,16 @@ EOF run ./setup.sh -c mail email add lorem@impsum.org test_test assert_success - initialpass=$(cat $(private_config_path mail)/postfix-accounts.cf | grep lorem@impsum.org | awk -F '|' '{print $2}') + initialpass=$(grep lorem@impsum.org "$(private_config_path mail)/postfix-accounts.cf" | awk -F '|' '{print $2}') [ "${initialpass}" != "" ] assert_success run ./setup.sh -c mail email update lorem@impsum.org my password assert_success - updatepass=$(cat $(private_config_path mail)/postfix-accounts.cf | grep lorem@impsum.org | awk -F '|' '{print $2}') + updatepass=$(grep lorem@impsum.org "$(private_config_path mail)/postfix-accounts.cf" | awk -F '|' '{print $2}') [ "${updatepass}" != "" ] - assert_success - [ "${initialpass}" != "${updatepass}" ] - assert_success docker exec mail doveadm pw -t "${updatepass}" -p 'my password' | grep 'verified' assert_success @@ -1262,7 +1259,7 @@ EOF # # run docker exec mail ls /var/mail/impsum.org/lorem # assert_failure - run grep lorem@impsum.org $(private_config_path mail)/postfix-accounts.cf + run grep lorem@impsum.org "$(private_config_path mail)/postfix-accounts.cf" assert_failure } @@ -1395,14 +1392,14 @@ EOF # debug @test "checking setup.sh: setup.sh debug fetchmail" { run ./setup.sh -c mail debug fetchmail - [ "${status}" -eq 11 ] - [[ "${output}" == *"fetchmail: normal termination, status 11"* ]] + assert_failure 11 + assert_output --partial "fetchmail: normal termination, status 11" } @test "checking setup.sh: setup.sh debug inspect" { run ./setup.sh -c mail debug inspect assert_success - [ "${lines[0]}" = "Image: tvial/docker-mailserver:testing" ] - [ "${lines[1]}" = "Container: mail" ] + assert_line --index 0 "Image: tvial/docker-mailserver:testing" + assert_line --index 1 "Container: mail" } @test "checking setup.sh: setup.sh debug login ls" { run ./setup.sh -c mail debug login ls From 7fb13c18cde35f3d6653397c8dd4cb3968d32c66 Mon Sep 17 00:00:00 2001 From: Martin Schulze Date: Sun, 18 Oct 2020 02:25:03 +0200 Subject: [PATCH 33/50] Reinstane required (empty) folder this is needed to make test "checking accounts: user3 should have been added to /tmp/docker-mailserver/postfix-accounts.cf even when that file does not exist" pass --- .gitignore | 1 - test/config/without-accounts/.gitkeep | 0 2 files changed, 1 deletion(-) create mode 100644 test/config/without-accounts/.gitkeep diff --git a/.gitignore b/.gitignore index c5f8cfa6..4a11d7c5 100644 --- a/.gitignore +++ b/.gitignore @@ -34,7 +34,6 @@ test/config/postfix-send-access.cf test/config/postfix-send-access.cfe test/config/relay-hosts/chksum test/config/relay-hosts/postfix-aliases.cf -test/config/without-accounts/ test/config/without-virtual/ test/config/with-domain/ test/onedir diff --git a/test/config/without-accounts/.gitkeep b/test/config/without-accounts/.gitkeep new file mode 100644 index 00000000..e69de29b From 5030e8278cbae2264e33cfc7dffd0ae1bd9b676d Mon Sep 17 00:00:00 2001 From: Martin Schulze Date: Sun, 18 Oct 2020 03:11:10 +0200 Subject: [PATCH 34/50] Add tests for test/common.bash --- test/test_helper.bats | 93 ++++++++++++++++++++++++++++++++++++ test/test_helper/common.bash | 16 ++----- 2 files changed, 98 insertions(+), 11 deletions(-) create mode 100644 test/test_helper.bats diff --git a/test/test_helper.bats b/test/test_helper.bats new file mode 100644 index 00000000..30f791b6 --- /dev/null +++ b/test/test_helper.bats @@ -0,0 +1,93 @@ +load 'test_helper/bats-support/load' +load 'test_helper/bats-assert/load' +load 'test_helper/common' + +@test "repeat_until_success_or_timeout returns instantly on success" { + SECONDS=0 + repeat_until_success_or_timeout 1 true + [[ $SECONDS -le 1 ]] +} + +@test "repeat_until_success_or_timeout waits for timeout on persistent failure" { + SECONDS=0 + run repeat_until_success_or_timeout 2 false + [[ $SECONDS -ge 2 ]] + assert_failure + assert_output --partial "Timed out on command" +} + +@test "repeat_until_success_or_timeout aborts immediately on fatal failure" { + SECONDS=0 + run repeat_until_success_or_timeout --fatal-test false 2 false + [[ $SECONDS -le 1 ]] + assert_failure + assert_output --partial "early aborting" +} + +@test "repeat_until_success_or_timeout expects integer timeout" { + run repeat_until_success_or_timeout 1 true + assert_success + + run repeat_until_success_or_timeout timeout true + assert_failure + + run repeat_until_success_or_timeout --fatal-test true timeout true + assert_failure +} + +@test "run_until_success_or_timeout returns instantly on success" { + SECONDS=0 + run_until_success_or_timeout 2 true + [[ $SECONDS -le 1 ]] + assert_success +} + +@test "run_until_success_or_timeout waits for timeout on persistent failure" { + SECONDS=0 + ! run_until_success_or_timeout 2 false + [[ $SECONDS -ge 2 ]] + assert_failure +} + +@test "repeat_in_container_until_success_or_timeout fails immediately for non-running container" { + SECONDS=0 + ! repeat_in_container_until_success_or_timeout 10 name-of-non-existing-container true + [[ $SECONDS -le 1 ]] +} + +@test "repeat_in_container_until_success_or_timeout run command in container" { + local CONTAINER_NAME=$(docker run --rm -d alpine sleep 100) + SECONDS=0 + ! repeat_in_container_until_success_or_timeout 10 "$CONTAINER_NAME" sh -c "echo '$CONTAINER_NAME' > /tmp/marker" + [[ $SECONDS -le 1 ]] + run docker exec "$CONTAINER_NAME" cat /tmp/marker + assert_output "$CONTAINER_NAME" +} + +@test "container_is_running" { + local CONTAINER_NAME=$(docker run --rm -d alpine sleep 100) + container_is_running "$CONTAINER_NAME" + docker rm -f "$CONTAINER_NAME" + ! container_is_running "$CONTAINER_NAME" +} + +@test "wait_for_smtp_port_in_container aborts wait after timeout" { + local CONTAINER_NAME=$(docker run --rm -d alpine sleep 100) + SECONDS=0 + TEST_TIMEOUT_IN_SECONDS=2 run wait_for_smtp_port_in_container "$CONTAINER_NAME" + [[ $SECONDS -ge 2 ]] + assert_failure + assert_output --partial "Timed out on command" +} + +@test "wait_for_smtp_port_in_container returns immediately when port found" { + local CONTAINER_NAME=$(docker run --rm -d alpine sh -c "sleep 10") + + docker exec "$CONTAINER_NAME" apk add netcat-openbsd + docker exec "$CONTAINER_NAME" nc -l 25 & + + SECONDS=0 + TEST_TIMEOUT_IN_SECONDS=5 run wait_for_smtp_port_in_container "$CONTAINER_NAME" + [[ $SECONDS -lt 5 ]] + assert_success +} \ No newline at end of file diff --git a/test/test_helper/common.bash b/test/test_helper/common.bash index 95800011..e65dd3ec 100644 --- a/test/test_helper/common.bash +++ b/test/test_helper/common.bash @@ -27,9 +27,9 @@ function repeat_until_success_or_timeout { do if [[ -n "${fatal_failure_test_command}" ]] && ! eval "${fatal_failure_test_command}"; then echo "\`${fatal_failure_test_command}\` failed, early aborting repeat_until_success of \`${*}\`" >&2 - exit 1 + return 1 fi - sleep 5 + sleep 1 if [[ $(( SECONDS - STARTTIME )) -gt ${TIMEOUT} ]]; then echo "Timed out on command: ${*}" >&2 return 1 @@ -51,7 +51,7 @@ function run_until_success_or_timeout { until run "${@}" && [[ ${status} -eq 0 ]] do sleep 1 - if [[ $(( SECONDS - STARTTIME )) -gt ${TIMEOUT} ]]; then + if (( SECONDS - STARTTIME > TIMEOUT )); then echo "Timed out on command: ${*}" >&2 return 1 fi @@ -153,7 +153,8 @@ function private_config_path() { # @param ${2} (optional) container name, defaults to ${BATS_TEST_FILENAME} # @return path to the folder where the config is duplicated function duplicate_config_for_container() { - local OUTPUT_FOLDER="$(private_config_path "${2}")" + local OUTPUT_FOLDER + OUTPUT_FOLDER="$(private_config_path "${2}")" rm -rf "${OUTPUT_FOLDER:?}/" # cleanup mkdir -p "${OUTPUT_FOLDER}" cp -r "${PWD}/test/config/${1:?}/." "${OUTPUT_FOLDER}" @@ -173,13 +174,6 @@ function wait_for_service() { container_has_service_running "${CONTAINER_NAME}" "${SERVICE_NAME}" } -function count_processed_changes() { - local CONTAINER_NAME=${1} - docker exec "${CONTAINER_NAME}" cat /var/log/supervisor/changedetector.log | grep "Change detected" -c \ - || [[ ${?} == 1 ]] # don't error when no matches were found -} - - function wait_for_changes_to_be_detected_in_container() { local CONTAINER_NAME="${1}" local TIMEOUT=${TEST_TIMEOUT_IN_SECONDS} From 0da7ee0c1d0067a81254e4944c529e868210c5ba Mon Sep 17 00:00:00 2001 From: Georg Lauterbach Date: Sun, 18 Oct 2020 15:44:01 +0200 Subject: [PATCH 35/50] {} and uppercase --- test/mail_dhparams_manual_not_one_dir.bats | 6 ++-- test/mail_lmtp_ip.bats | 4 +-- test/mail_ssl_letsencrypt.bats | 18 +++++----- test/test_helper.bats | 42 +++++++++++----------- test/test_helper/common.bash | 24 +++++++------ 5 files changed, 48 insertions(+), 46 deletions(-) diff --git a/test/mail_dhparams_manual_not_one_dir.bats b/test/mail_dhparams_manual_not_one_dir.bats index f2072a8b..928e3bb3 100644 --- a/test/mail_dhparams_manual_not_one_dir.bats +++ b/test/mail_dhparams_manual_not_one_dir.bats @@ -21,12 +21,12 @@ function teardown() { } function setup_file() { - private_config=$(duplicate_config_for_container .) + PRIVATE_CONFIG=$(duplicate_config_for_container .) # copy the custom DHE params in local config - cp "`pwd`/test/test-files/ssl/custom-dhe-params.pem" "${private_config}/dhparams.pem" + cp "`pwd`/test/test-files/ssl/custom-dhe-params.pem" "${PRIVATE_CONFIG}/dhparams.pem" docker run -d --name mail_manual_dhparams_not_one_dir \ - -v "${private_config}":/tmp/docker-mailserver \ + -v "${PRIVATE_CONFIG}":/tmp/docker-mailserver \ -v "`pwd`/test/test-files":/tmp/docker-mailserver-test:ro \ -e DMS_DEBUG=0 \ -e ONE_DIR=0 \ diff --git a/test/mail_lmtp_ip.bats b/test/mail_lmtp_ip.bats index 02547436..42ad9639 100644 --- a/test/mail_lmtp_ip.bats +++ b/test/mail_lmtp_ip.bats @@ -43,7 +43,7 @@ teardown_file() { wait_for_smtp_port_in_container mail_lmtp_ip run docker exec mail_lmtp_ip /bin/sh -c "nc 0.0.0.0 25 < /tmp/docker-mailserver-test/email-templates/existing-user1.txt" assert_success - + # polling needs to avoid wc -l's unconditionally successful return status repeat_until_success_or_timeout 60 docker exec mail_lmtp_ip /bin/sh -c "grep 'postfix/lmtp' /var/log/mail/mail.log | grep 'status=sent' | grep ' Saved)'" run docker exec mail_lmtp_ip /bin/sh -c "grep 'postfix/lmtp' /var/log/mail/mail.log | grep 'status=sent' | grep ' Saved)' | wc -l" @@ -53,4 +53,4 @@ teardown_file() { @test "last" { skip 'only used to call teardown_file from teardown' -} \ No newline at end of file +} diff --git a/test/mail_ssl_letsencrypt.bats b/test/mail_ssl_letsencrypt.bats index c6e74a91..45714509 100644 --- a/test/mail_ssl_letsencrypt.bats +++ b/test/mail_ssl_letsencrypt.bats @@ -9,31 +9,31 @@ function teardown() { } function setup_file() { - private_config="$(duplicate_config_for_container . mail_lets_domain)" + PRIVATE_CONFIG="$(duplicate_config_for_container . mail_lets_domain)" docker run -d --name mail_lets_domain \ - -v "${private_config}":/tmp/docker-mailserver \ + -v "${PRIVATE_CONFIG}":/tmp/docker-mailserver \ -v "`pwd`/test/test-files":/tmp/docker-mailserver-test:ro \ - -v "${private_config}/letsencrypt/my-domain.com":/etc/letsencrypt/live/my-domain.com \ + -v "${PRIVATE_CONFIG}/letsencrypt/my-domain.com":/etc/letsencrypt/live/my-domain.com \ -e DMS_DEBUG=0 \ -e SSL_TYPE=letsencrypt \ -h mail.my-domain.com -t ${NAME} wait_for_finished_setup_in_container mail_lets_domain - private_config="$(duplicate_config_for_container . mail_lets_hostname)" + PRIVATE_CONFIG="$(duplicate_config_for_container . mail_lets_hostname)" docker run -d --name mail_lets_hostname \ - -v "${private_config}":/tmp/docker-mailserver \ + -v "${PRIVATE_CONFIG}":/tmp/docker-mailserver \ -v "`pwd`/test/test-files":/tmp/docker-mailserver-test:ro \ - -v "${private_config}/letsencrypt/mail.my-domain.com":/etc/letsencrypt/live/mail.my-domain.com \ + -v "${PRIVATE_CONFIG}/letsencrypt/mail.my-domain.com":/etc/letsencrypt/live/mail.my-domain.com \ -e DMS_DEBUG=0 \ -e SSL_TYPE=letsencrypt \ -h mail.my-domain.com -t ${NAME} wait_for_finished_setup_in_container mail_lets_hostname - private_config="$(duplicate_config_for_container . mail_lets_acme_json)" + PRIVATE_CONFIG="$(duplicate_config_for_container . mail_lets_acme_json)" cp "$(private_config_path mail_lets_acme_json)/letsencrypt/acme.json" "$(private_config_path mail_lets_acme_json)/acme.json" docker run -d --name mail_lets_acme_json \ - -v "${private_config}":/tmp/docker-mailserver \ - -v "${private_config}/acme.json":/etc/letsencrypt/acme.json:ro \ + -v "${PRIVATE_CONFIG}":/tmp/docker-mailserver \ + -v "${PRIVATE_CONFIG}/acme.json":/etc/letsencrypt/acme.json:ro \ -v "`pwd`/test/test-files":/tmp/docker-mailserver-test:ro \ -e DMS_DEBUG=0 \ -e SSL_TYPE=letsencrypt \ diff --git a/test/test_helper.bats b/test/test_helper.bats index 30f791b6..f69b368b 100644 --- a/test/test_helper.bats +++ b/test/test_helper.bats @@ -5,13 +5,13 @@ load 'test_helper/common' @test "repeat_until_success_or_timeout returns instantly on success" { SECONDS=0 repeat_until_success_or_timeout 1 true - [[ $SECONDS -le 1 ]] + [[ ${SECONDS} -le 1 ]] } @test "repeat_until_success_or_timeout waits for timeout on persistent failure" { SECONDS=0 run repeat_until_success_or_timeout 2 false - [[ $SECONDS -ge 2 ]] + [[ ${SECONDS} -ge 2 ]] assert_failure assert_output --partial "Timed out on command" } @@ -19,7 +19,7 @@ load 'test_helper/common' @test "repeat_until_success_or_timeout aborts immediately on fatal failure" { SECONDS=0 run repeat_until_success_or_timeout --fatal-test false 2 false - [[ $SECONDS -le 1 ]] + [[ ${SECONDS} -le 1 ]] assert_failure assert_output --partial "early aborting" } @@ -30,7 +30,7 @@ load 'test_helper/common' run repeat_until_success_or_timeout timeout true assert_failure - + run repeat_until_success_or_timeout --fatal-test true timeout true assert_failure } @@ -38,44 +38,44 @@ load 'test_helper/common' @test "run_until_success_or_timeout returns instantly on success" { SECONDS=0 run_until_success_or_timeout 2 true - [[ $SECONDS -le 1 ]] + [[ ${SECONDS} -le 1 ]] assert_success } @test "run_until_success_or_timeout waits for timeout on persistent failure" { SECONDS=0 ! run_until_success_or_timeout 2 false - [[ $SECONDS -ge 2 ]] + [[ ${SECONDS} -ge 2 ]] assert_failure } @test "repeat_in_container_until_success_or_timeout fails immediately for non-running container" { SECONDS=0 ! repeat_in_container_until_success_or_timeout 10 name-of-non-existing-container true - [[ $SECONDS -le 1 ]] + [[ ${SECONDS} -le 1 ]] } @test "repeat_in_container_until_success_or_timeout run command in container" { local CONTAINER_NAME=$(docker run --rm -d alpine sleep 100) SECONDS=0 - ! repeat_in_container_until_success_or_timeout 10 "$CONTAINER_NAME" sh -c "echo '$CONTAINER_NAME' > /tmp/marker" - [[ $SECONDS -le 1 ]] - run docker exec "$CONTAINER_NAME" cat /tmp/marker - assert_output "$CONTAINER_NAME" + ! repeat_in_container_until_success_or_timeout 10 "${CONTAINER_NAME}" sh -c "echo '${CONTAINER_NAME}' > /tmp/marker" + [[ ${SECONDS} -le 1 ]] + run docker exec "${CONTAINER_NAME}" cat /tmp/marker + assert_output "${CONTAINER_NAME}" } @test "container_is_running" { local CONTAINER_NAME=$(docker run --rm -d alpine sleep 100) - container_is_running "$CONTAINER_NAME" - docker rm -f "$CONTAINER_NAME" - ! container_is_running "$CONTAINER_NAME" + container_is_running "${CONTAINER_NAME}" + docker rm -f "${CONTAINER_NAME}" + ! container_is_running "${CONTAINER_NAME}" } @test "wait_for_smtp_port_in_container aborts wait after timeout" { local CONTAINER_NAME=$(docker run --rm -d alpine sleep 100) SECONDS=0 - TEST_TIMEOUT_IN_SECONDS=2 run wait_for_smtp_port_in_container "$CONTAINER_NAME" - [[ $SECONDS -ge 2 ]] + TEST_TIMEOUT_IN_SECONDS=2 run wait_for_smtp_port_in_container "${CONTAINER_NAME}" + [[ ${SECONDS} -ge 2 ]] assert_failure assert_output --partial "Timed out on command" } @@ -83,11 +83,11 @@ load 'test_helper/common' @test "wait_for_smtp_port_in_container returns immediately when port found" { local CONTAINER_NAME=$(docker run --rm -d alpine sh -c "sleep 10") - docker exec "$CONTAINER_NAME" apk add netcat-openbsd - docker exec "$CONTAINER_NAME" nc -l 25 & + docker exec "${CONTAINER_NAME}" apk add netcat-openbsd + docker exec "${CONTAINER_NAME}" nc -l 25 & SECONDS=0 - TEST_TIMEOUT_IN_SECONDS=5 run wait_for_smtp_port_in_container "$CONTAINER_NAME" - [[ $SECONDS -lt 5 ]] + TEST_TIMEOUT_IN_SECONDS=5 run wait_for_smtp_port_in_container "${CONTAINER_NAME}" + [[ ${SECONDS} -lt 5 ]] assert_success -} \ No newline at end of file +} diff --git a/test/test_helper/common.bash b/test/test_helper/common.bash index e65dd3ec..120f835d 100644 --- a/test/test_helper/common.bash +++ b/test/test_helper/common.bash @@ -1,7 +1,7 @@ load 'test_helper/bats-support/load' load 'test_helper/bats-assert/load' -NAME=tvial/docker-mailserver:testing +# NAME=tvial/docker-mailserver:testing # default timeout is 120 seconds TEST_TIMEOUT_IN_SECONDS=${TEST_TIMEOUT_IN_SECONDS-120} @@ -11,9 +11,9 @@ NUMBER_OF_LOG_LINES=${NUMBER_OF_LOG_LINES-10} # @param --fatal-test additional test whose failure aborts immediately # @param ... test to run function repeat_until_success_or_timeout { - local fatal_failure_test_command + local FATAL_FAILURE_TEST_COMMAND if [[ "${1}" == "--fatal-test" ]]; then - fatal_failure_test_command="${2}" + FATAL_FAILURE_TEST_COMMAND="${2}" shift 2 fi if ! [[ "${1}" =~ ^[0-9]+$ ]]; then @@ -25,8 +25,8 @@ function repeat_until_success_or_timeout { shift 1 until "${@}" do - if [[ -n "${fatal_failure_test_command}" ]] && ! eval "${fatal_failure_test_command}"; then - echo "\`${fatal_failure_test_command}\` failed, early aborting repeat_until_success of \`${*}\`" >&2 + if [[ -n "${FATAL_FAILURE_TEST_COMMAND}" ]] && ! eval "${FATAL_FAILURE_TEST_COMMAND}"; then + echo "\`${FATAL_FAILURE_TEST_COMMAND}\` failed, early aborting repeat_until_success of \`${*}\`" >&2 return 1 fi sleep 1 @@ -75,7 +75,7 @@ function container_is_running() { # @param ${1} port # @param ${2} container name function wait_for_tcp_port_in_container() { - repeat_until_success_or_timeout --fatal-test "container_is_running ${2}" "${TEST_TIMEOUT_IN_SECONDS}" docker exec ${2} /bin/sh -c "nc -z 0.0.0.0 ${1}" + repeat_until_success_or_timeout --fatal-test "container_is_running ${2}" "${TEST_TIMEOUT_IN_SECONDS}" docker exec "${2}" /bin/sh -c "nc -z 0.0.0.0 ${1}" } # @param ${1} name of the postfix container @@ -90,13 +90,13 @@ function wait_for_amavis_port_in_container() { # @param ${1} name of the postfix container function wait_for_finished_setup_in_container() { - local status=0 - repeat_until_success_or_timeout --fatal-test "container_is_running ${1}" "${TEST_TIMEOUT_IN_SECONDS}" sh -c "docker logs ${1} | grep 'is up and running'" || status=1 - if [[ ${status} -eq 1 ]]; then + local STATUS=0 + repeat_until_success_or_timeout --fatal-test "container_is_running ${1}" "${TEST_TIMEOUT_IN_SECONDS}" sh -c "docker logs ${1} | grep 'is up and running'" || STATUS=1 + if [[ ${STATUS} -eq 1 ]]; then echo "Last ${NUMBER_OF_LOG_LINES} lines of container \`${1}\`'s log" docker logs "${1}" | tail -n "${NUMBER_OF_LOG_LINES}" fi - return ${status} + return ${STATUS} } SETUP_FILE_MARKER="${BATS_TMPDIR}/$(basename "${BATS_TEST_FILENAME}").setup_file" @@ -177,6 +177,8 @@ function wait_for_service() { function wait_for_changes_to_be_detected_in_container() { local CONTAINER_NAME="${1}" local TIMEOUT=${TEST_TIMEOUT_IN_SECONDS} - repeat_in_container_until_success_or_timeout "${TIMEOUT}" "${CONTAINER_NAME}" \ + repeat_in_container_until_success_or_timeout \ + "${TIMEOUT}" \ + "${CONTAINER_NAME}" \ bash -c 'source /usr/local/bin/helper_functions.sh; cmp --silent -- <(_monitored_files_checksums) "${CHKSUM_FILE}" >/dev/null' } From a3acedaf1910407f32977bad4a809b3f946cba2b Mon Sep 17 00:00:00 2001 From: Georg Lauterbach Date: Mon, 19 Oct 2020 12:12:13 +0200 Subject: [PATCH 36/50] fixing NAME --- test/test_helper/common.bash | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/test_helper/common.bash b/test/test_helper/common.bash index 120f835d..6e0ebb80 100644 --- a/test/test_helper/common.bash +++ b/test/test_helper/common.bash @@ -1,7 +1,7 @@ load 'test_helper/bats-support/load' load 'test_helper/bats-assert/load' -# NAME=tvial/docker-mailserver:testing +NAME=tvial/docker-mailserver:testing # default timeout is 120 seconds TEST_TIMEOUT_IN_SECONDS=${TEST_TIMEOUT_IN_SECONDS-120} From 0d219800ffd79dfc45188f2384b59cf63205739a Mon Sep 17 00:00:00 2001 From: Georg Lauterbach Date: Mon, 19 Oct 2020 12:15:44 +0200 Subject: [PATCH 37/50] replacing all occurences of `private_config` with the uppercase variable --- test/tests.bats | 140 ++++++++++++++++++++++++------------------------ 1 file changed, 70 insertions(+), 70 deletions(-) diff --git a/test/tests.bats b/test/tests.bats index c1c721be..b4ab4277 100644 --- a/test/tests.bats +++ b/test/tests.bats @@ -10,10 +10,10 @@ setup() { } setup_file() { - private_config="$(duplicate_config_for_container . mail)" - mv "${private_config}/user-patches/user-patches.sh" "${private_config}/user-patches.sh" + PRIVATE_CONFIG="$(duplicate_config_for_container . mail)" + mv "${PRIVATE_CONFIG}/user-patches/user-patches.sh" "${PRIVATE_CONFIG}/user-patches.sh" docker run --rm -d --name mail \ - -v "${private_config}":/tmp/docker-mailserver \ + -v "${PRIVATE_CONFIG}":/tmp/docker-mailserver \ -v "$(pwd)/test/test-files":/tmp/docker-mailserver-test:ro \ -v "$(pwd)/test/onedir":/var/mail-state \ -e ENABLE_CLAMAV=1 \ @@ -35,13 +35,13 @@ setup_file() { -h mail.my-domain.com -t "${NAME}" wait_for_finished_setup_in_container mail - + # generate accounts after container has been started - docker run --rm -e MAIL_USER=added@localhost.localdomain -e MAIL_PASS=mypassword -t "${NAME}" /bin/sh -c 'echo "${MAIL_USER}|$(doveadm pw -s SHA512-CRYPT -u ${MAIL_USER} -p ${MAIL_PASS})"' >> "${private_config}/postfix-accounts.cf" + docker run --rm -e MAIL_USER=added@localhost.localdomain -e MAIL_PASS=mypassword -t "${NAME}" /bin/sh -c 'echo "${MAIL_USER}|$(doveadm pw -s SHA512-CRYPT -u ${MAIL_USER} -p ${MAIL_PASS})"' >> "${PRIVATE_CONFIG}/postfix-accounts.cf" docker exec mail addmailuser pass@localhost.localdomain 'may be \a `p^a.*ssword' - + # setup sieve - docker cp "${private_config}/sieve/dovecot.sieve" mail:/var/mail/localhost.localdomain/user1/.dovecot.sieve + docker cp "${PRIVATE_CONFIG}/sieve/dovecot.sieve" mail:/var/mail/localhost.localdomain/user1/.dovecot.sieve # this relies on the checksum file beeing updated after all changes have been applied wait_for_changes_to_be_detected_in_container mail @@ -364,7 +364,7 @@ EOF @test "checking postfix: vhost file is correct" { run docker exec mail cat /etc/postfix/vhost assert_success - assert_line --index 0 "localdomain2.com" + assert_line --index 0 "localdomain2.com" assert_line --index 1 "localhost.localdomain" assert_line --index 2 "otherdomain.tld" } @@ -460,21 +460,21 @@ EOF # Instead it tests the file-size (here 511) - which may differ with a different domain names # This test may be re-used as a global test to provide better test coverage. @test "checking opendkim: generator creates default keys size" { - private_config="$(duplicate_config_for_container . mail_default_key_size)" + PRIVATE_CONFIG="$(duplicate_config_for_container . mail_default_key_size)" # Prepare default key size 2048 - rm -rf "${private_config}/keyDefault" - mkdir -p "${private_config}/keyDefault" + rm -rf "${PRIVATE_CONFIG}/keyDefault" + mkdir -p "${PRIVATE_CONFIG}/keyDefault" run docker run --rm \ - -v "${private_config}/keyDefault/":/tmp/docker-mailserver/ \ - -v "${private_config}/postfix-accounts.cf":/tmp/docker-mailserver/postfix-accounts.cf \ - -v "${private_config}/postfix-virtual.cf":/tmp/docker-mailserver/postfix-virtual.cf \ + -v "${PRIVATE_CONFIG}/keyDefault/":/tmp/docker-mailserver/ \ + -v "${PRIVATE_CONFIG}/postfix-accounts.cf":/tmp/docker-mailserver/postfix-accounts.cf \ + -v "${PRIVATE_CONFIG}/postfix-virtual.cf":/tmp/docker-mailserver/postfix-virtual.cf \ "${IMAGE_NAME:?}" /bin/sh -c 'generate-dkim-config | wc -l' assert_success assert_output 6 run docker run --rm \ - -v "${private_config}/keyDefault/opendkim":/etc/opendkim \ + -v "${PRIVATE_CONFIG}/keyDefault/opendkim":/etc/opendkim \ "${IMAGE_NAME:?}" \ /bin/sh -c 'stat -c%s /etc/opendkim/keys/localhost.localdomain/mail.txt' @@ -486,20 +486,20 @@ EOF # Instead it tests the file-size (here 511) - which may differ with a different domain names # This test may be re-used as a global test to provide better test coverage. @test "checking opendkim: generator creates key size 2048" { - private_config="$(duplicate_config_for_container . mail_key_size_2048)" + PRIVATE_CONFIG="$(duplicate_config_for_container . mail_key_size_2048)" # Prepare set key size 2048 - rm -rf "${private_config}/key2048" - mkdir -p "${private_config}/config/key2048" + rm -rf "${PRIVATE_CONFIG}/key2048" + mkdir -p "${PRIVATE_CONFIG}/config/key2048" run docker run --rm \ - -v "${private_config}/key2048/":/tmp/docker-mailserver/ \ - -v "${private_config}/postfix-accounts.cf":/tmp/docker-mailserver/postfix-accounts.cf \ - -v "${private_config}/postfix-virtual.cf":/tmp/docker-mailserver/postfix-virtual.cf \ + -v "${PRIVATE_CONFIG}/key2048/":/tmp/docker-mailserver/ \ + -v "${PRIVATE_CONFIG}/postfix-accounts.cf":/tmp/docker-mailserver/postfix-accounts.cf \ + -v "${PRIVATE_CONFIG}/postfix-virtual.cf":/tmp/docker-mailserver/postfix-virtual.cf \ "${IMAGE_NAME:?}" /bin/sh -c 'generate-dkim-config 2048 | wc -l' assert_success assert_output 6 run docker run --rm \ - -v "${private_config}/key2048/opendkim":/etc/opendkim \ + -v "${PRIVATE_CONFIG}/key2048/opendkim":/etc/opendkim \ "${IMAGE_NAME:?}" \ /bin/sh -c 'stat -c%s /etc/opendkim/keys/localhost.localdomain/mail.txt' @@ -511,20 +511,20 @@ EOF # Instead it tests the file-size (here 329) - which may differ with a different domain names # This test may be re-used as a global test to provide better test coverage. @test "checking opendkim: generator creates key size 1024" { - private_config="$(duplicate_config_for_container . mail_key_size_1024)" + PRIVATE_CONFIG="$(duplicate_config_for_container . mail_key_size_1024)" # Prepare set key size 1024 - rm -rf "${private_config}/key1024" - mkdir -p "${private_config}/key1024" + rm -rf "${PRIVATE_CONFIG}/key1024" + mkdir -p "${PRIVATE_CONFIG}/key1024" run docker run --rm \ - -v "${private_config}/key1024/":/tmp/docker-mailserver/ \ - -v "${private_config}/postfix-accounts.cf":/tmp/docker-mailserver/postfix-accounts.cf \ - -v "${private_config}/postfix-virtual.cf":/tmp/docker-mailserver/postfix-virtual.cf \ + -v "${PRIVATE_CONFIG}/key1024/":/tmp/docker-mailserver/ \ + -v "${PRIVATE_CONFIG}/postfix-accounts.cf":/tmp/docker-mailserver/postfix-accounts.cf \ + -v "${PRIVATE_CONFIG}/postfix-virtual.cf":/tmp/docker-mailserver/postfix-virtual.cf \ "${IMAGE_NAME:?}" /bin/sh -c 'generate-dkim-config 1024 | wc -l' assert_success assert_output 6 run docker run --rm \ - -v "${private_config}/key1024/opendkim":/etc/opendkim \ + -v "${PRIVATE_CONFIG}/key1024/opendkim":/etc/opendkim \ "${IMAGE_NAME:?}" \ /bin/sh -c 'stat -c%s /etc/opendkim/keys/localhost.localdomain/mail.txt' @@ -533,146 +533,146 @@ EOF } @test "checking opendkim: generator creates keys, tables and TrustedHosts" { - private_config="$(duplicate_config_for_container . mail_dkim_generator_creates_keys_tables_TrustedHosts)" - rm -rf "${private_config}/empty" - mkdir -p "${private_config}/empty" + PRIVATE_CONFIG="$(duplicate_config_for_container . mail_dkim_generator_creates_keys_tables_TrustedHosts)" + rm -rf "${PRIVATE_CONFIG}/empty" + mkdir -p "${PRIVATE_CONFIG}/empty" run docker run --rm \ - -v "${private_config}/empty/":/tmp/docker-mailserver/ \ - -v "${private_config}/postfix-accounts.cf":/tmp/docker-mailserver/postfix-accounts.cf \ - -v "${private_config}/postfix-virtual.cf":/tmp/docker-mailserver/postfix-virtual.cf \ + -v "${PRIVATE_CONFIG}/empty/":/tmp/docker-mailserver/ \ + -v "${PRIVATE_CONFIG}/postfix-accounts.cf":/tmp/docker-mailserver/postfix-accounts.cf \ + -v "${PRIVATE_CONFIG}/postfix-virtual.cf":/tmp/docker-mailserver/postfix-virtual.cf \ "${IMAGE_NAME:?}" /bin/sh -c 'generate-dkim-config | wc -l' assert_success assert_output 6 # Check keys for localhost.localdomain run docker run --rm \ - -v "${private_config}/empty/opendkim":/etc/opendkim \ + -v "${PRIVATE_CONFIG}/empty/opendkim":/etc/opendkim \ "${IMAGE_NAME:?}" /bin/sh -c 'ls -1 /etc/opendkim/keys/localhost.localdomain/ | wc -l' assert_success assert_output 2 # Check keys for otherdomain.tld run docker run --rm \ - -v "${private_config}/empty/opendkim":/etc/opendkim \ + -v "${PRIVATE_CONFIG}/empty/opendkim":/etc/opendkim \ "${IMAGE_NAME:?}" /bin/sh -c 'ls -1 /etc/opendkim/keys/otherdomain.tld | wc -l' assert_success assert_output 2 # Check presence of tables and TrustedHosts run docker run --rm \ - -v "${private_config}/empty/opendkim":/etc/opendkim \ + -v "${PRIVATE_CONFIG}/empty/opendkim":/etc/opendkim \ "${IMAGE_NAME:?}" /bin/sh -c "ls -1 /etc/opendkim | grep -E 'KeyTable|SigningTable|TrustedHosts|keys'|wc -l" assert_success assert_output 4 } @test "checking opendkim: generator creates keys, tables and TrustedHosts without postfix-accounts.cf" { - private_config="$(duplicate_config_for_container . mail_dkim_generator_creates_keys_tables_TrustedHosts_without_postfix_accounts.cf)" - rm -rf "${private_config}/without-accounts" - mkdir -p "${private_config}/without-accounts" + PRIVATE_CONFIG="$(duplicate_config_for_container . mail_dkim_generator_creates_keys_tables_TrustedHosts_without_postfix_accounts.cf)" + rm -rf "${PRIVATE_CONFIG}/without-accounts" + mkdir -p "${PRIVATE_CONFIG}/without-accounts" run docker run --rm \ - -v "${private_config}/without-accounts/":/tmp/docker-mailserver/ \ - -v "${private_config}/postfix-virtual.cf":/tmp/docker-mailserver/postfix-virtual.cf \ + -v "${PRIVATE_CONFIG}/without-accounts/":/tmp/docker-mailserver/ \ + -v "${PRIVATE_CONFIG}/postfix-virtual.cf":/tmp/docker-mailserver/postfix-virtual.cf \ "${IMAGE_NAME:?}" /bin/sh -c 'generate-dkim-config | wc -l' assert_success assert_output 5 # Check keys for localhost.localdomain run docker run --rm \ - -v "${private_config}/without-accounts/opendkim":/etc/opendkim \ + -v "${PRIVATE_CONFIG}/without-accounts/opendkim":/etc/opendkim \ "${IMAGE_NAME:?}" /bin/sh -c 'ls -1 /etc/opendkim/keys/localhost.localdomain/ | wc -l' assert_success assert_output 2 # Check keys for otherdomain.tld # run docker run --rm \ - # -v "${private_config}/without-accounts/opendkim":/etc/opendkim \ + # -v "${PRIVATE_CONFIG}/without-accounts/opendkim":/etc/opendkim \ # "${IMAGE_NAME:?}" /bin/sh -c 'ls -1 /etc/opendkim/keys/otherdomain.tld | wc -l' # assert_success # [ "${output}" -eq 0 ] # Check presence of tables and TrustedHosts run docker run --rm \ - -v "${private_config}/without-accounts/opendkim":/etc/opendkim \ + -v "${PRIVATE_CONFIG}/without-accounts/opendkim":/etc/opendkim \ "${IMAGE_NAME:?}" /bin/sh -c "ls -1 /etc/opendkim | grep -E 'KeyTable|SigningTable|TrustedHosts|keys'|wc -l" assert_success assert_output 4 } @test "checking opendkim: generator creates keys, tables and TrustedHosts without postfix-virtual.cf" { - private_config="$(duplicate_config_for_container . mail_dkim_generator_creates_keys_tables_TrustedHosts_without_postfix_virtual.cf)" - rm -rf "${private_config}/without-virtual" - mkdir -p "${private_config}/without-virtual" + PRIVATE_CONFIG="$(duplicate_config_for_container . mail_dkim_generator_creates_keys_tables_TrustedHosts_without_postfix_virtual.cf)" + rm -rf "${PRIVATE_CONFIG}/without-virtual" + mkdir -p "${PRIVATE_CONFIG}/without-virtual" run docker run --rm \ - -v "${private_config}/without-virtual/":/tmp/docker-mailserver/ \ - -v "${private_config}/postfix-accounts.cf":/tmp/docker-mailserver/postfix-accounts.cf \ + -v "${PRIVATE_CONFIG}/without-virtual/":/tmp/docker-mailserver/ \ + -v "${PRIVATE_CONFIG}/postfix-accounts.cf":/tmp/docker-mailserver/postfix-accounts.cf \ "${IMAGE_NAME:?}" /bin/sh -c 'generate-dkim-config | wc -l' assert_success assert_output 5 # Check keys for localhost.localdomain run docker run --rm \ - -v "${private_config}/without-virtual/opendkim":/etc/opendkim \ + -v "${PRIVATE_CONFIG}/without-virtual/opendkim":/etc/opendkim \ "${IMAGE_NAME:?}" /bin/sh -c 'ls -1 /etc/opendkim/keys/localhost.localdomain/ | wc -l' assert_success assert_output 2 # Check keys for otherdomain.tld run docker run --rm \ - -v "${private_config}/without-virtual/opendkim":/etc/opendkim \ + -v "${PRIVATE_CONFIG}/without-virtual/opendkim":/etc/opendkim \ "${IMAGE_NAME:?}" /bin/sh -c 'ls -1 /etc/opendkim/keys/otherdomain.tld | wc -l' assert_success assert_output 2 # Check presence of tables and TrustedHosts run docker run --rm \ - -v "${private_config}/without-virtual/opendkim":/etc/opendkim \ + -v "${PRIVATE_CONFIG}/without-virtual/opendkim":/etc/opendkim \ "${IMAGE_NAME:?}" /bin/sh -c "ls -1 /etc/opendkim | grep -E 'KeyTable|SigningTable|TrustedHosts|keys'|wc -l" assert_success assert_output 4 } @test "checking opendkim: generator creates keys, tables and TrustedHosts using domain name" { - private_config="$(duplicate_config_for_container . mail_dkim_generator_creates_keys_tables_TrustedHosts_without_postfix_virtual.cf)" - rm -rf "${private_config}/with-domain" && mkdir -p "${private_config}/with-domain" + PRIVATE_CONFIG="$(duplicate_config_for_container . mail_dkim_generator_creates_keys_tables_TrustedHosts_without_postfix_virtual.cf)" + rm -rf "${PRIVATE_CONFIG}/with-domain" && mkdir -p "${PRIVATE_CONFIG}/with-domain" run docker run --rm \ - -v "${private_config}/with-domain/":/tmp/docker-mailserver/ \ - -v "${private_config}/postfix-accounts.cf":/tmp/docker-mailserver/postfix-accounts.cf \ - -v "${private_config}/postfix-virtual.cf":/tmp/docker-mailserver/postfix-virtual.cf \ + -v "${PRIVATE_CONFIG}/with-domain/":/tmp/docker-mailserver/ \ + -v "${PRIVATE_CONFIG}/postfix-accounts.cf":/tmp/docker-mailserver/postfix-accounts.cf \ + -v "${PRIVATE_CONFIG}/postfix-virtual.cf":/tmp/docker-mailserver/postfix-virtual.cf \ "${IMAGE_NAME:?}" /bin/sh -c 'generate-dkim-config | wc -l' assert_success assert_output 6 # Generate key using domain name run docker run --rm \ - -v "${private_config}/with-domain/":/tmp/docker-mailserver/ \ + -v "${PRIVATE_CONFIG}/with-domain/":/tmp/docker-mailserver/ \ "${IMAGE_NAME:?}" /bin/sh -c 'generate-dkim-domain testdomain.tld | wc -l' assert_success assert_output 1 # Check keys for localhost.localdomain run docker run --rm \ - -v "${private_config}/with-domain/opendkim":/etc/opendkim \ + -v "${PRIVATE_CONFIG}/with-domain/opendkim":/etc/opendkim \ "${IMAGE_NAME:?}" /bin/sh -c 'ls -1 /etc/opendkim/keys/localhost.localdomain/ | wc -l' assert_success assert_output 2 # Check keys for otherdomain.tld run docker run --rm \ - -v "${private_config}/with-domain/opendkim":/etc/opendkim \ + -v "${PRIVATE_CONFIG}/with-domain/opendkim":/etc/opendkim \ "${IMAGE_NAME:?}" /bin/sh -c 'ls -1 /etc/opendkim/keys/otherdomain.tld | wc -l' assert_success assert_output 2 # Check keys for testdomain.tld run docker run --rm \ - -v "${private_config}/with-domain/opendkim":/etc/opendkim \ + -v "${PRIVATE_CONFIG}/with-domain/opendkim":/etc/opendkim \ "${IMAGE_NAME:?}" /bin/sh -c 'ls -1 /etc/opendkim/keys/testdomain.tld | wc -l' assert_success assert_output 2 # Check presence of tables and TrustedHosts run docker run --rm \ - -v "${private_config}/with-domain/opendkim":/etc/opendkim \ + -v "${PRIVATE_CONFIG}/with-domain/opendkim":/etc/opendkim \ "${IMAGE_NAME:?}" /bin/sh -c "ls -1 /etc/opendkim | grep -E 'KeyTable|SigningTable|TrustedHosts|keys' | wc -l" assert_success assert_output 4 # Check valid entries actually present in KeyTable run docker run --rm \ - -v "${private_config}/with-domain/opendkim":/etc/opendkim \ + -v "${PRIVATE_CONFIG}/with-domain/opendkim":/etc/opendkim \ "${IMAGE_NAME:?}" /bin/sh -c \ "egrep 'localhost.localdomain|otherdomain.tld|localdomain2.com|testdomain.tld' /etc/opendkim/KeyTable | wc -l" assert_success assert_output 4 # Check valid entries actually present in SigningTable run docker run --rm \ - -v "${private_config}/with-domain/opendkim":/etc/opendkim \ + -v "${PRIVATE_CONFIG}/with-domain/opendkim":/etc/opendkim \ "${IMAGE_NAME:?}" /bin/sh -c \ "egrep 'localhost.localdomain|otherdomain.tld|localdomain2.com|testdomain.tld' /etc/opendkim/SigningTable | wc -l" assert_success @@ -932,13 +932,13 @@ EOF } @test "checking accounts: user3 should have been added to /tmp/docker-mailserver/postfix-accounts.cf even when that file does not exist" { - private_config=$(duplicate_config_for_container without-accounts/ without-accounts_file_does_not_exist) + PRIVATE_CONFIG=$(duplicate_config_for_container without-accounts/ without-accounts_file_does_not_exist) run docker run --rm \ - -v "${private_config}/without-accounts/":/tmp/docker-mailserver/ \ + -v "${PRIVATE_CONFIG}/without-accounts/":/tmp/docker-mailserver/ \ "${IMAGE_NAME:?}" /bin/sh -c 'addmailuser user3@domain.tld mypassword' assert_success run docker run --rm \ - -v "${private_config}/without-accounts/":/tmp/docker-mailserver/ \ + -v "${PRIVATE_CONFIG}/without-accounts/":/tmp/docker-mailserver/ \ "${IMAGE_NAME:?}" /bin/sh -c 'grep user3@domain.tld -i /tmp/docker-mailserver/postfix-accounts.cf' assert_success [ -n "${output}" ] @@ -1398,7 +1398,7 @@ EOF @test "checking setup.sh: setup.sh debug inspect" { run ./setup.sh -c mail debug inspect assert_success - assert_line --index 0 "Image: tvial/docker-mailserver:testing" + assert_line --index 0 "Image: tvial/docker-mailserver:testing" assert_line --index 1 "Container: mail" } @test "checking setup.sh: setup.sh debug login ls" { From 3f5c518950e0735f7aea35c82bbb28bd16a207f2 Mon Sep 17 00:00:00 2001 From: Georg Lauterbach Date: Mon, 19 Oct 2020 13:13:42 +0200 Subject: [PATCH 38/50] mostly `pwd` replacements and introduction of local keywords --- test/default_relay_host.bats | 4 ++-- test/mail_dhparams_default.bats | 4 ++-- test/mail_dhparams_manual_not_one_dir.bats | 16 ++++++++-------- test/mail_dhparams_manual_one_dir.bats | 4 ++-- test/mail_disabled_clamav_spamassassin.bats | 2 +- test/mail_fail2ban.bats | 6 +++--- test/mail_fetchmail.bats | 4 ++-- test/mail_lmtp_ip.bats | 2 +- test/mail_override_hostname.bats | 4 ++-- test/mail_pop3.bats | 4 ++-- test/mail_postfix_inet.bats | 8 ++++---- test/mail_postscreen.bats | 4 ++-- test/mail_privacy.bats | 2 +- test/mail_quotas_disabled.bats | 2 +- test/mail_smtponly.bats | 2 +- test/mail_spam_bounced.bats | 4 ++-- test/mail_spam_junk_folder.bats | 4 ++-- test/mail_special_use_folders.bats | 2 +- test/mail_srs_domainname.bats | 6 +++--- test/mail_ssl_letsencrypt.bats | 8 +++++--- test/mail_ssl_manual.bats | 4 ++-- test/mail_undef_spam_subject.bats | 8 ++++---- test/mail_with_imap.bats | 2 +- test/mail_with_ldap.bats | 8 ++++---- test/mail_with_mdbox.bats | 2 +- test/mail_with_postgrey.bats | 4 ++-- ...mail_with_postgrey_disabled_by_default.bats | 4 ++-- test/mail_with_relays.bats | 2 +- test/mail_with_sdbox.bats | 2 +- test/permit_docker.bats | 6 +++--- test/test_helper/common.bash | 8 +++----- test/tests.bats | 18 +++++++++--------- 32 files changed, 80 insertions(+), 80 deletions(-) diff --git a/test/default_relay_host.bats b/test/default_relay_host.bats index faa0abd5..e006ed8b 100644 --- a/test/default_relay_host.bats +++ b/test/default_relay_host.bats @@ -3,7 +3,7 @@ load 'test_helper/common' function setup() { docker run -d --name mail_with_default_relay \ -v "$(duplicate_config_for_container relay-hosts)":/tmp/docker-mailserver \ - -v "`pwd`/test/test-files":/tmp/docker-mailserver-test:ro \ + -v "$(pwd)/test/test-files":/tmp/docker-mailserver-test:ro \ -e DEFAULT_RELAY_HOST=default.relay.host.invalid:25 \ --cap-add=SYS_PTRACE \ -e PERMIT_DOCKER=host \ @@ -23,4 +23,4 @@ function teardown() { @test "checking default relay host: default relay host is added to main.cf" { run docker exec mail_with_default_relay /bin/sh -c 'grep -e "^relayhost =" /etc/postfix/main.cf' assert_output 'relayhost = default.relay.host.invalid:25' -} \ No newline at end of file +} diff --git a/test/mail_dhparams_default.bats b/test/mail_dhparams_default.bats index 72a789ea..ff984576 100644 --- a/test/mail_dhparams_default.bats +++ b/test/mail_dhparams_default.bats @@ -23,7 +23,7 @@ function teardown() { function setup_file() { docker run -d --name mail_default_dhparams_one_dir \ -v "$(duplicate_config_for_container . mail_default_dhparams_both_one_dir)":/tmp/docker-mailserver \ - -v "`pwd`/test/test-files":/tmp/docker-mailserver-test:ro \ + -v "$(pwd)/test/test-files":/tmp/docker-mailserver-test:ro \ -e DMS_DEBUG=0 \ -e ONE_DIR=1 \ -h mail.my-domain.com -t ${NAME} @@ -31,7 +31,7 @@ function setup_file() { docker run -d --name mail_default_dhparams_not_one_dir \ -v "$(duplicate_config_for_container . mail_default_dhparams_both_not_one_dir)":/tmp/docker-mailserver \ - -v "`pwd`/test/test-files":/tmp/docker-mailserver-test:ro \ + -v "$(pwd)/test/test-files":/tmp/docker-mailserver-test:ro \ -e DMS_DEBUG=0 \ -e ONE_DIR=0 \ -h mail.my-domain.com -t ${NAME} diff --git a/test/mail_dhparams_manual_not_one_dir.bats b/test/mail_dhparams_manual_not_one_dir.bats index 928e3bb3..e8b76efe 100644 --- a/test/mail_dhparams_manual_not_one_dir.bats +++ b/test/mail_dhparams_manual_not_one_dir.bats @@ -13,21 +13,21 @@ load 'test_helper/common' function setup() { - run_setup_file_if_necessary + run_setup_file_if_necessary } function teardown() { - run_teardown_file_if_necessary + run_teardown_file_if_necessary } function setup_file() { - PRIVATE_CONFIG=$(duplicate_config_for_container .) - # copy the custom DHE params in local config - cp "`pwd`/test/test-files/ssl/custom-dhe-params.pem" "${PRIVATE_CONFIG}/dhparams.pem" + local PRIVATE_CONFIG=$(duplicate_config_for_container .) + # copy the custom DHE params in local config + cp "$(pwd)/test/test-files/ssl/custom-dhe-params.pem" "${PRIVATE_CONFIG}/dhparams.pem" - docker run -d --name mail_manual_dhparams_not_one_dir \ + docker run -d --name mail_manual_dhparams_not_one_dir \ -v "${PRIVATE_CONFIG}":/tmp/docker-mailserver \ - -v "`pwd`/test/test-files":/tmp/docker-mailserver-test:ro \ + -v "$(pwd)/test/test-files":/tmp/docker-mailserver-test:ro \ -e DMS_DEBUG=0 \ -e ONE_DIR=0 \ -h mail.my-domain.com -t ${NAME} @@ -35,7 +35,7 @@ function setup_file() { } function teardown_file() { - docker rm -f mail_manual_dhparams_not_one_dir + docker rm -f mail_manual_dhparams_not_one_dir } @test "first" { diff --git a/test/mail_dhparams_manual_one_dir.bats b/test/mail_dhparams_manual_one_dir.bats index 69091d83..5063fa42 100644 --- a/test/mail_dhparams_manual_one_dir.bats +++ b/test/mail_dhparams_manual_one_dir.bats @@ -22,8 +22,8 @@ function teardown() { function setup_file() { docker run -d --name mail_manual_dhparams_one_dir \ -v "$(duplicate_config_for_container .)":/tmp/docker-mailserver \ - -v "`pwd`/test/test-files":/tmp/docker-mailserver-test:ro \ - -v "`pwd`/test/test-files/ssl/custom-dhe-params.pem":/var/mail-state/lib-shared/dhparams.pem:ro \ + -v "$(pwd)/test/test-files":/tmp/docker-mailserver-test:ro \ + -v "$(pwd)/test/test-files/ssl/custom-dhe-params.pem":/var/mail-state/lib-shared/dhparams.pem:ro \ -e DMS_DEBUG=0 \ -e ONE_DIR=1 \ -h mail.my-domain.com -t ${NAME} diff --git a/test/mail_disabled_clamav_spamassassin.bats b/test/mail_disabled_clamav_spamassassin.bats index a85cd712..f05be894 100644 --- a/test/mail_disabled_clamav_spamassassin.bats +++ b/test/mail_disabled_clamav_spamassassin.bats @@ -11,7 +11,7 @@ teardown() { setup_file() { docker run --rm -d --name mail_disabled_clamav_spamassassin \ -v "$(duplicate_config_for_container .)":/tmp/docker-mailserver \ - -v "`pwd`/test/test-files":/tmp/docker-mailserver-test:ro \ + -v "$(pwd)/test/test-files":/tmp/docker-mailserver-test:ro \ -e ENABLE_CLAMAV=0 \ -e ENABLE_SPAMASSASSIN=0 \ -e DMS_DEBUG=0 \ diff --git a/test/mail_fail2ban.bats b/test/mail_fail2ban.bats index d96b2cfa..b764ce2e 100644 --- a/test/mail_fail2ban.bats +++ b/test/mail_fail2ban.bats @@ -11,7 +11,7 @@ function teardown() { function setup_file() { docker run --rm -d --name mail_fail2ban \ -v "$(duplicate_config_for_container .)":/tmp/docker-mailserver \ - -v "`pwd`/test/test-files":/tmp/docker-mailserver-test:ro \ + -v "$(pwd)/test/test-files":/tmp/docker-mailserver-test:ro \ -e ENABLE_FAIL2BAN=1 \ -e POSTSCREEN_ACTION=ignore \ --cap-add=NET_ADMIN \ @@ -25,7 +25,7 @@ function setup_file() { tail -f /var/log/faillog wait_for_finished_setup_in_container mail_fail2ban - + } function teardown_file() { @@ -146,4 +146,4 @@ function teardown_file() { @test "last" { skip 'this test is only there to reliably mark the end for the teardown_file' -} \ No newline at end of file +} diff --git a/test/mail_fetchmail.bats b/test/mail_fetchmail.bats index cdafafdc..d56014f2 100644 --- a/test/mail_fetchmail.bats +++ b/test/mail_fetchmail.bats @@ -11,7 +11,7 @@ function teardown() { function setup_file() { docker run -d --name mail_fetchmail \ -v "$(duplicate_config_for_container .)":/tmp/docker-mailserver \ - -v "`pwd`/test/test-files":/tmp/docker-mailserver-test:ro \ + -v "$(pwd)/test/test-files":/tmp/docker-mailserver-test:ro \ -e ENABLE_FETCHMAIL=1 \ --cap-add=NET_ADMIN \ -e DMS_DEBUG=0 \ @@ -61,4 +61,4 @@ function teardown_file() { @test "last" { skip 'this test is only there to reliably mark the end for the teardown_file' -} \ No newline at end of file +} diff --git a/test/mail_lmtp_ip.bats b/test/mail_lmtp_ip.bats index 42ad9639..bfb1c2e0 100644 --- a/test/mail_lmtp_ip.bats +++ b/test/mail_lmtp_ip.bats @@ -12,7 +12,7 @@ setup_file() { docker run -d --name mail_lmtp_ip \ -v "$(duplicate_config_for_container .)":/tmp/docker-mailserver \ -v "$(duplicate_config_for_container dovecot-lmtp/ mail_lmtp_ip_dovecot-lmtp)":/etc/dovecot \ - -v "`pwd`/test/test-files":/tmp/docker-mailserver-test:ro \ + -v "$(pwd)/test/test-files":/tmp/docker-mailserver-test:ro \ -e ENABLE_POSTFIX_VIRTUAL_TRANSPORT=1 \ -e POSTFIX_DAGENT=lmtp:127.0.0.1:24 \ -e DMS_DEBUG=0 \ diff --git a/test/mail_override_hostname.bats b/test/mail_override_hostname.bats index 1a6da949..2e1ea3f3 100644 --- a/test/mail_override_hostname.bats +++ b/test/mail_override_hostname.bats @@ -7,7 +7,7 @@ function setup() { function setup_file() { docker run --rm -d --name mail_override_hostname \ -v "$(duplicate_config_for_container .)":/tmp/docker-mailserver \ - -v "`pwd`/test/test-files":/tmp/docker-mailserver-test:ro \ + -v "$(pwd)/test/test-files":/tmp/docker-mailserver-test:ro \ -e PERMIT_DOCKER=network \ -e DMS_DEBUG=0 \ -e ENABLE_SRS=1 \ @@ -15,7 +15,7 @@ function setup_file() { -h unknown.domain.tld \ -t ${NAME} - wait_for_smtp_port_in_container mail_override_hostname + wait_for_smtp_port_in_container mail_override_hostname # postfix virtual transport lmtp docker exec mail_override_hostname /bin/sh -c "nc 0.0.0.0 25 < /tmp/docker-mailserver-test/email-templates/existing-user1.txt" } diff --git a/test/mail_pop3.bats b/test/mail_pop3.bats index c6d429e5..b3f8b705 100644 --- a/test/mail_pop3.bats +++ b/test/mail_pop3.bats @@ -11,7 +11,7 @@ function teardown() { function setup_file() { docker run -d --name mail_pop3 \ -v "$(duplicate_config_for_container .)":/tmp/docker-mailserver \ - -v "`pwd`/test/test-files":/tmp/docker-mailserver-test:ro \ + -v "$(pwd)/test/test-files":/tmp/docker-mailserver-test:ro \ -e ENABLE_POP3=1 \ -e DMS_DEBUG=0 \ -h mail.my-domain.com -t ${NAME} @@ -91,4 +91,4 @@ function teardown_file() { @test "last" { skip 'this test is only there to reliably mark the end for the teardown_file' -} \ No newline at end of file +} diff --git a/test/mail_postfix_inet.bats b/test/mail_postfix_inet.bats index 94328f11..18220438 100644 --- a/test/mail_postfix_inet.bats +++ b/test/mail_postfix_inet.bats @@ -16,14 +16,14 @@ function teardown() { function setup_file() { docker run -d --name mail_postfix_inet_default \ -v "$(duplicate_config_for_container . mail_postfix_inet_default)":/tmp/docker-mailserver \ - -v "`pwd`/test/test-files":/tmp/docker-mailserver-test:ro \ + -v "$(pwd)/test/test-files":/tmp/docker-mailserver-test:ro \ -h mail.my-domain.com -t "${NAME}" wait_for_finished_setup_in_container mail_postfix_inet_default docker run -d --name mail_postfix_inet_all \ -v "$(duplicate_config_for_container . mail_postfix_inet_all)":/tmp/docker-mailserver \ - -v "`pwd`/test/test-files":/tmp/docker-mailserver-test:ro \ + -v "$(pwd)/test/test-files":/tmp/docker-mailserver-test:ro \ -e POSTFIX_INET_PROTOCOLS=all \ -h mail.my-domain.com -t "${NAME}" @@ -31,7 +31,7 @@ function setup_file() { docker run -d --name mail_postfix_inet_ipv4 \ -v "$(duplicate_config_for_container . mail_postfix_inet_ipv4)":/tmp/docker-mailserver \ - -v "`pwd`/test/test-files":/tmp/docker-mailserver-test:ro \ + -v "$(pwd)/test/test-files":/tmp/docker-mailserver-test:ro \ -e POSTFIX_INET_PROTOCOLS=ipv4 \ -h mail.my-domain.com -t "${NAME}" @@ -39,7 +39,7 @@ function setup_file() { docker run -d --name mail_postfix_inet_ipv6 \ -v "$(duplicate_config_for_container . mail_postfix_inet_ipv6)":/tmp/docker-mailserver \ - -v "`pwd`/test/test-files":/tmp/docker-mailserver-test:ro \ + -v "$(pwd)/test/test-files":/tmp/docker-mailserver-test:ro \ -e POSTFIX_INET_PROTOCOLS=ipv6 \ -h mail.my-domain.com -t "${NAME}" diff --git a/test/mail_postscreen.bats b/test/mail_postscreen.bats index 8df044bc..e303fbe6 100644 --- a/test/mail_postscreen.bats +++ b/test/mail_postscreen.bats @@ -14,7 +14,7 @@ teardown() { setup_file() { docker run -d --name mail_postscreen \ -v "$(duplicate_config_for_container .)":/tmp/docker-mailserver \ - -v "`pwd`/test/test-files":/tmp/docker-mailserver-test:ro \ + -v "$(pwd)/test/test-files":/tmp/docker-mailserver-test:ro \ -e POSTSCREEN_ACTION=enforce \ --cap-add=NET_ADMIN \ -h mail.my-domain.com -t ${NAME} @@ -59,4 +59,4 @@ teardown_file() { @test "last" { skip 'only used to call teardown_file from teardown' -} \ No newline at end of file +} diff --git a/test/mail_privacy.bats b/test/mail_privacy.bats index a425f6b8..c6d664ba 100644 --- a/test/mail_privacy.bats +++ b/test/mail_privacy.bats @@ -11,7 +11,7 @@ function teardown() { function setup_file() { docker run -d --name mail_privacy \ -v "$(duplicate_config_for_container .)":/tmp/docker-mailserver \ - -v "`pwd`/test/test-files":/tmp/docker-mailserver-test:ro \ + -v "$(pwd)/test/test-files":/tmp/docker-mailserver-test:ro \ -e SASL_PASSWD="external-domain.com username:password" \ -e ENABLE_MANAGESIEVE=1 \ --cap-add=SYS_PTRACE \ diff --git a/test/mail_quotas_disabled.bats b/test/mail_quotas_disabled.bats index faefd2af..cbdd2137 100644 --- a/test/mail_quotas_disabled.bats +++ b/test/mail_quotas_disabled.bats @@ -16,7 +16,7 @@ function teardown() { function setup_file() { docker run -d --name mail_no_quotas \ -v "$(duplicate_config_for_container .)":/tmp/docker-mailserver \ - -v "`pwd`/test/test-files":/tmp/docker-mailserver-test:ro \ + -v "$(pwd)/test/test-files":/tmp/docker-mailserver-test:ro \ -e DMS_DEBUG=0 \ -e ENABLE_QUOTAS=0 \ -h mail.my-domain.com -t "${NAME}" diff --git a/test/mail_smtponly.bats b/test/mail_smtponly.bats index 7b9cec5c..5ab37274 100644 --- a/test/mail_smtponly.bats +++ b/test/mail_smtponly.bats @@ -11,7 +11,7 @@ function teardown() { function setup_file() { docker run --rm -d --name mail_smtponly \ -v "$(duplicate_config_for_container .)":/tmp/docker-mailserver \ - -v "`pwd`/test/test-files":/tmp/docker-mailserver-test:ro \ + -v "$(pwd)/test/test-files":/tmp/docker-mailserver-test:ro \ -e SMTP_ONLY=1 \ -e PERMIT_DOCKER=network \ -e DMS_DEBUG=0 \ diff --git a/test/mail_spam_bounced.bats b/test/mail_spam_bounced.bats index f6af38ae..ebe87675 100644 --- a/test/mail_spam_bounced.bats +++ b/test/mail_spam_bounced.bats @@ -16,7 +16,7 @@ function teardown() { function setup_file() { docker run -d --name mail_spam_bounced_defined \ -v "$(duplicate_config_for_container . mail_spam_bounced_defined)":/tmp/docker-mailserver \ - -v "`pwd`/test/test-files":/tmp/docker-mailserver-test:ro \ + -v "$(pwd)/test/test-files":/tmp/docker-mailserver-test:ro \ -e ENABLE_SPAMASSASSIN=1 \ -e SPAMASSASSIN_SPAM_TO_INBOX=0 \ -h mail.my-domain.com -t "${NAME}" @@ -25,7 +25,7 @@ function setup_file() { docker run -d --name mail_spam_bounced_undefined \ -v "$(duplicate_config_for_container . mail_spam_bounced_defined)":/tmp/docker-mailserver \ - -v "`pwd`/test/test-files":/tmp/docker-mailserver-test:ro \ + -v "$(pwd)/test/test-files":/tmp/docker-mailserver-test:ro \ -e ENABLE_SPAMASSASSIN=1 \ -h mail.my-domain.com -t "${NAME}" diff --git a/test/mail_spam_junk_folder.bats b/test/mail_spam_junk_folder.bats index 6e7259e2..c53f7e63 100644 --- a/test/mail_spam_junk_folder.bats +++ b/test/mail_spam_junk_folder.bats @@ -16,7 +16,7 @@ function teardown() { function setup_file() { docker run -d --name mail_spam_moved_junk \ -v "$(duplicate_config_for_container . mail_spam_moved_junk)":/tmp/docker-mailserver \ - -v "`pwd`/test/test-files":/tmp/docker-mailserver-test:ro \ + -v "$(pwd)/test/test-files":/tmp/docker-mailserver-test:ro \ -e ENABLE_SPAMASSASSIN=1 \ -e SPAMASSASSIN_SPAM_TO_INBOX=1 \ -e MOVE_SPAM_TO_JUNK=1 \ @@ -27,7 +27,7 @@ function setup_file() { docker run -d --name mail_spam_moved_new \ -v "$(duplicate_config_for_container . mail_spam_moved_new)":/tmp/docker-mailserver \ - -v "`pwd`/test/test-files":/tmp/docker-mailserver-test:ro \ + -v "$(pwd)/test/test-files":/tmp/docker-mailserver-test:ro \ -e ENABLE_SPAMASSASSIN=1 \ -e SPAMASSASSIN_SPAM_TO_INBOX=1 \ -e MOVE_SPAM_TO_JUNK=0 \ diff --git a/test/mail_special_use_folders.bats b/test/mail_special_use_folders.bats index cb6eb84a..5bbee43b 100644 --- a/test/mail_special_use_folders.bats +++ b/test/mail_special_use_folders.bats @@ -11,7 +11,7 @@ teardown() { setup_file() { docker run -d --name mail_special_use_folders \ -v "$(duplicate_config_for_container .)":/tmp/docker-mailserver \ - -v "`pwd`/test/test-files":/tmp/docker-mailserver-test:ro \ + -v "$(pwd)/test/test-files":/tmp/docker-mailserver-test:ro \ -e SASL_PASSWD="external-domain.com username:password" \ -e ENABLE_CLAMAV=0 \ -e ENABLE_SPAMASSASSIN=0 \ diff --git a/test/mail_srs_domainname.bats b/test/mail_srs_domainname.bats index efbc5d83..13c482d0 100644 --- a/test/mail_srs_domainname.bats +++ b/test/mail_srs_domainname.bats @@ -3,7 +3,7 @@ load 'test_helper/common' @test "checking SRS: SRS_DOMAINNAME is used correctly" { docker run --rm -d --name mail_srs_domainname \ -v "$(duplicate_config_for_container . mail_srs_domainname)":/tmp/docker-mailserver \ - -v "`pwd`/test/test-files":/tmp/docker-mailserver-test:ro \ + -v "$(pwd)/test/test-files":/tmp/docker-mailserver-test:ro \ -e PERMIT_DOCKER=network \ -e DMS_DEBUG=0 \ -e ENABLE_SRS=1 \ @@ -20,7 +20,7 @@ load 'test_helper/common' @test "checking SRS: DOMAINNAME is handled correctly" { docker run --rm -d --name mail_domainname \ -v "$(duplicate_config_for_container . mail_domainname)":/tmp/docker-mailserver \ - -v "`pwd`/test/test-files":/tmp/docker-mailserver-test:ro \ + -v "$(pwd)/test/test-files":/tmp/docker-mailserver-test:ro \ -e PERMIT_DOCKER=network \ -e DMS_DEBUG=0 \ -e ENABLE_SRS=1 \ @@ -31,4 +31,4 @@ load 'test_helper/common' teardown() { docker rm -f mail_domainname; } repeat_until_success_or_timeout 15 docker exec mail_domainname grep "SRS_DOMAIN=my-domain.com" /etc/default/postsrsd -} \ No newline at end of file +} diff --git a/test/mail_ssl_letsencrypt.bats b/test/mail_ssl_letsencrypt.bats index 45714509..45694923 100644 --- a/test/mail_ssl_letsencrypt.bats +++ b/test/mail_ssl_letsencrypt.bats @@ -9,10 +9,12 @@ function teardown() { } function setup_file() { + local PRIVATE_CONFIG + PRIVATE_CONFIG="$(duplicate_config_for_container . mail_lets_domain)" docker run -d --name mail_lets_domain \ -v "${PRIVATE_CONFIG}":/tmp/docker-mailserver \ - -v "`pwd`/test/test-files":/tmp/docker-mailserver-test:ro \ + -v "$(pwd)/test/test-files":/tmp/docker-mailserver-test:ro \ -v "${PRIVATE_CONFIG}/letsencrypt/my-domain.com":/etc/letsencrypt/live/my-domain.com \ -e DMS_DEBUG=0 \ -e SSL_TYPE=letsencrypt \ @@ -22,7 +24,7 @@ function setup_file() { PRIVATE_CONFIG="$(duplicate_config_for_container . mail_lets_hostname)" docker run -d --name mail_lets_hostname \ -v "${PRIVATE_CONFIG}":/tmp/docker-mailserver \ - -v "`pwd`/test/test-files":/tmp/docker-mailserver-test:ro \ + -v "$(pwd)/test/test-files":/tmp/docker-mailserver-test:ro \ -v "${PRIVATE_CONFIG}/letsencrypt/mail.my-domain.com":/etc/letsencrypt/live/mail.my-domain.com \ -e DMS_DEBUG=0 \ -e SSL_TYPE=letsencrypt \ @@ -34,7 +36,7 @@ function setup_file() { docker run -d --name mail_lets_acme_json \ -v "${PRIVATE_CONFIG}":/tmp/docker-mailserver \ -v "${PRIVATE_CONFIG}/acme.json":/etc/letsencrypt/acme.json:ro \ - -v "`pwd`/test/test-files":/tmp/docker-mailserver-test:ro \ + -v "$(pwd)/test/test-files":/tmp/docker-mailserver-test:ro \ -e DMS_DEBUG=0 \ -e SSL_TYPE=letsencrypt \ -e "SSL_DOMAIN=*.example.com" \ diff --git a/test/mail_ssl_manual.bats b/test/mail_ssl_manual.bats index 0ce0a90c..a9d0faee 100644 --- a/test/mail_ssl_manual.bats +++ b/test/mail_ssl_manual.bats @@ -11,7 +11,7 @@ function teardown() { function setup_file() { docker run -d --name mail_manual_ssl \ -v "$(duplicate_config_for_container .)":/tmp/docker-mailserver \ - -v "`pwd`/test/test-files":/tmp/docker-mailserver-test:ro \ + -v "$(pwd)/test/test-files":/tmp/docker-mailserver-test:ro \ -e SSL_TYPE=manual \ -e SSL_CERT_PATH=/tmp/docker-mailserver/letsencrypt/mail.my-domain.com/fullchain.pem \ -e SSL_KEY_PATH=/tmp/docker-mailserver/letsencrypt/mail.my-domain.com/privkey.pem \ @@ -57,4 +57,4 @@ function teardown_file() { @test "last" { skip 'this test is only there to reliably mark the end for the teardown_file' -} \ No newline at end of file +} diff --git a/test/mail_undef_spam_subject.bats b/test/mail_undef_spam_subject.bats index 0f9b83c7..6cc61314 100644 --- a/test/mail_undef_spam_subject.bats +++ b/test/mail_undef_spam_subject.bats @@ -3,14 +3,14 @@ load 'test_helper/common' function setup() { docker run -d --name mail_undef_spam_subject \ -v "$(duplicate_config_for_container .)":/tmp/docker-mailserver \ - -v "`pwd`/test/test-files":/tmp/docker-mailserver-test:ro \ + -v "$(pwd)/test/test-files":/tmp/docker-mailserver-test:ro \ -e ENABLE_SPAMASSASSIN=1 \ -e SA_SPAM_SUBJECT="undef" \ -h mail.my-domain.com -t ${NAME} CONTAINER=$(docker run -d \ -v "$(duplicate_config_for_container . mail_undef_spam_subject_2)":/tmp/docker-mailserver \ - -v "`pwd`/test/test-files":/tmp/docker-mailserver-test:ro \ - -v "`pwd`/test/onedir":/var/mail-state \ + -v "$(pwd)/test/test-files":/tmp/docker-mailserver-test:ro \ + -v "$(pwd)/test/onedir":/var/mail-state \ -e ENABLE_CLAMAV=1 \ -e SPOOF_PROTECTION=1 \ -e ENABLE_SPAMASSASSIN=1 \ @@ -47,4 +47,4 @@ function teardown() { assert_success run docker exec mail_undef_spam_subject /bin/sh -c "grep '\$sa_spam_subject_tag' /etc/amavis/conf.d/20-debian_defaults | grep '= undef'" assert_success -} \ No newline at end of file +} diff --git a/test/mail_with_imap.bats b/test/mail_with_imap.bats index 0b23693a..ac16c2c1 100644 --- a/test/mail_with_imap.bats +++ b/test/mail_with_imap.bats @@ -12,7 +12,7 @@ teardown() { setup_file() { docker run -d --name mail_with_imap \ -v "$(duplicate_config_for_container .)":/tmp/docker-mailserver \ - -v "`pwd`/test/test-files":/tmp/docker-mailserver-test:ro \ + -v "$(pwd)/test/test-files":/tmp/docker-mailserver-test:ro \ -e ENABLE_SASLAUTHD=1 \ -e SASLAUTHD_MECHANISMS=rimap \ -e SASLAUTHD_MECH_OPTIONS=127.0.0.1 \ diff --git a/test/mail_with_ldap.bats b/test/mail_with_ldap.bats index 3b4254a8..098e986a 100644 --- a/test/mail_with_ldap.bats +++ b/test/mail_with_ldap.bats @@ -15,11 +15,11 @@ function setup_file() { docker run -d --name ldap_for_mail \ -e LDAP_DOMAIN="localhost.localdomain" \ - -h ldap.my-domain.com -t ldap - + -h ldap.my-domain.com -t ldap + docker run -d --name mail_with_ldap \ -v "$(duplicate_config_for_container .)":/tmp/docker-mailserver \ - -v "`pwd`/test/test-files":/tmp/docker-mailserver-test:ro \ + -v "$(pwd)/test/test-files":/tmp/docker-mailserver-test:ro \ -e ENABLE_LDAP=1 \ -e LDAP_SERVER_HOST=ldap \ -e LDAP_START_TLS=no \ @@ -214,7 +214,7 @@ function teardown_file() { # Pflogsumm delivery check # -@test "checking pflogsum delivery" { +@test "checking pflogsum delivery" { # checking default sender is correctly set when env variable not defined run docker exec mail_with_ldap grep "mailserver-report@mail.my-domain.com" /etc/logrotate.d/maillog assert_success diff --git a/test/mail_with_mdbox.bats b/test/mail_with_mdbox.bats index 8913eff4..0ad9361f 100644 --- a/test/mail_with_mdbox.bats +++ b/test/mail_with_mdbox.bats @@ -11,7 +11,7 @@ teardown() { setup_file() { docker run -d --name mail_with_mdbox_format \ -v "$(duplicate_config_for_container .)":/tmp/docker-mailserver \ - -v "`pwd`/test/test-files":/tmp/docker-mailserver-test:ro \ + -v "$(pwd)/test/test-files":/tmp/docker-mailserver-test:ro \ -e SASL_PASSWD="external-domain.com username:password" \ -e ENABLE_CLAMAV=0 \ -e ENABLE_SPAMASSASSIN=0 \ diff --git a/test/mail_with_postgrey.bats b/test/mail_with_postgrey.bats index 11ce2f04..247852ae 100644 --- a/test/mail_with_postgrey.bats +++ b/test/mail_with_postgrey.bats @@ -11,7 +11,7 @@ function teardown() { function setup_file() { docker run -d --name mail_with_postgrey \ -v "$(duplicate_config_for_container .)":/tmp/docker-mailserver \ - -v "`pwd`/test/test-files":/tmp/docker-mailserver-test:ro \ + -v "$(pwd)/test/test-files":/tmp/docker-mailserver-test:ro \ -e ENABLE_POSTGREY=1 \ -e POSTGREY_DELAY=15 \ -e POSTGREY_MAX_AGE=35 \ @@ -98,4 +98,4 @@ function teardown_file() { @test "last" { # this test is only there to reliably mark the end for the teardown_file -} \ No newline at end of file +} diff --git a/test/mail_with_postgrey_disabled_by_default.bats b/test/mail_with_postgrey_disabled_by_default.bats index 31b4baf5..dc3ae80c 100644 --- a/test/mail_with_postgrey_disabled_by_default.bats +++ b/test/mail_with_postgrey_disabled_by_default.bats @@ -3,7 +3,7 @@ load 'test_helper/common' function setup() { CONTAINER=$(docker run -d \ -v "$(duplicate_config_for_container .)":/tmp/docker-mailserver \ - -v "`pwd`/test/test-files":/tmp/docker-mailserver-test:ro \ + -v "$(pwd)/test/test-files":/tmp/docker-mailserver-test:ro \ -e DMS_DEBUG=0 \ -h mail.my-domain.com -t ${NAME}) # using postfix availability as start indicator, this might be insufficient for postgrey @@ -17,4 +17,4 @@ function teardown() { @test "checking process: postgrey (disabled in default configuration)" { run docker exec $CONTAINER /bin/bash -c "ps aux --forest | grep -v grep | grep 'postgrey'" assert_failure -} \ No newline at end of file +} diff --git a/test/mail_with_relays.bats b/test/mail_with_relays.bats index 07afab7e..a374efd4 100644 --- a/test/mail_with_relays.bats +++ b/test/mail_with_relays.bats @@ -16,7 +16,7 @@ function setup_file() { docker run -d --name mail_with_relays \ -v "$tmp_confdir":/tmp/docker-mailserver \ - -v "`pwd`/test/test-files":/tmp/docker-mailserver-test:ro \ + -v "$(pwd)/test/test-files":/tmp/docker-mailserver-test:ro \ -e RELAY_HOST=default.relay.com \ -e RELAY_PORT=2525 \ -e RELAY_USER=smtp_user \ diff --git a/test/mail_with_sdbox.bats b/test/mail_with_sdbox.bats index 2056d480..25589aee 100644 --- a/test/mail_with_sdbox.bats +++ b/test/mail_with_sdbox.bats @@ -11,7 +11,7 @@ teardown() { setup_file() { docker run -d --name mail_with_sdbox_format \ -v "$(duplicate_config_for_container .)":/tmp/docker-mailserver \ - -v "`pwd`/test/test-files":/tmp/docker-mailserver-test:ro \ + -v "$(pwd)/test/test-files":/tmp/docker-mailserver-test:ro \ -e SASL_PASSWD="external-domain.com username:password" \ -e ENABLE_CLAMAV=0 \ -e ENABLE_SPAMASSASSIN=0 \ diff --git a/test/permit_docker.bats b/test/permit_docker.bats index 3edb6cdd..400966e3 100644 --- a/test/permit_docker.bats +++ b/test/permit_docker.bats @@ -9,7 +9,7 @@ setup() { # instead we need to use create, network connect and start (see https://success.docker.com/article/multiple-docker-networks) docker create --name mail_smtponly_second_network \ -v "$(duplicate_config_for_container . mail_smtponly_second_network)":/tmp/docker-mailserver \ - -v "`pwd`/test/test-files":/tmp/docker-mailserver-test:ro \ + -v "$(pwd)/test/test-files":/tmp/docker-mailserver-test:ro \ -e SMTP_ONLY=1 \ -e PERMIT_DOCKER=connected-networks \ -e DMS_DEBUG=0 \ @@ -20,7 +20,7 @@ setup() { docker start mail_smtponly_second_network docker run -d --name mail_smtponly_second_network_sender \ -v "$(duplicate_config_for_container . mail_smtponly_second_network_sender)":/tmp/docker-mailserver \ - -v "`pwd`/test/test-files":/tmp/docker-mailserver-test:ro \ + -v "$(pwd)/test/test-files":/tmp/docker-mailserver-test:ro \ -e SMTP_ONLY=1 \ -e PERMIT_DOCKER=connected-networks \ -e DMS_DEBUG=0 \ @@ -56,4 +56,4 @@ teardown() { repeat_until_success_or_timeout 60 run docker exec mail_smtponly_second_network /bin/sh -c 'grep -cE "to=.*status\=sent" /var/log/mail/mail.log' [ "$status" -ge 0 ] -} \ No newline at end of file +} diff --git a/test/test_helper/common.bash b/test/test_helper/common.bash index 6e0ebb80..d768cc65 100644 --- a/test/test_helper/common.bash +++ b/test/test_helper/common.bash @@ -75,7 +75,7 @@ function container_is_running() { # @param ${1} port # @param ${2} container name function wait_for_tcp_port_in_container() { - repeat_until_success_or_timeout --fatal-test "container_is_running ${2}" "${TEST_TIMEOUT_IN_SECONDS}" docker exec "${2}" /bin/sh -c "nc -z 0.0.0.0 ${1}" + repeat_until_success_or_timeout --fatal-test "container_is_running ${2}" "${TEST_TIMEOUT_IN_SECONDS}" docker exec ${2} /bin/sh -c "nc -z 0.0.0.0 ${1}" } # @param ${1} name of the postfix container @@ -177,8 +177,6 @@ function wait_for_service() { function wait_for_changes_to_be_detected_in_container() { local CONTAINER_NAME="${1}" local TIMEOUT=${TEST_TIMEOUT_IN_SECONDS} - repeat_in_container_until_success_or_timeout \ - "${TIMEOUT}" \ - "${CONTAINER_NAME}" \ - bash -c 'source /usr/local/bin/helper_functions.sh; cmp --silent -- <(_monitored_files_checksums) "${CHKSUM_FILE}" >/dev/null' + repeat_in_container_until_success_or_timeout "${TIMEOUT}" "${CONTAINER_NAME}" \ + bash -c 'source /usr/local/bin/helper_functions.sh; cmp --silent -- <(_monitored_files_checksums) "${CHKSUM_FILE}" >/dev/null' } diff --git a/test/tests.bats b/test/tests.bats index b4ab4277..e6219606 100644 --- a/test/tests.bats +++ b/test/tests.bats @@ -10,7 +10,7 @@ setup() { } setup_file() { - PRIVATE_CONFIG="$(duplicate_config_for_container . mail)" + local PRIVATE_CONFIG="$(duplicate_config_for_container . mail)" mv "${PRIVATE_CONFIG}/user-patches/user-patches.sh" "${PRIVATE_CONFIG}/user-patches.sh" docker run --rm -d --name mail \ -v "${PRIVATE_CONFIG}":/tmp/docker-mailserver \ @@ -460,7 +460,7 @@ EOF # Instead it tests the file-size (here 511) - which may differ with a different domain names # This test may be re-used as a global test to provide better test coverage. @test "checking opendkim: generator creates default keys size" { - PRIVATE_CONFIG="$(duplicate_config_for_container . mail_default_key_size)" + local PRIVATE_CONFIG="$(duplicate_config_for_container . mail_default_key_size)" # Prepare default key size 2048 rm -rf "${PRIVATE_CONFIG}/keyDefault" mkdir -p "${PRIVATE_CONFIG}/keyDefault" @@ -486,7 +486,7 @@ EOF # Instead it tests the file-size (here 511) - which may differ with a different domain names # This test may be re-used as a global test to provide better test coverage. @test "checking opendkim: generator creates key size 2048" { - PRIVATE_CONFIG="$(duplicate_config_for_container . mail_key_size_2048)" + local PRIVATE_CONFIG="$(duplicate_config_for_container . mail_key_size_2048)" # Prepare set key size 2048 rm -rf "${PRIVATE_CONFIG}/key2048" mkdir -p "${PRIVATE_CONFIG}/config/key2048" @@ -511,7 +511,7 @@ EOF # Instead it tests the file-size (here 329) - which may differ with a different domain names # This test may be re-used as a global test to provide better test coverage. @test "checking opendkim: generator creates key size 1024" { - PRIVATE_CONFIG="$(duplicate_config_for_container . mail_key_size_1024)" + local PRIVATE_CONFIG="$(duplicate_config_for_container . mail_key_size_1024)" # Prepare set key size 1024 rm -rf "${PRIVATE_CONFIG}/key1024" mkdir -p "${PRIVATE_CONFIG}/key1024" @@ -533,7 +533,7 @@ EOF } @test "checking opendkim: generator creates keys, tables and TrustedHosts" { - PRIVATE_CONFIG="$(duplicate_config_for_container . mail_dkim_generator_creates_keys_tables_TrustedHosts)" + local PRIVATE_CONFIG="$(duplicate_config_for_container . mail_dkim_generator_creates_keys_tables_TrustedHosts)" rm -rf "${PRIVATE_CONFIG}/empty" mkdir -p "${PRIVATE_CONFIG}/empty" run docker run --rm \ @@ -564,7 +564,7 @@ EOF } @test "checking opendkim: generator creates keys, tables and TrustedHosts without postfix-accounts.cf" { - PRIVATE_CONFIG="$(duplicate_config_for_container . mail_dkim_generator_creates_keys_tables_TrustedHosts_without_postfix_accounts.cf)" + local PRIVATE_CONFIG="$(duplicate_config_for_container . mail_dkim_generator_creates_keys_tables_TrustedHosts_without_postfix_accounts.cf)" rm -rf "${PRIVATE_CONFIG}/without-accounts" mkdir -p "${PRIVATE_CONFIG}/without-accounts" run docker run --rm \ @@ -594,7 +594,7 @@ EOF } @test "checking opendkim: generator creates keys, tables and TrustedHosts without postfix-virtual.cf" { - PRIVATE_CONFIG="$(duplicate_config_for_container . mail_dkim_generator_creates_keys_tables_TrustedHosts_without_postfix_virtual.cf)" + local PRIVATE_CONFIG="$(duplicate_config_for_container . mail_dkim_generator_creates_keys_tables_TrustedHosts_without_postfix_virtual.cf)" rm -rf "${PRIVATE_CONFIG}/without-virtual" mkdir -p "${PRIVATE_CONFIG}/without-virtual" run docker run --rm \ @@ -624,7 +624,7 @@ EOF } @test "checking opendkim: generator creates keys, tables and TrustedHosts using domain name" { - PRIVATE_CONFIG="$(duplicate_config_for_container . mail_dkim_generator_creates_keys_tables_TrustedHosts_without_postfix_virtual.cf)" + local PRIVATE_CONFIG="$(duplicate_config_for_container . mail_dkim_generator_creates_keys_tables_TrustedHosts_without_postfix_virtual.cf)" rm -rf "${PRIVATE_CONFIG}/with-domain" && mkdir -p "${PRIVATE_CONFIG}/with-domain" run docker run --rm \ -v "${PRIVATE_CONFIG}/with-domain/":/tmp/docker-mailserver/ \ @@ -932,7 +932,7 @@ EOF } @test "checking accounts: user3 should have been added to /tmp/docker-mailserver/postfix-accounts.cf even when that file does not exist" { - PRIVATE_CONFIG=$(duplicate_config_for_container without-accounts/ without-accounts_file_does_not_exist) + local PRIVATE_CONFIG=$(duplicate_config_for_container without-accounts/ without-accounts_file_does_not_exist) run docker run --rm \ -v "${PRIVATE_CONFIG}/without-accounts/":/tmp/docker-mailserver/ \ "${IMAGE_NAME:?}" /bin/sh -c 'addmailuser user3@domain.tld mypassword' From ab1da1e3f39ee62848f4a2ab826005dd67b77b47 Mon Sep 17 00:00:00 2001 From: Georg Lauterbach Date: Mon, 19 Oct 2020 14:10:32 +0200 Subject: [PATCH 39/50] small changes in common.bash --- test/test_helper/common.bash | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/test/test_helper/common.bash b/test/test_helper/common.bash index d768cc65..b495a4fd 100644 --- a/test/test_helper/common.bash +++ b/test/test_helper/common.bash @@ -1,6 +1,7 @@ load 'test_helper/bats-support/load' load 'test_helper/bats-assert/load' +# shellcheck disable=SC2034 NAME=tvial/docker-mailserver:testing # default timeout is 120 seconds @@ -25,7 +26,7 @@ function repeat_until_success_or_timeout { shift 1 until "${@}" do - if [[ -n "${FATAL_FAILURE_TEST_COMMAND}" ]] && ! eval "${FATAL_FAILURE_TEST_COMMAND}"; then + if [[ -n ${FATAL_FAILURE_TEST_COMMAND} ]] && ! eval "${FATAL_FAILURE_TEST_COMMAND}"; then echo "\`${FATAL_FAILURE_TEST_COMMAND}\` failed, early aborting repeat_until_success of \`${*}\`" >&2 return 1 fi @@ -41,14 +42,14 @@ function repeat_until_success_or_timeout { # @param ${1} timeout # @param ... test command to run function run_until_success_or_timeout { - if ! [[ "${1}" =~ ^[0-9]+$ ]]; then + if ! [[ ${1} =~ ^[0-9]+$ ]]; then echo "First parameter for timeout must be an integer, recieved \"${1}\"" return 1 fi local TIMEOUT=${1} local STARTTIME=${SECONDS} shift 1 - until run "${@}" && [[ ${status} -eq 0 ]] + until run "${@}" && [[ $status -eq 0 ]] do sleep 1 if (( SECONDS - STARTTIME > TIMEOUT )); then @@ -75,7 +76,7 @@ function container_is_running() { # @param ${1} port # @param ${2} container name function wait_for_tcp_port_in_container() { - repeat_until_success_or_timeout --fatal-test "container_is_running ${2}" "${TEST_TIMEOUT_IN_SECONDS}" docker exec ${2} /bin/sh -c "nc -z 0.0.0.0 ${1}" + repeat_until_success_or_timeout --fatal-test "container_is_running ${2}" "${TEST_TIMEOUT_IN_SECONDS}" docker exec "${2}" /bin/sh -c "nc -z 0.0.0.0 ${1}" } # @param ${1} name of the postfix container @@ -177,6 +178,6 @@ function wait_for_service() { function wait_for_changes_to_be_detected_in_container() { local CONTAINER_NAME="${1}" local TIMEOUT=${TEST_TIMEOUT_IN_SECONDS} - repeat_in_container_until_success_or_timeout "${TIMEOUT}" "${CONTAINER_NAME}" \ - bash -c 'source /usr/local/bin/helper_functions.sh; cmp --silent -- <(_monitored_files_checksums) "${CHKSUM_FILE}" >/dev/null' + # shellcheck disable=SC2016 + repeat_in_container_until_success_or_timeout "${TIMEOUT}" "${CONTAINER_NAME}" bash -c 'source /usr/local/bin/helper_functions.sh; cmp --silent -- <(_monitored_files_checksums) "${CHKSUM_FILE}" >/dev/null' } From 3720dbafc072ebb7c82274e5be1c7b7962d37660 Mon Sep 17 00:00:00 2001 From: Georg Lauterbach Date: Mon, 19 Oct 2020 15:19:34 +0200 Subject: [PATCH 40/50] removed `local VAR=$(...)` assignments --- test/mail_dhparams_manual_not_one_dir.bats | 3 ++- test/test_helper.bats | 12 ++++++---- test/tests.bats | 27 ++++++++++++++-------- 3 files changed, 28 insertions(+), 14 deletions(-) diff --git a/test/mail_dhparams_manual_not_one_dir.bats b/test/mail_dhparams_manual_not_one_dir.bats index e8b76efe..1569f67c 100644 --- a/test/mail_dhparams_manual_not_one_dir.bats +++ b/test/mail_dhparams_manual_not_one_dir.bats @@ -21,7 +21,8 @@ function teardown() { } function setup_file() { - local PRIVATE_CONFIG=$(duplicate_config_for_container .) + local PRIVATE_CONFIG + PRIVATE_CONFIG=$(duplicate_config_for_container .) # copy the custom DHE params in local config cp "$(pwd)/test/test-files/ssl/custom-dhe-params.pem" "${PRIVATE_CONFIG}/dhparams.pem" diff --git a/test/test_helper.bats b/test/test_helper.bats index f69b368b..82ff8a0f 100644 --- a/test/test_helper.bats +++ b/test/test_helper.bats @@ -56,7 +56,8 @@ load 'test_helper/common' } @test "repeat_in_container_until_success_or_timeout run command in container" { - local CONTAINER_NAME=$(docker run --rm -d alpine sleep 100) + local CONTAINER_NAME + CONTAINER_NAME=$(docker run --rm -d alpine sleep 100) SECONDS=0 ! repeat_in_container_until_success_or_timeout 10 "${CONTAINER_NAME}" sh -c "echo '${CONTAINER_NAME}' > /tmp/marker" [[ ${SECONDS} -le 1 ]] @@ -65,14 +66,16 @@ load 'test_helper/common' } @test "container_is_running" { - local CONTAINER_NAME=$(docker run --rm -d alpine sleep 100) + local CONTAINER_NAME + CONTAINER_NAME=$(docker run --rm -d alpine sleep 100) container_is_running "${CONTAINER_NAME}" docker rm -f "${CONTAINER_NAME}" ! container_is_running "${CONTAINER_NAME}" } @test "wait_for_smtp_port_in_container aborts wait after timeout" { - local CONTAINER_NAME=$(docker run --rm -d alpine sleep 100) + local CONTAINER_NAME + CONTAINER_NAME=$(docker run --rm -d alpine sleep 100) SECONDS=0 TEST_TIMEOUT_IN_SECONDS=2 run wait_for_smtp_port_in_container "${CONTAINER_NAME}" [[ ${SECONDS} -ge 2 ]] @@ -81,7 +84,8 @@ load 'test_helper/common' } @test "wait_for_smtp_port_in_container returns immediately when port found" { - local CONTAINER_NAME=$(docker run --rm -d alpine sh -c "sleep 10") + local CONTAINER_NAME + CONTAINER_NAME=$(docker run --rm -d alpine sh -c "sleep 10") docker exec "${CONTAINER_NAME}" apk add netcat-openbsd docker exec "${CONTAINER_NAME}" nc -l 25 & diff --git a/test/tests.bats b/test/tests.bats index e6219606..528fcfc0 100644 --- a/test/tests.bats +++ b/test/tests.bats @@ -10,7 +10,8 @@ setup() { } setup_file() { - local PRIVATE_CONFIG="$(duplicate_config_for_container . mail)" + local PRIVATE_CONFIG + PRIVATE_CONFIG="$(duplicate_config_for_container . mail)" mv "${PRIVATE_CONFIG}/user-patches/user-patches.sh" "${PRIVATE_CONFIG}/user-patches.sh" docker run --rm -d --name mail \ -v "${PRIVATE_CONFIG}":/tmp/docker-mailserver \ @@ -460,7 +461,8 @@ EOF # Instead it tests the file-size (here 511) - which may differ with a different domain names # This test may be re-used as a global test to provide better test coverage. @test "checking opendkim: generator creates default keys size" { - local PRIVATE_CONFIG="$(duplicate_config_for_container . mail_default_key_size)" + local PRIVATE_CONFIG + PRIVATE_CONFIG="$(duplicate_config_for_container . mail_default_key_size)" # Prepare default key size 2048 rm -rf "${PRIVATE_CONFIG}/keyDefault" mkdir -p "${PRIVATE_CONFIG}/keyDefault" @@ -486,7 +488,8 @@ EOF # Instead it tests the file-size (here 511) - which may differ with a different domain names # This test may be re-used as a global test to provide better test coverage. @test "checking opendkim: generator creates key size 2048" { - local PRIVATE_CONFIG="$(duplicate_config_for_container . mail_key_size_2048)" + local PRIVATE_CONFIG + PRIVATE_CONFIG="$(duplicate_config_for_container . mail_key_size_2048)" # Prepare set key size 2048 rm -rf "${PRIVATE_CONFIG}/key2048" mkdir -p "${PRIVATE_CONFIG}/config/key2048" @@ -511,7 +514,8 @@ EOF # Instead it tests the file-size (here 329) - which may differ with a different domain names # This test may be re-used as a global test to provide better test coverage. @test "checking opendkim: generator creates key size 1024" { - local PRIVATE_CONFIG="$(duplicate_config_for_container . mail_key_size_1024)" + local PRIVATE_CONFIG + PRIVATE_CONFIG="$(duplicate_config_for_container . mail_key_size_1024)" # Prepare set key size 1024 rm -rf "${PRIVATE_CONFIG}/key1024" mkdir -p "${PRIVATE_CONFIG}/key1024" @@ -533,7 +537,8 @@ EOF } @test "checking opendkim: generator creates keys, tables and TrustedHosts" { - local PRIVATE_CONFIG="$(duplicate_config_for_container . mail_dkim_generator_creates_keys_tables_TrustedHosts)" + local PRIVATE_CONFIG + PRIVATE_CONFIG="$(duplicate_config_for_container . mail_dkim_generator_creates_keys_tables_TrustedHosts)" rm -rf "${PRIVATE_CONFIG}/empty" mkdir -p "${PRIVATE_CONFIG}/empty" run docker run --rm \ @@ -564,7 +569,8 @@ EOF } @test "checking opendkim: generator creates keys, tables and TrustedHosts without postfix-accounts.cf" { - local PRIVATE_CONFIG="$(duplicate_config_for_container . mail_dkim_generator_creates_keys_tables_TrustedHosts_without_postfix_accounts.cf)" + local PRIVATE_CONFIG + PRIVATE_CONFIG="$(duplicate_config_for_container . mail_dkim_generator_creates_keys_tables_TrustedHosts_without_postfix_accounts.cf)" rm -rf "${PRIVATE_CONFIG}/without-accounts" mkdir -p "${PRIVATE_CONFIG}/without-accounts" run docker run --rm \ @@ -594,7 +600,8 @@ EOF } @test "checking opendkim: generator creates keys, tables and TrustedHosts without postfix-virtual.cf" { - local PRIVATE_CONFIG="$(duplicate_config_for_container . mail_dkim_generator_creates_keys_tables_TrustedHosts_without_postfix_virtual.cf)" + local PRIVATE_CONFIG + PRIVATE_CONFIG="$(duplicate_config_for_container . mail_dkim_generator_creates_keys_tables_TrustedHosts_without_postfix_virtual.cf)" rm -rf "${PRIVATE_CONFIG}/without-virtual" mkdir -p "${PRIVATE_CONFIG}/without-virtual" run docker run --rm \ @@ -624,7 +631,8 @@ EOF } @test "checking opendkim: generator creates keys, tables and TrustedHosts using domain name" { - local PRIVATE_CONFIG="$(duplicate_config_for_container . mail_dkim_generator_creates_keys_tables_TrustedHosts_without_postfix_virtual.cf)" + local PRIVATE_CONFIG + PRIVATE_CONFIG="$(duplicate_config_for_container . mail_dkim_generator_creates_keys_tables_TrustedHosts_without_postfix_virtual.cf)" rm -rf "${PRIVATE_CONFIG}/with-domain" && mkdir -p "${PRIVATE_CONFIG}/with-domain" run docker run --rm \ -v "${PRIVATE_CONFIG}/with-domain/":/tmp/docker-mailserver/ \ @@ -932,7 +940,8 @@ EOF } @test "checking accounts: user3 should have been added to /tmp/docker-mailserver/postfix-accounts.cf even when that file does not exist" { - local PRIVATE_CONFIG=$(duplicate_config_for_container without-accounts/ without-accounts_file_does_not_exist) + local PRIVATE_CONFIG + PRIVATE_CONFIG=$(duplicate_config_for_container without-accounts/ without-accounts_file_does_not_exist) run docker run --rm \ -v "${PRIVATE_CONFIG}/without-accounts/":/tmp/docker-mailserver/ \ "${IMAGE_NAME:?}" /bin/sh -c 'addmailuser user3@domain.tld mypassword' From b948e01d3958f1d14b0b580018849a93b0f486fe Mon Sep 17 00:00:00 2001 From: Georg Lauterbach Date: Mon, 19 Oct 2020 15:23:42 +0200 Subject: [PATCH 41/50] re-trigger wget through exception in the last test --- test/test_helper/common.bash | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/test_helper/common.bash b/test/test_helper/common.bash index b495a4fd..b9e82542 100644 --- a/test/test_helper/common.bash +++ b/test/test_helper/common.bash @@ -1,3 +1,5 @@ +#! /bin/bash + load 'test_helper/bats-support/load' load 'test_helper/bats-assert/load' From 7ae4a73d3b35b808cc41fad4fd4afaaff63e7e6f Mon Sep 17 00:00:00 2001 From: Martin Schulze Date: Mon, 19 Oct 2020 23:33:54 +0200 Subject: [PATCH 42/50] Fix tests failing when emails are not yet delivered --- test/test_helper.bats | 25 +++++++++++++++++++++++++ test/test_helper/common.bash | 6 ++++++ test/tests.bats | 4 ++-- 3 files changed, 33 insertions(+), 2 deletions(-) diff --git a/test/test_helper.bats b/test/test_helper.bats index 82ff8a0f..07577bba 100644 --- a/test/test_helper.bats +++ b/test/test_helper.bats @@ -95,3 +95,28 @@ load 'test_helper/common' [[ ${SECONDS} -lt 5 ]] assert_success } + +@test "wait_for_empty_mail_queue_in_container" { + # variable not local to make visible to teardown + CONTAINER_NAME="$(docker run -d --rm \ + -v "$(duplicate_config_for_container .)":/tmp/docker-mailserver \ + -v "$(pwd)/test/test-files":/tmp/docker-mailserver-test:ro \ + -h mail.my-domain.com -t "${NAME}")" + + teardown() { docker rm -f "${CONTAINER_NAME}"; } + + wait_for_smtp_port_in_container "${CONTAINER_NAME}" || docker logs "${CONTAINER_NAME}" + + SECONDS=0 + # no mails -> should return immediately + TEST_TIMEOUT_IN_SECONDS=5 wait_for_empty_mail_queue_in_container "${CONTAINER_NAME}" + [[ $SECONDS -lt 5 ]] + + # fill the queue with a message + docker exec "${CONTAINER_NAME}" /bin/sh -c "nc 0.0.0.0 25 < /tmp/docker-mailserver-test/email-templates/amavis-virus.txt" + # the first shot should fail + ! TEST_TIMEOUT_IN_SECONDS=0 wait_for_empty_mail_queue_in_container "${CONTAINER_NAME}" + + # now give it some time to clear the queue + wait_for_empty_mail_queue_in_container "${CONTAINER_NAME}" +} diff --git a/test/test_helper/common.bash b/test/test_helper/common.bash index b9e82542..a6c64cfe 100644 --- a/test/test_helper/common.bash +++ b/test/test_helper/common.bash @@ -183,3 +183,9 @@ function wait_for_changes_to_be_detected_in_container() { # shellcheck disable=SC2016 repeat_in_container_until_success_or_timeout "${TIMEOUT}" "${CONTAINER_NAME}" bash -c 'source /usr/local/bin/helper_functions.sh; cmp --silent -- <(_monitored_files_checksums) "${CHKSUM_FILE}" >/dev/null' } + +function wait_for_empty_mail_queue_in_container() { + local CONTAINER_NAME="${1}" + local TIMEOUT=${TEST_TIMEOUT_IN_SECONDS} + repeat_in_container_until_success_or_timeout "${TIMEOUT}" "${CONTAINER_NAME}" bash -c '[[ $(mailq) == *"Mail queue is empty"* ]]' +} diff --git a/test/tests.bats b/test/tests.bats index 528fcfc0..e1181873 100644 --- a/test/tests.bats +++ b/test/tests.bats @@ -66,8 +66,8 @@ setup_file() { docker exec mail /bin/sh -c "nc 0.0.0.0 25 < /tmp/docker-mailserver-test/email-templates/sieve-pipe.txt" docker exec mail /bin/sh -c "nc 0.0.0.0 25 < /tmp/docker-mailserver-test/email-templates/non-existing-user.txt" docker exec mail /bin/sh -c "sendmail root < /tmp/docker-mailserver-test/email-templates/root-email.txt" - # wait for mails to be analyzed - #sleep 80 + + wait_for_empty_mail_queue_in_container mail } teardown() { From 9471ce73463c0ed6acbdb88c365565265ad0cd38 Mon Sep 17 00:00:00 2001 From: Martin Schulze Date: Mon, 19 Oct 2020 23:34:39 +0200 Subject: [PATCH 43/50] Fix errors due to trying to send emails too early when clamav has not fully come up yet --- test/tests.bats | 3 +++ 1 file changed, 3 insertions(+) diff --git a/test/tests.bats b/test/tests.bats index e1181873..2411634c 100644 --- a/test/tests.bats +++ b/test/tests.bats @@ -49,6 +49,9 @@ setup_file() { wait_for_smtp_port_in_container mail + # wait for clamav to be fully setup or we will get errors on the log + repeat_in_container_until_success_or_timeout 60 mail test -e /var/run/clamav/clamd.ctl + # sending test mails docker exec mail /bin/sh -c "nc 0.0.0.0 25 < /tmp/docker-mailserver-test/email-templates/amavis-spam.txt" docker exec mail /bin/sh -c "nc 0.0.0.0 25 < /tmp/docker-mailserver-test/email-templates/amavis-virus.txt" From 7bdac2a91035cbf5cc0979bd0060311022c1bd97 Mon Sep 17 00:00:00 2001 From: Martin Schulze Date: Tue, 20 Oct 2020 00:50:19 +0200 Subject: [PATCH 44/50] Add tests for remaining test_helper functions --- test/test_helper.bats | 121 +++++++++++++++++++++++++++++++++-- test/test_helper/common.bash | 10 +-- 2 files changed, 121 insertions(+), 10 deletions(-) diff --git a/test/test_helper.bats b/test/test_helper.bats index 07577bba..d1dcd473 100644 --- a/test/test_helper.bats +++ b/test/test_helper.bats @@ -96,11 +96,102 @@ load 'test_helper/common' assert_success } -@test "wait_for_empty_mail_queue_in_container" { +@test "wait_for_finished_setup_in_container" { # variable not local to make visible to teardown + CONTAINER_NAME="$(docker run -d --rm \ + -v "$(duplicate_config_for_container .)":/tmp/docker-mailserver \ + -h mail.my-domain.com -t "${NAME}")" + teardown() { docker rm -f "${CONTAINER_NAME}"; } + + # the setup should not be finished immediately after starting + ! TEST_TIMEOUT_IN_SECONDS=0 wait_for_finished_setup_in_container "${CONTAINER_NAME}" + + # but it will finish eventually + SECONDS=1 + wait_for_finished_setup_in_container "${CONTAINER_NAME}" + [[ $SECONDS -gt 0 ]] +} + +@test "duplicate_config_for_container" { + local path + path="$(duplicate_config_for_container duplicate_config_test)" + + run cat "$path/marker" + assert_output "This marker file is there to identify the correct config being copied" + + run duplicate_config_for_container non-existant-source-folder "${BATS_TEST_NAME}2" + assert_failure +} + +@test "container_has_service_running/wait_for_service" { + # variable not local to make visible to teardown + CONTAINER_NAME="$(docker run -d --rm \ + -v "$(duplicate_config_for_container .)":/tmp/docker-mailserver \ + -h mail.my-domain.com -t "${NAME}")" + teardown() { docker rm -f "${CONTAINER_NAME}"; } + + # pick a service that was not started + ! container_has_service_running "${CONTAINER_NAME}" clamav + + # wait for a service that should be started + wait_for_service "${CONTAINER_NAME}" postfix + + # shut down the service + docker exec "${CONTAINER_NAME}" supervisorctl stop postfix + + # now it should be off + SECONDS=0 + TEST_TIMEOUT_IN_SECONDS=5 run wait_for_service "${CONTAINER_NAME}" postfix + [[ $SECONDS -ge 5 ]] + assert_failure +} + +@test "wait_for_changes_to_be_detected_in_container fails when timeout is reached" { + # variable not local to make visible to teardown + CONTAINER_NAME="$(docker run -d --rm \ + -v "$(duplicate_config_for_container .)":/tmp/docker-mailserver \ + -h mail.my-domain.com -t "${NAME}")" + teardown() { docker rm -f "${CONTAINER_NAME}"; } + + # wait for the initial checksum detection to complete + repeat_in_container_until_success_or_timeout 60 "${CONTAINER_NAME}" test -e /tmp/docker-mailserver-config-chksum + + # there should be no changes in the beginning + TEST_TIMEOUT_IN_SECONDS=0 wait_for_changes_to_be_detected_in_container "${CONTAINER_NAME}" + + # trigger some change + docker exec "${CONTAINER_NAME}" /bin/sh -c "addmailuser auser3@mail.my-domain.com mypassword" + + # that should be picked up as not yet detected + ! TEST_TIMEOUT_IN_SECONDS=0 wait_for_changes_to_be_detected_in_container "${CONTAINER_NAME}" +} + +@test "wait_for_changes_to_be_detected_in_container succeeds within timeout" { + # variable not local to make visible to teardown + CONTAINER_NAME="$(docker run -d --rm \ + -v "$(duplicate_config_for_container .)":/tmp/docker-mailserver \ + -h mail.my-domain.com -t "${NAME}")" + teardown() { docker rm -f "${CONTAINER_NAME}"; } + + # wait for the initial checksum detection to complete + repeat_in_container_until_success_or_timeout 60 "${CONTAINER_NAME}" test -e /tmp/docker-mailserver-config-chksum + + # trigger some change + docker exec "${CONTAINER_NAME}" /bin/sh -c "addmailuser auser3@mail.my-domain.com mypassword" + + # that should eventually be detected + SECONDS=0 + wait_for_changes_to_be_detected_in_container "${CONTAINER_NAME}" + [[ $SECONDS -gt 0 ]] +} + +@test "wait_for_empty_mail_queue_in_container fails when timeout reached" { + # variable not local to make visible to teardown + # enable clamav to make message delivery slower, so we can detect it CONTAINER_NAME="$(docker run -d --rm \ -v "$(duplicate_config_for_container .)":/tmp/docker-mailserver \ -v "$(pwd)/test/test-files":/tmp/docker-mailserver-test:ro \ + -e ENABLE_CLAMAV=1 \ -h mail.my-domain.com -t "${NAME}")" teardown() { docker rm -f "${CONTAINER_NAME}"; } @@ -114,9 +205,29 @@ load 'test_helper/common' # fill the queue with a message docker exec "${CONTAINER_NAME}" /bin/sh -c "nc 0.0.0.0 25 < /tmp/docker-mailserver-test/email-templates/amavis-virus.txt" - # the first shot should fail + + # that should still be stuck in the queue ! TEST_TIMEOUT_IN_SECONDS=0 wait_for_empty_mail_queue_in_container "${CONTAINER_NAME}" - - # now give it some time to clear the queue - wait_for_empty_mail_queue_in_container "${CONTAINER_NAME}" +} + +@test "wait_for_empty_mail_queue_in_container succeeds within timeout" { + # variable not local to make visible to teardown + # enable clamav to make message delivery slower, so we can detect it + CONTAINER_NAME="$(docker run -d --rm \ + -v "$(duplicate_config_for_container .)":/tmp/docker-mailserver \ + -v "$(pwd)/test/test-files":/tmp/docker-mailserver-test:ro \ + -e ENABLE_CLAMAV=1 \ + -h mail.my-domain.com -t "${NAME}")" + + teardown() { docker rm -f "${CONTAINER_NAME}"; } + + wait_for_smtp_port_in_container "${CONTAINER_NAME}" || docker logs "${CONTAINER_NAME}" + + # fill the queue with a message + docker exec "${CONTAINER_NAME}" /bin/sh -c "nc 0.0.0.0 25 < /tmp/docker-mailserver-test/email-templates/amavis-virus.txt" + + # give it some time to clear the queue + SECONDS=0 + wait_for_empty_mail_queue_in_container "${CONTAINER_NAME}" + [[ $SECONDS -gt 0 ]] } diff --git a/test/test_helper/common.bash b/test/test_helper/common.bash index a6c64cfe..6552945a 100644 --- a/test/test_helper/common.bash +++ b/test/test_helper/common.bash @@ -157,10 +157,10 @@ function private_config_path() { # @return path to the folder where the config is duplicated function duplicate_config_for_container() { local OUTPUT_FOLDER - OUTPUT_FOLDER="$(private_config_path "${2}")" - rm -rf "${OUTPUT_FOLDER:?}/" # cleanup - mkdir -p "${OUTPUT_FOLDER}" - cp -r "${PWD}/test/config/${1:?}/." "${OUTPUT_FOLDER}" + OUTPUT_FOLDER="$(private_config_path "${2}")" || return $? + rm -rf "${OUTPUT_FOLDER:?}/" || return $? # cleanup + mkdir -p "${OUTPUT_FOLDER}" || return $? + cp -r "${PWD}/test/config/${1:?}/." "${OUTPUT_FOLDER}" || return $? echo "${OUTPUT_FOLDER}" } @@ -173,7 +173,7 @@ function container_has_service_running() { function wait_for_service() { local CONTAINER_NAME="${1}" local SERVICE_NAME="${2}" - repeat_until_success_or_timeout --fatal-test "container_is_running ${CONTAINER_NAME}" 60 \ + repeat_until_success_or_timeout --fatal-test "container_is_running ${CONTAINER_NAME}" "${TEST_TIMEOUT_IN_SECONDS}" \ container_has_service_running "${CONTAINER_NAME}" "${SERVICE_NAME}" } From 1ac5245f04f6ee7f4f604094ea8acdfe1dbaea1e Mon Sep 17 00:00:00 2001 From: Martin Schulze Date: Tue, 20 Oct 2020 01:05:01 +0200 Subject: [PATCH 45/50] Add missing file --- test/config/duplicate_config_test/marker | 1 + 1 file changed, 1 insertion(+) create mode 100644 test/config/duplicate_config_test/marker diff --git a/test/config/duplicate_config_test/marker b/test/config/duplicate_config_test/marker new file mode 100644 index 00000000..c4f3e5df --- /dev/null +++ b/test/config/duplicate_config_test/marker @@ -0,0 +1 @@ +This marker file is there to identify the correct config being copied \ No newline at end of file From 5884f866d3b6863946869c036939f8e271417bdb Mon Sep 17 00:00:00 2001 From: Martin Schulze Date: Tue, 20 Oct 2020 09:33:14 +0200 Subject: [PATCH 46/50] Fix duplicate configuration name clashes --- test/tests.bats | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/tests.bats b/test/tests.bats index 2411634c..e99f3f8a 100644 --- a/test/tests.bats +++ b/test/tests.bats @@ -573,7 +573,7 @@ EOF @test "checking opendkim: generator creates keys, tables and TrustedHosts without postfix-accounts.cf" { local PRIVATE_CONFIG - PRIVATE_CONFIG="$(duplicate_config_for_container . mail_dkim_generator_creates_keys_tables_TrustedHosts_without_postfix_accounts.cf)" + PRIVATE_CONFIG="$(duplicate_config_for_container . )" rm -rf "${PRIVATE_CONFIG}/without-accounts" mkdir -p "${PRIVATE_CONFIG}/without-accounts" run docker run --rm \ @@ -604,7 +604,7 @@ EOF @test "checking opendkim: generator creates keys, tables and TrustedHosts without postfix-virtual.cf" { local PRIVATE_CONFIG - PRIVATE_CONFIG="$(duplicate_config_for_container . mail_dkim_generator_creates_keys_tables_TrustedHosts_without_postfix_virtual.cf)" + PRIVATE_CONFIG="$(duplicate_config_for_container . )" rm -rf "${PRIVATE_CONFIG}/without-virtual" mkdir -p "${PRIVATE_CONFIG}/without-virtual" run docker run --rm \ @@ -635,7 +635,7 @@ EOF @test "checking opendkim: generator creates keys, tables and TrustedHosts using domain name" { local PRIVATE_CONFIG - PRIVATE_CONFIG="$(duplicate_config_for_container . mail_dkim_generator_creates_keys_tables_TrustedHosts_without_postfix_virtual.cf)" + PRIVATE_CONFIG="$(duplicate_config_for_container . )" rm -rf "${PRIVATE_CONFIG}/with-domain" && mkdir -p "${PRIVATE_CONFIG}/with-domain" run docker run --rm \ -v "${PRIVATE_CONFIG}/with-domain/":/tmp/docker-mailserver/ \ From 0453240098a84bd2e1d405f40c51a6a0ba230758 Mon Sep 17 00:00:00 2001 From: Martin Schulze Date: Tue, 20 Oct 2020 09:33:47 +0200 Subject: [PATCH 47/50] Catch errors on config duplication command --- test/default_relay_host.bats | 4 +- test/mail_dhparams_default.bats | 7 +- test/mail_dhparams_manual_one_dir.bats | 4 +- test/mail_disabled_clamav_spamassassin.bats | 4 +- test/mail_fail2ban.bats | 4 +- test/mail_fetchmail.bats | 4 +- test/mail_lmtp_ip.bats | 7 +- test/mail_override_hostname.bats | 4 +- test/mail_pop3.bats | 4 +- test/mail_postfix_inet.bats | 107 ++++++++---------- test/mail_postscreen.bats | 12 +- test/mail_privacy.bats | 18 +-- test/mail_quotas_disabled.bats | 12 +- test/mail_smtponly.bats | 16 +-- test/mail_spam_bounced.bats | 21 ++-- test/mail_spam_junk_folder.bats | 31 ++--- test/mail_special_use_folders.bats | 4 +- test/mail_srs_domainname.bats | 38 ++++--- test/mail_ssl_manual.bats | 16 +-- test/mail_undef_spam_subject.bats | 46 ++++---- test/mail_with_imap.bats | 4 +- test/mail_with_ldap.bats | 4 +- test/mail_with_mdbox.bats | 6 +- test/mail_with_postgrey.bats | 20 ++-- ...ail_with_postgrey_disabled_by_default.bats | 10 +- test/mail_with_sdbox.bats | 6 +- test/permit_docker.bats | 37 +++--- test/test_helper.bats | 50 +++++--- 28 files changed, 286 insertions(+), 214 deletions(-) diff --git a/test/default_relay_host.bats b/test/default_relay_host.bats index e006ed8b..ff39881c 100644 --- a/test/default_relay_host.bats +++ b/test/default_relay_host.bats @@ -1,8 +1,10 @@ load 'test_helper/common' function setup() { + local PRIVATE_CONFIG + PRIVATE_CONFIG="$(duplicate_config_for_container relay-hosts)" docker run -d --name mail_with_default_relay \ - -v "$(duplicate_config_for_container relay-hosts)":/tmp/docker-mailserver \ + -v "${PRIVATE_CONFIG}":/tmp/docker-mailserver \ -v "$(pwd)/test/test-files":/tmp/docker-mailserver-test:ro \ -e DEFAULT_RELAY_HOST=default.relay.host.invalid:25 \ --cap-add=SYS_PTRACE \ diff --git a/test/mail_dhparams_default.bats b/test/mail_dhparams_default.bats index ff984576..1444120c 100644 --- a/test/mail_dhparams_default.bats +++ b/test/mail_dhparams_default.bats @@ -21,16 +21,19 @@ function teardown() { } function setup_file() { + local PRIVATE_CONFIG + PRIVATE_CONFIG="$(duplicate_config_for_container . mail_default_dhparams_both_one_dir)" docker run -d --name mail_default_dhparams_one_dir \ - -v "$(duplicate_config_for_container . mail_default_dhparams_both_one_dir)":/tmp/docker-mailserver \ + -v "${PRIVATE_CONFIG}":/tmp/docker-mailserver \ -v "$(pwd)/test/test-files":/tmp/docker-mailserver-test:ro \ -e DMS_DEBUG=0 \ -e ONE_DIR=1 \ -h mail.my-domain.com -t ${NAME} wait_for_finished_setup_in_container mail_default_dhparams_one_dir + PRIVATE_CONFIG="$(duplicate_config_for_container . mail_default_dhparams_both_not_one_dir)" docker run -d --name mail_default_dhparams_not_one_dir \ - -v "$(duplicate_config_for_container . mail_default_dhparams_both_not_one_dir)":/tmp/docker-mailserver \ + -v "${PRIVATE_CONFIG}":/tmp/docker-mailserver \ -v "$(pwd)/test/test-files":/tmp/docker-mailserver-test:ro \ -e DMS_DEBUG=0 \ -e ONE_DIR=0 \ diff --git a/test/mail_dhparams_manual_one_dir.bats b/test/mail_dhparams_manual_one_dir.bats index 5063fa42..56971a86 100644 --- a/test/mail_dhparams_manual_one_dir.bats +++ b/test/mail_dhparams_manual_one_dir.bats @@ -20,8 +20,10 @@ function teardown() { } function setup_file() { + local PRIVATE_CONFIG + PRIVATE_CONFIG="$(duplicate_config_for_container .)" docker run -d --name mail_manual_dhparams_one_dir \ - -v "$(duplicate_config_for_container .)":/tmp/docker-mailserver \ + -v "${PRIVATE_CONFIG}":/tmp/docker-mailserver \ -v "$(pwd)/test/test-files":/tmp/docker-mailserver-test:ro \ -v "$(pwd)/test/test-files/ssl/custom-dhe-params.pem":/var/mail-state/lib-shared/dhparams.pem:ro \ -e DMS_DEBUG=0 \ diff --git a/test/mail_disabled_clamav_spamassassin.bats b/test/mail_disabled_clamav_spamassassin.bats index f05be894..506be7cb 100644 --- a/test/mail_disabled_clamav_spamassassin.bats +++ b/test/mail_disabled_clamav_spamassassin.bats @@ -9,8 +9,10 @@ teardown() { } setup_file() { + local PRIVATE_CONFIG + PRIVATE_CONFIG="$(duplicate_config_for_container .)" docker run --rm -d --name mail_disabled_clamav_spamassassin \ - -v "$(duplicate_config_for_container .)":/tmp/docker-mailserver \ + -v "${PRIVATE_CONFIG}":/tmp/docker-mailserver \ -v "$(pwd)/test/test-files":/tmp/docker-mailserver-test:ro \ -e ENABLE_CLAMAV=0 \ -e ENABLE_SPAMASSASSIN=0 \ diff --git a/test/mail_fail2ban.bats b/test/mail_fail2ban.bats index b764ce2e..f02311a2 100644 --- a/test/mail_fail2ban.bats +++ b/test/mail_fail2ban.bats @@ -9,8 +9,10 @@ function teardown() { } function setup_file() { + local PRIVATE_CONFIG + PRIVATE_CONFIG="$(duplicate_config_for_container .)" docker run --rm -d --name mail_fail2ban \ - -v "$(duplicate_config_for_container .)":/tmp/docker-mailserver \ + -v "${PRIVATE_CONFIG}":/tmp/docker-mailserver \ -v "$(pwd)/test/test-files":/tmp/docker-mailserver-test:ro \ -e ENABLE_FAIL2BAN=1 \ -e POSTSCREEN_ACTION=ignore \ diff --git a/test/mail_fetchmail.bats b/test/mail_fetchmail.bats index d56014f2..90a23f99 100644 --- a/test/mail_fetchmail.bats +++ b/test/mail_fetchmail.bats @@ -9,8 +9,10 @@ function teardown() { } function setup_file() { + local PRIVATE_CONFIG + PRIVATE_CONFIG="$(duplicate_config_for_container .)" docker run -d --name mail_fetchmail \ - -v "$(duplicate_config_for_container .)":/tmp/docker-mailserver \ + -v "${PRIVATE_CONFIG}":/tmp/docker-mailserver \ -v "$(pwd)/test/test-files":/tmp/docker-mailserver-test:ro \ -e ENABLE_FETCHMAIL=1 \ --cap-add=NET_ADMIN \ diff --git a/test/mail_lmtp_ip.bats b/test/mail_lmtp_ip.bats index bfb1c2e0..415739a0 100644 --- a/test/mail_lmtp_ip.bats +++ b/test/mail_lmtp_ip.bats @@ -9,9 +9,12 @@ teardown() { } setup_file() { + local PRIVATE_CONFIG PRIVATE_ETC + PRIVATE_CONFIG="$(duplicate_config_for_container .)" + PRIVATE_ETC="$(duplicate_config_for_container dovecot-lmtp/ mail_lmtp_ip_dovecot-lmtp)" docker run -d --name mail_lmtp_ip \ - -v "$(duplicate_config_for_container .)":/tmp/docker-mailserver \ - -v "$(duplicate_config_for_container dovecot-lmtp/ mail_lmtp_ip_dovecot-lmtp)":/etc/dovecot \ + -v "${PRIVATE_CONFIG}":/tmp/docker-mailserver \ + -v "${PRIVATE_ETC}":/etc/dovecot \ -v "$(pwd)/test/test-files":/tmp/docker-mailserver-test:ro \ -e ENABLE_POSTFIX_VIRTUAL_TRANSPORT=1 \ -e POSTFIX_DAGENT=lmtp:127.0.0.1:24 \ diff --git a/test/mail_override_hostname.bats b/test/mail_override_hostname.bats index 2e1ea3f3..91fc6799 100644 --- a/test/mail_override_hostname.bats +++ b/test/mail_override_hostname.bats @@ -5,8 +5,10 @@ function setup() { } function setup_file() { + local PRIVATE_CONFIG + PRIVATE_CONFIG="$(duplicate_config_for_container .)" docker run --rm -d --name mail_override_hostname \ - -v "$(duplicate_config_for_container .)":/tmp/docker-mailserver \ + -v "${PRIVATE_CONFIG}":/tmp/docker-mailserver \ -v "$(pwd)/test/test-files":/tmp/docker-mailserver-test:ro \ -e PERMIT_DOCKER=network \ -e DMS_DEBUG=0 \ diff --git a/test/mail_pop3.bats b/test/mail_pop3.bats index b3f8b705..d07514c2 100644 --- a/test/mail_pop3.bats +++ b/test/mail_pop3.bats @@ -9,8 +9,10 @@ function teardown() { } function setup_file() { + local PRIVATE_CONFIG + PRIVATE_CONFIG="$(duplicate_config_for_container .)" docker run -d --name mail_pop3 \ - -v "$(duplicate_config_for_container .)":/tmp/docker-mailserver \ + -v "${PRIVATE_CONFIG}":/tmp/docker-mailserver \ -v "$(pwd)/test/test-files":/tmp/docker-mailserver-test:ro \ -e ENABLE_POP3=1 \ -e DMS_DEBUG=0 \ diff --git a/test/mail_postfix_inet.bats b/test/mail_postfix_inet.bats index 18220438..14977e0a 100644 --- a/test/mail_postfix_inet.bats +++ b/test/mail_postfix_inet.bats @@ -4,80 +4,73 @@ load 'test_helper/common' # --------- # POSTFIX_INET_PROTOCOLS value is set - -function setup() { - run_setup_file_if_necessary -} - -function teardown() { - run_teardown_file_if_necessary -} - -function setup_file() { - docker run -d --name mail_postfix_inet_default \ - -v "$(duplicate_config_for_container . mail_postfix_inet_default)":/tmp/docker-mailserver \ - -v "$(pwd)/test/test-files":/tmp/docker-mailserver-test:ro \ - -h mail.my-domain.com -t "${NAME}" - - wait_for_finished_setup_in_container mail_postfix_inet_default - - docker run -d --name mail_postfix_inet_all \ - -v "$(duplicate_config_for_container . mail_postfix_inet_all)":/tmp/docker-mailserver \ - -v "$(pwd)/test/test-files":/tmp/docker-mailserver-test:ro \ - -e POSTFIX_INET_PROTOCOLS=all \ - -h mail.my-domain.com -t "${NAME}" - - wait_for_finished_setup_in_container mail_postfix_inet_all - - docker run -d --name mail_postfix_inet_ipv4 \ - -v "$(duplicate_config_for_container . mail_postfix_inet_ipv4)":/tmp/docker-mailserver \ - -v "$(pwd)/test/test-files":/tmp/docker-mailserver-test:ro \ - -e POSTFIX_INET_PROTOCOLS=ipv4 \ - -h mail.my-domain.com -t "${NAME}" - - wait_for_finished_setup_in_container mail_postfix_inet_ipv4 - - docker run -d --name mail_postfix_inet_ipv6 \ - -v "$(duplicate_config_for_container . mail_postfix_inet_ipv6)":/tmp/docker-mailserver \ - -v "$(pwd)/test/test-files":/tmp/docker-mailserver-test:ro \ - -e POSTFIX_INET_PROTOCOLS=ipv6 \ - -h mail.my-domain.com -t "${NAME}" - - wait_for_finished_setup_in_container mail_postfix_inet_ipv6 -} - -function teardown_file() { - docker rm -f mail_postfix_inet_default - docker rm -f mail_postfix_inet_all - docker rm -f mail_postfix_inet_ipv4 - docker rm -f mail_postfix_inet_ipv6 -} - -@test "first" { - skip 'this test must come first to reliably identify when to run setup_file' -} - @test "checking postfix: inet default" { + local PRIVATE_CONFIG + PRIVATE_CONFIG="$(duplicate_config_for_container . )" + docker run -d --name mail_postfix_inet_default \ + -v "${PRIVATE_CONFIG}":/tmp/docker-mailserver \ + -v "$(pwd)/test/test-files":/tmp/docker-mailserver-test:ro \ + -h mail.my-domain.com -t "${NAME}" + + teardown() { docker rm -f mail_postfix_inet_default; } + + wait_for_finished_setup_in_container mail_postfix_inet_default + run docker exec mail_postfix_inet_default postconf inet_protocols assert_output "inet_protocols = all" assert_success } + @test "checking postfix: inet all" { + local PRIVATE_CONFIG + PRIVATE_CONFIG="$(duplicate_config_for_container . )" + docker run -d --name mail_postfix_inet_all \ + -v "${PRIVATE_CONFIG}":/tmp/docker-mailserver \ + -v "$(pwd)/test/test-files":/tmp/docker-mailserver-test:ro \ + -e POSTFIX_INET_PROTOCOLS=all \ + -h mail.my-domain.com -t "${NAME}" + + teardown() { docker rm -f mail_postfix_inet_all; } + + wait_for_finished_setup_in_container mail_postfix_inet_all + run docker exec mail_postfix_inet_all postconf inet_protocols assert_output "inet_protocols = all" assert_success } + @test "checking postfix: inet ipv4" { + local PRIVATE_CONFIG + PRIVATE_CONFIG="$(duplicate_config_for_container . )" + docker run -d --name mail_postfix_inet_ipv4 \ + -v "${PRIVATE_CONFIG}":/tmp/docker-mailserver \ + -v "$(pwd)/test/test-files":/tmp/docker-mailserver-test:ro \ + -e POSTFIX_INET_PROTOCOLS=ipv4 \ + -h mail.my-domain.com -t "${NAME}" + + teardown() { docker rm -f mail_postfix_inet_ipv4; } + + wait_for_finished_setup_in_container mail_postfix_inet_ipv4 + run docker exec mail_postfix_inet_ipv4 postconf inet_protocols assert_output "inet_protocols = ipv4" assert_success } + @test "checking postfix: inet ipv6" { + local PRIVATE_CONFIG + PRIVATE_CONFIG="$(duplicate_config_for_container . )" + docker run -d --name mail_postfix_inet_ipv6 \ + -v "${PRIVATE_CONFIG}":/tmp/docker-mailserver \ + -v "$(pwd)/test/test-files":/tmp/docker-mailserver-test:ro \ + -e POSTFIX_INET_PROTOCOLS=ipv6 \ + -h mail.my-domain.com -t "${NAME}" + + teardown() { docker rm -f mail_postfix_inet_ipv6; } + + wait_for_finished_setup_in_container mail_postfix_inet_ipv6 + run docker exec mail_postfix_inet_ipv6 postconf inet_protocols assert_output "inet_protocols = ipv6" assert_success } - -@test "last" { - skip 'this test is only there to reliably mark the end for the teardown_file' -} diff --git a/test/mail_postscreen.bats b/test/mail_postscreen.bats index e303fbe6..553e763a 100644 --- a/test/mail_postscreen.bats +++ b/test/mail_postscreen.bats @@ -12,12 +12,14 @@ teardown() { } setup_file() { + local PRIVATE_CONFIG + PRIVATE_CONFIG="$(duplicate_config_for_container .)" docker run -d --name mail_postscreen \ - -v "$(duplicate_config_for_container .)":/tmp/docker-mailserver \ - -v "$(pwd)/test/test-files":/tmp/docker-mailserver-test:ro \ - -e POSTSCREEN_ACTION=enforce \ - --cap-add=NET_ADMIN \ - -h mail.my-domain.com -t ${NAME} + -v "${PRIVATE_CONFIG}":/tmp/docker-mailserver \ + -v "$(pwd)/test/test-files":/tmp/docker-mailserver-test:ro \ + -e POSTSCREEN_ACTION=enforce \ + --cap-add=NET_ADMIN \ + -h mail.my-domain.com -t ${NAME} docker run --name mail_postscreen_sender \ -v "$(pwd)/test/test-files":/tmp/docker-mailserver-test:ro \ diff --git a/test/mail_privacy.bats b/test/mail_privacy.bats index c6d664ba..01949979 100644 --- a/test/mail_privacy.bats +++ b/test/mail_privacy.bats @@ -9,15 +9,17 @@ function teardown() { } function setup_file() { + local PRIVATE_CONFIG + PRIVATE_CONFIG="$(duplicate_config_for_container .)" docker run -d --name mail_privacy \ - -v "$(duplicate_config_for_container .)":/tmp/docker-mailserver \ - -v "$(pwd)/test/test-files":/tmp/docker-mailserver-test:ro \ - -e SASL_PASSWD="external-domain.com username:password" \ - -e ENABLE_MANAGESIEVE=1 \ - --cap-add=SYS_PTRACE \ - -e PERMIT_DOCKER=host \ - -e DMS_DEBUG=0 \ - -h mail.my-domain.com -t ${NAME} + -v "${PRIVATE_CONFIG}":/tmp/docker-mailserver \ + -v "$(pwd)/test/test-files":/tmp/docker-mailserver-test:ro \ + -e SASL_PASSWD="external-domain.com username:password" \ + -e ENABLE_MANAGESIEVE=1 \ + --cap-add=SYS_PTRACE \ + -e PERMIT_DOCKER=host \ + -e DMS_DEBUG=0 \ + -h mail.my-domain.com -t ${NAME} wait_for_amavis_port_in_container mail_privacy wait_for_smtp_port_in_container mail_privacy diff --git a/test/mail_quotas_disabled.bats b/test/mail_quotas_disabled.bats index cbdd2137..13b61de4 100644 --- a/test/mail_quotas_disabled.bats +++ b/test/mail_quotas_disabled.bats @@ -14,12 +14,14 @@ function teardown() { } function setup_file() { + local PRIVATE_CONFIG + PRIVATE_CONFIG="$(duplicate_config_for_container .)" docker run -d --name mail_no_quotas \ - -v "$(duplicate_config_for_container .)":/tmp/docker-mailserver \ - -v "$(pwd)/test/test-files":/tmp/docker-mailserver-test:ro \ - -e DMS_DEBUG=0 \ - -e ENABLE_QUOTAS=0 \ - -h mail.my-domain.com -t "${NAME}" + -v "${PRIVATE_CONFIG}":/tmp/docker-mailserver \ + -v "$(pwd)/test/test-files":/tmp/docker-mailserver-test:ro \ + -e DMS_DEBUG=0 \ + -e ENABLE_QUOTAS=0 \ + -h mail.my-domain.com -t "${NAME}" wait_for_finished_setup_in_container mail_no_quotas } diff --git a/test/mail_smtponly.bats b/test/mail_smtponly.bats index 5ab37274..d8eb7a30 100644 --- a/test/mail_smtponly.bats +++ b/test/mail_smtponly.bats @@ -9,14 +9,16 @@ function teardown() { } function setup_file() { + local PRIVATE_CONFIG + PRIVATE_CONFIG="$(duplicate_config_for_container .)" docker run --rm -d --name mail_smtponly \ - -v "$(duplicate_config_for_container .)":/tmp/docker-mailserver \ - -v "$(pwd)/test/test-files":/tmp/docker-mailserver-test:ro \ - -e SMTP_ONLY=1 \ - -e PERMIT_DOCKER=network \ - -e DMS_DEBUG=0 \ - -e OVERRIDE_HOSTNAME=mail.my-domain.com \ - -t ${NAME} + -v "${PRIVATE_CONFIG}":/tmp/docker-mailserver \ + -v "$(pwd)/test/test-files":/tmp/docker-mailserver-test:ro \ + -e SMTP_ONLY=1 \ + -e PERMIT_DOCKER=network \ + -e DMS_DEBUG=0 \ + -e OVERRIDE_HOSTNAME=mail.my-domain.com \ + -t ${NAME} wait_for_finished_setup_in_container mail_smtponly } diff --git a/test/mail_spam_bounced.bats b/test/mail_spam_bounced.bats index ebe87675..da62e3e3 100644 --- a/test/mail_spam_bounced.bats +++ b/test/mail_spam_bounced.bats @@ -14,20 +14,23 @@ function teardown() { } function setup_file() { + local PRIVATE_CONFIG + PRIVATE_CONFIG="$(duplicate_config_for_container . mail_spam_bounced_defined)" docker run -d --name mail_spam_bounced_defined \ - -v "$(duplicate_config_for_container . mail_spam_bounced_defined)":/tmp/docker-mailserver \ - -v "$(pwd)/test/test-files":/tmp/docker-mailserver-test:ro \ - -e ENABLE_SPAMASSASSIN=1 \ - -e SPAMASSASSIN_SPAM_TO_INBOX=0 \ - -h mail.my-domain.com -t "${NAME}" + -v "${PRIVATE_CONFIG}":/tmp/docker-mailserver \ + -v "$(pwd)/test/test-files":/tmp/docker-mailserver-test:ro \ + -e ENABLE_SPAMASSASSIN=1 \ + -e SPAMASSASSIN_SPAM_TO_INBOX=0 \ + -h mail.my-domain.com -t "${NAME}" wait_for_finished_setup_in_container mail_spam_bounced_defined + PRIVATE_CONFIG="$(duplicate_config_for_container . mail_spam_bounced_defined)" docker run -d --name mail_spam_bounced_undefined \ - -v "$(duplicate_config_for_container . mail_spam_bounced_defined)":/tmp/docker-mailserver \ - -v "$(pwd)/test/test-files":/tmp/docker-mailserver-test:ro \ - -e ENABLE_SPAMASSASSIN=1 \ - -h mail.my-domain.com -t "${NAME}" + -v "${PRIVATE_CONFIG}":/tmp/docker-mailserver \ + -v "$(pwd)/test/test-files":/tmp/docker-mailserver-test:ro \ + -e ENABLE_SPAMASSASSIN=1 \ + -h mail.my-domain.com -t "${NAME}" wait_for_finished_setup_in_container mail_spam_bounced_undefined } diff --git a/test/mail_spam_junk_folder.bats b/test/mail_spam_junk_folder.bats index c53f7e63..0c2965e4 100644 --- a/test/mail_spam_junk_folder.bats +++ b/test/mail_spam_junk_folder.bats @@ -14,25 +14,28 @@ function teardown() { } function setup_file() { + local PRIVATE_CONFIG + PRIVATE_CONFIG="$(duplicate_config_for_container . mail_spam_moved_junk)" docker run -d --name mail_spam_moved_junk \ - -v "$(duplicate_config_for_container . mail_spam_moved_junk)":/tmp/docker-mailserver \ - -v "$(pwd)/test/test-files":/tmp/docker-mailserver-test:ro \ - -e ENABLE_SPAMASSASSIN=1 \ - -e SPAMASSASSIN_SPAM_TO_INBOX=1 \ - -e MOVE_SPAM_TO_JUNK=1 \ - -e SA_SPAM_SUBJECT="SPAM: " \ - -h mail.my-domain.com -t "${NAME}" + -v "${PRIVATE_CONFIG}":/tmp/docker-mailserver \ + -v "$(pwd)/test/test-files":/tmp/docker-mailserver-test:ro \ + -e ENABLE_SPAMASSASSIN=1 \ + -e SPAMASSASSIN_SPAM_TO_INBOX=1 \ + -e MOVE_SPAM_TO_JUNK=1 \ + -e SA_SPAM_SUBJECT="SPAM: " \ + -h mail.my-domain.com -t "${NAME}" wait_for_finished_setup_in_container mail_spam_moved_junk + PRIVATE_CONFIG="$(duplicate_config_for_container . mail_spam_moved_new)" docker run -d --name mail_spam_moved_new \ - -v "$(duplicate_config_for_container . mail_spam_moved_new)":/tmp/docker-mailserver \ - -v "$(pwd)/test/test-files":/tmp/docker-mailserver-test:ro \ - -e ENABLE_SPAMASSASSIN=1 \ - -e SPAMASSASSIN_SPAM_TO_INBOX=1 \ - -e MOVE_SPAM_TO_JUNK=0 \ - -e SA_SPAM_SUBJECT="SPAM: " \ - -h mail.my-domain.com -t "${NAME}" + -v "${PRIVATE_CONFIG}":/tmp/docker-mailserver \ + -v "$(pwd)/test/test-files":/tmp/docker-mailserver-test:ro \ + -e ENABLE_SPAMASSASSIN=1 \ + -e SPAMASSASSIN_SPAM_TO_INBOX=1 \ + -e MOVE_SPAM_TO_JUNK=0 \ + -e SA_SPAM_SUBJECT="SPAM: " \ + -h mail.my-domain.com -t "${NAME}" wait_for_finished_setup_in_container mail_spam_moved_new } diff --git a/test/mail_special_use_folders.bats b/test/mail_special_use_folders.bats index 5bbee43b..888b2fce 100644 --- a/test/mail_special_use_folders.bats +++ b/test/mail_special_use_folders.bats @@ -9,8 +9,10 @@ teardown() { } setup_file() { + local PRIVATE_CONFIG + PRIVATE_CONFIG="$(duplicate_config_for_container .)" docker run -d --name mail_special_use_folders \ - -v "$(duplicate_config_for_container .)":/tmp/docker-mailserver \ + -v "${PRIVATE_CONFIG}":/tmp/docker-mailserver \ -v "$(pwd)/test/test-files":/tmp/docker-mailserver-test:ro \ -e SASL_PASSWD="external-domain.com username:password" \ -e ENABLE_CLAMAV=0 \ diff --git a/test/mail_srs_domainname.bats b/test/mail_srs_domainname.bats index 13c482d0..b6f38761 100644 --- a/test/mail_srs_domainname.bats +++ b/test/mail_srs_domainname.bats @@ -1,16 +1,18 @@ load 'test_helper/common' @test "checking SRS: SRS_DOMAINNAME is used correctly" { + local PRIVATE_CONFIG + PRIVATE_CONFIG="$(duplicate_config_for_container . mail_srs_domainname)" docker run --rm -d --name mail_srs_domainname \ - -v "$(duplicate_config_for_container . mail_srs_domainname)":/tmp/docker-mailserver \ - -v "$(pwd)/test/test-files":/tmp/docker-mailserver-test:ro \ - -e PERMIT_DOCKER=network \ - -e DMS_DEBUG=0 \ - -e ENABLE_SRS=1 \ - -e SRS_DOMAINNAME=srs.my-domain.com \ - -e DOMAINNAME=my-domain.com \ - -h unknown.domain.tld \ - -t ${NAME} + -v "${PRIVATE_CONFIG}":/tmp/docker-mailserver \ + -v "$(pwd)/test/test-files":/tmp/docker-mailserver-test:ro \ + -e PERMIT_DOCKER=network \ + -e DMS_DEBUG=0 \ + -e ENABLE_SRS=1 \ + -e SRS_DOMAINNAME=srs.my-domain.com \ + -e DOMAINNAME=my-domain.com \ + -h unknown.domain.tld \ + -t ${NAME} teardown() { docker rm -f mail_srs_domainname; } @@ -18,15 +20,17 @@ load 'test_helper/common' } @test "checking SRS: DOMAINNAME is handled correctly" { + local PRIVATE_CONFIG + PRIVATE_CONFIG="$(duplicate_config_for_container . mail_domainname)" docker run --rm -d --name mail_domainname \ - -v "$(duplicate_config_for_container . mail_domainname)":/tmp/docker-mailserver \ - -v "$(pwd)/test/test-files":/tmp/docker-mailserver-test:ro \ - -e PERMIT_DOCKER=network \ - -e DMS_DEBUG=0 \ - -e ENABLE_SRS=1 \ - -e DOMAINNAME=my-domain.com \ - -h unknown.domain.tld \ - -t ${NAME} + -v "${PRIVATE_CONFIG}":/tmp/docker-mailserver \ + -v "$(pwd)/test/test-files":/tmp/docker-mailserver-test:ro \ + -e PERMIT_DOCKER=network \ + -e DMS_DEBUG=0 \ + -e ENABLE_SRS=1 \ + -e DOMAINNAME=my-domain.com \ + -h unknown.domain.tld \ + -t ${NAME} teardown() { docker rm -f mail_domainname; } diff --git a/test/mail_ssl_manual.bats b/test/mail_ssl_manual.bats index a9d0faee..496ebaec 100644 --- a/test/mail_ssl_manual.bats +++ b/test/mail_ssl_manual.bats @@ -9,14 +9,16 @@ function teardown() { } function setup_file() { + local PRIVATE_CONFIG + PRIVATE_CONFIG="$(duplicate_config_for_container .)" docker run -d --name mail_manual_ssl \ - -v "$(duplicate_config_for_container .)":/tmp/docker-mailserver \ - -v "$(pwd)/test/test-files":/tmp/docker-mailserver-test:ro \ - -e SSL_TYPE=manual \ - -e SSL_CERT_PATH=/tmp/docker-mailserver/letsencrypt/mail.my-domain.com/fullchain.pem \ - -e SSL_KEY_PATH=/tmp/docker-mailserver/letsencrypt/mail.my-domain.com/privkey.pem \ - -e DMS_DEBUG=0 \ - -h mail.my-domain.com -t ${NAME} + -v "${PRIVATE_CONFIG}":/tmp/docker-mailserver \ + -v "$(pwd)/test/test-files":/tmp/docker-mailserver-test:ro \ + -e SSL_TYPE=manual \ + -e SSL_CERT_PATH=/tmp/docker-mailserver/letsencrypt/mail.my-domain.com/fullchain.pem \ + -e SSL_KEY_PATH=/tmp/docker-mailserver/letsencrypt/mail.my-domain.com/privkey.pem \ + -e DMS_DEBUG=0 \ + -h mail.my-domain.com -t ${NAME} wait_for_finished_setup_in_container mail_manual_ssl } diff --git a/test/mail_undef_spam_subject.bats b/test/mail_undef_spam_subject.bats index 6cc61314..a12e3dd5 100644 --- a/test/mail_undef_spam_subject.bats +++ b/test/mail_undef_spam_subject.bats @@ -1,33 +1,37 @@ load 'test_helper/common' function setup() { + local PRIVATE_CONFIG + PRIVATE_CONFIG="$(duplicate_config_for_container .)" docker run -d --name mail_undef_spam_subject \ - -v "$(duplicate_config_for_container .)":/tmp/docker-mailserver \ + -v "${PRIVATE_CONFIG}":/tmp/docker-mailserver \ -v "$(pwd)/test/test-files":/tmp/docker-mailserver-test:ro \ -e ENABLE_SPAMASSASSIN=1 \ -e SA_SPAM_SUBJECT="undef" \ -h mail.my-domain.com -t ${NAME} + + PRIVATE_CONFIG="$(duplicate_config_for_container . mail_undef_spam_subject_2)" CONTAINER=$(docker run -d \ - -v "$(duplicate_config_for_container . mail_undef_spam_subject_2)":/tmp/docker-mailserver \ - -v "$(pwd)/test/test-files":/tmp/docker-mailserver-test:ro \ - -v "$(pwd)/test/onedir":/var/mail-state \ - -e ENABLE_CLAMAV=1 \ - -e SPOOF_PROTECTION=1 \ - -e ENABLE_SPAMASSASSIN=1 \ - -e REPORT_RECIPIENT=user1@localhost.localdomain \ - -e REPORT_SENDER=report1@mail.my-domain.com \ - -e SA_TAG=-5.0 \ - -e SA_TAG2=2.0 \ - -e SA_KILL=3.0 \ - -e SA_SPAM_SUBJECT="SPAM: " \ - -e VIRUSMAILS_DELETE_DELAY=7 \ - -e ENABLE_SRS=1 \ - -e SASL_PASSWD="external-domain.com username:password" \ - -e ENABLE_MANAGESIEVE=1 \ - --cap-add=SYS_PTRACE \ - -e PERMIT_DOCKER=host \ - -e DMS_DEBUG=0 \ - -h mail.my-domain.com -t ${NAME}) + -v "${PRIVATE_CONFIG}":/tmp/docker-mailserver \ + -v "$(pwd)/test/test-files":/tmp/docker-mailserver-test:ro \ + -v "$(pwd)/test/onedir":/var/mail-state \ + -e ENABLE_CLAMAV=1 \ + -e SPOOF_PROTECTION=1 \ + -e ENABLE_SPAMASSASSIN=1 \ + -e REPORT_RECIPIENT=user1@localhost.localdomain \ + -e REPORT_SENDER=report1@mail.my-domain.com \ + -e SA_TAG=-5.0 \ + -e SA_TAG2=2.0 \ + -e SA_KILL=3.0 \ + -e SA_SPAM_SUBJECT="SPAM: " \ + -e VIRUSMAILS_DELETE_DELAY=7 \ + -e ENABLE_SRS=1 \ + -e SASL_PASSWD="external-domain.com username:password" \ + -e ENABLE_MANAGESIEVE=1 \ + --cap-add=SYS_PTRACE \ + -e PERMIT_DOCKER=host \ + -e DMS_DEBUG=0 \ + -h mail.my-domain.com -t ${NAME}) wait_for_finished_setup_in_container mail_undef_spam_subject wait_for_finished_setup_in_container "$CONTAINER" } diff --git a/test/mail_with_imap.bats b/test/mail_with_imap.bats index ac16c2c1..1fc51af4 100644 --- a/test/mail_with_imap.bats +++ b/test/mail_with_imap.bats @@ -10,8 +10,10 @@ teardown() { } setup_file() { + local PRIVATE_CONFIG + PRIVATE_CONFIG="$(duplicate_config_for_container .)" docker run -d --name mail_with_imap \ - -v "$(duplicate_config_for_container .)":/tmp/docker-mailserver \ + -v "${PRIVATE_CONFIG}":/tmp/docker-mailserver \ -v "$(pwd)/test/test-files":/tmp/docker-mailserver-test:ro \ -e ENABLE_SASLAUTHD=1 \ -e SASLAUTHD_MECHANISMS=rimap \ diff --git a/test/mail_with_ldap.bats b/test/mail_with_ldap.bats index 098e986a..04a2b33f 100644 --- a/test/mail_with_ldap.bats +++ b/test/mail_with_ldap.bats @@ -17,8 +17,10 @@ function setup_file() { -e LDAP_DOMAIN="localhost.localdomain" \ -h ldap.my-domain.com -t ldap + local PRIVATE_CONFIG + PRIVATE_CONFIG="$(duplicate_config_for_container .)" docker run -d --name mail_with_ldap \ - -v "$(duplicate_config_for_container .)":/tmp/docker-mailserver \ + -v "${PRIVATE_CONFIG}":/tmp/docker-mailserver \ -v "$(pwd)/test/test-files":/tmp/docker-mailserver-test:ro \ -e ENABLE_LDAP=1 \ -e LDAP_SERVER_HOST=ldap \ diff --git a/test/mail_with_mdbox.bats b/test/mail_with_mdbox.bats index 0ad9361f..7bc28285 100644 --- a/test/mail_with_mdbox.bats +++ b/test/mail_with_mdbox.bats @@ -9,9 +9,11 @@ teardown() { } setup_file() { + local PRIVATE_CONFIG + PRIVATE_CONFIG="$(duplicate_config_for_container .)" docker run -d --name mail_with_mdbox_format \ - -v "$(duplicate_config_for_container .)":/tmp/docker-mailserver \ - -v "$(pwd)/test/test-files":/tmp/docker-mailserver-test:ro \ + -v "${PRIVATE_CONFIG}":/tmp/docker-mailserver \ + -v "$(pwd)/test/test-files":/tmp/docker-mailserver-test:ro \ -e SASL_PASSWD="external-domain.com username:password" \ -e ENABLE_CLAMAV=0 \ -e ENABLE_SPAMASSASSIN=0 \ diff --git a/test/mail_with_postgrey.bats b/test/mail_with_postgrey.bats index 247852ae..a7aaf2c3 100644 --- a/test/mail_with_postgrey.bats +++ b/test/mail_with_postgrey.bats @@ -9,16 +9,18 @@ function teardown() { } function setup_file() { + local PRIVATE_CONFIG + PRIVATE_CONFIG="$(duplicate_config_for_container .)" docker run -d --name mail_with_postgrey \ - -v "$(duplicate_config_for_container .)":/tmp/docker-mailserver \ - -v "$(pwd)/test/test-files":/tmp/docker-mailserver-test:ro \ - -e ENABLE_POSTGREY=1 \ - -e POSTGREY_DELAY=15 \ - -e POSTGREY_MAX_AGE=35 \ - -e POSTGREY_AUTO_WHITELIST_CLIENTS=5 \ - -e POSTGREY_TEXT="Delayed by postgrey" \ - -e DMS_DEBUG=0 \ - -h mail.my-domain.com -t ${NAME} + -v "${PRIVATE_CONFIG}":/tmp/docker-mailserver \ + -v "$(pwd)/test/test-files":/tmp/docker-mailserver-test:ro \ + -e ENABLE_POSTGREY=1 \ + -e POSTGREY_DELAY=15 \ + -e POSTGREY_MAX_AGE=35 \ + -e POSTGREY_AUTO_WHITELIST_CLIENTS=5 \ + -e POSTGREY_TEXT="Delayed by postgrey" \ + -e DMS_DEBUG=0 \ + -h mail.my-domain.com -t ${NAME} # using postfix availability as start indicator, this might be insufficient for postgrey wait_for_smtp_port_in_container mail_with_postgrey } diff --git a/test/mail_with_postgrey_disabled_by_default.bats b/test/mail_with_postgrey_disabled_by_default.bats index dc3ae80c..9dec8022 100644 --- a/test/mail_with_postgrey_disabled_by_default.bats +++ b/test/mail_with_postgrey_disabled_by_default.bats @@ -1,11 +1,13 @@ load 'test_helper/common' function setup() { + local PRIVATE_CONFIG + PRIVATE_CONFIG="$(duplicate_config_for_container .)" CONTAINER=$(docker run -d \ - -v "$(duplicate_config_for_container .)":/tmp/docker-mailserver \ - -v "$(pwd)/test/test-files":/tmp/docker-mailserver-test:ro \ - -e DMS_DEBUG=0 \ - -h mail.my-domain.com -t ${NAME}) + -v "${PRIVATE_CONFIG}":/tmp/docker-mailserver \ + -v "$(pwd)/test/test-files":/tmp/docker-mailserver-test:ro \ + -e DMS_DEBUG=0 \ + -h mail.my-domain.com -t ${NAME}) # using postfix availability as start indicator, this might be insufficient for postgrey wait_for_smtp_port_in_container $CONTAINER } diff --git a/test/mail_with_sdbox.bats b/test/mail_with_sdbox.bats index 25589aee..3391bd9b 100644 --- a/test/mail_with_sdbox.bats +++ b/test/mail_with_sdbox.bats @@ -9,9 +9,11 @@ teardown() { } setup_file() { + local PRIVATE_CONFIG + PRIVATE_CONFIG="$(duplicate_config_for_container .)" docker run -d --name mail_with_sdbox_format \ - -v "$(duplicate_config_for_container .)":/tmp/docker-mailserver \ - -v "$(pwd)/test/test-files":/tmp/docker-mailserver-test:ro \ + -v "${PRIVATE_CONFIG}":/tmp/docker-mailserver \ + -v "$(pwd)/test/test-files":/tmp/docker-mailserver-test:ro \ -e SASL_PASSWD="external-domain.com username:password" \ -e ENABLE_CLAMAV=0 \ -e ENABLE_SPAMASSASSIN=0 \ diff --git a/test/permit_docker.bats b/test/permit_docker.bats index 400966e3..8d889e06 100644 --- a/test/permit_docker.bats +++ b/test/permit_docker.bats @@ -7,26 +7,29 @@ setup() { # use two networks (default ("bridge") and our custom network) to recreate problematic test case where PERMIT_DOCKER=host would not help # currently we cannot use --network in `docker run` multiple times, it will just use the last one # instead we need to use create, network connect and start (see https://success.docker.com/article/multiple-docker-networks) + local PRIVATE_CONFIG + PRIVATE_CONFIG="$(duplicate_config_for_container . mail_smtponly_second_network)" docker create --name mail_smtponly_second_network \ - -v "$(duplicate_config_for_container . mail_smtponly_second_network)":/tmp/docker-mailserver \ - -v "$(pwd)/test/test-files":/tmp/docker-mailserver-test:ro \ - -e SMTP_ONLY=1 \ - -e PERMIT_DOCKER=connected-networks \ - -e DMS_DEBUG=0 \ - -e OVERRIDE_HOSTNAME=mail.my-domain.com \ - --network ${NON_DEFAULT_DOCKER_MAIL_NETWORK_NAME} \ - -t ${NAME} - docker network connect ${NON_DEFAULT_DOCKER_MAIL_NETWORK_NAME}2 mail_smtponly_second_network + -v "${PRIVATE_CONFIG}":/tmp/docker-mailserver \ + -v "$(pwd)/test/test-files":/tmp/docker-mailserver-test:ro \ + -e SMTP_ONLY=1 \ + -e PERMIT_DOCKER=connected-networks \ + -e DMS_DEBUG=0 \ + -e OVERRIDE_HOSTNAME=mail.my-domain.com \ + --network "${NON_DEFAULT_DOCKER_MAIL_NETWORK_NAME}" \ + -t "${NAME}" + docker network connect "${NON_DEFAULT_DOCKER_MAIL_NETWORK_NAME}2" mail_smtponly_second_network docker start mail_smtponly_second_network + PRIVATE_CONFIG="$(duplicate_config_for_container . mail_smtponly_second_network_sender)" docker run -d --name mail_smtponly_second_network_sender \ - -v "$(duplicate_config_for_container . mail_smtponly_second_network_sender)":/tmp/docker-mailserver \ - -v "$(pwd)/test/test-files":/tmp/docker-mailserver-test:ro \ - -e SMTP_ONLY=1 \ - -e PERMIT_DOCKER=connected-networks \ - -e DMS_DEBUG=0 \ - -e OVERRIDE_HOSTNAME=mail.my-domain.com \ - --network ${NON_DEFAULT_DOCKER_MAIL_NETWORK_NAME}2 \ - -t ${NAME} + -v "${PRIVATE_CONFIG}":/tmp/docker-mailserver \ + -v "$(pwd)/test/test-files":/tmp/docker-mailserver-test:ro \ + -e SMTP_ONLY=1 \ + -e PERMIT_DOCKER=connected-networks \ + -e DMS_DEBUG=0 \ + -e OVERRIDE_HOSTNAME=mail.my-domain.com \ + --network "${NON_DEFAULT_DOCKER_MAIL_NETWORK_NAME}2" \ + -t "${NAME}" # wait until postfix is up wait_for_smtp_port_in_container mail_smtponly_second_network diff --git a/test/test_helper.bats b/test/test_helper.bats index d1dcd473..ed6429a9 100644 --- a/test/test_helper.bats +++ b/test/test_helper.bats @@ -98,9 +98,12 @@ load 'test_helper/common' @test "wait_for_finished_setup_in_container" { # variable not local to make visible to teardown + local PRIVATE_CONFIG + PRIVATE_CONFIG="$(duplicate_config_for_container .)" CONTAINER_NAME="$(docker run -d --rm \ - -v "$(duplicate_config_for_container .)":/tmp/docker-mailserver \ - -h mail.my-domain.com -t "${NAME}")" + -v "${PRIVATE_CONFIG}":/tmp/docker-mailserver \ + -h mail.my-domain.com \ + -t "${NAME}")" teardown() { docker rm -f "${CONTAINER_NAME}"; } # the setup should not be finished immediately after starting @@ -124,10 +127,13 @@ load 'test_helper/common' } @test "container_has_service_running/wait_for_service" { + local PRIVATE_CONFIG + PRIVATE_CONFIG="$(duplicate_config_for_container .)" # variable not local to make visible to teardown CONTAINER_NAME="$(docker run -d --rm \ - -v "$(duplicate_config_for_container .)":/tmp/docker-mailserver \ - -h mail.my-domain.com -t "${NAME}")" + -v "${PRIVATE_CONFIG}":/tmp/docker-mailserver \ + -h mail.my-domain.com \ + -t "${NAME}")" teardown() { docker rm -f "${CONTAINER_NAME}"; } # pick a service that was not started @@ -147,10 +153,13 @@ load 'test_helper/common' } @test "wait_for_changes_to_be_detected_in_container fails when timeout is reached" { + local PRIVATE_CONFIG + PRIVATE_CONFIG="$(duplicate_config_for_container .)" # variable not local to make visible to teardown CONTAINER_NAME="$(docker run -d --rm \ - -v "$(duplicate_config_for_container .)":/tmp/docker-mailserver \ - -h mail.my-domain.com -t "${NAME}")" + -v "${PRIVATE_CONFIG}":/tmp/docker-mailserver \ + -h mail.my-domain.com \ + -t "${NAME}")" teardown() { docker rm -f "${CONTAINER_NAME}"; } # wait for the initial checksum detection to complete @@ -167,10 +176,13 @@ load 'test_helper/common' } @test "wait_for_changes_to_be_detected_in_container succeeds within timeout" { + local PRIVATE_CONFIG + PRIVATE_CONFIG="$(duplicate_config_for_container .)" # variable not local to make visible to teardown CONTAINER_NAME="$(docker run -d --rm \ - -v "$(duplicate_config_for_container .)":/tmp/docker-mailserver \ - -h mail.my-domain.com -t "${NAME}")" + -v "${PRIVATE_CONFIG}":/tmp/docker-mailserver \ + -h mail.my-domain.com \ + -t "${NAME}")" teardown() { docker rm -f "${CONTAINER_NAME}"; } # wait for the initial checksum detection to complete @@ -186,13 +198,16 @@ load 'test_helper/common' } @test "wait_for_empty_mail_queue_in_container fails when timeout reached" { + local PRIVATE_CONFIG + PRIVATE_CONFIG="$(duplicate_config_for_container .)" # variable not local to make visible to teardown # enable clamav to make message delivery slower, so we can detect it CONTAINER_NAME="$(docker run -d --rm \ - -v "$(duplicate_config_for_container .)":/tmp/docker-mailserver \ - -v "$(pwd)/test/test-files":/tmp/docker-mailserver-test:ro \ - -e ENABLE_CLAMAV=1 \ - -h mail.my-domain.com -t "${NAME}")" + -v "${PRIVATE_CONFIG}":/tmp/docker-mailserver \ + -v "$(pwd)/test/test-files":/tmp/docker-mailserver-test:ro \ + -e ENABLE_CLAMAV=1 \ + -h mail.my-domain.com \ + -t "${NAME}")" teardown() { docker rm -f "${CONTAINER_NAME}"; } @@ -211,13 +226,16 @@ load 'test_helper/common' } @test "wait_for_empty_mail_queue_in_container succeeds within timeout" { + local PRIVATE_CONFIG + PRIVATE_CONFIG="$(duplicate_config_for_container .)" # variable not local to make visible to teardown # enable clamav to make message delivery slower, so we can detect it CONTAINER_NAME="$(docker run -d --rm \ - -v "$(duplicate_config_for_container .)":/tmp/docker-mailserver \ - -v "$(pwd)/test/test-files":/tmp/docker-mailserver-test:ro \ - -e ENABLE_CLAMAV=1 \ - -h mail.my-domain.com -t "${NAME}")" + -v "${PRIVATE_CONFIG}":/tmp/docker-mailserver \ + -v "$(pwd)/test/test-files":/tmp/docker-mailserver-test:ro \ + -e ENABLE_CLAMAV=1 \ + -h mail.my-domain.com \ + -t "${NAME}")" teardown() { docker rm -f "${CONTAINER_NAME}"; } From 2de5c52b83f5aa90d2f759d1714a6dda14121489 Mon Sep 17 00:00:00 2001 From: Martin Schulze Date: Tue, 20 Oct 2020 12:05:40 +0200 Subject: [PATCH 48/50] Fix nameclash in config names --- test/tests.bats | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/tests.bats b/test/tests.bats index e99f3f8a..803ef294 100644 --- a/test/tests.bats +++ b/test/tests.bats @@ -604,7 +604,7 @@ EOF @test "checking opendkim: generator creates keys, tables and TrustedHosts without postfix-virtual.cf" { local PRIVATE_CONFIG - PRIVATE_CONFIG="$(duplicate_config_for_container . )" + PRIVATE_CONFIG="$(duplicate_config_for_container . "${BATS_TEST_NAME}")" rm -rf "${PRIVATE_CONFIG}/without-virtual" mkdir -p "${PRIVATE_CONFIG}/without-virtual" run docker run --rm \ @@ -635,7 +635,7 @@ EOF @test "checking opendkim: generator creates keys, tables and TrustedHosts using domain name" { local PRIVATE_CONFIG - PRIVATE_CONFIG="$(duplicate_config_for_container . )" + PRIVATE_CONFIG="$(duplicate_config_for_container . "${BATS_TEST_NAME}")" rm -rf "${PRIVATE_CONFIG}/with-domain" && mkdir -p "${PRIVATE_CONFIG}/with-domain" run docker run --rm \ -v "${PRIVATE_CONFIG}/with-domain/":/tmp/docker-mailserver/ \ From 5cce70b3a9bf86c40f0265ab08c03945ae7eb4ef Mon Sep 17 00:00:00 2001 From: Martin Schulze Date: Tue, 20 Oct 2020 13:48:16 +0200 Subject: [PATCH 49/50] Fix timing dependent failures --- test/mail_spam_junk_folder.bats | 55 +++++++++++---------------------- test/mail_ssl_manual.bats | 1 + 2 files changed, 19 insertions(+), 37 deletions(-) diff --git a/test/mail_spam_junk_folder.bats b/test/mail_spam_junk_folder.bats index 0c2965e4..fda69bb3 100644 --- a/test/mail_spam_junk_folder.bats +++ b/test/mail_spam_junk_folder.bats @@ -4,16 +4,7 @@ load 'test_helper/common' # --------- # When SPAMASSASSIN_SPAM_TO_INBOX=1, spam messages must be delivered and eventually (MOVE_SPAM_TO_JUNK=1) moved to the Junk folder. - -function setup() { - run_setup_file_if_necessary -} - -function teardown() { - run_teardown_file_if_necessary -} - -function setup_file() { +@test "checking amavis: spam message is delivered and moved to the Junk folder (MOVE_SPAM_TO_JUNK=1)" { local PRIVATE_CONFIG PRIVATE_CONFIG="$(duplicate_config_for_container . mail_spam_moved_junk)" docker run -d --name mail_spam_moved_junk \ @@ -25,31 +16,10 @@ function setup_file() { -e SA_SPAM_SUBJECT="SPAM: " \ -h mail.my-domain.com -t "${NAME}" - wait_for_finished_setup_in_container mail_spam_moved_junk + teardown() { docker rm -f mail_spam_moved_junk; } - PRIVATE_CONFIG="$(duplicate_config_for_container . mail_spam_moved_new)" - docker run -d --name mail_spam_moved_new \ - -v "${PRIVATE_CONFIG}":/tmp/docker-mailserver \ - -v "$(pwd)/test/test-files":/tmp/docker-mailserver-test:ro \ - -e ENABLE_SPAMASSASSIN=1 \ - -e SPAMASSASSIN_SPAM_TO_INBOX=1 \ - -e MOVE_SPAM_TO_JUNK=0 \ - -e SA_SPAM_SUBJECT="SPAM: " \ - -h mail.my-domain.com -t "${NAME}" + wait_for_smtp_port_in_container mail_spam_moved_junk - wait_for_finished_setup_in_container mail_spam_moved_new -} - -function teardown_file() { - docker rm -f mail_spam_moved_new - docker rm -f mail_spam_moved_junk -} - -@test "first" { - skip 'this test must come first to reliably identify when to run setup_file' -} - -@test "checking amavis: spam message is delivered and moved to the Junk folder (MOVE_SPAM_TO_JUNK=1)" { # send a spam message run docker exec mail_spam_moved_junk /bin/sh -c "nc 0.0.0.0 25 < /tmp/docker-mailserver-test/email-templates/amavis-spam.txt" assert_success @@ -63,6 +33,21 @@ function teardown_file() { } @test "checking amavis: spam message is delivered to INBOX (MOVE_SPAM_TO_JUNK=0)" { + local PRIVATE_CONFIG + PRIVATE_CONFIG="$(duplicate_config_for_container . mail_spam_moved_new)" + docker run -d --name mail_spam_moved_new \ + -v "${PRIVATE_CONFIG}":/tmp/docker-mailserver \ + -v "$(pwd)/test/test-files":/tmp/docker-mailserver-test:ro \ + -e ENABLE_SPAMASSASSIN=1 \ + -e SPAMASSASSIN_SPAM_TO_INBOX=1 \ + -e MOVE_SPAM_TO_JUNK=0 \ + -e SA_SPAM_SUBJECT="SPAM: " \ + -h mail.my-domain.com -t "${NAME}" + + teardown() { docker rm -f mail_spam_moved_new; } + + wait_for_smtp_port_in_container mail_spam_moved_new + # send a spam message run docker exec mail_spam_moved_new /bin/sh -c "nc 0.0.0.0 25 < /tmp/docker-mailserver-test/email-templates/amavis-spam.txt" assert_success @@ -74,7 +59,3 @@ function teardown_file() { run repeat_until_success_or_timeout 20 sh -c "docker exec mail_spam_moved_new sh -c 'grep \"Subject: SPAM: \" /var/mail/localhost.localdomain/user1/new/ -R'" assert_success } - -@test "last" { - skip 'this test is only there to reliably mark the end for the teardown_file' -} diff --git a/test/mail_ssl_manual.bats b/test/mail_ssl_manual.bats index 496ebaec..5ad6e7a8 100644 --- a/test/mail_ssl_manual.bats +++ b/test/mail_ssl_manual.bats @@ -53,6 +53,7 @@ function teardown_file() { } @test "checking ssl: manual cert works correctly" { + wait_for_tcp_port_in_container 587 mail_manual_ssl run docker exec mail_manual_ssl /bin/sh -c "timeout 1 openssl s_client -connect 0.0.0.0:587 -starttls smtp -CApath /etc/ssl/certs/ | grep 'Verify return code: 10 (certificate has expired)'" assert_success } From 0015c62303e542db771959d5b9c1140a13df59a7 Mon Sep 17 00:00:00 2001 From: Martin Schulze Date: Tue, 20 Oct 2020 15:02:31 +0200 Subject: [PATCH 50/50] Fix linter issue --- test/config/duplicate_config_test/marker | 2 +- test/test_helper.bats | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/test/config/duplicate_config_test/marker b/test/config/duplicate_config_test/marker index c4f3e5df..9344493a 100644 --- a/test/config/duplicate_config_test/marker +++ b/test/config/duplicate_config_test/marker @@ -1 +1 @@ -This marker file is there to identify the correct config being copied \ No newline at end of file +This marker file is there to identify the correct config being copied diff --git a/test/test_helper.bats b/test/test_helper.bats index ed6429a9..7473241d 100644 --- a/test/test_helper.bats +++ b/test/test_helper.bats @@ -120,7 +120,7 @@ load 'test_helper/common' path="$(duplicate_config_for_container duplicate_config_test)" run cat "$path/marker" - assert_output "This marker file is there to identify the correct config being copied" + assert_line "This marker file is there to identify the correct config being copied" run duplicate_config_for_container non-existant-source-folder "${BATS_TEST_NAME}2" assert_failure