From 3b728848bb6cb534ff3b2120ef4f4fb7e8e802ef Mon Sep 17 00:00:00 2001 From: Martin Schulze Date: Fri, 16 Aug 2019 19:36:03 +0200 Subject: [PATCH] Extract mail_lmtp_ip into own test file --- Makefile | 11 --------- test/mail_lmtp_ip.bats | 54 ++++++++++++++++++++++++++++++++++++++++++ test/tests.bats | 14 ----------- 3 files changed, 54 insertions(+), 25 deletions(-) create mode 100644 test/mail_lmtp_ip.bats diff --git a/Makefile b/Makefile index 13a9c4c6..3ac43073 100644 --- a/Makefile +++ b/Makefile @@ -205,15 +205,6 @@ run: --cap-add=NET_ADMIN \ -h mail.my-domain.com -t $(NAME) sleep 15 - docker run -d --name mail_lmtp_ip \ - -v "`pwd`/test/config":/tmp/docker-mailserver \ - -v "`pwd`/test/config/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 \ - -e DMS_DEBUG=0 \ - -h mail.my-domain.com -t $(NAME) - sleep 30 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 @@ -246,7 +237,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_lmtp_ip /bin/sh -c "nc 0.0.0.0 25 < /tmp/docker-mailserver-test/email-templates/existing-user1.txt" 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 @@ -282,7 +272,6 @@ clean: ldap_for_mail \ mail_with_ldap \ mail_with_imap \ - mail_lmtp_ip \ mail_postscreen \ mail_override_hostname \ mail_domainname \ diff --git a/test/mail_lmtp_ip.bats b/test/mail_lmtp_ip.bats new file mode 100644 index 00000000..241a9704 --- /dev/null +++ b/test/mail_lmtp_ip.bats @@ -0,0 +1,54 @@ +load 'test_helper/common' + +setup() { + run_setup_file_if_necessary +} + +teardown() { + run_teardown_file_if_necessary +} + +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 "`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 \ + -h mail.my-domain.com -t ${NAME} + wait_for_finished_setup_in_container mail_lmtp_ip +} + + +teardown_file() { + docker rm -f mail_lmtp_ip +} + +@test "first" { + skip 'only used to call setup_file from setup' +} + +# +# Postfix VIRTUAL_TRANSPORT +# +@test "checking postfix-lmtp: virtual_transport config is set" { + run docker exec mail_lmtp_ip /bin/sh -c "grep 'virtual_transport = lmtp:127.0.0.1:24' /etc/postfix/main.cf" + assert_success +} + +@test "checking postfix-lmtp: delivers mail to existing account" { + # maybe we can move this into the setup to speed things up futher. + # this likely would need an async coroutine to avoid blocking the other tests while waiting for the server to come up + 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 + + repeat_until_success_or_timeout 60 run docker exec mail_lmtp_ip /bin/sh -c "grep 'postfix/lmtp' /var/log/mail/mail.log | grep 'status=sent' | grep ' Saved)' | wc -l" + assert_success + assert_output 1 +} + +@test "last" { + skip 'only used to call teardown_file from teardown' +} \ No newline at end of file diff --git a/test/tests.bats b/test/tests.bats index 3facd129..357f7f4a 100644 --- a/test/tests.bats +++ b/test/tests.bats @@ -1585,20 +1585,6 @@ function count_processed_changes() { assert_success } -# -# Postfix VIRTUAL_TRANSPORT -# -@test "checking postfix-lmtp: virtual_transport config is set" { - run docker exec mail_lmtp_ip /bin/sh -c "grep 'virtual_transport = lmtp:127.0.0.1:24' /etc/postfix/main.cf" - assert_success -} - -@test "checking postfix-lmtp: delivers mail to existing account" { - run docker exec mail_lmtp_ip /bin/sh -c "grep 'postfix/lmtp' /var/log/mail/mail.log | grep 'status=sent' | grep ' Saved)' | wc -l" - assert_success - assert_output 1 -} - # # Pflogsumm delivery check #