diff --git a/Makefile b/Makefile index 3e9f5d9c..749a99eb 100644 --- a/Makefile +++ b/Makefile @@ -48,23 +48,6 @@ run: -e DMS_DEBUG=0 \ -h mail.my-domain.com -t $(NAME) sleep 15 - docker run --rm -d --name mail_privacy \ - -v "`pwd`/test/config":/tmp/docker-mailserver \ - -v "`pwd`/test/test-files":/tmp/docker-mailserver-test:ro \ - -e ENABLE_CLAMAV=1 \ - -e ENABLE_SPAMASSASSIN=1 \ - -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 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 15 docker run --rm -d --name mail_smtponly_without_config \ -e SMTP_ONLY=1 \ -e ENABLE_LDAP=1 \ @@ -143,7 +126,6 @@ fixtures: 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_privacy /bin/sh -c "openssl s_client -quiet -starttls smtp -connect 0.0.0.0:587 < /tmp/docker-mailserver-test/email-templates/send-privacy-email.txt" 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_privacy.bats b/test/mail_privacy.bats new file mode 100644 index 00000000..ae6400a5 --- /dev/null +++ b/test/mail_privacy.bats @@ -0,0 +1,61 @@ +load 'test_helper/common' + +function setup() { + run_setup_file_if_necessary +} + +function teardown() { + run_teardown_file_if_necessary +} + +function setup_file() { + docker run -d --name mail_privacy \ + -v "`pwd`/test/config":/tmp/docker-mailserver \ + -v "`pwd`/test/test-files":/tmp/docker-mailserver-test:ro \ + -e ENABLE_CLAMAV=1 \ + -e ENABLE_SPAMASSASSIN=1 \ + -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 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 +} + +function teardown_file() { + docker rm -f mail_privacy +} + +@test "first" { + skip 'this test must come first to reliably identify when to run setup_file' +} + +# +# LDAP +# + +# postfix + +@test "checking postfix: remove privacy details of the sender" { + docker exec mail_privacy /bin/sh -c "openssl s_client -quiet -starttls smtp -connect 0.0.0.0:587 < /tmp/docker-mailserver-test/email-templates/send-privacy-email.txt" + repeat_until_success_or_timeout 120 docker exec mail_privacy /bin/sh -c '[ $(ls /var/mail/localhost.localdomain/user1/new | wc -l) -eq 1 ]' + docker logs mail_privacy + run docker exec mail_privacy /bin/sh -c "ls /var/mail/localhost.localdomain/user1/new | wc -l" + assert_success + assert_output 1 + run docker exec mail_privacy /bin/sh -c "grep -rE "^User-Agent:" /var/mail/localhost.localdomain/user1/new | wc -l" + assert_success + assert_output 0 +} + + +@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/test_helper/common.bash b/test/test_helper/common.bash index 00d1635f..eeb27a13 100644 --- a/test/test_helper/common.bash +++ b/test/test_helper/common.bash @@ -25,9 +25,20 @@ function repeat_until_success_or_timeout { done } +# @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" +} + # @param $1 name of the postfix container function wait_for_smtp_port_in_container() { - repeat_until_success_or_timeout $TEST_TIMEOUT_IN_SECONDS docker exec $1 /bin/sh -c "nc -z 0.0.0.0 25" + 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 } # @param $1 name of the postfix container diff --git a/test/tests.bats b/test/tests.bats index 1465dd6b..c130c46f 100644 --- a/test/tests.bats +++ b/test/tests.bats @@ -1144,15 +1144,6 @@ function count_processed_changes() { # postfix -@test "checking postfix: remove privacy details of the sender" { - run docker exec mail_privacy /bin/sh -c "ls /var/mail/localhost.localdomain/user1/new | wc -l" - assert_success - assert_output 1 - run docker exec mail_privacy /bin/sh -c "grep -rE "^User-Agent:" /var/mail/localhost.localdomain/user1/new | wc -l" - assert_success - assert_output 0 -} - @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