From 6e39d63697dae2fa8fdf1aaca7beed08ee126956 Mon Sep 17 00:00:00 2001 From: kamuri Date: Sun, 8 Oct 2017 22:42:26 +0200 Subject: [PATCH] Add Test and small Fixes. postfix restart via supervisorctl is buggy. see.: https://github.com/tomav/docker-mailserver/issues/552#issuecomment-335035758 --- .travis.yml | 2 +- Makefile | 8 +++-- target/check_for_changes.sh | 30 ++++++++++++----- test/auth/added-imap-auth.txt | 4 +++ test/auth/added-pop3-auth.txt | 4 +++ test/auth/added-smtp-auth-login-wrong.txt | 4 +++ test/auth/added-smtp-auth-login.txt | 4 +++ test/auth/added-smtp-auth-plain-wrong.txt | 3 ++ test/auth/added-smtp-auth-plain.txt | 3 ++ test/email-templates/existing-added.txt | 12 +++++++ test/tests.bats | 41 +++++++++++++++++++++-- 11 files changed, 102 insertions(+), 13 deletions(-) create mode 100644 test/auth/added-imap-auth.txt create mode 100644 test/auth/added-pop3-auth.txt create mode 100644 test/auth/added-smtp-auth-login-wrong.txt create mode 100644 test/auth/added-smtp-auth-login.txt create mode 100644 test/auth/added-smtp-auth-plain-wrong.txt create mode 100644 test/auth/added-smtp-auth-plain.txt create mode 100644 test/email-templates/existing-added.txt diff --git a/.travis.yml b/.travis.yml index b6bf81c5..9bccf6d4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -8,7 +8,7 @@ services: install: - travis_retry travis_wait make build-no-cache script: -- make generate-accounts run fixtures tests +- make generate-accounts run generate-accounts-after-run fixtures tests after_script: - make clean notifications: diff --git a/Makefile b/Makefile index 496e18d1..5a67b89a 100644 --- a/Makefile +++ b/Makefile @@ -160,7 +160,10 @@ run: -h mail.my-domain.com -t $(NAME) sleep 20 - +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 + sleep 10 + fixtures: cp config/postfix-accounts.cf config/postfix-accounts.cf.bak # Setup sieve & create filtering folder (INBOX/spam) @@ -175,6 +178,7 @@ fixtures: 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" @@ -188,7 +192,7 @@ fixtures: 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 60 + sleep 75 tests: # Start tests diff --git a/target/check_for_changes.sh b/target/check_for_changes.sh index a78b58ff..ca27752d 100755 --- a/target/check_for_changes.sh +++ b/target/check_for_changes.sh @@ -1,8 +1,18 @@ #! /bin/bash -while true; do +# Prevent a start too early +sleep 5 + +# change directory cd /tmp/docker-mailserver +# Update / generate after start +echo 'Makeing new chksum' +sha512sum --tag postfix-accounts.cf --tag postfix-virtual.cf > chksum + +# Run forever +while true; do + # Check postfix-virtual.cf exist else break if [ ! -f postfix-virtual.cf ]; then echo 'postfix-virtual.cf is missing! exit!' @@ -15,10 +25,6 @@ if [ ! -f postfix-accounts.cf ]; then break; fi -# Check chksum exist else create -if [ ! -f chksum ]; then - sha512sum --tag postfix-accounts.cf --tag postfix-virtual.cf > chksum -fi # Get chksum and check it. chksum=$(sha512sum -c chksum) @@ -100,10 +106,18 @@ if ! [ $resu_acc = "OK" ] || ! [ $resu_vir = "OK" ]; then if [ `find /var/mail -maxdepth 3 -a \( \! -user 5000 -o \! -group 5000 \) | grep -c .` != 0 ]; then chown -R 5000:5000 /var/mail fi + + + #supervisorctl restart postfix # Buggy causes error while testing. + postfix reload + + # Prevent restart of dovecot when smtp_only=1 + if [ ! -f $SMTP_ONLY = 1 ]; then + supervisorctl restart dovecot + fi - supervisorctl restart postfix - supervisorctl restart dovecot - sha512sum --tag postfix-accounts.cf --tag postfix-virtual.cf > chksum + echo 'Update chksum' + sha512sum --tag postfix-accounts.cf --tag postfix-virtual.cf > chksum fi sleep 1 diff --git a/test/auth/added-imap-auth.txt b/test/auth/added-imap-auth.txt new file mode 100644 index 00000000..83267a1f --- /dev/null +++ b/test/auth/added-imap-auth.txt @@ -0,0 +1,4 @@ +a1 LOGIN added@localhost.localdomain mypassword +a3 EXAMINE INBOX +a4 FETCH 1 BODY[] +a5 LOGOUT diff --git a/test/auth/added-pop3-auth.txt b/test/auth/added-pop3-auth.txt new file mode 100644 index 00000000..dcc93631 --- /dev/null +++ b/test/auth/added-pop3-auth.txt @@ -0,0 +1,4 @@ +USER added@localhost.localdomain +PASS mypassword +LIST +quit diff --git a/test/auth/added-smtp-auth-login-wrong.txt b/test/auth/added-smtp-auth-login-wrong.txt new file mode 100644 index 00000000..a75856f1 --- /dev/null +++ b/test/auth/added-smtp-auth-login-wrong.txt @@ -0,0 +1,4 @@ +EHLO mail +AUTH LOGIN YWRkZWRAbG9jYWxob3N0LmxvY2FsZG9tYWlu +Bn3JKisq4HQ2RO== +QUIT diff --git a/test/auth/added-smtp-auth-login.txt b/test/auth/added-smtp-auth-login.txt new file mode 100644 index 00000000..5276b7f4 --- /dev/null +++ b/test/auth/added-smtp-auth-login.txt @@ -0,0 +1,4 @@ +EHLO mail +AUTH LOGIN YWRkZWRAbG9jYWxob3N0LmxvY2FsZG9tYWlu +bXlwYXNzd29yZA== +QUIT diff --git a/test/auth/added-smtp-auth-plain-wrong.txt b/test/auth/added-smtp-auth-plain-wrong.txt new file mode 100644 index 00000000..6ce5a383 --- /dev/null +++ b/test/auth/added-smtp-auth-plain-wrong.txt @@ -0,0 +1,3 @@ +EHLO mail +AUTH PLAIN YWRkZWRAbG9jYWxob3N0LmxvY2FsZG9tYWluAGFkZGVkQGxvY2FsaG9zdC5sb2NhbGRvbWFpbgBCQURQQVNTV09SRA== +QUIT diff --git a/test/auth/added-smtp-auth-plain.txt b/test/auth/added-smtp-auth-plain.txt new file mode 100644 index 00000000..ed48d77d --- /dev/null +++ b/test/auth/added-smtp-auth-plain.txt @@ -0,0 +1,3 @@ +EHLO mail +AUTH PLAIN YWRkZWRAbG9jYWxob3N0LmxvY2FsZG9tYWluAGFkZGVkQGxvY2FsaG9zdC5sb2NhbGRvbWFpbgBteXBhc3N3b3Jk +QUIT diff --git a/test/email-templates/existing-added.txt b/test/email-templates/existing-added.txt new file mode 100644 index 00000000..aa97fb2f --- /dev/null +++ b/test/email-templates/existing-added.txt @@ -0,0 +1,12 @@ +HELO mail.external.tld +MAIL FROM: user@external.tld +RCPT TO: added@localhost.localdomain +DATA +From: Docker Mail Server +To: Existing Local User +Date: Sat, 22 May 2010 07:43:25 -0400 +Subject: Test Message +This is a test mail. + +. +QUIT diff --git a/test/tests.bats b/test/tests.bats index b729fbf9..3754c378 100644 --- a/test/tests.bats +++ b/test/tests.bats @@ -197,6 +197,11 @@ load 'test_helper/bats-assert/load' assert_success } +@test "checking imap: added user authentication works" { + run docker exec mail /bin/sh -c "nc -w 1 0.0.0.0 143 < /tmp/docker-mailserver-test/auth/added-imap-auth.txt" + assert_success +} + # # pop # @@ -211,6 +216,11 @@ load 'test_helper/bats-assert/load' assert_success } +@test "checking pop: added user authentication works" { + run docker exec mail_pop3 /bin/sh -c "nc -w 1 0.0.0.0 110 < /tmp/docker-mailserver-test/auth/added-pop3-auth.txt" + assert_success +} + # # sasl # @@ -264,10 +274,30 @@ load 'test_helper/bats-assert/load' assert_success } +@test "checking smtp: added user 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/added-smtp-auth-plain.txt | grep 'Authentication successful'" + assert_success +} + +@test "checking smtp: added user 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/added-smtp-auth-plain-wrong.txt | grep 'authentication failed'" + assert_success +} + +@test "checking smtp: added user 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/added-smtp-auth-login.txt | grep 'Authentication successful'" + assert_success +} + +@test "checking smtp: added user 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/added-smtp-auth-login-wrong.txt | grep 'authentication failed'" + assert_success +} + @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)' | wc -l" assert_success - assert_output 9 + assert_output 10 } @test "checking smtp: delivers mail to existing alias" { @@ -349,6 +379,7 @@ load 'test_helper/bats-assert/load' assert_success [ "${lines[0]}" = "user1@localhost.localdomain" ] [ "${lines[1]}" = "user2@otherdomain.tld" ] + [ "${lines[2]}" = "added@localhost.localdomain" ] } @test "checking accounts: user mail folders for user1" { @@ -363,6 +394,12 @@ load 'test_helper/bats-assert/load' assert_output 7 } +@test "checking accounts: user mail folders for added user" { + run docker exec mail /bin/bash -c "ls -A /var/mail/localhost.localdomain/added | grep -E '.Drafts|.Sent|.Trash|cur|new|subscriptions|tmp' | wc -l" + assert_success + assert_output 7 +} + @test "checking accounts: comments are not parsed" { run docker exec mail /bin/bash -c "ls /var/mail | grep 'comment'" assert_failure @@ -1315,7 +1352,7 @@ load 'test_helper/bats-assert/load' } @test "checking restart of process: amavisd-new" { - run docker exec mail /bin/bash -c "pkill amavi && sleep 10 && ps aux --forest | grep -v grep | grep '/usr/sbin/amavisd-new (master)'" + run docker exec mail /bin/bash -c "pkill amavi && sleep 12 && ps aux --forest | grep -v grep | grep '/usr/sbin/amavisd-new (master)'" assert_success }