Deliver root mail (#952)

* Configure delivery of root's mail to postmaster
* Tests for delivery of root mail
* add missing email template
This commit is contained in:
Paul Adams 2018-04-23 19:35:33 +01:00 committed by Johan Smits
parent 39954da78e
commit ea848eb86f
6 changed files with 26 additions and 7 deletions

View file

@ -249,6 +249,7 @@ fixtures:
docker exec mail /bin/sh -c "nc 0.0.0.0 25 < /tmp/docker-mailserver-test/email-templates/sieve-pipe.txt" docker exec mail /bin/sh -c "nc 0.0.0.0 25 < /tmp/docker-mailserver-test/email-templates/sieve-pipe.txt"
docker exec mail /bin/sh -c "nc 0.0.0.0 25 < /tmp/docker-mailserver-test/email-templates/non-existing-user.txt" docker exec mail /bin/sh -c "nc 0.0.0.0 25 < /tmp/docker-mailserver-test/email-templates/non-existing-user.txt"
docker exec mail_disabled_clamav_spamassassin /bin/sh -c "nc 0.0.0.0 25 < /tmp/docker-mailserver-test/email-templates/existing-user1.txt" docker exec mail_disabled_clamav_spamassassin /bin/sh -c "nc 0.0.0.0 25 < /tmp/docker-mailserver-test/email-templates/existing-user1.txt"
docker exec mail /bin/sh -c "sendmail root < /tmp/docker-mailserver-test/email-templates/root-email.txt"
# postfix virtual transport lmtp # postfix virtual transport lmtp
docker exec mail_lmtp_ip /bin/sh -c "nc 0.0.0.0 25 < /tmp/docker-mailserver-test/email-templates/existing-user1.txt" docker exec mail_lmtp_ip /bin/sh -c "nc 0.0.0.0 25 < /tmp/docker-mailserver-test/email-templates/existing-user1.txt"
docker exec mail_privacy /bin/sh -c "openssl s_client -quiet -starttls smtp -connect 0.0.0.0:587 < /tmp/docker-mailserver-test/email-templates/send-privacy-email.txt" docker exec mail_privacy /bin/sh -c "openssl s_client -quiet -starttls smtp -connect 0.0.0.0:587 < /tmp/docker-mailserver-test/email-templates/send-privacy-email.txt"

View file

@ -7,9 +7,9 @@ readme_directory = no
# Basic configuration # Basic configuration
# myhostname = # myhostname =
alias_maps = texthash:/etc/aliases alias_maps = hash:/etc/aliases
alias_database = texthash:/etc/aliases alias_database = hash:/etc/aliases
mydestination = mydestination = $myhostname, localhost.$mydomain, localhost
relayhost = relayhost =
mynetworks = 127.0.0.0/8 [::1]/128 [fe80::]/64 mynetworks = 127.0.0.0/8 [::1]/128 [fe80::]/64
mailbox_size_limit = 0 mailbox_size_limit = 0

View file

@ -656,7 +656,7 @@ function _setup_spoof_protection () {
sed -i 's|smtpd_sender_restrictions =|smtpd_sender_restrictions = reject_authenticated_sender_login_mismatch,|' /etc/postfix/main.cf sed -i 's|smtpd_sender_restrictions =|smtpd_sender_restrictions = reject_authenticated_sender_login_mismatch,|' /etc/postfix/main.cf
[ "$ENABLE_LDAP" = 1 ] \ [ "$ENABLE_LDAP" = 1 ] \
&& postconf -e "smtpd_sender_login_maps=ldap:/etc/postfix/ldap-users.cf ldap:/etc/postfix/ldap-aliases.cf ldap:/etc/postfix/ldap-groups.cf" \ && postconf -e "smtpd_sender_login_maps=ldap:/etc/postfix/ldap-users.cf ldap:/etc/postfix/ldap-aliases.cf ldap:/etc/postfix/ldap-groups.cf" \
|| postconf -e "smtpd_sender_login_maps=texthash:/etc/postfix/virtual, texthash:/etc/aliases, pcre:/etc/postfix/maps/sender_login_maps.pcre" || postconf -e "smtpd_sender_login_maps=texthash:/etc/postfix/virtual, hash:/etc/aliases, pcre:/etc/postfix/maps/sender_login_maps.pcre"
} }
function _setup_postfix_access_control() { function _setup_postfix_access_control() {
@ -754,6 +754,10 @@ function _setup_postfix_aliases() {
s/$/ pcre:\/etc\/postfix\/regexp/ s/$/ pcre:\/etc\/postfix\/regexp/
}' /etc/postfix/main.cf }' /etc/postfix/main.cf
fi fi
notify 'inf' "Configuring root alias"
echo "root: ${POSTMASTER_ADDRESS}" > /etc/aliases
postalias /etc/aliases
} }
function _setup_SRS() { function _setup_SRS() {

View file

@ -1,2 +1,4 @@
/^test[0-9][0-9]*@localhost.localdomain/ user1@localhost.localdomain /^test[0-9][0-9]*@localhost.localdomain/ user1@localhost.localdomain
/^bounce.*@.*/ external1@otherdomain.tld /^bounce.*@.*/ external1@otherdomain.tld
/^postmaster@/ user1@localhost.localdomain

View file

@ -0,0 +1,3 @@
Subject: Root Test Message
This is a test mail.

View file

@ -296,7 +296,7 @@ load 'test_helper/bats-assert/load'
@test "checking smtp: delivers mail to existing account" { @test "checking smtp: delivers mail to existing account" {
run docker exec mail /bin/sh -c "grep 'postfix/lmtp' /var/log/mail/mail.log | grep 'status=sent' | grep ' Saved)' | wc -l" run docker exec mail /bin/sh -c "grep 'postfix/lmtp' /var/log/mail/mail.log | grep 'status=sent' | grep ' Saved)' | wc -l"
assert_success assert_success
assert_output 10 assert_output 12
} }
@test "checking smtp: delivers mail to existing alias" { @test "checking smtp: delivers mail to existing alias" {
@ -326,10 +326,10 @@ load 'test_helper/bats-assert/load'
assert_output 1 assert_output 1
} }
@test "checking smtp: user1 should have received 6 mails" { @test "checking smtp: user1 should have received 9 mails" {
run docker exec mail /bin/sh -c "ls -A /var/mail/localhost.localdomain/user1/new | wc -l" run docker exec mail /bin/sh -c "ls -A /var/mail/localhost.localdomain/user1/new | wc -l"
assert_success assert_success
assert_output 7 assert_output 9
} }
@test "checking smtp: rejects mail to unknown user" { @test "checking smtp: rejects mail to unknown user" {
@ -1708,3 +1708,12 @@ load 'test_helper/bats-assert/load'
run docker exec mail_with_relays /bin/sh -c 'cat /etc/postfix/sasl_passwd | grep -e "^\[default.relay.com\]:2525\s\+smtp_user:smtp_password" | wc -l | grep 1' run docker exec mail_with_relays /bin/sh -c 'cat /etc/postfix/sasl_passwd | grep -e "^\[default.relay.com\]:2525\s\+smtp_user:smtp_password" | wc -l | grep 1'
assert_success assert_success
} }
#
# root mail delivery
#
@test "checking that mail for root was delivered" {
run docker exec mail grep "Subject: Root Test Message" /var/mail/localhost.localdomain/user1/new/ -R
assert_success
}