2016-02-24 23:17:01 +00:00
|
|
|
#
|
|
|
|
# processes
|
|
|
|
#
|
|
|
|
|
|
|
|
@test "checking process: postfix" {
|
|
|
|
run docker exec mail /bin/bash -c "ps aux --forest | grep -v grep | grep '/usr/lib/postfix/master'"
|
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
}
|
|
|
|
|
|
|
|
@test "checking process: clamd" {
|
|
|
|
run docker exec mail /bin/bash -c "ps aux --forest | grep -v grep | grep '/usr/sbin/clamd'"
|
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
}
|
|
|
|
|
|
|
|
@test "checking process: new" {
|
|
|
|
run docker exec mail /bin/bash -c "ps aux --forest | grep -v grep | grep '/usr/sbin/amavisd-new'"
|
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
}
|
|
|
|
|
|
|
|
@test "checking process: opendkim" {
|
|
|
|
run docker exec mail /bin/bash -c "ps aux --forest | grep -v grep | grep '/usr/sbin/opendkim'"
|
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
}
|
|
|
|
|
|
|
|
@test "checking process: opendmarc" {
|
|
|
|
run docker exec mail /bin/bash -c "ps aux --forest | grep -v grep | grep '/usr/sbin/opendmarc'"
|
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
}
|
|
|
|
|
2016-03-31 10:33:47 +00:00
|
|
|
@test "checking process: fail2ban (disabled in default configuration)" {
|
2016-02-24 23:17:01 +00:00
|
|
|
run docker exec mail /bin/bash -c "ps aux --forest | grep -v grep | grep '/usr/bin/python /usr/bin/fail2ban-server'"
|
2016-03-31 10:33:47 +00:00
|
|
|
[ "$status" -eq 1 ]
|
|
|
|
}
|
|
|
|
|
|
|
|
@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'"
|
2016-02-24 23:17:01 +00:00
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
}
|
|
|
|
|
|
|
|
#
|
|
|
|
# imap
|
|
|
|
#
|
|
|
|
|
2016-04-13 21:16:46 +00:00
|
|
|
@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'"
|
2016-02-29 22:52:10 +00:00
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
}
|
|
|
|
|
2016-04-13 21:16:46 +00:00
|
|
|
@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'"
|
2016-02-29 22:52:10 +00:00
|
|
|
[ "$status" -eq 1 ]
|
|
|
|
}
|
|
|
|
|
2016-02-24 23:17:01 +00:00
|
|
|
@test "checking imap: server is ready with STARTTLS" {
|
2016-04-22 15:51:14 +00:00
|
|
|
run docker exec mail /bin/bash -c "nc -w 2 0.0.0.0 143 | grep '* OK' | grep 'STARTTLS' | grep 'ready'"
|
2016-02-24 23:17:01 +00:00
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
}
|
|
|
|
|
|
|
|
@test "checking imap: authentication works" {
|
2016-04-20 23:08:14 +00:00
|
|
|
run docker exec mail /bin/sh -c "nc -w 1 0.0.0.0 143 < /tmp/docker-mailserver-test/auth/imap-auth.txt"
|
2016-02-24 23:17:01 +00:00
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
}
|
|
|
|
|
|
|
|
#
|
|
|
|
# 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 ]
|
|
|
|
}
|
|
|
|
|
|
|
|
@test "checking pop: authentication works" {
|
2016-04-20 23:08:14 +00:00
|
|
|
run docker exec mail_pop3 /bin/sh -c "nc -w 1 0.0.0.0 110 < /tmp/docker-mailserver-test/auth/pop3-auth.txt"
|
2016-02-24 23:17:01 +00:00
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
}
|
|
|
|
|
|
|
|
#
|
|
|
|
# sasl
|
|
|
|
#
|
|
|
|
|
2016-04-17 10:01:05 +00:00
|
|
|
@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'"
|
2016-02-24 23:17:01 +00:00
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
}
|
|
|
|
|
2016-04-17 10:01:05 +00:00
|
|
|
@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'"
|
2016-02-24 23:17:01 +00:00
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
}
|
|
|
|
|
2016-03-18 19:12:18 +00:00
|
|
|
@test "checking sasl: sasl_passwd.db exists" {
|
|
|
|
run docker exec mail [ -f /etc/postfix/sasl_passwd.db ]
|
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
}
|
|
|
|
|
2016-04-07 22:23:12 +00:00
|
|
|
#
|
|
|
|
# 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 ]
|
|
|
|
}
|
|
|
|
|
2016-02-24 23:17:01 +00:00
|
|
|
#
|
|
|
|
# smtp
|
|
|
|
#
|
|
|
|
|
|
|
|
@test "checking smtp: authentication works with good password (plain)" {
|
2016-04-20 23:08:14 +00:00
|
|
|
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'"
|
2016-02-24 23:17:01 +00:00
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
}
|
|
|
|
|
|
|
|
@test "checking smtp: authentication fails with wrong password (plain)" {
|
2016-04-20 23:08:14 +00:00
|
|
|
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'"
|
2016-02-24 23:17:01 +00:00
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
}
|
|
|
|
|
|
|
|
@test "checking smtp: authentication works with good password (login)" {
|
2016-04-20 23:08:14 +00:00
|
|
|
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'"
|
2016-02-24 23:17:01 +00:00
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
}
|
|
|
|
|
|
|
|
@test "checking smtp: authentication fails with wrong password (login)" {
|
2016-04-20 23:08:14 +00:00
|
|
|
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'"
|
2016-02-24 23:17:01 +00:00
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
}
|
|
|
|
|
|
|
|
@test "checking smtp: delivers mail to existing account" {
|
2016-04-28 06:57:50 +00:00
|
|
|
run docker exec mail /bin/sh -c "grep 'status=sent (delivered via dovecot service)' /var/log/mail/mail.log | wc -l"
|
2016-02-24 23:17:01 +00:00
|
|
|
[ "$status" -eq 0 ]
|
2016-07-23 21:42:18 +00:00
|
|
|
[ "$output" -eq 6 ]
|
2016-02-24 23:17:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@test "checking smtp: delivers mail to existing alias" {
|
2016-04-01 15:18:13 +00:00
|
|
|
run docker exec mail /bin/sh -c "grep 'to=<user1@localhost.localdomain>, orig_to=<alias1@localhost.localdomain>' /var/log/mail/mail.log | grep 'status=sent' | wc -l"
|
2016-02-24 23:17:01 +00:00
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
[ "$output" = 1 ]
|
|
|
|
}
|
|
|
|
|
2016-07-23 21:42:18 +00:00
|
|
|
@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 ]
|
|
|
|
}
|
|
|
|
|
2016-05-24 04:30:22 +00:00
|
|
|
@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 ]
|
|
|
|
}
|
|
|
|
|
2016-07-23 21:42:18 +00:00
|
|
|
@test "checking smtp: user1 should have received 5 mails" {
|
2016-02-24 23:17:01 +00:00
|
|
|
run docker exec mail /bin/sh -c "ls -A /var/mail/localhost.localdomain/user1/new | wc -l"
|
|
|
|
[ "$status" -eq 0 ]
|
2016-07-23 21:42:18 +00:00
|
|
|
[ "$output" = 5 ]
|
2016-02-24 23:17:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@test "checking smtp: rejects mail to unknown user" {
|
2016-04-01 15:18:13 +00:00
|
|
|
run docker exec mail /bin/sh -c "grep '<nouser@localhost.localdomain>: Recipient address rejected: User unknown in virtual mailbox table' /var/log/mail/mail.log | wc -l"
|
2016-02-24 23:17:01 +00:00
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
[ "$output" = 1 ]
|
|
|
|
}
|
|
|
|
|
2016-05-24 04:30:22 +00:00
|
|
|
@test "checking smtp: redirects mail to external aliases" {
|
2016-04-01 15:18:13 +00:00
|
|
|
run docker exec mail /bin/sh -c "grep -- '-> <external1@otherdomain.tld>' /var/log/mail/mail.log | wc -l"
|
2016-02-24 23:17:01 +00:00
|
|
|
[ "$status" -eq 0 ]
|
2016-05-24 05:23:54 +00:00
|
|
|
[ "$output" = 2 ]
|
2016-02-24 23:17:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@test "checking smtp: rejects spam" {
|
2016-04-01 15:18:13 +00:00
|
|
|
run docker exec mail /bin/sh -c "grep 'Blocked SPAM' /var/log/mail/mail.log | grep spam@external.tld | wc -l"
|
2016-02-24 23:17:01 +00:00
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
[ "$output" = 1 ]
|
|
|
|
}
|
|
|
|
|
|
|
|
@test "checking smtp: rejects virus" {
|
2016-04-01 15:18:13 +00:00
|
|
|
run docker exec mail /bin/sh -c "grep 'Blocked INFECTED' /var/log/mail/mail.log | grep virus@external.tld | wc -l"
|
2016-02-24 23:17:01 +00:00
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
[ "$output" = 1 ]
|
|
|
|
}
|
|
|
|
|
|
|
|
#
|
|
|
|
# accounts
|
|
|
|
#
|
|
|
|
|
|
|
|
@test "checking accounts: user accounts" {
|
2016-04-17 10:01:05 +00:00
|
|
|
run docker exec mail doveadm user '*'
|
2016-02-24 23:17:01 +00:00
|
|
|
[ "$status" -eq 0 ]
|
2016-04-17 10:01:05 +00:00
|
|
|
[ "${lines[0]}" = "user1@localhost.localdomain" ]
|
|
|
|
[ "${lines[1]}" = "user2@otherdomain.tld" ]
|
2016-02-24 23:17:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@test "checking accounts: user mail folders for user1" {
|
2016-04-17 18:10:09 +00:00
|
|
|
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 ]
|
2016-02-24 23:17:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@test "checking accounts: user mail folders for user2" {
|
2016-04-17 18:10:09 +00:00
|
|
|
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 ]
|
2016-02-24 23:17:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#
|
|
|
|
# postfix
|
|
|
|
#
|
|
|
|
|
|
|
|
@test "checking postfix: vhost file is correct" {
|
|
|
|
run docker exec mail cat /etc/postfix/vhost
|
|
|
|
[ "$status" -eq 0 ]
|
2016-07-23 21:42:18 +00:00
|
|
|
[ "${lines[0]}" = "localdomain2.com" ]
|
|
|
|
[ "${lines[1]}" = "localhost.localdomain" ]
|
|
|
|
[ "${lines[2]}" = "otherdomain.tld" ]
|
2016-02-24 23:17:01 +00:00
|
|
|
}
|
|
|
|
|
2016-03-18 19:07:58 +00:00
|
|
|
@test "checking postfix: main.cf overrides" {
|
2016-04-17 10:01:05 +00:00
|
|
|
run docker exec mail grep -q 'max_idle = 600s' /tmp/docker-mailserver/postfix-main.cf
|
2016-03-18 19:07:58 +00:00
|
|
|
[ "$status" -eq 0 ]
|
2016-04-17 10:01:05 +00:00
|
|
|
run docker exec mail grep -q 'readme_directory = /tmp' /tmp/docker-mailserver/postfix-main.cf
|
2016-03-18 19:07:58 +00:00
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
}
|
|
|
|
|
2016-05-29 20:36:06 +00:00
|
|
|
#
|
|
|
|
# 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' ]
|
|
|
|
}
|
|
|
|
|
2016-02-24 23:17:01 +00:00
|
|
|
#
|
|
|
|
# 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 ]
|
|
|
|
}
|
|
|
|
|
|
|
|
@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
|
|
|
|
#
|
|
|
|
|
|
|
|
@test "checking opendkim: /etc/opendkim/KeyTable should contain 2 entries" {
|
|
|
|
run docker exec mail /bin/sh -c "cat /etc/opendkim/KeyTable | wc -l"
|
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
[ "$output" -eq 2 ]
|
|
|
|
}
|
|
|
|
|
|
|
|
@test "checking opendkim: /etc/opendkim/keys/ should contain 2 entries" {
|
|
|
|
run docker exec mail /bin/sh -c "ls -l /etc/opendkim/keys/ | grep '^d' | wc -l"
|
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
[ "$output" -eq 2 ]
|
|
|
|
}
|
|
|
|
|
2016-04-20 23:08:14 +00:00
|
|
|
@test "checking opendkim: generator creates keys, tables and TrustedHosts" {
|
2016-04-21 09:42:41 +00:00
|
|
|
rm -rf "$(pwd)/test/config/empty" && mkdir -p "$(pwd)/test/config/empty"
|
2016-04-20 21:01:32 +00:00
|
|
|
run docker run --rm \
|
2016-04-21 09:42:41 +00:00
|
|
|
-v "$(pwd)/test/config/empty/":/tmp/docker-mailserver/ \
|
|
|
|
-v "$(pwd)/test/config/postfix-accounts.cf":/tmp/docker-mailserver/postfix-accounts.cf \
|
|
|
|
-v "$(pwd)/test/config/postfix-virtual.cf":/tmp/docker-mailserver/postfix-virtual.cf \
|
2016-05-29 20:36:06 +00:00
|
|
|
`docker inspect --format '{{ .Config.Image }}' mail` /bin/sh -c 'generate-dkim-config | wc -l'
|
2016-04-20 21:01:32 +00:00
|
|
|
[ "$status" -eq 0 ]
|
2016-07-23 21:42:18 +00:00
|
|
|
[ "$output" -eq 6 ]
|
2016-04-21 09:42:41 +00:00
|
|
|
# Check keys for localhost.localdomain
|
|
|
|
run docker run --rm \
|
|
|
|
-v "$(pwd)/test/config/empty/opendkim":/etc/opendkim \
|
2016-05-29 20:36:06 +00:00
|
|
|
`docker inspect --format '{{ .Config.Image }}' mail` /bin/sh -c 'ls -1 /etc/opendkim/keys/localhost.localdomain/ | wc -l'
|
2016-04-21 09:42:41 +00:00
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
[ "$output" -eq 2 ]
|
|
|
|
# Check keys for otherdomain.tld
|
|
|
|
run docker run --rm \
|
|
|
|
-v "$(pwd)/test/config/empty/opendkim":/etc/opendkim \
|
2016-05-29 20:36:06 +00:00
|
|
|
`docker inspect --format '{{ .Config.Image }}' mail` /bin/sh -c 'ls -1 /etc/opendkim/keys/otherdomain.tld | wc -l'
|
2016-04-21 09:42:41 +00:00
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
[ "$output" -eq 2 ]
|
|
|
|
# Check presence of tables and TrustedHosts
|
|
|
|
run docker run --rm \
|
|
|
|
-v "$(pwd)/test/config/empty/opendkim":/etc/opendkim \
|
2016-05-29 20:36:06 +00:00
|
|
|
`docker inspect --format '{{ .Config.Image }}' mail` /bin/sh -c "ls -1 etc/opendkim | grep -E 'KeyTable|SigningTable|TrustedHosts|keys'|wc -l"
|
2016-04-21 09:42:41 +00:00
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
[ "$output" -eq 4 ]
|
2016-04-20 21:01:32 +00:00
|
|
|
}
|
|
|
|
|
2016-02-24 23:17:01 +00:00
|
|
|
#
|
|
|
|
# opendmarc
|
|
|
|
#
|
|
|
|
|
|
|
|
@test "checking opendkim: server fqdn should be added to /etc/opendmarc.conf as AuthservID" {
|
|
|
|
run docker exec mail grep ^AuthservID /etc/opendmarc.conf
|
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
[ "$output" = "AuthservID mail.my-domain.com" ]
|
|
|
|
}
|
|
|
|
|
|
|
|
@test "checking opendkim: server fqdn should be added to /etc/opendmarc.conf as TrustedAuthservIDs" {
|
|
|
|
run docker exec mail grep ^TrustedAuthservID /etc/opendmarc.conf
|
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
[ "$output" = "TrustedAuthservIDs mail.my-domain.com" ]
|
|
|
|
}
|
|
|
|
|
|
|
|
#
|
2016-04-26 17:39:08 +00:00
|
|
|
# ssl
|
2016-02-24 23:17:01 +00:00
|
|
|
#
|
|
|
|
|
2016-04-26 17:39:08 +00:00
|
|
|
@test "checking ssl: generated default cert works correctly" {
|
|
|
|
run docker exec mail /bin/sh -c "timeout 1 openssl s_client -connect 0.0.0.0:587 -starttls smtp -CApath /etc/ssl/certs/ | grep 'Verify return code: 0 (ok)'"
|
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
}
|
|
|
|
|
|
|
|
@test "checking ssl: lets-encrypt-x1-cross-signed.pem is installed" {
|
2016-02-24 23:17:01 +00:00
|
|
|
run docker exec mail grep 'BEGIN CERTIFICATE' /etc/ssl/certs/lets-encrypt-x1-cross-signed.pem
|
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
}
|
|
|
|
|
2016-04-26 17:39:08 +00:00
|
|
|
@test "checking ssl: lets-encrypt-x2-cross-signed.pem is installed" {
|
2016-02-24 23:17:01 +00:00
|
|
|
run docker exec mail grep 'BEGIN CERTIFICATE' /etc/ssl/certs/lets-encrypt-x2-cross-signed.pem
|
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
}
|
|
|
|
|
2016-04-26 17:39:08 +00:00
|
|
|
@test "checking ssl: letsencrypt configuration is correct" {
|
|
|
|
run docker exec mail_pop3 /bin/sh -c 'grep -ir "/etc/letsencrypt/live/mail.my-domain.com/" /etc/postfix/main.cf | wc -l'
|
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
[ "$output" -eq 2 ]
|
|
|
|
run docker exec mail_pop3 /bin/sh -c 'grep -ir "/etc/letsencrypt/live/mail.my-domain.com/" /etc/dovecot/conf.d/10-ssl.conf | wc -l'
|
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
[ "$output" -eq 2 ]
|
|
|
|
}
|
2016-02-24 23:17:01 +00:00
|
|
|
|
2016-04-26 17:39:08 +00:00
|
|
|
@test "checking ssl: letsencrypt combined.pem generated correctly" {
|
|
|
|
run docker exec mail_pop3 ls -1 /etc/letsencrypt/live/mail.my-domain.com/combined.pem
|
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
}
|
|
|
|
|
|
|
|
@test "checking ssl: letsencrypt cert works correctly" {
|
2016-07-23 16:20:19 +00:00
|
|
|
run docker exec mail_pop3 /bin/sh -c "timeout 1 openssl s_client -connect 0.0.0.0:587 -starttls smtp -CApath /etc/ssl/certs/ | grep 'Verify return code: 10 (certificate has expired)'"
|
2016-02-24 23:17:01 +00:00
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
}
|
|
|
|
|
|
|
|
#
|
|
|
|
# fail2ban
|
|
|
|
#
|
|
|
|
|
2016-04-17 20:59:35 +00:00
|
|
|
@test "checking fail2ban: localhost is not banned because ignored" {
|
2016-04-23 10:09:28 +00:00
|
|
|
run docker exec mail_fail2ban /bin/sh -c "fail2ban-client status postfix-sasl | grep 'IP list:.*127.0.0.1'"
|
2016-02-24 23:17:01 +00:00
|
|
|
[ "$status" -eq 1 ]
|
2016-04-17 20:59:35 +00:00
|
|
|
run docker exec mail_fail2ban /bin/sh -c "grep 'ignoreip = 127.0.0.1/8' /etc/fail2ban/jail.conf"
|
|
|
|
[ "$status" -eq 0 ]
|
2016-02-24 23:17:01 +00:00
|
|
|
}
|
|
|
|
|
2016-06-02 23:22:16 +00:00
|
|
|
@test "checking fail2ban: fail2ban-jail.cf overrides" {
|
2016-06-04 00:46:33 +00:00
|
|
|
FILTERS=(sshd postfix dovecot postfix-sasl)
|
|
|
|
|
2016-06-04 01:12:18 +00:00
|
|
|
for FILTER in "${FILTERS[@]}"; do
|
2016-06-04 00:46:33 +00:00
|
|
|
run docker exec mail_fail2ban /bin/sh -c "fail2ban-client get $FILTER bantime"
|
|
|
|
[ "$output" = 1234 ]
|
|
|
|
|
|
|
|
run docker exec mail_fail2ban /bin/sh -c "fail2ban-client get $FILTER findtime"
|
|
|
|
[ "$output" = 321 ]
|
|
|
|
|
|
|
|
run docker exec mail_fail2ban /bin/sh -c "fail2ban-client get $FILTER maxretry"
|
|
|
|
[ "$output" = 2 ]
|
|
|
|
done
|
2016-06-02 23:22:16 +00:00
|
|
|
}
|
|
|
|
|
2016-02-24 23:17:01 +00:00
|
|
|
@test "checking fail2ban: ban ip on multiple failed login" {
|
2016-04-17 20:59:35 +00:00
|
|
|
# Getting mail_fail2ban container IP
|
|
|
|
MAIL_FAIL2BAN_IP=$(docker inspect --format '{{ .NetworkSettings.IPAddress }}' mail_fail2ban)
|
2016-06-04 00:53:44 +00:00
|
|
|
|
2016-04-17 20:59:35 +00:00
|
|
|
# Create a container which will send wront authentications and should banned
|
2016-06-04 00:53:44 +00:00
|
|
|
docker run --name fail-auth-mailer -e MAIL_FAIL2BAN_IP=$MAIL_FAIL2BAN_IP -v "$(pwd)/test":/tmp/docker-mailserver-test -d $(docker inspect --format '{{ .Config.Image }}' mail) tail -f /var/log/faillog
|
|
|
|
|
2016-04-20 23:08:14 +00:00
|
|
|
docker exec fail-auth-mailer /bin/sh -c 'nc $MAIL_FAIL2BAN_IP 25 < /tmp/docker-mailserver-test/auth/smtp-auth-login-wrong.txt'
|
|
|
|
docker exec fail-auth-mailer /bin/sh -c 'nc $MAIL_FAIL2BAN_IP 25 < /tmp/docker-mailserver-test/auth/smtp-auth-login-wrong.txt'
|
2016-06-04 00:53:44 +00:00
|
|
|
|
2016-04-17 21:16:13 +00:00
|
|
|
sleep 5
|
2016-06-04 00:53:44 +00:00
|
|
|
|
2016-04-17 20:59:35 +00:00
|
|
|
# Checking that FAIL_AUTH_MAILER_IP is banned in mail_fail2ban
|
2016-04-17 21:16:13 +00:00
|
|
|
FAIL_AUTH_MAILER_IP=$(docker inspect --format '{{ .NetworkSettings.IPAddress }}' fail-auth-mailer)
|
2016-06-04 00:53:44 +00:00
|
|
|
|
|
|
|
run docker exec mail_fail2ban /bin/sh -c "fail2ban-client status postfix-sasl | grep '$FAIL_AUTH_MAILER_IP'"
|
2016-02-24 23:17:01 +00:00
|
|
|
[ "$status" -eq 0 ]
|
2016-06-04 00:53:44 +00:00
|
|
|
|
|
|
|
# Checking that FAIL_AUTH_MAILER_IP is banned by iptables
|
|
|
|
run docker exec mail_fail2ban /bin/sh -c "iptables -L f2b-postfix-sasl -n | grep REJECT | grep '$FAIL_AUTH_MAILER_IP'"
|
2016-04-22 15:51:14 +00:00
|
|
|
[ "$status" -eq 0 ]
|
2016-02-24 23:17:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@test "checking fail2ban: unban ip works" {
|
2016-04-17 21:44:41 +00:00
|
|
|
FAIL_AUTH_MAILER_IP=$(docker inspect --format '{{ .NetworkSettings.IPAddress }}' fail-auth-mailer)
|
2016-06-04 00:53:44 +00:00
|
|
|
|
2016-04-23 10:09:28 +00:00
|
|
|
docker exec mail_fail2ban fail2ban-client set postfix-sasl unbanip $FAIL_AUTH_MAILER_IP
|
2016-06-04 00:53:44 +00:00
|
|
|
|
2016-02-24 23:17:01 +00:00
|
|
|
sleep 5
|
2016-06-04 00:53:44 +00:00
|
|
|
|
2016-04-23 10:09:28 +00:00
|
|
|
run docker exec mail_fail2ban /bin/sh -c "fail2ban-client status postfix-sasl | grep 'IP list:.*$FAIL_AUTH_MAILER_IP'"
|
2016-02-24 23:17:01 +00:00
|
|
|
[ "$status" -eq 1 ]
|
2016-06-04 00:53:44 +00:00
|
|
|
|
|
|
|
# Checking that FAIL_AUTH_MAILER_IP is unbanned by iptables
|
|
|
|
run docker exec mail_fail2ban /bin/sh -c "iptables -L f2b-postfix-sasl -n | grep REJECT | grep '$FAIL_AUTH_MAILER_IP'"
|
2016-04-22 15:51:14 +00:00
|
|
|
[ "$status" -eq 1 ]
|
2016-02-24 23:17:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#
|
|
|
|
# system
|
|
|
|
#
|
|
|
|
|
|
|
|
@test "checking system: freshclam cron is enabled" {
|
|
|
|
run docker exec mail crontab -l
|
|
|
|
[ "$status" -eq 0 ]
|
2016-04-23 10:09:28 +00:00
|
|
|
[ "$output" = "0 0,6,12,18 * * * /usr/bin/freshclam --quiet" ]
|
2016-02-24 23:17:01 +00:00
|
|
|
}
|
|
|
|
|
2016-04-01 15:18:13 +00:00
|
|
|
@test "checking system: /var/log/mail/mail.log is error free" {
|
|
|
|
run docker exec mail grep 'non-null host address bits in' /var/log/mail/mail.log
|
2016-02-24 23:17:01 +00:00
|
|
|
[ "$status" -eq 1 ]
|
2016-07-23 19:01:01 +00:00
|
|
|
run docker exec mail grep 'mail system configuration error' /var/log/mail/mail.log
|
|
|
|
[ "$status" -eq 1 ]
|
2016-04-01 15:18:13 +00:00
|
|
|
run docker exec mail grep ': error:' /var/log/mail/mail.log
|
2016-02-24 23:17:01 +00:00
|
|
|
[ "$status" -eq 1 ]
|
2016-04-01 15:18:13 +00:00
|
|
|
run docker exec mail_pop3 grep 'non-null host address bits in' /var/log/mail/mail.log
|
2016-02-24 23:17:01 +00:00
|
|
|
[ "$status" -eq 1 ]
|
2016-04-01 15:18:13 +00:00
|
|
|
run docker exec mail_pop3 grep ': error:' /var/log/mail/mail.log
|
2016-02-24 23:17:01 +00:00
|
|
|
[ "$status" -eq 1 ]
|
|
|
|
}
|
|
|
|
|
|
|
|
@test "checking system: sets the server fqdn" {
|
|
|
|
run docker exec mail hostname
|
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
[ "$output" = "mail.my-domain.com" ]
|
|
|
|
}
|
|
|
|
|
|
|
|
@test "checking system: sets the server domain name in /etc/mailname" {
|
|
|
|
run docker exec mail cat /etc/mailname
|
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
[ "$output" = "my-domain.com" ]
|
|
|
|
}
|
2016-04-28 06:57:50 +00:00
|
|
|
|
|
|
|
#
|
|
|
|
# sieve
|
|
|
|
#
|
|
|
|
|
2016-04-28 08:25:11 +00:00
|
|
|
@test "checking sieve: user1 should have received 1 email in folder INBOX.spam" {
|
2016-04-28 06:57:50 +00:00
|
|
|
run docker exec mail /bin/sh -c "ls -A /var/mail/localhost.localdomain/user1/.INBOX.spam/new | wc -l"
|
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
[ "$output" = 1 ]
|
|
|
|
}
|
2016-04-29 13:24:10 +00:00
|
|
|
|
2016-04-29 15:09:48 +00:00
|
|
|
@test "checking manage sieve: server is ready when ENABLE_MANAGESIEVE has been set" {
|
2016-04-29 13:24:10 +00:00
|
|
|
run docker exec mail /bin/bash -c "nc -z 0.0.0.0 4190"
|
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
}
|
|
|
|
|
|
|
|
@test "checking manage sieve: disabled per default" {
|
|
|
|
run docker exec mail_pop3 /bin/bash -c "nc -z 0.0.0.0 4190"
|
|
|
|
[ "$status" -ne 0 ]
|
|
|
|
}
|
2016-06-14 14:17:06 +00:00
|
|
|
|
|
|
|
#
|
|
|
|
# accounts
|
|
|
|
#
|
|
|
|
|
|
|
|
@test "checking accounts: user3 should have been added to /tmp/docker-mailserver/postfix-accounts.cf" {
|
|
|
|
docker exec mail /bin/sh -c "addmailuser user3@domain.tld mypassword"
|
|
|
|
|
|
|
|
run docker exec mail /bin/sh -c "grep user3@domain.tld -i /tmp/docker-mailserver/postfix-accounts.cf"
|
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
[ ! -z "$output" ]
|
|
|
|
}
|
|
|
|
|
|
|
|
@test "checking accounts: user3 should have been removed from /tmp/docker-mailserver/postfix-accounts.cf" {
|
|
|
|
docker exec mail /bin/sh -c "delmailuser user3@domain.tld"
|
|
|
|
|
|
|
|
run docker exec mail /bin/sh -c "grep user3@domain.tld -i /tmp/docker-mailserver/postfix-accounts.cf"
|
|
|
|
[ "$status" -eq 1 ]
|
|
|
|
[ -z "$output" ]
|
|
|
|
}
|