From 9bcced6f29bb33fa5f85f27bade81906d0e16aa4 Mon Sep 17 00:00:00 2001 From: Thomas VIAL Date: Sun, 18 Oct 2015 21:02:46 +0200 Subject: [PATCH 1/6] Added integration testing - #28 --- .gitignore | 3 ++- .travis.yml | 6 ++++++ Dockerfile | 2 +- Makefile | 30 ++++++++++++++++++++++++++++++ postfix/main.cf | 2 +- test/accounts.cf | 2 ++ test/test.sh | 19 +++++++++++++++++++ test/virtual | 2 ++ 8 files changed, 63 insertions(+), 3 deletions(-) create mode 100644 .travis.yml create mode 100644 Makefile create mode 100644 test/accounts.cf create mode 100755 test/test.sh create mode 100644 test/virtual diff --git a/.gitignore b/.gitignore index 1c3101d7..97490340 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ .DS_Store docker-compose.yml -postfix/ssl/* \ No newline at end of file +postfix/ssl/* +assert.sh \ No newline at end of file diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 00000000..04835d1a --- /dev/null +++ b/.travis.yml @@ -0,0 +1,6 @@ +language: bash +sudo: required +services: + - docker +script: + - make all \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index e029caa4..ff1c1cb9 100644 --- a/Dockerfile +++ b/Dockerfile @@ -4,7 +4,7 @@ MAINTAINER Thomas VIAL # Packages RUN apt-get update -q --fix-missing RUN apt-get -y upgrade -RUN DEBIAN_FRONTEND=noninteractive apt-get -y install vim postfix sasl2-bin courier-imap courier-imap-ssl courier-authdaemon supervisor gamin amavisd-new spamassassin clamav clamav-daemon libnet-dns-perl libmail-spf-perl pyzor razor arj bzip2 cabextract cpio file gzip nomarch p7zip pax unzip zip zoo rsyslog +RUN DEBIAN_FRONTEND=noninteractive apt-get -y install vim postfix sasl2-bin courier-imap courier-imap-ssl courier-authdaemon supervisor gamin amavisd-new spamassassin clamav clamav-daemon libnet-dns-perl libmail-spf-perl pyzor razor arj bzip2 cabextract cpio file gzip nomarch p7zip pax unzip zip zoo rsyslog mailutils RUN apt-get autoclean # Configures Saslauthd diff --git a/Makefile b/Makefile new file mode 100644 index 00000000..45ea6de8 --- /dev/null +++ b/Makefile @@ -0,0 +1,30 @@ +NAME = tvial/docker-mailserver +VERSION = travis + +all: build run prepare fixtures tests + +build: + docker build --no-cache -t $(NAME):$(VERSION) . + +run: + # Copy test files + cp test/accounts.cf postfix/ + cp test/virtual postfix/ + # Run container + docker run -d --name mail -v "`pwd`/postfix":/tmp/postfix -v "`pwd`/spamassassin":/tmp/spamassassin -h mail.my-domain.com -t $(NAME):$(VERSION) + sleep 15 + +prepare: + # Reinitialize logs + docker exec mail /bin/sh -c 'echo "" > /var/log/mail.log' + +fixtures: + docker exec mail /bin/sh -c 'echo "This is a test mail" | mail -s "TEST-001" user@localhost.localdomain' + docker exec mail /bin/sh -c 'echo "This is a test mail" | mail -s "TEST-002" nouser@localhost.localdomain' + docker exec mail /bin/sh -c 'echo "This is a test mail" | mail -s "TEST-003" alias1@localhost.localdomain' + docker exec mail /bin/sh -c 'echo "This is a test mail" | mail -s "TEST-004" alias2@localhost.localdomain' + +tests: + # Start tests + ./test/test.sh + diff --git a/postfix/main.cf b/postfix/main.cf index 7bedd2e8..87f23f8c 100644 --- a/postfix/main.cf +++ b/postfix/main.cf @@ -9,7 +9,7 @@ readme_directory = no # myhostname = alias_maps = hash:/etc/aliases alias_database = hash:/etc/aliases -mydestination = localhost.localdomain, localhost +mydestination = relayhost = mynetworks = 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128 172.17.0.0/16 mailbox_size_limit = 0 diff --git a/test/accounts.cf b/test/accounts.cf new file mode 100644 index 00000000..8f209cc6 --- /dev/null +++ b/test/accounts.cf @@ -0,0 +1,2 @@ +user1@localhost.localdomain|mypassword +user2@otherdomain.tld|mypassword diff --git a/test/test.sh b/test/test.sh new file mode 100755 index 00000000..75575a6c --- /dev/null +++ b/test/test.sh @@ -0,0 +1,19 @@ +#!/bin/bash + +# Set up test framework +# wget -q https://raw.github.com/lehmannro/assert.sh/master/assert.sh +source assert.sh + +# Testing user creation +assert "docker exec mail ls -A /var/mail/localhost.localdomain/user1" "cur\nnew\ntmp" +assert "docker exec mail ls /var/mail/otherdomain.tld/user2" "cur\nnew\ntmp" + +# Testing that mail is received for existing user +assert_raises "docker exec mail grep 'status=sent (delivered to maildir)' /var/log/mail.log" "false" +assert "docker exec mail ls -A /var/mail/localhost.localdomain/user1/new | wc -l" " 1" + +# Ending tests +assert_end + + + diff --git a/test/virtual b/test/virtual new file mode 100644 index 00000000..e93eb8fb --- /dev/null +++ b/test/virtual @@ -0,0 +1,2 @@ +alias1@localhost.localdomain user1@localhost.localdomain +alias2@localhost.localdomain external1@otherdomain.tld From e8163dc7285925076043adaf541e6b1474fd82db Mon Sep 17 00:00:00 2001 From: Thomas VIAL Date: Sun, 18 Oct 2015 21:08:21 +0200 Subject: [PATCH 2/6] Added missing assert.sh --- test/test.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/test.sh b/test/test.sh index 75575a6c..9562d8ba 100755 --- a/test/test.sh +++ b/test/test.sh @@ -1,7 +1,7 @@ #!/bin/bash # Set up test framework -# wget -q https://raw.github.com/lehmannro/assert.sh/master/assert.sh +wget -q https://raw.github.com/lehmannro/assert.sh/master/assert.sh source assert.sh # Testing user creation From 678329276e255711004e0d2a6038952c49b3265e Mon Sep 17 00:00:00 2001 From: Thomas VIAL Date: Sun, 18 Oct 2015 21:30:53 +0200 Subject: [PATCH 3/6] Added new line when needed and fixed a test --- .gitignore | 2 +- .travis.yml | 2 +- Makefile | 1 - test/test.sh | 5 +---- 4 files changed, 3 insertions(+), 7 deletions(-) diff --git a/.gitignore b/.gitignore index 97490340..074b0b91 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,4 @@ .DS_Store docker-compose.yml postfix/ssl/* -assert.sh \ No newline at end of file +assert.sh diff --git a/.travis.yml b/.travis.yml index 04835d1a..3d271e53 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,4 +3,4 @@ sudo: required services: - docker script: - - make all \ No newline at end of file + - make all diff --git a/Makefile b/Makefile index 45ea6de8..e33e4809 100644 --- a/Makefile +++ b/Makefile @@ -27,4 +27,3 @@ fixtures: tests: # Start tests ./test/test.sh - diff --git a/test/test.sh b/test/test.sh index 9562d8ba..37b308cf 100755 --- a/test/test.sh +++ b/test/test.sh @@ -10,10 +10,7 @@ assert "docker exec mail ls /var/mail/otherdomain.tld/user2" "cur\nnew\ntmp" # Testing that mail is received for existing user assert_raises "docker exec mail grep 'status=sent (delivered to maildir)' /var/log/mail.log" "false" -assert "docker exec mail ls -A /var/mail/localhost.localdomain/user1/new | wc -l" " 1" +assert "docker exec mail ls -A /var/mail/localhost.localdomain/user1/new | wc -l" "1" # Ending tests assert_end - - - From c6ad590457912eb78d8b2845603220e2a460001b Mon Sep 17 00:00:00 2001 From: Thomas VIAL Date: Sun, 18 Oct 2015 21:38:22 +0200 Subject: [PATCH 4/6] Use TRAVIS env and updated README with Travis build status --- Makefile | 2 +- README.md | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index e33e4809..80bf968a 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ NAME = tvial/docker-mailserver -VERSION = travis +VERSION = $(TRAVIS_BUILD_ID) all: build run prepare fixtures tests diff --git a/README.md b/README.md index f02720af..82cf57b4 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,7 @@ # docker-mailserver +[![Build Status](https://travis-ci.org/tomav/docker-mailserver.svg)](https://travis-ci.org/tomav/docker-mailserver) + A fullstack but simple mail server (smtp, imap, antispam, antivirus...). Only configuration files, no SQL database. Keep it simple and versioned. Easy to deploy and upgrade. From 534b417800185ae2430e6907f61331bbe26f6683 Mon Sep 17 00:00:00 2001 From: Thomas VIAL Date: Sun, 18 Oct 2015 22:02:47 +0200 Subject: [PATCH 5/6] Added test for crontab and services --- .gitignore | 2 +- test/test.sh | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 074b0b91..2fc3256c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,4 @@ .DS_Store docker-compose.yml postfix/ssl/* -assert.sh +assert.sh* diff --git a/test/test.sh b/test/test.sh index 37b308cf..6cca8dcd 100755 --- a/test/test.sh +++ b/test/test.sh @@ -4,6 +4,12 @@ wget -q https://raw.github.com/lehmannro/assert.sh/master/assert.sh source assert.sh +# Testing that services are running +assert_raises "docker exec mail ps aux --forest | grep '/usr/lib/postfix/master'" "true" +assert_raises "docker exec mail ps aux --forest | grep '/usr/sbin/saslauthd'" "true" +assert_raises "docker exec mail ps aux --forest | grep '/usr/sbin/clamd'" "true" +assert_raises "docker exec mail ps aux --forest | grep '/usr/sbin/amavisd-new'" "true" + # Testing user creation assert "docker exec mail ls -A /var/mail/localhost.localdomain/user1" "cur\nnew\ntmp" assert "docker exec mail ls /var/mail/otherdomain.tld/user2" "cur\nnew\ntmp" @@ -12,5 +18,8 @@ assert "docker exec mail ls /var/mail/otherdomain.tld/user2" "cur\nnew\ntmp" assert_raises "docker exec mail grep 'status=sent (delivered to maildir)' /var/log/mail.log" "false" assert "docker exec mail ls -A /var/mail/localhost.localdomain/user1/new | wc -l" "1" +# Testing presence of freshclam CRON +assert "docker exec mail crontab -l" "0 1 * * * /usr/bin/freshclam --quiet" + # Ending tests assert_end From 7a8dd41c69f0924eb7da3d85c4a2a259260f30ac Mon Sep 17 00:00:00 2001 From: Thomas VIAL Date: Sun, 18 Oct 2015 22:08:21 +0200 Subject: [PATCH 6/6] Added comment --- Makefile | 1 + 1 file changed, 1 insertion(+) diff --git a/Makefile b/Makefile index 80bf968a..c7a0a323 100644 --- a/Makefile +++ b/Makefile @@ -19,6 +19,7 @@ prepare: docker exec mail /bin/sh -c 'echo "" > /var/log/mail.log' fixtures: + # Sending test mails docker exec mail /bin/sh -c 'echo "This is a test mail" | mail -s "TEST-001" user@localhost.localdomain' docker exec mail /bin/sh -c 'echo "This is a test mail" | mail -s "TEST-002" nouser@localhost.localdomain' docker exec mail /bin/sh -c 'echo "This is a test mail" | mail -s "TEST-003" alias1@localhost.localdomain'