Merge pull request #71 from tomav/fixing-tests

Added tests and simplified some of them
This commit is contained in:
Thomas VIAL 2016-02-04 08:29:06 +01:00
commit 401cb62b6c
3 changed files with 16 additions and 12 deletions

View file

@ -1,7 +1,8 @@
NAME = tvial/docker-mailserver NAME = tvial/docker-mailserver
VERSION = $(TRAVIS_BUILD_ID) VERSION = $(TRAVIS_BUILD_ID)
all: build run prepare fixtures tests all: build run fixtures tests clean
all-no-build: run fixtures tests clean
build: build:
docker build --no-cache -t $(NAME):$(VERSION) . docker build --no-cache -t $(NAME):$(VERSION) .
@ -13,12 +14,7 @@ run:
# Run containers # Run containers
docker run -d --name mail -v "`pwd`/postfix":/tmp/postfix -v "`pwd`/spamassassin":/tmp/spamassassin -v "`pwd`/test":/tmp/test -h mail.my-domain.com -t $(NAME):$(VERSION) docker run -d --name mail -v "`pwd`/postfix":/tmp/postfix -v "`pwd`/spamassassin":/tmp/spamassassin -v "`pwd`/test":/tmp/test -h mail.my-domain.com -t $(NAME):$(VERSION)
docker run -d --name mail_pop3 -v "`pwd`/postfix":/tmp/postfix -v "`pwd`/spamassassin":/tmp/spamassassin -v "`pwd`/test":/tmp/test -e ENABLE_POP3=1 -h mail.my-domain.com -t $(NAME):$(VERSION) docker run -d --name mail_pop3 -v "`pwd`/postfix":/tmp/postfix -v "`pwd`/spamassassin":/tmp/spamassassin -v "`pwd`/test":/tmp/test -e ENABLE_POP3=1 -h mail.my-domain.com -t $(NAME):$(VERSION)
sleep 25 sleep 60
prepare:
# Reinitialize logs
docker exec mail /bin/sh -c 'echo "" > /var/log/mail.log'
docker exec mail_pop3 /bin/sh -c 'echo "" > /var/log/mail.log'
fixtures: fixtures:
# Sending test mails # Sending test mails
@ -38,3 +34,4 @@ tests:
clean: clean:
# Get default files back # Get default files back
git checkout postfix/accounts.cf postfix/virtual git checkout postfix/accounts.cf postfix/virtual
docker rm -f mail mail_pop3

View file

