mirror of
https://github.com/docker-mailserver/docker-mailserver.git
synced 2025-08-04 18:15:29 +02:00
feat: Postfix permit DSN (Delivery Status Notification) only on authenticated ports (465 + 587) (#3572)
* add POSTFIX_DSN
* add tests for POSTFIX_DSN
* Revert "add POSTFIX_DSN"
This reverts commit d5bd0e9117
.
* discard DSN requests on unauthenticated ports
* make tests work with overrides instead of ENV
* Apply suggestions from code review
* fix test inconsistencies
---------
Co-authored-by: allddd <allddd@proton.me>
Co-authored-by: Brennan Kinney <5098581+polarathene@users.noreply.github.com>
This commit is contained in:
parent
811a769845
commit
eacc379cf1
8 changed files with 138 additions and 0 deletions
1
test/config/dsn/postfix-main.cf
Normal file
1
test/config/dsn/postfix-main.cf
Normal file
|
@ -0,0 +1 @@
|
|||
smtpd_discard_ehlo_keywords =
|
2
test/config/dsn/postfix-master.cf
Normal file
2
test/config/dsn/postfix-master.cf
Normal file
|
@ -0,0 +1,2 @@
|
|||
submission/inet/smtpd_discard_ehlo_keywords=silent-discard,dsn
|
||||
submissions/inet/smtpd_discard_ehlo_keywords=silent-discard,dsn
|
14
test/test-files/email-templates/dsn-authenticated.txt
Normal file
14
test/test-files/email-templates/dsn-authenticated.txt
Normal file
|
@ -0,0 +1,14 @@
|
|||
EHLO mail
|
||||
AUTH LOGIN dXNlcjFAbG9jYWxob3N0LmxvY2FsZG9tYWlu
|
||||
bXlwYXNzd29yZA==
|
||||
MAIL FROM: user1@localhost.localdomain
|
||||
RCPT TO: user1@localhost.localdomain NOTIFY=success,failure
|
||||
DATA
|
||||
From: Existing Local User <user1@localhost.localdomain>
|
||||
To: Existing Local User <user1@localhost.localdomain>
|
||||
Date: Sat, 22 May 2010 07:43:25 -0400
|
||||
Subject: Test Message
|
||||
This is a test mail.
|
||||
|
||||
.
|
||||
QUIT
|
12
test/test-files/email-templates/dsn-unauthenticated.txt
Normal file
12
test/test-files/email-templates/dsn-unauthenticated.txt
Normal file
|
@ -0,0 +1,12 @@
|
|||
HELO mail.external.tld
|
||||
MAIL FROM: user@external.tld
|
||||
RCPT TO: user1@localhost.localdomain NOTIFY=success,failure
|
||||
DATA
|
||||
From: Docker Mail Server <dockermailserver@external.tld>
|
||||
To: Existing Local User <user1@localhost.localdomain>
|
||||
Date: Sat, 22 May 2010 07:43:25 -0400
|
||||
Subject: Test Message
|
||||
This is a test mail.
|
||||
|
||||
.
|
||||
QUIT
|
95
test/tests/parallel/set3/mta/dsn.bats
Normal file
95
test/tests/parallel/set3/mta/dsn.bats
Normal file
|
@ -0,0 +1,95 @@
|
|||
load "${REPOSITORY_ROOT}/test/helper/setup"
|
||||
load "${REPOSITORY_ROOT}/test/helper/common"
|
||||
|
||||
BATS_TEST_NAME_PREFIX='[DSN] '
|
||||
CONTAINER1_NAME='dms-test_dsn_send_always'
|
||||
CONTAINER2_NAME='dms-test_dsn_send_auth'
|
||||
CONTAINER3_NAME='dms-test_dsn_send_none'
|
||||
# A similar line is added to the log when a DSN (Delivery Status Notification) is sent:
|
||||
#
|
||||
# postfix/bounce[1023]: C943BA6B46: sender delivery status notification: DBF86A6B4CO
|
||||
#
|
||||
LOG_DSN='delivery status notification'
|
||||
|
||||
function setup_file() {
|
||||
local CUSTOM_SETUP_ARGUMENTS=(
|
||||
# Required only for delivery via nc (_send_email)
|
||||
--env PERMIT_DOCKER=container
|
||||
)
|
||||
|
||||
export CONTAINER_NAME=${CONTAINER1_NAME}
|
||||
_init_with_defaults
|
||||
# Unset `smtpd_discard_ehlo_keywords` to allow DSNs by default on any `smtpd` service:
|
||||
cp "${TEST_TMP_CONFIG}/dsn/postfix-main.cf" "${TEST_TMP_CONFIG}/postfix-main.cf"
|
||||
_common_container_setup 'CUSTOM_SETUP_ARGUMENTS'
|
||||
_wait_for_service postfix
|
||||
_wait_for_smtp_port_in_container
|
||||
|
||||
export CONTAINER_NAME=${CONTAINER2_NAME}
|
||||
_init_with_defaults
|
||||
_common_container_setup 'CUSTOM_SETUP_ARGUMENTS'
|
||||
_wait_for_service postfix
|
||||
_wait_for_smtp_port_in_container
|
||||
|
||||
export CONTAINER_NAME=${CONTAINER3_NAME}
|
||||
_init_with_defaults
|
||||
# Mirror default main.cf (disable DSN on ports 465 + 587 too):
|
||||
cp "${TEST_TMP_CONFIG}/dsn/postfix-master.cf" "${TEST_TMP_CONFIG}/postfix-master.cf"
|
||||
_common_container_setup 'CUSTOM_SETUP_ARGUMENTS'
|
||||
_wait_for_service postfix
|
||||
_wait_for_smtp_port_in_container
|
||||
}
|
||||
|
||||
function teardown_file() {
|
||||
docker rm -f "${CONTAINER1_NAME}" "${CONTAINER2_NAME}" "${CONTAINER3_NAME}"
|
||||
}
|
||||
|
||||
@test "should always send a DSN when requested" {
|
||||
export CONTAINER_NAME=${CONTAINER1_NAME}
|
||||
|
||||
_send_email 'email-templates/dsn-unauthenticated'
|
||||
_send_email 'email-templates/dsn-authenticated' '0.0.0.0 465'
|
||||
_send_email 'email-templates/dsn-authenticated' '0.0.0.0 587'
|
||||
_wait_for_empty_mail_queue_in_container
|
||||
|
||||
_run_in_container grep "${LOG_DSN}" /var/log/mail/mail.log
|
||||
_should_output_number_of_lines 3
|
||||
}
|
||||
|
||||
# Defaults test case
|
||||
@test "should only send a DSN when requested from ports 465/587" {
|
||||
export CONTAINER_NAME=${CONTAINER2_NAME}
|
||||
|
||||
_send_email 'email-templates/dsn-unauthenticated'
|
||||
_wait_for_empty_mail_queue_in_container
|
||||
|
||||
# DSN requests can now only be made on ports 465 and 587,
|
||||
# so grep should not find anything.
|
||||
#
|
||||
# Although external requests are discarded, anyone who has requested a DSN
|
||||
# will still receive it, but it will come from the sending mail server, not this one.
|
||||
_run_in_container grep "${LOG_DSN}" /var/log/mail/mail.log
|
||||
assert_failure
|
||||
|
||||
# These ports are excluded via master.cf.
|
||||
_send_email 'email-templates/dsn-authenticated' '0.0.0.0 465'
|
||||
_send_email 'email-templates/dsn-authenticated' '0.0.0.0 587'
|
||||
_wait_for_empty_mail_queue_in_container
|
||||
|
||||
_run_in_container grep "${LOG_DSN}" /var/log/mail/mail.log
|
||||
_should_output_number_of_lines 2
|
||||
}
|
||||
|
||||
@test "should never send a DSN" {
|
||||
export CONTAINER_NAME=${CONTAINER3_NAME}
|
||||
|
||||
_send_email 'email-templates/dsn-unauthenticated'
|
||||
_send_email 'email-templates/dsn-authenticated' '0.0.0.0 465'
|
||||
_send_email 'email-templates/dsn-authenticated' '0.0.0.0 587'
|
||||
_wait_for_empty_mail_queue_in_container
|
||||
|
||||
# DSN requests are rejected regardless of origin.
|
||||
# This is usually a bad idea, as you won't get them either.
|
||||
_run_in_container grep "${LOG_DSN}" /var/log/mail/mail.log
|
||||
assert_failure
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue