diff --git a/.travis.yml b/.travis.yml index 69d2bbd7..550eff22 100644 --- a/.travis.yml +++ b/.travis.yml @@ -14,7 +14,7 @@ after_script: env: - SMTP_ONLY=0 ENABLE_CLAMAV=1 ENABLE_SPAMASSASSIN=1 ENABLE_FAIL2BAN=1 ONE_DIR=1 ENABLE_POP3=1 ENABLE_MANAGESIEVE=1 ENABLE_FETCHMAIL=1 PERMIT_DOCKER=host DMS_DEBUG=0 SA_TAG=1.0 SA_TAG2=2.0 SA_KILL=3.0 VIRUSMAILS_DELETE_DELAY=7 SASL_PASSWD="external domain.com username:password" - SMTP_ONLY=0 ENABLE_CLAMAV=0 ENABLE_SPAMASSASSIN=0 ENABLE_FAIL2BAN=0 ONE_DIR=0 ENABLE_POP3=0 ENABLE_MANAGESIEVE=0 ENABLE_FETCHMAIL=0 PERMIT_DOCKER=network DMS_DEBUG=1 -- SMTP_ONLY=1 +- SMTP_ONLY=1 ENABLE_LDAP=1 LDAP_SERVER_HOST=ldap LDAP_SEARCH_BASE=ou=people,dc=localhost,dc=localdomain LDAP_BIND_DN=cn=admin,dc=localhost,dc=localdomain ENABLE_SASLAUTHD=1 SASLAUTHD_MECHANISMS=ldap SASLAUTHD_LDAP_SERVER=ldap SASLAUTHD_LDAP_BIND_DN=cn=admin,dc=localhost,dc=localdomain SASLAUTHD_LDAP_PASSWORD=admin SASLAUTHD_LDAP_SEARCH_BASE=ou=people,dc=localhost,dc=localdomain POSTMASTER_ADDRESS=postmaster@localhost.localdomain notifications: slack: diff --git a/Makefile b/Makefile index 67e9c960..2f51a85e 100644 --- a/Makefile +++ b/Makefile @@ -17,6 +17,11 @@ generate-accounts: docker run --rm -e MAIL_USER=user2@otherdomain.tld -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 run: + if [ -z $(ENABLE_LDAP) ]; then + docker run -d --name ldap_for_mail \ + -e LDAP_DOMAIN="localhost.localdomain" \ + -h mail.my-domain.com -t ldap + fi # Run containers docker run -d --name mail \ -v "`pwd`/test/config":/tmp/docker-mailserver \ @@ -30,6 +35,16 @@ run: -e ENABLE_FETCHMAIL=$(ENABLE_FETCHMAIL) \ -e ONE_DIR=$(ONE_DIR) \ -e PERMIT_DOCKER=$(PERMIT_DOCKER) \ + -e ENABLE_LDAP=$(ENABLE_LDAP) \ + -e LDAP_SERVER_HOST=$(LDAP_SERVER_HOST) \ + -e LDAP_SEARCH_BASE=$(LDAP_SEARCH_BASE) \ + -e LDAP_BIND_DN=$(LDAP_BIND_DN) \ + -e ENABLE_SASLAUTHD=$(ENABLE_SASLAUTHD) \ + -e SASLAUTHD_MECHANISMS=$(SASLAUTHD_MECHANISMS) \ + -e SASLAUTHD_LDAP_SERVER=$(SASLAUTHD_LDAP_SERVER) \ + -e SASLAUTHD_LDAP_BIND_DN=$(SASLAUTHD_LDAP_BIND_DN) \ + -e SASLAUTHD_LDAP_PASSWORD=$(SASLAUTHD_LDAP_PASSWORD) \ + -e SASLAUTHD_LDAP_SEARCH_BASE=$(SASLAUTHD_LDAP_SEARCH_BASE) \ -e SMTP_ONLY=$(SMTP_ONLY) \ -e SA_TAG=$(SA_TAG) \ -e SA_TAG2=$(SA_TAG2) \ @@ -39,6 +54,8 @@ run: -e DMS_DEBUG=$(DMS_DEBUG) \ --cap-add=NET_ADMIN \ -h mail.my-domain.com -t $(NAME) + + # Wait for containers to fully start sleep 15 @@ -70,7 +87,8 @@ tests: clean: # Remove running test containers -docker rm -f \ - mail + mail \ + ldap_for_mail @if [ -f config/postfix-accounts.cf.bak ]; then\ rm -f config/postfix-accounts.cf ;\ diff --git a/test/tests.bats b/test/tests.bats index 54053b92..1fb0b8f2 100644 --- a/test/tests.bats +++ b/test/tests.bats @@ -86,18 +86,18 @@ } @test "checking process: saslauthd (enabled by ENABLE_SASLAUTHD=0)" { - if [" $ENABLE_FETCHMAIL" -eq 0 ]; then + if [" $ENABLE_SASLAUTHD" -eq 0 ]; then run docker exec mail /bin/bash -c "ps aux --forest | grep -v grep | grep '/usr/sbin/saslauthd'" [ "$status" -eq 1 ] - elif [ "$ENABLE_FETCHMAIL" -eq 1 ]; then + elif [ "$ENABLE_SASLAUTHD" -eq 1 ]; then skip fi } @test "checking process: saslauthd (enabled by ENABLE_SASLAUTHD=1)" { - if [ "$ENABLE_FETCHMAIL" -eq 0 ]; then + if [ "$ENABLE_SASLAUTHD" -eq 0 ]; then skip - elif [ "$ENABLE_FETCHMAIL" -eq 1 ]; then + elif [ "$ENABLE_SASLAUTHD" -eq 1 ]; then run docker exec mail /bin/bash -c "ps aux --forest | grep -v grep | grep '/usr/sbin/saslauthd'" [ "$status" -eq 0 ] fi @@ -961,6 +961,9 @@ # postfix @test "checking postfix: ldap lookup works correctly" { + if [ $ENABLE_LDAP -q 0 ]; then + skip + fi run docker exec mail /bin/sh -c "postmap -q some.user@localhost.localdomain ldap:/etc/postfix/ldap-users.cf" [ "$status" -eq 0 ] [ "$output" = "some.user@localhost.localdomain" ] @@ -974,11 +977,17 @@ # dovecot @test "checking dovecot: ldap imap connection and authentication works" { + if [ $ENABLE_LDAP -q 0 ]; then + skip + fi run docker exec mail /bin/sh -c "nc -w 1 0.0.0.0 143 < /tmp/docker-mailserver-test/auth/imap-ldap-auth.txt" [ "$status" -eq 0 ] } @test "checking dovecot: mail delivery works" { + if [ $ENABLE_LDAP -q 0 ]; then + skip + fi run docker exec mail /bin/sh -c "sendmail -f user@external.tld some.user@localhost.localdomain < /tmp/docker-mailserver-test/email-templates/test-email.txt" sleep 10 run docker exec mail /bin/sh -c "ls -A /var/mail/localhost.localdomain/some.user/new | wc -l" @@ -988,11 +997,17 @@ # saslauthd @test "checking saslauthd: sasl ldap authentication works" { + if [ $ENABLE_SASLAUTHD -q 0 ]; then + skip + fi run docker exec mail bash -c "testsaslauthd -u some.user -p secret" [ "$status" -eq 0 ] } @test "checking saslauthd: ldap smtp authentication" { + if [ $ENABLE_SASLAUTHD -q 0 ]; then + skip + fi run docker exec mail /bin/sh -c "nc -w 5 0.0.0.0 25 < /tmp/docker-mailserver-test/auth/sasl-ldap-smtp-auth.txt | grep 'Authentication successful'" [ "$status" -eq 0 ] }