From c813e6a4b3ac6e84d4d9b642d0e49a4614438319 Mon Sep 17 00:00:00 2001 From: Thomas VIAL <github@ifusio.com> Date: Sat, 23 Jul 2016 23:42:18 +0200 Subject: [PATCH] Added test on catchall --- Makefile | 1 + test/config/postfix-virtual.cf | 1 + .../existing-catchall-local.txt | 12 ++++++++++++ test/tests.bats | 19 +++++++++++++------ 4 files changed, 27 insertions(+), 6 deletions(-) create mode 100644 test/email-templates/existing-catchall-local.txt diff --git a/Makefile b/Makefile index 782b8c60..b2f97842 100644 --- a/Makefile +++ b/Makefile @@ -65,6 +65,7 @@ fixtures: 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/non-existing-user.txt" # Wait for mails to be analyzed diff --git a/test/config/postfix-virtual.cf b/test/config/postfix-virtual.cf index e93eb8fb..57d8158d 100644 --- a/test/config/postfix-virtual.cf +++ b/test/config/postfix-virtual.cf @@ -1,2 +1,3 @@ alias1@localhost.localdomain user1@localhost.localdomain alias2@localhost.localdomain external1@otherdomain.tld +@localdomain2.com user1@localhost.localdomain diff --git a/test/email-templates/existing-catchall-local.txt b/test/email-templates/existing-catchall-local.txt new file mode 100644 index 00000000..d2fe5d46 --- /dev/null +++ b/test/email-templates/existing-catchall-local.txt @@ -0,0 +1,12 @@ +HELO mail.external.tld +MAIL FROM: user@external.tld +RCPT TO: wildcard@localdomain2.com +DATA +From: Docker Mail Server <dockermailserver@external.tld> +To: Existing Local User <wildcard@localdomain2.com> +Date: Sat, 22 May 2010 07:43:25 -0400 +Subject: Test Message +This is a test mail. + +. +QUIT \ No newline at end of file diff --git a/test/tests.bats b/test/tests.bats index e1f37c27..724a3058 100644 --- a/test/tests.bats +++ b/test/tests.bats @@ -131,7 +131,7 @@ @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 5 ] + [ "$output" -eq 6 ] } @test "checking smtp: delivers mail to existing alias" { @@ -140,16 +140,22 @@ [ "$output" = 1 ] } +@test "checking smtp: delivers mail to existing catchall" { + run docker exec mail /bin/sh -c "grep 'to=<user1@localhost.localdomain>, orig_to=<wildcard@localdomain2.com>' /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=<user1@localhost.localdomain>, orig_to=<test123@localhost.localdomain>' /var/log/mail/mail.log | grep 'status=sent' | wc -l" [ "$status" -eq 0 ] [ "$output" = 1 ] } -@test "checking smtp: user1 should have received 3 mails" { +@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" = 4 ] + [ "$output" = 5 ] } @test "checking smtp: rejects mail to unknown user" { @@ -206,8 +212,9 @@ @test "checking postfix: vhost file is correct" { run docker exec mail cat /etc/postfix/vhost [ "$status" -eq 0 ] - [ "${lines[0]}" = "localhost.localdomain" ] - [ "${lines[1]}" = "otherdomain.tld" ] + [ "${lines[0]}" = "localdomain2.com" ] + [ "${lines[1]}" = "localhost.localdomain" ] + [ "${lines[2]}" = "otherdomain.tld" ] } @test "checking postfix: main.cf overrides" { @@ -275,7 +282,7 @@ -v "$(pwd)/test/config/postfix-virtual.cf":/tmp/docker-mailserver/postfix-virtual.cf \ `docker inspect --format '{{ .Config.Image }}' mail` /bin/sh -c 'generate-dkim-config | wc -l' [ "$status" -eq 0 ] - [ "$output" -eq 5 ] + [ "$output" -eq 6 ] # Check keys for localhost.localdomain run docker run --rm \ -v "$(pwd)/test/config/empty/opendkim":/etc/opendkim \