@ -88,6 +88,8 @@ Example:
* *empty* (default) => POP3 service disabled * *empty* (default) => POP3 service disabled
* 1 => Enables POP3 service * 1 => Enables POP3 service
Please read [how the container starts](https://github.com/tomav/docker-mailserver/blob/master/start-mailserver.sh) to understand what's expected.
## SSL ## SSL
Please read [SSL.md](SSL.md) for more information. Please read [SSL.md](SSL.md) for more information.

View file

@ -8,8 +8,9 @@ assert_raises "docker exec mail ps aux --forest | grep '/usr/lib/postfix/master'
assert_raises "docker exec mail ps aux --forest | grep '/usr/sbin/saslauthd'" 0 assert_raises "docker exec mail ps aux --forest | grep '/usr/sbin/saslauthd'" 0
assert_raises "docker exec mail ps aux --forest | grep '/usr/sbin/clamd'" 0 assert_raises "docker exec mail ps aux --forest | grep '/usr/sbin/clamd'" 0
assert_raises "docker exec mail ps aux --forest | grep '/usr/sbin/amavisd-new'" 0 assert_raises "docker exec mail ps aux --forest | grep '/usr/sbin/amavisd-new'" 0
assert_raises "docker exec mail ps aux --forest | grep '/usr/lib/courier/courier/courierpop3d'" 1
assert_raises "docker exec mail ps aux --forest | grep '/usr/sbin/opendkim'" 0 assert_raises "docker exec mail ps aux --forest | grep '/usr/sbin/opendkim'" 0
assert_raises "docker exec mail ps aux --forest | grep '/usr/sbin/opendmarc'" 0
assert_raises "docker exec mail ps aux --forest | grep '/usr/lib/courier/courier/courierpop3d'" 1
# Testing services of pop3 container # Testing services of pop3 container
assert_raises "docker exec mail_pop3 ps aux --forest | grep '/usr/lib/courier/courier/courierpop3d'" 0 assert_raises "docker exec mail_pop3 ps aux --forest | grep '/usr/lib/courier/courier/courierpop3d'" 0
@ -38,7 +39,7 @@ assert "docker exec mail cat /etc/postfix/vhost" "localhost.localdomain\notherdo
# Testing that mail is received for existing user # Testing that mail is received for existing user
assert_raises "docker exec mail grep 'status=sent (delivered to maildir)' /var/log/mail.log" 0 assert_raises "docker exec mail grep 'status=sent (delivered to maildir)' /var/log/mail.log" 0
assert "docker exec mail ls -A /var/mail/localhost.localdomain/user1/new | wc -l | sed -e 's/^[ \t]*//'" "2" assert "docker exec mail ls -A /var/mail/localhost.localdomain/user1/new | wc -l" "2"
# Testing that mail is rejected for non existing user # Testing that mail is rejected for non existing user
assert_raises "docker exec mail grep '<nouser@localhost.localdomain>: Recipient address rejected: User unknown in virtual mailbox table' /var/log/mail.log" 0 assert_raises "docker exec mail grep '<nouser@localhost.localdomain>: Recipient address rejected: User unknown in virtual mailbox table' /var/log/mail.log" 0
@ -50,10 +51,10 @@ assert_raises "docker exec mail grep 'to=<user1@localhost.localdomain>, orig_to=
assert_raises "docker exec mail grep -- '-> <external1@otherdomain.tld>' /var/log/mail.log" 0 assert_raises "docker exec mail grep -- '-> <external1@otherdomain.tld>' /var/log/mail.log" 0
# Testing that a SPAM is rejected # Testing that a SPAM is rejected
assert_raises "docker exec mail grep 'Blocked SPAM' /var/log/mail.log | grep spam@external.tld" assert_raises "docker exec mail grep 'Blocked SPAM' /var/log/mail.log | grep spam@external.tld" 0
# Testing that a Virus is rejected # Testing that a Virus is rejected
assert_raises "docker exec mail grep 'Blocked INFECTED' /var/log/mail.log | grep virus@external.tld" assert_raises "docker exec mail grep 'Blocked INFECTED' /var/log/mail.log | grep virus@external.tld" 0
# Testing presence of freshclam CRON # Testing presence of freshclam CRON
assert "docker exec mail crontab -l" "0 1 * * * /usr/bin/freshclam --quiet" assert "docker exec mail crontab -l" "0 1 * * * /usr/bin/freshclam --quiet"
@ -67,11 +68,15 @@ assert_raises "docker exec mail_pop3 grep 'non-null host address bits in' /var/l
assert_raises "docker exec mail_pop3 grep ': error:' /var/log/mail.log" 1 assert_raises "docker exec mail_pop3 grep ': error:' /var/log/mail.log" 1
# Testing OpenDKIM # Testing OpenDKIM
assert "docker exec mail cat /etc/opendkim/KeyTable | wc -l | sed -e 's/^[ \t]*//'" "2" assert "docker exec mail cat /etc/opendkim/KeyTable | wc -l" "2"
assert "docker exec mail ls -l /etc/opendkim/keys/ | grep '^d' | wc -l" "2"
# Testing OpenDMARC # Testing OpenDMARC
assert "docker exec mail cat /etc/opendmarc.conf | grep ^AuthservID | wc -l" "1" assert "docker exec mail cat /etc/opendmarc.conf | grep ^AuthservID | wc -l" "1"
assert "docker exec mail cat /etc/opendmarc.conf | grep ^TrustedAuthservID | wc -l" "1" assert "docker exec mail cat /etc/opendmarc.conf | grep ^TrustedAuthservID | wc -l" "1"
# Testing hostname config
assert "docker exec mail cat /etc/mailname" "my-domain.com"
# Ending tests # Ending tests
assert_end assert_end