From dedcb8f5d0f5a9109cc76e0b6fd9e83f7e001e1e Mon Sep 17 00:00:00 2001 From: Thomas VIAL Date: Sun, 14 Aug 2016 22:44:26 +0200 Subject: [PATCH 01/28] Testing Travis CI matrix --- .travis.yml | 28 +++++++++++++++++++++++++ Makefile | 54 +++++++++---------------------------------------- test/tests.bats | 22 ++++++++++++-------- 3 files changed, 51 insertions(+), 53 deletions(-) diff --git a/.travis.yml b/.travis.yml index 3d271e53..537ce161 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,3 +4,31 @@ services: - docker script: - make all +env: + - ENABLE_POP3=0 + - ENABLE_POP3=1 + - ENABLE_FAIL2BAN=0 + - ENABLE_FAIL2BAN=1 + - ENABLE_MANAGESIEVE=0 + - ENABLE_MANAGESIEVE=1 + - SMTP_ONLY=0 + - SMTP_ONLY=1 + - SASL_PASSWD= + - SASL_PASSWD="bar.com username:password" + - ONE_DIR=0 + - ONE_DIR=1 + - SA_TAG= + - SA_TAG=1.0 + - SA_TAG2= + - SA_TAG2=2.0 + - SA_KILL= + - SA_KILL=3.0 + + + + +# SSL_TYPE +# +# DISABLE_AMAVIS=0 +# DISABLE_SPAMASSASSIN=1 +# DISABLE_CLAMAV=1 diff --git a/Makefile b/Makefile index c8bd2498..fdaaf348 100644 --- a/Makefile +++ b/Makefile @@ -20,51 +20,15 @@ run: -v "`pwd`/test/config":/tmp/docker-mailserver \ -v "`pwd`/test":/tmp/docker-mailserver-test \ -v "`pwd`/test/onedir":/var/mail-state \ - -e SA_TAG=1.0 \ - -e SA_TAG2=2.0 \ - -e SA_KILL=3.0 \ - -e SASL_PASSWD="external-domain.com username:password" \ - -e ENABLE_MANAGESIEVE=1 \ - -e ONE_DIR=1 \ - -h mail.my-domain.com -t $(NAME) - sleep 20 - docker run -d --name mail_pop3 \ - -v "`pwd`/test/config":/tmp/docker-mailserver \ - -v "`pwd`/test":/tmp/docker-mailserver-test \ - -v "`pwd`/test/config/letsencrypt":/etc/letsencrypt/live \ - -e ENABLE_POP3=1 \ - -e SSL_TYPE=letsencrypt \ - -h mail.my-domain.com -t $(NAME) - sleep 20 - docker run -d --name mail_smtponly \ - -v "`pwd`/test/config":/tmp/docker-mailserver \ - -v "`pwd`/test":/tmp/docker-mailserver-test \ - -e SMTP_ONLY=1 \ - -h mail.my-domain.com -t $(NAME) - sleep 20 - docker run -d --name mail_fail2ban \ - -v "`pwd`/test/config":/tmp/docker-mailserver \ - -v "`pwd`/test":/tmp/docker-mailserver-test \ - -e ENABLE_FAIL2BAN=1 \ - --cap-add=NET_ADMIN \ - -h mail.my-domain.com -t $(NAME) - sleep 20 - docker run -d --name mail_disabled_amavis \ - -v "`pwd`/test/config":/tmp/docker-mailserver \ - -v "`pwd`/test":/tmp/docker-mailserver-test \ - -e DISABLE_AMAVIS=1 \ - -h mail.my-domain.com -t $(NAME) - sleep 20 - docker run -d --name mail_disabled_spamassassin \ - -v "`pwd`/test/config":/tmp/docker-mailserver \ - -v "`pwd`/test":/tmp/docker-mailserver-test \ - -e DISABLE_SPAMASSASSIN=1 \ - -h mail.my-domain.com -t $(NAME) - sleep 20 - docker run -d --name mail_disabled_clamav \ - -v "`pwd`/test/config":/tmp/docker-mailserver \ - -v "`pwd`/test":/tmp/docker-mailserver-test \ - -e DISABLE_CLAMAV=1 \ + -e ENABLE_POP3=$ENABLE_POP3 \ + -e ENABLE_FAIL2BAN=$ENABLE_FAIL2BAN \ + -e ENABLE_MANAGESIEVE=$ENABLE_MANAGESIEVE \ + -e SMTP_ONLY=$SMTP_ONLY \ + -e SA_TAG=$SA_TAG \ + -e SA_TAG2=$SA_TAG2 \ + -e SA_KILL=$SA_KILL \ + -e SASL_PASSWD=$SASL_PASSWD \ + -e ONE_DIR=$ONE_DIR \ -h mail.my-domain.com -t $(NAME) # Wait for containers to fully start sleep 20 diff --git a/test/tests.bats b/test/tests.bats index f19a8542..e5fcd156 100644 --- a/test/tests.bats +++ b/test/tests.bats @@ -80,15 +80,21 @@ # pop # -@test "checking pop: server is ready" { - run docker exec mail_pop3 /bin/bash -c "nc -w 1 0.0.0.0 110 | grep '+OK'" - [ "$status" -eq 0 ] -} +if [ $ENABLE_POP3 = 1 ]; then -@test "checking pop: authentication works" { - run docker exec mail_pop3 /bin/sh -c "nc -w 1 0.0.0.0 110 < /tmp/docker-mailserver-test/auth/pop3-auth.txt" - [ "$status" -eq 0 ] -} + echo "Testing POP3" + + @test "checking pop: server is ready" { + run docker exec mail /bin/bash -c "nc -w 1 0.0.0.0 110 | grep '+OK'" + [ "$status" -eq 0 ] + } + + @test "checking pop: authentication works" { + run docker exec mail /bin/sh -c "nc -w 1 0.0.0.0 110 < /tmp/docker-mailserver-test/auth/pop3-auth.txt" + [ "$status" -eq 0 ] + } + +fi # # sasl From 38cc862638baa2feb4f04a0a89b3d690375403f5 Mon Sep 17 00:00:00 2001 From: Thomas VIAL Date: Sun, 14 Aug 2016 23:09:13 +0200 Subject: [PATCH 02/28] Refactored. --- .travis.yml | 8 +++- Makefile | 22 +++++----- test/tests.bats | 112 ++++++++++++++++++++++++++++++++---------------- 3 files changed, 91 insertions(+), 51 deletions(-) diff --git a/.travis.yml b/.travis.yml index 537ce161..059962c9 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,8 +2,12 @@ language: bash sudo: required services: - docker +before_script: + - make build-no-cache generate-accounts run fixtures script: - - make all + - make tests +after_script: + - make clean env: - ENABLE_POP3=0 - ENABLE_POP3=1 @@ -14,7 +18,7 @@ env: - SMTP_ONLY=0 - SMTP_ONLY=1 - SASL_PASSWD= - - SASL_PASSWD="bar.com username:password" + - SASL_PASSWD="external-domain.com username:password" - ONE_DIR=0 - ONE_DIR=1 - SA_TAG= diff --git a/Makefile b/Makefile index fdaaf348..f7a2589b 100644 --- a/Makefile +++ b/Makefile @@ -20,15 +20,15 @@ run: -v "`pwd`/test/config":/tmp/docker-mailserver \ -v "`pwd`/test":/tmp/docker-mailserver-test \ -v "`pwd`/test/onedir":/var/mail-state \ - -e ENABLE_POP3=$ENABLE_POP3 \ - -e ENABLE_FAIL2BAN=$ENABLE_FAIL2BAN \ - -e ENABLE_MANAGESIEVE=$ENABLE_MANAGESIEVE \ - -e SMTP_ONLY=$SMTP_ONLY \ - -e SA_TAG=$SA_TAG \ - -e SA_TAG2=$SA_TAG2 \ - -e SA_KILL=$SA_KILL \ - -e SASL_PASSWD=$SASL_PASSWD \ - -e ONE_DIR=$ONE_DIR \ + -e ENABLE_POP3=$$ENABLE_POP3 \ + -e ENABLE_FAIL2BAN=$$ENABLE_FAIL2BAN \ + -e ENABLE_MANAGESIEVE=$$ENABLE_MANAGESIEVE \ + -e SMTP_ONLY=$$SMTP_ONLY \ + -e SA_TAG=$$SA_TAG \ + -e SA_TAG2=$$SA_TAG2 \ + -e SA_KILL=$$SA_KILL \ + -e SASL_PASSWD=$$SASL_PASSWD \ + -e ONE_DIR=$$ONE_DIR \ -h mail.my-domain.com -t $(NAME) # Wait for containers to fully start sleep 20 @@ -58,5 +58,5 @@ tests: ./test/bats/bats test/tests.bats clean: - # Remove running test containers - docker rm -f mail mail_pop3 mail_smtponly mail_fail2ban fail-auth-mailer mail_disabled_amavis mail_disabled_spamassassin mail_disabled_clamav + # Remove running test container + docker rm -f mail \ No newline at end of file diff --git a/test/tests.bats b/test/tests.bats index e5fcd156..a6207ace 100644 --- a/test/tests.bats +++ b/test/tests.bats @@ -27,15 +27,23 @@ [ "$status" -eq 0 ] } -@test "checking process: fail2ban (disabled in default configuration)" { - run docker exec mail /bin/bash -c "ps aux --forest | grep -v grep | grep '/usr/bin/python /usr/bin/fail2ban-server'" - [ "$status" -eq 1 ] -} +if [ $ENABLE_FAIL2BAN = 0 ]; then -@test "checking process: fail2ban (fail2ban server enabled)" { - run docker exec mail_fail2ban /bin/bash -c "ps aux --forest | grep -v grep | grep '/usr/bin/python /usr/bin/fail2ban-server'" - [ "$status" -eq 0 ] -} + @test "checking process: fail2ban (disabled in default configuration)" { + run docker exec mail /bin/bash -c "ps aux --forest | grep -v grep | grep '/usr/bin/python /usr/bin/fail2ban-server'" + [ "$status" -eq 1 ] + } + +fi + +if [ $ENABLE_FAIL2BAN = 1 ]; then + + @test "checking process: fail2ban (fail2ban server enabled)" { + run docker exec mail_fail2ban /bin/bash -c "ps aux --forest | grep -v grep | grep '/usr/bin/python /usr/bin/fail2ban-server'" + [ "$status" -eq 0 ] + } + +fi @test "checking process: amavis (amavis disabled by DISABLE_AMAVIS)" { run docker exec mail_disabled_amavis /bin/bash -c "ps aux --forest | grep -v grep | grep '/usr/sbin/amavisd-new'" @@ -82,8 +90,6 @@ if [ $ENABLE_POP3 = 1 ]; then - echo "Testing POP3" - @test "checking pop: server is ready" { run docker exec mail /bin/bash -c "nc -w 1 0.0.0.0 110 | grep '+OK'" [ "$status" -eq 0 ] @@ -100,20 +106,24 @@ fi # sasl # -@test "checking sasl: doveadm auth test works with good password" { - run docker exec mail /bin/sh -c "doveadm auth test -x service=smtp user2@otherdomain.tld mypassword | grep 'auth succeeded'" - [ "$status" -eq 0 ] -} +if [ $SASL_PASSWD == "external-domain.com username:password" ]; then -@test "checking sasl: doveadm auth test fails with bad password" { - run docker exec mail /bin/sh -c "doveadm auth test -x service=smtp user2@otherdomain.tld BADPASSWORD | grep 'auth failed'" - [ "$status" -eq 0 ] -} + @test "checking sasl: doveadm auth test works with good password" { + run docker exec mail /bin/sh -c "doveadm auth test -x service=smtp user2@otherdomain.tld mypassword | grep 'auth succeeded'" + [ "$status" -eq 0 ] + } -@test "checking sasl: sasl_passwd.db exists" { - run docker exec mail [ -f /etc/postfix/sasl_passwd.db ] - [ "$status" -eq 0 ] -} + @test "checking sasl: doveadm auth test fails with bad password" { + run docker exec mail /bin/sh -c "doveadm auth test -x service=smtp user2@otherdomain.tld BADPASSWORD | grep 'auth failed'" + [ "$status" -eq 0 ] + } + + @test "checking sasl: sasl_passwd.db exists" { + run docker exec mail [ -f /etc/postfix/sasl_passwd.db ] + [ "$status" -eq 0 ] + } + +fi # # logs @@ -261,23 +271,49 @@ fi # spamassassin # -@test "checking spamassassin: docker env variables are set correctly (default)" { - run docker exec mail_pop3 /bin/sh -c "grep '\$sa_tag_level_deflt' /etc/amavis/conf.d/20-debian_defaults | grep '= 2.0'" - [ "$status" -eq 0 ] - run docker exec mail_pop3 /bin/sh -c "grep '\$sa_tag2_level_deflt' /etc/amavis/conf.d/20-debian_defaults | grep '= 6.31'" - [ "$status" -eq 0 ] - run docker exec mail_pop3 /bin/sh -c "grep '\$sa_kill_level_deflt' /etc/amavis/conf.d/20-debian_defaults | grep '= 6.31'" - [ "$status" -eq 0 ] -} +if [ -z $SA_TAG ]; then + @test "checking spamassassin: docker env variables are set correctly (default)" { + run docker exec mail_pop3 /bin/sh -c "grep '\$sa_tag_level_deflt' /etc/amavis/conf.d/20-debian_defaults | grep '= 2.0'" + [ "$status" -eq 0 ] + } +fi + +if [ -z $SA_TAG2 ]; then + @test "checking spamassassin: docker env variables are set correctly (default)" { + run docker exec mail_pop3 /bin/sh -c "grep '\$sa_tag2_level_deflt' /etc/amavis/conf.d/20-debian_defaults | grep '= 6.31'" + [ "$status" -eq 0 ] + } +fi + +if [ -z $SA_KILL ]; then + @test "checking spamassassin: docker env variables are set correctly (default)" { + run docker exec mail_pop3 /bin/sh -c "grep '\$sa_kill_level_deflt' /etc/amavis/conf.d/20-debian_defaults | grep '= 6.31'" + [ "$status" -eq 0 ] + } +fi + + +if [ -n $SA_TAG ]; then + @test "checking spamassassin: docker env variables are set correctly (default)" { + run docker exec mail_pop3 /bin/sh -c "grep '\$sa_tag_level_deflt' /etc/amavis/conf.d/20-debian_defaults | grep '= $SA_TAG'" + [ "$status" -eq 0 ] + } +fi + +if [ -n $SA_TAG2 ]; then + @test "checking spamassassin: docker env variables are set correctly (default)" { + run docker exec mail_pop3 /bin/sh -c "grep '\$sa_tag2_level_deflt' /etc/amavis/conf.d/20-debian_defaults | grep '= $SA_TAG2'" + [ "$status" -eq 0 ] + } +fi + +if [ -n $SA_KILL ]; then + @test "checking spamassassin: docker env variables are set correctly (default)" { + run docker exec mail_pop3 /bin/sh -c "grep '\$sa_kill_level_deflt' /etc/amavis/conf.d/20-debian_defaults | grep '= $SA_KILL'" + [ "$status" -eq 0 ] + } +fi -@test "checking spamassassin: docker env variables are set correctly (custom)" { - run docker exec mail /bin/sh -c "grep '\$sa_tag_level_deflt' /etc/amavis/conf.d/20-debian_defaults | grep '= 1.0'" - [ "$status" -eq 0 ] - run docker exec mail /bin/sh -c "grep '\$sa_tag2_level_deflt' /etc/amavis/conf.d/20-debian_defaults | grep '= 2.0'" - [ "$status" -eq 0 ] - run docker exec mail /bin/sh -c "grep '\$sa_kill_level_deflt' /etc/amavis/conf.d/20-debian_defaults | grep '= 3.0'" - [ "$status" -eq 0 ] -} # # opendkim From 8beaedcdc5c30b92118e28b800c2e3a076f54c19 Mon Sep 17 00:00:00 2001 From: Thomas VIAL Date: Sun, 14 Aug 2016 23:23:53 +0200 Subject: [PATCH 03/28] Refactored. --- Makefile | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/Makefile b/Makefile index f7a2589b..116840cc 100644 --- a/Makefile +++ b/Makefile @@ -20,15 +20,15 @@ run: -v "`pwd`/test/config":/tmp/docker-mailserver \ -v "`pwd`/test":/tmp/docker-mailserver-test \ -v "`pwd`/test/onedir":/var/mail-state \ - -e ENABLE_POP3=$$ENABLE_POP3 \ - -e ENABLE_FAIL2BAN=$$ENABLE_FAIL2BAN \ - -e ENABLE_MANAGESIEVE=$$ENABLE_MANAGESIEVE \ - -e SMTP_ONLY=$$SMTP_ONLY \ - -e SA_TAG=$$SA_TAG \ - -e SA_TAG2=$$SA_TAG2 \ - -e SA_KILL=$$SA_KILL \ - -e SASL_PASSWD=$$SASL_PASSWD \ - -e ONE_DIR=$$ONE_DIR \ + -e ENABLE_POP3=$(ENABLE_POP3) \ + -e ENABLE_FAIL2BAN=$(ENABLE_FAIL2BAN) \ + -e ENABLE_MANAGESIEVE=$(ENABLE_MANAGESIEVE) \ + -e SMTP_ONLY=$(SMTP_ONLY) \ + -e SA_TAG=$(SA_TAG) \ + -e SA_TAG2=$(SA_TAG2) \ + -e SA_KILL=$(SA_KILL) \ + -e SASL_PASSWD=$(SASL_PASSWD) \ + -e ONE_DIR=$(ONE_DIR) \ -h mail.my-domain.com -t $(NAME) # Wait for containers to fully start sleep 20 From bf2b1c94ce9d3707b8685b93fb60ed1a7607d5c9 Mon Sep 17 00:00:00 2001 From: Thomas VIAL Date: Sun, 14 Aug 2016 23:29:51 +0200 Subject: [PATCH 04/28] Refactored. --- test/tests.bats | 18 ------------------ 1 file changed, 18 deletions(-) diff --git a/test/tests.bats b/test/tests.bats index a6207ace..fe8b9b07 100644 --- a/test/tests.bats +++ b/test/tests.bats @@ -84,24 +84,6 @@ fi [ "$status" -eq 0 ] } -# -# pop -# - -if [ $ENABLE_POP3 = 1 ]; then - - @test "checking pop: server is ready" { - run docker exec mail /bin/bash -c "nc -w 1 0.0.0.0 110 | grep '+OK'" - [ "$status" -eq 0 ] - } - - @test "checking pop: authentication works" { - run docker exec mail /bin/sh -c "nc -w 1 0.0.0.0 110 < /tmp/docker-mailserver-test/auth/pop3-auth.txt" - [ "$status" -eq 0 ] - } - -fi - # # sasl # From 6050f0f3ebd5dbf99f157489958db49a7559f95e Mon Sep 17 00:00:00 2001 From: Thomas VIAL Date: Sun, 14 Aug 2016 23:37:16 +0200 Subject: [PATCH 05/28] Refactored. --- Makefile | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 116840cc..6f68372d 100644 --- a/Makefile +++ b/Makefile @@ -55,7 +55,9 @@ fixtures: tests: # Start tests - ./test/bats/bats test/tests.bats + if [ -z $ENABLE_POP3 ]; then + ./test/bats/bats test/ENABLE_POP3.bats + fi clean: # Remove running test container From ae2ad56252db39ec28f50665aa6caac89a81a6f0 Mon Sep 17 00:00:00 2001 From: Thomas VIAL Date: Mon, 15 Aug 2016 00:05:00 +0200 Subject: [PATCH 06/28] Refactored. --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 6f68372d..bb9bd281 100644 --- a/Makefile +++ b/Makefile @@ -55,7 +55,7 @@ fixtures: tests: # Start tests - if [ -z $ENABLE_POP3 ]; then + if [ -z $(ENABLE_POP3) ]; then ./test/bats/bats test/ENABLE_POP3.bats fi From 8c2b96122b72e2e88efa40842837b44fc531ab64 Mon Sep 17 00:00:00 2001 From: Thomas VIAL Date: Mon, 15 Aug 2016 20:59:20 +0200 Subject: [PATCH 07/28] Refactored. --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index bb9bd281..6f68372d 100644 --- a/Makefile +++ b/Makefile @@ -55,7 +55,7 @@ fixtures: tests: # Start tests - if [ -z $(ENABLE_POP3) ]; then + if [ -z $ENABLE_POP3 ]; then ./test/bats/bats test/ENABLE_POP3.bats fi From 799959fba06520abcbaba3430493ad09f8b4b96f Mon Sep 17 00:00:00 2001 From: Thomas VIAL Date: Mon, 15 Aug 2016 21:21:16 +0200 Subject: [PATCH 08/28] Refactored. --- .travis.yml | 28 ++++++++++++++-------------- Makefile | 4 ++-- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/.travis.yml b/.travis.yml index 059962c9..e86c6a30 100644 --- a/.travis.yml +++ b/.travis.yml @@ -11,22 +11,22 @@ after_script: env: - ENABLE_POP3=0 - ENABLE_POP3=1 - - ENABLE_FAIL2BAN=0 - - ENABLE_FAIL2BAN=1 - - ENABLE_MANAGESIEVE=0 - - ENABLE_MANAGESIEVE=1 - - SMTP_ONLY=0 - - SMTP_ONLY=1 + # - ENABLE_FAIL2BAN=0 + # - ENABLE_FAIL2BAN=1 + # - ENABLE_MANAGESIEVE=0 + # - ENABLE_MANAGESIEVE=1 + # - SMTP_ONLY=0 + # - SMTP_ONLY=1 - SASL_PASSWD= - SASL_PASSWD="external-domain.com username:password" - - ONE_DIR=0 - - ONE_DIR=1 - - SA_TAG= - - SA_TAG=1.0 - - SA_TAG2= - - SA_TAG2=2.0 - - SA_KILL= - - SA_KILL=3.0 + # - ONE_DIR=0 + # - ONE_DIR=1 + # - SA_TAG= + # - SA_TAG=1.0 + # - SA_TAG2= + # - SA_TAG2=2.0 + # - SA_KILL= + # - SA_KILL=3.0 diff --git a/Makefile b/Makefile index 6f68372d..d9e75aea 100644 --- a/Makefile +++ b/Makefile @@ -55,9 +55,9 @@ fixtures: tests: # Start tests - if [ -z $ENABLE_POP3 ]; then + ifdef($(ENABLE_POP3)) ./test/bats/bats test/ENABLE_POP3.bats - fi + endif clean: # Remove running test container From 9048050b30491d7d7780252c6d2cfa6ae4e2d53d Mon Sep 17 00:00:00 2001 From: Thomas VIAL Date: Mon, 15 Aug 2016 21:52:31 +0200 Subject: [PATCH 09/28] Refactored. --- Makefile | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/Makefile b/Makefile index d9e75aea..c157459c 100644 --- a/Makefile +++ b/Makefile @@ -54,10 +54,11 @@ fixtures: sleep 10 tests: - # Start tests - ifdef($(ENABLE_POP3)) - ./test/bats/bats test/ENABLE_POP3.bats - endif +# Start tests +ifdef ENABLE_POP3 + @echo "ENABLE_POP3 => $(ENABLE_POP3)" + ./test/bats/bats test/ENABLE_POP3.bats +endif clean: # Remove running test container From 7c33cfa6f51d31dae4e2a2b0b02929059003a073 Mon Sep 17 00:00:00 2001 From: Thomas VIAL Date: Mon, 15 Aug 2016 21:58:31 +0200 Subject: [PATCH 10/28] Refactored. --- Makefile | 2 +- test/ENABLE_POP3.bats | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 test/ENABLE_POP3.bats diff --git a/Makefile b/Makefile index c157459c..422a653e 100644 --- a/Makefile +++ b/Makefile @@ -62,4 +62,4 @@ endif clean: # Remove running test container - docker rm -f mail \ No newline at end of file + docker rm -f mail diff --git a/test/ENABLE_POP3.bats b/test/ENABLE_POP3.bats new file mode 100644 index 00000000..838bc956 --- /dev/null +++ b/test/ENABLE_POP3.bats @@ -0,0 +1,15 @@ +@test "checking pop: server is ready" { + if [ $ENABLE_POP != 1 ]; then + skip + fi + run docker exec mail /bin/bash -c "nc -w 1 0.0.0.0 110 | grep '+OK'" + [ "$status" -eq 0 ] +} + +@test "checking pop: authentication works" { + if [ $ENABLE_POP != 1 ]; then + skip + fi + run docker exec mail /bin/sh -c "nc -w 1 0.0.0.0 110 < /tmp/docker-mailserver-test/auth/pop3-auth.txt" + [ "$status" -eq 0 ] +} From 08c6792d4ad60c4627d193ac82dc107275f1b1d8 Mon Sep 17 00:00:00 2001 From: Thomas VIAL Date: Mon, 15 Aug 2016 22:14:02 +0200 Subject: [PATCH 11/28] Refactored. --- test/ENABLE_POP3.bats | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/test/ENABLE_POP3.bats b/test/ENABLE_POP3.bats index 838bc956..39ebaaf8 100644 --- a/test/ENABLE_POP3.bats +++ b/test/ENABLE_POP3.bats @@ -13,3 +13,16 @@ run docker exec mail /bin/sh -c "nc -w 1 0.0.0.0 110 < /tmp/docker-mailserver-test/auth/pop3-auth.txt" [ "$status" -eq 0 ] } + + + + +@test "checking pop: server is ready" { + run docker exec mail /bin/bash -c "nc -w 1 0.0.0.0 110 | grep '+OK'" + [ "$status" -eq 0 ] +} + +@test "checking pop: authentication works" { + run docker exec mail /bin/sh -c "nc -w 1 0.0.0.0 110 < /tmp/docker-mailserver-test/auth/pop3-auth.txt" + [ "$status" -eq 0 ] +} From ec8198da9d1ce73f2b003a217b9af1692667d235 Mon Sep 17 00:00:00 2001 From: Thomas VIAL Date: Mon, 15 Aug 2016 22:36:58 +0200 Subject: [PATCH 12/28] Refactored. --- test/ENABLE_POP3.bats | 33 ++++++++++++--------------------- 1 file changed, 12 insertions(+), 21 deletions(-) diff --git a/test/ENABLE_POP3.bats b/test/ENABLE_POP3.bats index 39ebaaf8..a39ce94b 100644 --- a/test/ENABLE_POP3.bats +++ b/test/ENABLE_POP3.bats @@ -1,28 +1,19 @@ -@test "checking pop: server is ready" { - if [ $ENABLE_POP != 1 ]; then - skip - fi - run docker exec mail /bin/bash -c "nc -w 1 0.0.0.0 110 | grep '+OK'" - [ "$status" -eq 0 ] -} - -@test "checking pop: authentication works" { - if [ $ENABLE_POP != 1 ]; then - skip - fi - run docker exec mail /bin/sh -c "nc -w 1 0.0.0.0 110 < /tmp/docker-mailserver-test/auth/pop3-auth.txt" - [ "$status" -eq 0 ] -} - - - - @test "checking pop: server is ready" { run docker exec mail /bin/bash -c "nc -w 1 0.0.0.0 110 | grep '+OK'" - [ "$status" -eq 0 ] + + if [ $ENABLE_POP -eq 1 ]; then + [ "$status" -eq 0 ] + else + [ "$status" -eq 1 ] + fi } @test "checking pop: authentication works" { run docker exec mail /bin/sh -c "nc -w 1 0.0.0.0 110 < /tmp/docker-mailserver-test/auth/pop3-auth.txt" - [ "$status" -eq 0 ] + + if [ $ENABLE_POP -eq 1 ]; then + [ "$status" -eq 0 ] + else + [ "$status" -eq 1 ] + fi } From 21ed11b5b6baf9b1ca3f8a99150afb04f778a26f Mon Sep 17 00:00:00 2001 From: Thomas VIAL Date: Mon, 15 Aug 2016 22:49:07 +0200 Subject: [PATCH 13/28] Refactored. --- test/ENABLE_POP3.bats | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/ENABLE_POP3.bats b/test/ENABLE_POP3.bats index a39ce94b..53aaf0d5 100644 --- a/test/ENABLE_POP3.bats +++ b/test/ENABLE_POP3.bats @@ -1,7 +1,7 @@ @test "checking pop: server is ready" { run docker exec mail /bin/bash -c "nc -w 1 0.0.0.0 110 | grep '+OK'" - if [ $ENABLE_POP -eq 1 ]; then + if [ "$ENABLE_POP" -eq 1 ]; then [ "$status" -eq 0 ] else [ "$status" -eq 1 ] @@ -11,7 +11,7 @@ @test "checking pop: authentication works" { run docker exec mail /bin/sh -c "nc -w 1 0.0.0.0 110 < /tmp/docker-mailserver-test/auth/pop3-auth.txt" - if [ $ENABLE_POP -eq 1 ]; then + if [ "$ENABLE_POP" -eq 1 ]; then [ "$status" -eq 0 ] else [ "$status" -eq 1 ] From ce4c2059bbf584273aa4d406710e6f21a15f269c Mon Sep 17 00:00:00 2001 From: Thomas VIAL Date: Mon, 15 Aug 2016 23:17:49 +0200 Subject: [PATCH 14/28] Refactored. --- Makefile | 4 ++++ test/SASL_PASSWD.bats | 29 +++++++++++++++++++++++++++++ test/tests.bats | 23 ----------------------- 3 files changed, 33 insertions(+), 23 deletions(-) create mode 100644 test/SASL_PASSWD.bats diff --git a/Makefile b/Makefile index 422a653e..4439fa31 100644 --- a/Makefile +++ b/Makefile @@ -59,6 +59,10 @@ ifdef ENABLE_POP3 @echo "ENABLE_POP3 => $(ENABLE_POP3)" ./test/bats/bats test/ENABLE_POP3.bats endif +ifdef SASL_PASSWD + @echo "SASL_PASSWD => $(SASL_PASSWD)" + ./test/bats/bats test/SASL_PASSWD.bats +endif clean: # Remove running test container diff --git a/test/SASL_PASSWD.bats b/test/SASL_PASSWD.bats new file mode 100644 index 00000000..e01cc2f0 --- /dev/null +++ b/test/SASL_PASSWD.bats @@ -0,0 +1,29 @@ +@test "checking sasl: doveadm auth test works with good password" { + run docker exec mail /bin/sh -c "doveadm auth test -x service=smtp user2@otherdomain.tld mypassword | grep 'auth succeeded'" + + if [ -n "$SASL_PASSWD" ]; then + [ "$status" -eq 0 ] + else + [ "$status" -eq 1 ] + fi +} + +@test "checking sasl: doveadm auth test fails with bad password" { + run docker exec mail /bin/sh -c "doveadm auth test -x service=smtp user2@otherdomain.tld BADPASSWORD | grep 'auth failed'" + + if [ -n "$SASL_PASSWD" ]; then + [ "$status" -eq 0 ] + else + [ "$status" -eq 1 ] + fi +} + +@test "checking sasl: sasl_passwd.db exists" { + run docker exec mail [ -f /etc/postfix/sasl_passwd.db ] + + if [ -n "$SASL_PASSWD" ]; then + [ "$status" -eq 0 ] + else + [ "$status" -eq 1 ] + fi +} diff --git a/test/tests.bats b/test/tests.bats index fe8b9b07..27cbf331 100644 --- a/test/tests.bats +++ b/test/tests.bats @@ -84,29 +84,6 @@ fi [ "$status" -eq 0 ] } -# -# sasl -# - -if [ $SASL_PASSWD == "external-domain.com username:password" ]; then - - @test "checking sasl: doveadm auth test works with good password" { - run docker exec mail /bin/sh -c "doveadm auth test -x service=smtp user2@otherdomain.tld mypassword | grep 'auth succeeded'" - [ "$status" -eq 0 ] - } - - @test "checking sasl: doveadm auth test fails with bad password" { - run docker exec mail /bin/sh -c "doveadm auth test -x service=smtp user2@otherdomain.tld BADPASSWORD | grep 'auth failed'" - [ "$status" -eq 0 ] - } - - @test "checking sasl: sasl_passwd.db exists" { - run docker exec mail [ -f /etc/postfix/sasl_passwd.db ] - [ "$status" -eq 0 ] - } - -fi - # # logs # From 5dd25f7868d6dc504e3deac2661146839161cf3e Mon Sep 17 00:00:00 2001 From: Thomas VIAL Date: Mon, 15 Aug 2016 23:32:52 +0200 Subject: [PATCH 15/28] Refactored. --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 4439fa31..23f0c52a 100644 --- a/Makefile +++ b/Makefile @@ -27,7 +27,7 @@ run: -e SA_TAG=$(SA_TAG) \ -e SA_TAG2=$(SA_TAG2) \ -e SA_KILL=$(SA_KILL) \ - -e SASL_PASSWD=$(SASL_PASSWD) \ + -e SASL_PASSWD="$(SASL_PASSWD)" \ -e ONE_DIR=$(ONE_DIR) \ -h mail.my-domain.com -t $(NAME) # Wait for containers to fully start From ff8ca5b5b74952487a1ec11a488297aed7e768c6 Mon Sep 17 00:00:00 2001 From: Thomas VIAL Date: Tue, 16 Aug 2016 15:20:48 +0200 Subject: [PATCH 16/28] Refactored. --- test/ENABLE_POP3.bats | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/test/ENABLE_POP3.bats b/test/ENABLE_POP3.bats index 53aaf0d5..1cc08fb4 100644 --- a/test/ENABLE_POP3.bats +++ b/test/ENABLE_POP3.bats @@ -1,19 +1,18 @@ -@test "checking pop: server is ready" { - run docker exec mail /bin/bash -c "nc -w 1 0.0.0.0 110 | grep '+OK'" +@test "checking pop: ENABLE_POP3=1 => server is running" { + if [ "$ENABLE_POP3" != 1 ]; then + skip + fi - if [ "$ENABLE_POP" -eq 1 ]; then + run docker exec mail /bin/bash -c "nc -w 1 0.0.0.0 110 | grep '+OK'" [ "$status" -eq 0 ] - else - [ "$status" -eq 1 ] - fi -} + } -@test "checking pop: authentication works" { - run docker exec mail /bin/sh -c "nc -w 1 0.0.0.0 110 < /tmp/docker-mailserver-test/auth/pop3-auth.txt" - if [ "$ENABLE_POP" -eq 1 ]; then +@test "checking pop: ENABLE_POP3=1 => authentication works" { + if [ "$ENABLE_POP3" != 1 ]; then + skip + fi + + run docker exec mail /bin/sh -c "nc -w 1 0.0.0.0 110 < /tmp/docker-mailserver-test/auth/pop3-auth.txt" [ "$status" -eq 0 ] - else - [ "$status" -eq 1 ] - fi } From bec2b0ac1dc0a1c45a3c187449c89147a14a2277 Mon Sep 17 00:00:00 2001 From: Thomas VIAL Date: Tue, 16 Aug 2016 18:07:09 +0200 Subject: [PATCH 17/28] Refactored. --- Makefile | 4 ++-- test/ENABLE_POP3.bats | 18 ------------------ test/SASL_PASSWD.bats | 29 ----------------------------- 3 files changed, 2 insertions(+), 49 deletions(-) delete mode 100644 test/ENABLE_POP3.bats delete mode 100644 test/SASL_PASSWD.bats diff --git a/Makefile b/Makefile index 23f0c52a..39ea1771 100644 --- a/Makefile +++ b/Makefile @@ -57,11 +57,11 @@ tests: # Start tests ifdef ENABLE_POP3 @echo "ENABLE_POP3 => $(ENABLE_POP3)" - ./test/bats/bats test/ENABLE_POP3.bats + ./test/bats/bats test/ENABLE_POP3_$(ENABLE_POP3).bats endif ifdef SASL_PASSWD @echo "SASL_PASSWD => $(SASL_PASSWD)" - ./test/bats/bats test/SASL_PASSWD.bats + ./test/bats/bats test/SASL_PASSWD_$(SASL_PASSWD_).bats endif clean: diff --git a/test/ENABLE_POP3.bats b/test/ENABLE_POP3.bats deleted file mode 100644 index 1cc08fb4..00000000 --- a/test/ENABLE_POP3.bats +++ /dev/null @@ -1,18 +0,0 @@ -@test "checking pop: ENABLE_POP3=1 => server is running" { - if [ "$ENABLE_POP3" != 1 ]; then - skip - fi - - run docker exec mail /bin/bash -c "nc -w 1 0.0.0.0 110 | grep '+OK'" - [ "$status" -eq 0 ] - } - - -@test "checking pop: ENABLE_POP3=1 => authentication works" { - if [ "$ENABLE_POP3" != 1 ]; then - skip - fi - - run docker exec mail /bin/sh -c "nc -w 1 0.0.0.0 110 < /tmp/docker-mailserver-test/auth/pop3-auth.txt" - [ "$status" -eq 0 ] -} diff --git a/test/SASL_PASSWD.bats b/test/SASL_PASSWD.bats deleted file mode 100644 index e01cc2f0..00000000 --- a/test/SASL_PASSWD.bats +++ /dev/null @@ -1,29 +0,0 @@ -@test "checking sasl: doveadm auth test works with good password" { - run docker exec mail /bin/sh -c "doveadm auth test -x service=smtp user2@otherdomain.tld mypassword | grep 'auth succeeded'" - - if [ -n "$SASL_PASSWD" ]; then - [ "$status" -eq 0 ] - else - [ "$status" -eq 1 ] - fi -} - -@test "checking sasl: doveadm auth test fails with bad password" { - run docker exec mail /bin/sh -c "doveadm auth test -x service=smtp user2@otherdomain.tld BADPASSWORD | grep 'auth failed'" - - if [ -n "$SASL_PASSWD" ]; then - [ "$status" -eq 0 ] - else - [ "$status" -eq 1 ] - fi -} - -@test "checking sasl: sasl_passwd.db exists" { - run docker exec mail [ -f /etc/postfix/sasl_passwd.db ] - - if [ -n "$SASL_PASSWD" ]; then - [ "$status" -eq 0 ] - else - [ "$status" -eq 1 ] - fi -} From 80007a7b535c63f9f6c211f68e4134ce475e167f Mon Sep 17 00:00:00 2001 From: Thomas VIAL Date: Tue, 16 Aug 2016 18:07:40 +0200 Subject: [PATCH 18/28] Refactored. --- test/ENABLE_POP3_0.bats | 9 +++++++++ test/ENABLE_POP3_1.bats | 14 ++++++++++++++ test/SASL_PASSWD_0.bats | 4 ++++ test/SASL_PASSWD_1.bats | 14 ++++++++++++++ 4 files changed, 41 insertions(+) create mode 100644 test/ENABLE_POP3_0.bats create mode 100644 test/ENABLE_POP3_1.bats create mode 100644 test/SASL_PASSWD_0.bats create mode 100644 test/SASL_PASSWD_1.bats diff --git a/test/ENABLE_POP3_0.bats b/test/ENABLE_POP3_0.bats new file mode 100644 index 00000000..30229bd1 --- /dev/null +++ b/test/ENABLE_POP3_0.bats @@ -0,0 +1,9 @@ +@test "checking process: process is not running" { + run docker exec mail /bin/bash -c "ps aux | grep 'dovecot/pop'" + [ "$status" -eq 1 ] +} + +@test "checking pop: server does not respond on port 110" { + run docker exec mail /bin/bash -c "nc -w 1 0.0.0.0 110" + [ "$status" -eq 1 ] +} diff --git a/test/ENABLE_POP3_1.bats b/test/ENABLE_POP3_1.bats new file mode 100644 index 00000000..ccf13b0b --- /dev/null +++ b/test/ENABLE_POP3_1.bats @@ -0,0 +1,14 @@ +@test "checking process: process is running" { + run docker exec mail /bin/bash -c "ps aux | grep 'dovecot/pop'" + [ "$status" -eq 0 ] +} + +@test "checking pop: server responds on port 110" { + run docker exec mail /bin/bash -c "nc -w 1 0.0.0.0 110 | grep '+OK'" + [ "$status" -eq 0 ] +} + +@test "checking pop: authentication works" { + run docker exec mail /bin/sh -c "nc -w 1 0.0.0.0 110 < /tmp/docker-mailserver-test/auth/pop3-auth.txt" + [ "$status" -eq 0 ] +} diff --git a/test/SASL_PASSWD_0.bats b/test/SASL_PASSWD_0.bats new file mode 100644 index 00000000..10c2971e --- /dev/null +++ b/test/SASL_PASSWD_0.bats @@ -0,0 +1,4 @@ +@test "checking sasl: sasl_passwd.db should not exist" { + run docker exec mail [ -f /etc/postfix/sasl_passwd.db ] + [ "$status" -eq 1 ] +} diff --git a/test/SASL_PASSWD_1.bats b/test/SASL_PASSWD_1.bats new file mode 100644 index 00000000..7c472850 --- /dev/null +++ b/test/SASL_PASSWD_1.bats @@ -0,0 +1,14 @@ +@test "checking sasl: doveadm auth test works with good password" { + run docker exec mail /bin/sh -c "doveadm auth test -x service=smtp user2@otherdomain.tld mypassword | grep 'auth succeeded'" + [ "$status" -eq 0 ] +} + +@test "checking sasl: doveadm auth test fails with bad password" { + run docker exec mail /bin/sh -c "doveadm auth test -x service=smtp user2@otherdomain.tld BADPASSWORD | grep 'auth failed'" + [ "$status" -eq 0 ] +} + +@test "checking sasl: sasl_passwd.db exists" { + run docker exec mail [ -f /etc/postfix/sasl_passwd.db ] + [ "$status" -eq 0 ] +} From 7ab528c938bc02741443d20f56608cc2ebfa8b34 Mon Sep 17 00:00:00 2001 From: Thomas VIAL Date: Tue, 16 Aug 2016 19:10:02 +0200 Subject: [PATCH 19/28] Refactored. --- .travis.yml | 6 +++--- Makefile | 17 +++++++++-------- test/ENABLE_POP3_1.bats | 2 +- 3 files changed, 13 insertions(+), 12 deletions(-) diff --git a/.travis.yml b/.travis.yml index e86c6a30..542b4edc 100644 --- a/.travis.yml +++ b/.travis.yml @@ -9,7 +9,7 @@ script: after_script: - make clean env: - - ENABLE_POP3=0 + - ENABLE_POP3=0 - ENABLE_POP3=1 # - ENABLE_FAIL2BAN=0 # - ENABLE_FAIL2BAN=1 @@ -17,8 +17,8 @@ env: # - ENABLE_MANAGESIEVE=1 # - SMTP_ONLY=0 # - SMTP_ONLY=1 - - SASL_PASSWD= - - SASL_PASSWD="external-domain.com username:password" + # - SASL_PASSWD= + # - SASL_PASSWD="external-domain.com username:password" # - ONE_DIR=0 # - ONE_DIR=1 # - SA_TAG= diff --git a/Makefile b/Makefile index 39ea1771..6fa91aa7 100644 --- a/Makefile +++ b/Makefile @@ -55,14 +55,15 @@ fixtures: tests: # Start tests -ifdef ENABLE_POP3 - @echo "ENABLE_POP3 => $(ENABLE_POP3)" - ./test/bats/bats test/ENABLE_POP3_$(ENABLE_POP3).bats -endif -ifdef SASL_PASSWD - @echo "SASL_PASSWD => $(SASL_PASSWD)" - ./test/bats/bats test/SASL_PASSWD_$(SASL_PASSWD_).bats -endif +# ifdef ENABLE_POP3 +# @echo "ENABLE_POP3 => $(ENABLE_POP3)" +# ./test/bats/bats test/ENABLE_POP3_$(ENABLE_POP3).bats +# endif +# ifdef SASL_PASSWD +# @echo "SASL_PASSWD => $(SASL_PASSWD)" +# ./test/bats/bats test/SASL_PASSWD_$(SASL_PASSWD_).bats +# endif + ./test/bats/bats test/ENABLE_POP3.bats clean: # Remove running test container diff --git a/test/ENABLE_POP3_1.bats b/test/ENABLE_POP3_1.bats index ccf13b0b..03eec3b3 100644 --- a/test/ENABLE_POP3_1.bats +++ b/test/ENABLE_POP3_1.bats @@ -1,4 +1,4 @@ -@test "checking process: process is running" { +@test "checking pop: process is running" { run docker exec mail /bin/bash -c "ps aux | grep 'dovecot/pop'" [ "$status" -eq 0 ] } From ad99e1126e951b6e5f60df9575345b290057fbce Mon Sep 17 00:00:00 2001 From: Thomas VIAL Date: Tue, 16 Aug 2016 19:15:28 +0200 Subject: [PATCH 20/28] Refactored. --- test/ENABLE_POP3.bats | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 test/ENABLE_POP3.bats diff --git a/test/ENABLE_POP3.bats b/test/ENABLE_POP3.bats new file mode 100644 index 00000000..0e0337f8 --- /dev/null +++ b/test/ENABLE_POP3.bats @@ -0,0 +1,30 @@ +if [ "$ENABLE_POP3" = 1 ]; then + + @test "checking pop: process is running" { + run docker exec mail /bin/bash -c "ps aux | grep 'dovecot/pop'" + [ "$status" -eq 0 ] + } + + @test "checking pop: server responds on port 110" { + run docker exec mail /bin/bash -c "nc -w 1 0.0.0.0 110 | grep '+OK'" + [ "$status" -eq 0 ] + } + + @test "checking pop: authentication works" { + run docker exec mail /bin/sh -c "nc -w 1 0.0.0.0 110 < /tmp/docker-mailserver-test/auth/pop3-auth.txt" + [ "$status" -eq 0 ] + } + +else #################################################################################################### + + @test "checking process: process is not running" { + run docker exec mail /bin/bash -c "ps aux | grep 'dovecot/pop'" + [ "$status" -eq 1 ] + } + + @test "checking pop: server does not respond on port 110" { + run docker exec mail /bin/bash -c "nc -w 1 0.0.0.0 110" + [ "$status" -eq 1 ] + } + +fi From efecf09ebf53c10bbce5a1ec1a141f68c2eba83c Mon Sep 17 00:00:00 2001 From: Thomas VIAL Date: Tue, 16 Aug 2016 19:28:48 +0200 Subject: [PATCH 21/28] Refactored. --- test/ENABLE_POP3.bats | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/ENABLE_POP3.bats b/test/ENABLE_POP3.bats index 0e0337f8..ebd549df 100644 --- a/test/ENABLE_POP3.bats +++ b/test/ENABLE_POP3.bats @@ -15,10 +15,10 @@ if [ "$ENABLE_POP3" = 1 ]; then [ "$status" -eq 0 ] } -else #################################################################################################### +else skip #################################################################################################### @test "checking process: process is not running" { - run docker exec mail /bin/bash -c "ps aux | grep 'dovecot/pop'" + run docker exec mail /bin/bash -c "ps aux | grep -v grep | grep 'dovecot/pop'" [ "$status" -eq 1 ] } From be5feec1be2445eaa6d361c755977546a9352881 Mon Sep 17 00:00:00 2001 From: Thomas VIAL Date: Tue, 16 Aug 2016 19:34:41 +0200 Subject: [PATCH 22/28] Refactored. --- test/ENABLE_POP3.bats | 68 ++++++++++++++++++++++++++++--------------- 1 file changed, 45 insertions(+), 23 deletions(-) diff --git a/test/ENABLE_POP3.bats b/test/ENABLE_POP3.bats index ebd549df..9fba601c 100644 --- a/test/ENABLE_POP3.bats +++ b/test/ENABLE_POP3.bats @@ -1,30 +1,52 @@ -if [ "$ENABLE_POP3" = 1 ]; then +#################################################################################################### +# +# ENABLE_POP3=1 +# +#################################################################################################### - @test "checking pop: process is running" { - run docker exec mail /bin/bash -c "ps aux | grep 'dovecot/pop'" - [ "$status" -eq 0 ] - } +@test "checking pop: process is running" { + if [ "$ENABLE_POP3" != 1 ]; then + skip + fi + run docker exec mail /bin/bash -c "ps aux | grep 'dovecot/pop'" + [ "$status" -eq 0 ] +} - @test "checking pop: server responds on port 110" { - run docker exec mail /bin/bash -c "nc -w 1 0.0.0.0 110 | grep '+OK'" - [ "$status" -eq 0 ] - } +@test "checking pop: server responds on port 110" { + if [ "$ENABLE_POP3" != 1 ]; then + skip + fi + run docker exec mail /bin/bash -c "nc -w 1 0.0.0.0 110 | grep '+OK'" + [ "$status" -eq 0 ] +} - @test "checking pop: authentication works" { - run docker exec mail /bin/sh -c "nc -w 1 0.0.0.0 110 < /tmp/docker-mailserver-test/auth/pop3-auth.txt" - [ "$status" -eq 0 ] - } +@test "checking pop: authentication works" { + if [ "$ENABLE_POP3" != 1 ]; then + skip + fi + run docker exec mail /bin/sh -c "nc -w 1 0.0.0.0 110 < /tmp/docker-mailserver-test/auth/pop3-auth.txt" + [ "$status" -eq 0 ] +} -else skip #################################################################################################### +#################################################################################################### +# +# ENABLE_POP3!=1 +# +#################################################################################################### - @test "checking process: process is not running" { - run docker exec mail /bin/bash -c "ps aux | grep -v grep | grep 'dovecot/pop'" - [ "$status" -eq 1 ] - } +@test "checking process: process is not running" { + if [ "$ENABLE_POP3" = 1 ]; then + skip + fi + run docker exec mail /bin/bash -c "ps aux | grep -v grep | grep 'dovecot/pop'" + [ "$status" -eq 1 ] +} - @test "checking pop: server does not respond on port 110" { - run docker exec mail /bin/bash -c "nc -w 1 0.0.0.0 110" - [ "$status" -eq 1 ] - } +@test "checking pop: server does not respond on port 110" { + if [ "$ENABLE_POP3" = 1 ]; then + skip + fi + run docker exec mail /bin/bash -c "nc -w 1 0.0.0.0 110" + [ "$status" -eq 1 ] +} -fi From e57724befd58af3d78dd3ddb39c89bc139fe9fed Mon Sep 17 00:00:00 2001 From: Thomas VIAL Date: Tue, 16 Aug 2016 19:44:46 +0200 Subject: [PATCH 23/28] Refactored. --- Makefile | 9 +-------- test/ENABLE_POP3_0.bats | 9 --------- test/ENABLE_POP3_1.bats | 14 -------------- test/SASL_PASSWD.bats | 43 +++++++++++++++++++++++++++++++++++++++++ test/SASL_PASSWD_0.bats | 4 ---- test/SASL_PASSWD_1.bats | 14 -------------- 6 files changed, 44 insertions(+), 49 deletions(-) delete mode 100644 test/ENABLE_POP3_0.bats delete mode 100644 test/ENABLE_POP3_1.bats create mode 100644 test/SASL_PASSWD.bats delete mode 100644 test/SASL_PASSWD_0.bats delete mode 100644 test/SASL_PASSWD_1.bats diff --git a/Makefile b/Makefile index 6fa91aa7..3979a268 100644 --- a/Makefile +++ b/Makefile @@ -55,15 +55,8 @@ fixtures: tests: # Start tests -# ifdef ENABLE_POP3 -# @echo "ENABLE_POP3 => $(ENABLE_POP3)" -# ./test/bats/bats test/ENABLE_POP3_$(ENABLE_POP3).bats -# endif -# ifdef SASL_PASSWD -# @echo "SASL_PASSWD => $(SASL_PASSWD)" -# ./test/bats/bats test/SASL_PASSWD_$(SASL_PASSWD_).bats -# endif ./test/bats/bats test/ENABLE_POP3.bats + ./test/bats/bats test/SASL_PASSWD.bats clean: # Remove running test container diff --git a/test/ENABLE_POP3_0.bats b/test/ENABLE_POP3_0.bats deleted file mode 100644 index 30229bd1..00000000 --- a/test/ENABLE_POP3_0.bats +++ /dev/null @@ -1,9 +0,0 @@ -@test "checking process: process is not running" { - run docker exec mail /bin/bash -c "ps aux | grep 'dovecot/pop'" - [ "$status" -eq 1 ] -} - -@test "checking pop: server does not respond on port 110" { - run docker exec mail /bin/bash -c "nc -w 1 0.0.0.0 110" - [ "$status" -eq 1 ] -} diff --git a/test/ENABLE_POP3_1.bats b/test/ENABLE_POP3_1.bats deleted file mode 100644 index 03eec3b3..00000000 --- a/test/ENABLE_POP3_1.bats +++ /dev/null @@ -1,14 +0,0 @@ -@test "checking pop: process is running" { - run docker exec mail /bin/bash -c "ps aux | grep 'dovecot/pop'" - [ "$status" -eq 0 ] -} - -@test "checking pop: server responds on port 110" { - run docker exec mail /bin/bash -c "nc -w 1 0.0.0.0 110 | grep '+OK'" - [ "$status" -eq 0 ] -} - -@test "checking pop: authentication works" { - run docker exec mail /bin/sh -c "nc -w 1 0.0.0.0 110 < /tmp/docker-mailserver-test/auth/pop3-auth.txt" - [ "$status" -eq 0 ] -} diff --git a/test/SASL_PASSWD.bats b/test/SASL_PASSWD.bats new file mode 100644 index 00000000..ac7111eb --- /dev/null +++ b/test/SASL_PASSWD.bats @@ -0,0 +1,43 @@ +#################################################################################################### +# +# SASL_PASSWD provided +# +#################################################################################################### + +@test "checking sasl: doveadm auth test works with good password" { + if [ -z "$SASL_PASSWD" ]; then + skip + fi + run docker exec mail /bin/sh -c "doveadm auth test -x service=smtp user2@otherdomain.tld mypassword | grep 'auth succeeded'" + [ "$status" -eq 0 ] +} + +@test "checking sasl: doveadm auth test fails with bad password" { + if [ -z "$SASL_PASSWD" ]; then + skip + fi + run docker exec mail /bin/sh -c "doveadm auth test -x service=smtp user2@otherdomain.tld BADPASSWORD | grep 'auth failed'" + [ "$status" -eq 0 ] +} + +@test "checking sasl: sasl_passwd.db exists" { + if [ -z "$SASL_PASSWD" ]; then + skip + fi + run docker exec mail [ -f /etc/postfix/sasl_passwd.db ] + [ "$status" -eq 0 ] +} + +#################################################################################################### +# +# SASL_PASSWD not provided +# +#################################################################################################### + +@test "checking sasl: sasl_passwd.db should not exist" { + if [ -n "$SASL_PASSWD" ]; then + skip + fi + run docker exec mail [ -f /etc/postfix/sasl_passwd.db ] + [ "$status" -eq 1 ] +} diff --git a/test/SASL_PASSWD_0.bats b/test/SASL_PASSWD_0.bats deleted file mode 100644 index 10c2971e..00000000 --- a/test/SASL_PASSWD_0.bats +++ /dev/null @@ -1,4 +0,0 @@ -@test "checking sasl: sasl_passwd.db should not exist" { - run docker exec mail [ -f /etc/postfix/sasl_passwd.db ] - [ "$status" -eq 1 ] -} diff --git a/test/SASL_PASSWD_1.bats b/test/SASL_PASSWD_1.bats deleted file mode 100644 index 7c472850..00000000 --- a/test/SASL_PASSWD_1.bats +++ /dev/null @@ -1,14 +0,0 @@ -@test "checking sasl: doveadm auth test works with good password" { - run docker exec mail /bin/sh -c "doveadm auth test -x service=smtp user2@otherdomain.tld mypassword | grep 'auth succeeded'" - [ "$status" -eq 0 ] -} - -@test "checking sasl: doveadm auth test fails with bad password" { - run docker exec mail /bin/sh -c "doveadm auth test -x service=smtp user2@otherdomain.tld BADPASSWORD | grep 'auth failed'" - [ "$status" -eq 0 ] -} - -@test "checking sasl: sasl_passwd.db exists" { - run docker exec mail [ -f /etc/postfix/sasl_passwd.db ] - [ "$status" -eq 0 ] -} From 5f602aa323fc465f644aff1a50765a165480e75d Mon Sep 17 00:00:00 2001 From: Thomas VIAL Date: Tue, 16 Aug 2016 19:46:27 +0200 Subject: [PATCH 24/28] Refactored. --- .travis.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 542b4edc..2dd5bbea 100644 --- a/.travis.yml +++ b/.travis.yml @@ -17,8 +17,8 @@ env: # - ENABLE_MANAGESIEVE=1 # - SMTP_ONLY=0 # - SMTP_ONLY=1 - # - SASL_PASSWD= - # - SASL_PASSWD="external-domain.com username:password" + - SASL_PASSWD= + - SASL_PASSWD="external-domain.com username:password" # - ONE_DIR=0 # - ONE_DIR=1 # - SA_TAG= From aa396c5af5c538c393c2939041c0160080590268 Mon Sep 17 00:00:00 2001 From: Thomas VIAL Date: Wed, 17 Aug 2016 10:15:34 +0200 Subject: [PATCH 25/28] Refactored. --- Makefile | 5 ++--- test/{tests.bats => tests._bats} | 0 2 files changed, 2 insertions(+), 3 deletions(-) rename test/{tests.bats => tests._bats} (100%) diff --git a/Makefile b/Makefile index 3979a268..6a2b8df6 100644 --- a/Makefile +++ b/Makefile @@ -54,9 +54,8 @@ fixtures: sleep 10 tests: -# Start tests - ./test/bats/bats test/ENABLE_POP3.bats - ./test/bats/bats test/SASL_PASSWD.bats + # Start tests + ./test/bats/bats test/*.bats clean: # Remove running test container diff --git a/test/tests.bats b/test/tests._bats similarity index 100% rename from test/tests.bats rename to test/tests._bats From 7becd45f64e3be822ef11eaf677ab31f369fbeda Mon Sep 17 00:00:00 2001 From: Thomas VIAL Date: Wed, 17 Aug 2016 14:03:33 +0200 Subject: [PATCH 26/28] Refactored. --- ...{ENABLE_POP3.bats => env_ENABLE_POP3.bats} | 2 +- ...{SASL_PASSWD.bats => env_SASL_PASSWD.bats} | 0 test/env_SA_XXX.bats | 59 +++++ test/env_SMTP_ONLY.bats | 4 + test/global.bats | 160 +++++++++++++ test/tests._bats | 214 ------------------ 6 files changed, 224 insertions(+), 215 deletions(-) rename test/{ENABLE_POP3.bats => env_ENABLE_POP3.bats} (96%) rename test/{SASL_PASSWD.bats => env_SASL_PASSWD.bats} (100%) create mode 100644 test/env_SA_XXX.bats create mode 100644 test/env_SMTP_ONLY.bats create mode 100644 test/global.bats diff --git a/test/ENABLE_POP3.bats b/test/env_ENABLE_POP3.bats similarity index 96% rename from test/ENABLE_POP3.bats rename to test/env_ENABLE_POP3.bats index 9fba601c..b1e1fbcc 100644 --- a/test/ENABLE_POP3.bats +++ b/test/env_ENABLE_POP3.bats @@ -34,7 +34,7 @@ # #################################################################################################### -@test "checking process: process is not running" { +@test "checking pop: process is not running" { if [ "$ENABLE_POP3" = 1 ]; then skip fi diff --git a/test/SASL_PASSWD.bats b/test/env_SASL_PASSWD.bats similarity index 100% rename from test/SASL_PASSWD.bats rename to test/env_SASL_PASSWD.bats diff --git a/test/env_SA_XXX.bats b/test/env_SA_XXX.bats new file mode 100644 index 00000000..f486eab1 --- /dev/null +++ b/test/env_SA_XXX.bats @@ -0,0 +1,59 @@ +#################################################################################################### +# +# SA_XXX with default configuraton +# +#################################################################################################### + +@test "checking spamassassin: docker env variables are set correctly (default)" { + if [ -n "$SA_TAG" ]; then + skip + fi + run docker exec mail /bin/sh -c "grep '\$sa_tag_level_deflt' /etc/amavis/conf.d/20-debian_defaults | grep '= 2.0'" + [ "$status" -eq 0 ] +} + +@test "checking spamassassin: docker env variables are set correctly (default)" { + if [ -n "$SA_TAG2" ]; then + skip + fi + run docker exec mail /bin/sh -c "grep '\$sa_tag2_level_deflt' /etc/amavis/conf.d/20-debian_defaults | grep '= 6.31'" + [ "$status" -eq 0 ] +} + +@test "checking spamassassin: docker env variables are set correctly (default)" { + if [ -n "$SA_KILL" ]; then + skip + fi + run docker exec mail /bin/sh -c "grep '\$sa_kill_level_deflt' /etc/amavis/conf.d/20-debian_defaults | grep '= 6.31'" + [ "$status" -eq 0 ] +} + +#################################################################################################### +# +# SA_XXX with custom configuraton +# +#################################################################################################### + +@test "checking spamassassin: docker env variables are set correctly (default)" { + if [ -z "$SA_TAG" ]; then + skip + fi + run docker exec mail /bin/sh -c "grep '\$sa_tag_level_deflt' /etc/amavis/conf.d/20-debian_defaults | grep '= $SA_TAG'" + [ "$status" -eq 0 ] +} + +@test "checking spamassassin: docker env variables are set correctly (default)" { + if [ -z "$SA_TAG" ]; then + skip + fi + run docker exec mail /bin/sh -c "grep '\$sa_tag2_level_deflt' /etc/amavis/conf.d/20-debian_defaults | grep '= $SA_TAG2'" + [ "$status" -eq 0 ] +} + +@test "checking spamassassin: docker env variables are set correctly (default)" { + if [ -z "$SA_TAG" ]; then + skip + fi + run docker exec mail /bin/sh -c "grep '\$sa_kill_level_deflt' /etc/amavis/conf.d/20-debian_defaults | grep '= $SA_KILL'" + [ "$status" -eq 0 ] +} diff --git a/test/env_SMTP_ONLY.bats b/test/env_SMTP_ONLY.bats new file mode 100644 index 00000000..7d90ea3c --- /dev/null +++ b/test/env_SMTP_ONLY.bats @@ -0,0 +1,4 @@ +@test "checking process: dovecot imaplogin (disabled using SMTP_ONLY)" { + run docker exec mail_smtponly /bin/bash -c "ps aux --forest | grep -v grep | grep '/usr/sbin/dovecot'" + [ "$status" -eq 1 ] +} \ No newline at end of file diff --git a/test/global.bats b/test/global.bats new file mode 100644 index 00000000..23204c78 --- /dev/null +++ b/test/global.bats @@ -0,0 +1,160 @@ +# +# imap +# + +@test "checking process: dovecot imaplogin (enabled in default configuration)" { + run docker exec mail /bin/bash -c "ps aux --forest | grep -v grep | grep '/usr/sbin/dovecot'" + [ "$status" -eq 0 ] +} + +@test "checking imap: server is ready with STARTTLS" { + run docker exec mail /bin/bash -c "nc -w 2 0.0.0.0 143 | grep '* OK' | grep 'STARTTLS' | grep 'ready'" + [ "$status" -eq 0 ] +} + +@test "checking imap: authentication works" { + run docker exec mail /bin/sh -c "nc -w 1 0.0.0.0 143 < /tmp/docker-mailserver-test/auth/imap-auth.txt" + [ "$status" -eq 0 ] +} + +# +# logs +# + +@test "checking logs: mail related logs should be located in a subdirectory" { + run docker exec mail /bin/sh -c "ls -1 /var/log/mail/ | grep -E 'clamav|freshclam|mail'|wc -l" + [ "$status" -eq 0 ] + [ "$output" = 3 ] +} + +# +# smtp +# + +@test "checking smtp: authentication works with good password (plain)" { + run docker exec mail /bin/sh -c "nc -w 5 0.0.0.0 25 < /tmp/docker-mailserver-test/auth/smtp-auth-plain.txt | grep 'Authentication successful'" + [ "$status" -eq 0 ] +} + +@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'" + [ "$status" -eq 0 ] +} + +@test "checking smtp: authentication works with good password (login)" { + run docker exec mail /bin/sh -c "nc -w 5 0.0.0.0 25 < /tmp/docker-mailserver-test/auth/smtp-auth-login.txt | grep 'Authentication successful'" + [ "$status" -eq 0 ] +} + +@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'" + [ "$status" -eq 0 ] +} + +@test "checking smtp: delivers mail to existing account" { + run docker exec mail /bin/sh -c "grep 'status=sent (delivered via dovecot service)' /var/log/mail/mail.log | wc -l" + [ "$status" -eq 0 ] + [ "$output" -eq 6 ] +} + +@test "checking smtp: delivers mail to existing alias" { + run docker exec mail /bin/sh -c "grep 'to=, orig_to=' /var/log/mail/mail.log | grep 'status=sent' | wc -l" + [ "$status" -eq 0 ] + [ "$output" = 1 ] +} + +@test "checking smtp: delivers mail to existing catchall" { + run docker exec mail /bin/sh -c "grep 'to=, orig_to=' /var/log/mail/mail.log | grep 'status=sent' | wc -l" + [ "$status" -eq 0 ] + [ "$output" = 1 ] +} + +@test "checking smtp: delivers mail to regexp alias" { + run docker exec mail /bin/sh -c "grep 'to=, orig_to=' /var/log/mail/mail.log | grep 'status=sent' | wc -l" + [ "$status" -eq 0 ] + [ "$output" = 1 ] +} + +@test "checking smtp: user1 should have received 5 mails" { + run docker exec mail /bin/sh -c "ls -A /var/mail/localhost.localdomain/user1/new | wc -l" + [ "$status" -eq 0 ] + [ "$output" = 5 ] +} + +@test "checking smtp: rejects mail to unknown user" { + run docker exec mail /bin/sh -c "grep ': Recipient address rejected: User unknown in virtual mailbox table' /var/log/mail/mail.log | wc -l" + [ "$status" -eq 0 ] + [ "$output" = 1 ] +} + +@test "checking smtp: redirects mail to external aliases" { + run docker exec mail /bin/sh -c "grep -- '-> ' /var/log/mail/mail.log | wc -l" + [ "$status" -eq 0 ] + [ "$output" = 2 ] +} + +@test "checking smtp: rejects spam" { + run docker exec mail /bin/sh -c "grep 'Blocked SPAM' /var/log/mail/mail.log | grep spam@external.tld | wc -l" + [ "$status" -eq 0 ] + [ "$output" = 1 ] +} + +@test "checking smtp: rejects virus" { + run docker exec mail /bin/sh -c "grep 'Blocked INFECTED' /var/log/mail/mail.log | grep virus@external.tld | wc -l" + [ "$status" -eq 0 ] + [ "$output" = 1 ] +} + +# +# accounts +# + +@test "checking accounts: user accounts" { + run docker exec mail doveadm user '*' + [ "$status" -eq 0 ] + [ "${lines[0]}" = "user1@localhost.localdomain" ] + [ "${lines[1]}" = "user2@otherdomain.tld" ] +} + +@test "checking accounts: user mail folders for user1" { + run docker exec mail /bin/bash -c "ls -A /var/mail/localhost.localdomain/user1 | grep -E '.Drafts|.Sent|.Trash|cur|new|subscriptions|tmp' | wc -l" + [ "$status" -eq 0 ] + [ "$output" -eq 7 ] +} + +@test "checking accounts: user mail folders for user2" { + run docker exec mail /bin/bash -c "ls -A /var/mail/otherdomain.tld/user2 | grep -E '.Drafts|.Sent|.Trash|cur|new|subscriptions|tmp' | wc -l" + [ "$status" -eq 0 ] + [ "$output" -eq 7 ] +} + +# +# postfix +# + +@test "checking postfix: vhost file is correct" { + run docker exec mail cat /etc/postfix/vhost + [ "$status" -eq 0 ] + [ "${lines[0]}" = "localdomain2.com" ] + [ "${lines[1]}" = "localhost.localdomain" ] + [ "${lines[2]}" = "otherdomain.tld" ] +} + +@test "checking postfix: main.cf overrides" { + run docker exec mail grep -q 'max_idle = 600s' /tmp/docker-mailserver/postfix-main.cf + [ "$status" -eq 0 ] + run docker exec mail grep -q 'readme_directory = /tmp' /tmp/docker-mailserver/postfix-main.cf + [ "$status" -eq 0 ] +} + +# +# dovecot +# + +@test "checking dovecot: config additions" { + run docker exec mail grep -q 'mail_max_userip_connections = 69' /tmp/docker-mailserver/dovecot.cf + [ "$status" -eq 0 ] + run docker exec mail /bin/sh -c "doveconf | grep 'mail_max_userip_connections = 69'" + [ "$status" -eq 0 ] + [ "$output" = 'mail_max_userip_connections = 69' ] +} \ No newline at end of file diff --git a/test/tests._bats b/test/tests._bats index 27cbf331..5d24a7d8 100644 --- a/test/tests._bats +++ b/test/tests._bats @@ -60,220 +60,6 @@ fi [ "$status" -eq 1 ] } -# -# imap -# - -@test "checking process: dovecot imaplogin (enabled in default configuration)" { - run docker exec mail /bin/bash -c "ps aux --forest | grep -v grep | grep '/usr/sbin/dovecot'" - [ "$status" -eq 0 ] -} - -@test "checking process: dovecot imaplogin (disabled using SMTP_ONLY)" { - run docker exec mail_smtponly /bin/bash -c "ps aux --forest | grep -v grep | grep '/usr/sbin/dovecot'" - [ "$status" -eq 1 ] -} - -@test "checking imap: server is ready with STARTTLS" { - run docker exec mail /bin/bash -c "nc -w 2 0.0.0.0 143 | grep '* OK' | grep 'STARTTLS' | grep 'ready'" - [ "$status" -eq 0 ] -} - -@test "checking imap: authentication works" { - run docker exec mail /bin/sh -c "nc -w 1 0.0.0.0 143 < /tmp/docker-mailserver-test/auth/imap-auth.txt" - [ "$status" -eq 0 ] -} - -# -# logs -# - -@test "checking logs: mail related logs should be located in a subdirectory" { - run docker exec mail /bin/sh -c "ls -1 /var/log/mail/ | grep -E 'clamav|freshclam|mail'|wc -l" - [ "$status" -eq 0 ] - [ "$output" = 3 ] -} - -# -# smtp -# - -@test "checking smtp: authentication works with good password (plain)" { - run docker exec mail /bin/sh -c "nc -w 5 0.0.0.0 25 < /tmp/docker-mailserver-test/auth/smtp-auth-plain.txt | grep 'Authentication successful'" - [ "$status" -eq 0 ] -} - -@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'" - [ "$status" -eq 0 ] -} - -@test "checking smtp: authentication works with good password (login)" { - run docker exec mail /bin/sh -c "nc -w 5 0.0.0.0 25 < /tmp/docker-mailserver-test/auth/smtp-auth-login.txt | grep 'Authentication successful'" - [ "$status" -eq 0 ] -} - -@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'" - [ "$status" -eq 0 ] -} - -@test "checking smtp: delivers mail to existing account" { - run docker exec mail /bin/sh -c "grep 'status=sent (delivered via dovecot service)' /var/log/mail/mail.log | wc -l" - [ "$status" -eq 0 ] - [ "$output" -eq 6 ] -} - -@test "checking smtp: delivers mail to existing alias" { - run docker exec mail /bin/sh -c "grep 'to=, orig_to=' /var/log/mail/mail.log | grep 'status=sent' | wc -l" - [ "$status" -eq 0 ] - [ "$output" = 1 ] -} - -@test "checking smtp: delivers mail to existing catchall" { - run docker exec mail /bin/sh -c "grep 'to=, orig_to=' /var/log/mail/mail.log | grep 'status=sent' | wc -l" - [ "$status" -eq 0 ] - [ "$output" = 1 ] -} - -@test "checking smtp: delivers mail to regexp alias" { - run docker exec mail /bin/sh -c "grep 'to=, orig_to=' /var/log/mail/mail.log | grep 'status=sent' | wc -l" - [ "$status" -eq 0 ] - [ "$output" = 1 ] -} - -@test "checking smtp: user1 should have received 5 mails" { - run docker exec mail /bin/sh -c "ls -A /var/mail/localhost.localdomain/user1/new | wc -l" - [ "$status" -eq 0 ] - [ "$output" = 5 ] -} - -@test "checking smtp: rejects mail to unknown user" { - run docker exec mail /bin/sh -c "grep ': Recipient address rejected: User unknown in virtual mailbox table' /var/log/mail/mail.log | wc -l" - [ "$status" -eq 0 ] - [ "$output" = 1 ] -} - -@test "checking smtp: redirects mail to external aliases" { - run docker exec mail /bin/sh -c "grep -- '-> ' /var/log/mail/mail.log | wc -l" - [ "$status" -eq 0 ] - [ "$output" = 2 ] -} - -@test "checking smtp: rejects spam" { - run docker exec mail /bin/sh -c "grep 'Blocked SPAM' /var/log/mail/mail.log | grep spam@external.tld | wc -l" - [ "$status" -eq 0 ] - [ "$output" = 1 ] -} - -@test "checking smtp: rejects virus" { - run docker exec mail /bin/sh -c "grep 'Blocked INFECTED' /var/log/mail/mail.log | grep virus@external.tld | wc -l" - [ "$status" -eq 0 ] - [ "$output" = 1 ] -} - -# -# accounts -# - -@test "checking accounts: user accounts" { - run docker exec mail doveadm user '*' - [ "$status" -eq 0 ] - [ "${lines[0]}" = "user1@localhost.localdomain" ] - [ "${lines[1]}" = "user2@otherdomain.tld" ] -} - -@test "checking accounts: user mail folders for user1" { - run docker exec mail /bin/bash -c "ls -A /var/mail/localhost.localdomain/user1 | grep -E '.Drafts|.Sent|.Trash|cur|new|subscriptions|tmp' | wc -l" - [ "$status" -eq 0 ] - [ "$output" -eq 7 ] -} - -@test "checking accounts: user mail folders for user2" { - run docker exec mail /bin/bash -c "ls -A /var/mail/otherdomain.tld/user2 | grep -E '.Drafts|.Sent|.Trash|cur|new|subscriptions|tmp' | wc -l" - [ "$status" -eq 0 ] - [ "$output" -eq 7 ] -} - -# -# postfix -# - -@test "checking postfix: vhost file is correct" { - run docker exec mail cat /etc/postfix/vhost - [ "$status" -eq 0 ] - [ "${lines[0]}" = "localdomain2.com" ] - [ "${lines[1]}" = "localhost.localdomain" ] - [ "${lines[2]}" = "otherdomain.tld" ] -} - -@test "checking postfix: main.cf overrides" { - run docker exec mail grep -q 'max_idle = 600s' /tmp/docker-mailserver/postfix-main.cf - [ "$status" -eq 0 ] - run docker exec mail grep -q 'readme_directory = /tmp' /tmp/docker-mailserver/postfix-main.cf - [ "$status" -eq 0 ] -} - -# -# dovecot -# - -@test "checking dovecot: config additions" { - run docker exec mail grep -q 'mail_max_userip_connections = 69' /tmp/docker-mailserver/dovecot.cf - [ "$status" -eq 0 ] - run docker exec mail /bin/sh -c "doveconf | grep 'mail_max_userip_connections = 69'" - [ "$status" -eq 0 ] - [ "$output" = 'mail_max_userip_connections = 69' ] -} - -# -# spamassassin -# - -if [ -z $SA_TAG ]; then - @test "checking spamassassin: docker env variables are set correctly (default)" { - run docker exec mail_pop3 /bin/sh -c "grep '\$sa_tag_level_deflt' /etc/amavis/conf.d/20-debian_defaults | grep '= 2.0'" - [ "$status" -eq 0 ] - } -fi - -if [ -z $SA_TAG2 ]; then - @test "checking spamassassin: docker env variables are set correctly (default)" { - run docker exec mail_pop3 /bin/sh -c "grep '\$sa_tag2_level_deflt' /etc/amavis/conf.d/20-debian_defaults | grep '= 6.31'" - [ "$status" -eq 0 ] - } -fi - -if [ -z $SA_KILL ]; then - @test "checking spamassassin: docker env variables are set correctly (default)" { - run docker exec mail_pop3 /bin/sh -c "grep '\$sa_kill_level_deflt' /etc/amavis/conf.d/20-debian_defaults | grep '= 6.31'" - [ "$status" -eq 0 ] - } -fi - - -if [ -n $SA_TAG ]; then - @test "checking spamassassin: docker env variables are set correctly (default)" { - run docker exec mail_pop3 /bin/sh -c "grep '\$sa_tag_level_deflt' /etc/amavis/conf.d/20-debian_defaults | grep '= $SA_TAG'" - [ "$status" -eq 0 ] - } -fi - -if [ -n $SA_TAG2 ]; then - @test "checking spamassassin: docker env variables are set correctly (default)" { - run docker exec mail_pop3 /bin/sh -c "grep '\$sa_tag2_level_deflt' /etc/amavis/conf.d/20-debian_defaults | grep '= $SA_TAG2'" - [ "$status" -eq 0 ] - } -fi - -if [ -n $SA_KILL ]; then - @test "checking spamassassin: docker env variables are set correctly (default)" { - run docker exec mail_pop3 /bin/sh -c "grep '\$sa_kill_level_deflt' /etc/amavis/conf.d/20-debian_defaults | grep '= $SA_KILL'" - [ "$status" -eq 0 ] - } -fi - - # # opendkim # From 4d41f3857643e1f34cabce129af1684cbd03a001 Mon Sep 17 00:00:00 2001 From: Thomas VIAL Date: Wed, 17 Aug 2016 14:06:48 +0200 Subject: [PATCH 27/28] Refactored. --- .travis.yml | 29 ++++++++++------------------- test/env_SMTP_ONLY.bats | 3 +++ 2 files changed, 13 insertions(+), 19 deletions(-) diff --git a/.travis.yml b/.travis.yml index 2dd5bbea..6bf3a6e6 100644 --- a/.travis.yml +++ b/.travis.yml @@ -11,28 +11,19 @@ after_script: env: - ENABLE_POP3=0 - ENABLE_POP3=1 + - SA_TAG= SA_TAG2= SA_KILL= + - SA_TAG=1.0 SA_TAG2=2.0 SA_KILL=3.0 + - SASL_PASSWD= + - SASL_PASSWD="external-domain.com username:password" + - SMTP_ONLY=0 + - SMTP_ONLY=1 # - ENABLE_FAIL2BAN=0 # - ENABLE_FAIL2BAN=1 # - ENABLE_MANAGESIEVE=0 # - ENABLE_MANAGESIEVE=1 - # - SMTP_ONLY=0 - # - SMTP_ONLY=1 - - SASL_PASSWD= - - SASL_PASSWD="external-domain.com username:password" # - ONE_DIR=0 # - ONE_DIR=1 - # - SA_TAG= - # - SA_TAG=1.0 - # - SA_TAG2= - # - SA_TAG2=2.0 - # - SA_KILL= - # - SA_KILL=3.0 - - - - -# SSL_TYPE -# -# DISABLE_AMAVIS=0 -# DISABLE_SPAMASSASSIN=1 -# DISABLE_CLAMAV=1 + # - SSL_TYPE + # - DISABLE_AMAVIS=0 + # - DISABLE_SPAMASSASSIN=1 + # - DISABLE_CLAMAV=1 diff --git a/test/env_SMTP_ONLY.bats b/test/env_SMTP_ONLY.bats index 7d90ea3c..339ea76c 100644 --- a/test/env_SMTP_ONLY.bats +++ b/test/env_SMTP_ONLY.bats @@ -1,4 +1,7 @@ @test "checking process: dovecot imaplogin (disabled using SMTP_ONLY)" { + if [ "$SMTP_ONLY" != 1 ]; then + skip + fi run docker exec mail_smtponly /bin/bash -c "ps aux --forest | grep -v grep | grep '/usr/sbin/dovecot'" [ "$status" -eq 1 ] } \ No newline at end of file From 140cbc787b8deb6fa1974a01675d3295b97d408f Mon Sep 17 00:00:00 2001 From: Thomas VIAL Date: Wed, 17 Aug 2016 14:17:55 +0200 Subject: [PATCH 28/28] Refactored. --- test/env_SA_XXX.bats | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/test/env_SA_XXX.bats b/test/env_SA_XXX.bats index f486eab1..920c0f17 100644 --- a/test/env_SA_XXX.bats +++ b/test/env_SA_XXX.bats @@ -4,7 +4,7 @@ # #################################################################################################### -@test "checking spamassassin: docker env variables are set correctly (default)" { +@test "checking spamassassin: sa_tag_level_deflt is set correctly (default)" { if [ -n "$SA_TAG" ]; then skip fi @@ -12,7 +12,7 @@ [ "$status" -eq 0 ] } -@test "checking spamassassin: docker env variables are set correctly (default)" { +@test "checking spamassassin: sa_tag2_level_deflt is set correctly (default)" { if [ -n "$SA_TAG2" ]; then skip fi @@ -20,7 +20,7 @@ [ "$status" -eq 0 ] } -@test "checking spamassassin: docker env variables are set correctly (default)" { +@test "checking spamassassin: sa_kill_level_deflt is set correctly (default)" { if [ -n "$SA_KILL" ]; then skip fi @@ -34,7 +34,7 @@ # #################################################################################################### -@test "checking spamassassin: docker env variables are set correctly (default)" { +@test "checking spamassassin: sa_tag_level_deflt is set correctly (custom)" { if [ -z "$SA_TAG" ]; then skip fi @@ -42,7 +42,7 @@ [ "$status" -eq 0 ] } -@test "checking spamassassin: docker env variables are set correctly (default)" { +@test "checking spamassassin: sa_tag2_level_deflt is set correctly (custom)" { if [ -z "$SA_TAG" ]; then skip fi @@ -50,7 +50,7 @@ [ "$status" -eq 0 ] } -@test "checking spamassassin: docker env variables are set correctly (default)" { +@test "checking spamassassin: sa_kill_level_deflt is set correctly (custom)" { if [ -z "$SA_TAG" ]; then skip fi