mirror of
https://github.com/docker-mailserver/docker-mailserver.git
synced 2025-08-31 15:30:50 +02:00
tests(refactor): Improve consistency and documentation for test helpers (#3012)
This commit is contained in:
parent
fb82082cf1
commit
e3c4ef76c6
32 changed files with 936 additions and 656 deletions
|
@ -5,19 +5,19 @@ BATS_TEST_NAME_PREFIX='[Relay] (ENV) '
|
|||
CONTAINER_NAME='dms-test_default-relay-host'
|
||||
|
||||
function setup_file() {
|
||||
init_with_defaults
|
||||
_init_with_defaults
|
||||
|
||||
local CUSTOM_SETUP_ARGUMENTS=(
|
||||
--env DEFAULT_RELAY_HOST=default.relay.host.invalid:25
|
||||
--env PERMIT_DOCKER=host
|
||||
)
|
||||
|
||||
common_container_setup 'CUSTOM_SETUP_ARGUMENTS'
|
||||
_common_container_setup 'CUSTOM_SETUP_ARGUMENTS'
|
||||
}
|
||||
|
||||
function teardown_file() { _default_teardown ; }
|
||||
|
||||
@test "'DEFAULT_RELAY_HOST' should configure 'main.cf:relayhost'" {
|
||||
_run_in_container bash -c 'grep -e "^relayhost =" /etc/postfix/main.cf'
|
||||
_run_in_container_bash 'grep -e "^relayhost =" /etc/postfix/main.cf'
|
||||
assert_output 'relayhost = default.relay.host.invalid:25'
|
||||
}
|
||||
|
|
|
@ -5,7 +5,7 @@ BATS_TEST_NAME_PREFIX='[Amavis] '
|
|||
CONTAINER_NAME='dms-test_amavis'
|
||||
|
||||
function setup_file() {
|
||||
init_with_defaults
|
||||
_init_with_defaults
|
||||
|
||||
local CUSTOM_SETUP_ARGUMENTS=(
|
||||
--env ENABLE_AMAVIS=1
|
||||
|
@ -13,14 +13,14 @@ function setup_file() {
|
|||
--env ENABLE_SPAMASSASSIN=1
|
||||
)
|
||||
|
||||
common_container_setup 'CUSTOM_SETUP_ARGUMENTS'
|
||||
_common_container_setup 'CUSTOM_SETUP_ARGUMENTS'
|
||||
}
|
||||
|
||||
function teardown_file() { _default_teardown ; }
|
||||
|
||||
@test "SpamAssassin integration should be active" {
|
||||
# give Amavis just a bit of time to print out its full debug log
|
||||
run repeat_in_container_until_success_or_timeout 5 "${CONTAINER_NAME}" grep 'ANTI-SPAM-SA' /var/log/mail/mail.log
|
||||
run _repeat_in_container_until_success_or_timeout 5 "${CONTAINER_NAME}" grep 'ANTI-SPAM-SA' /var/log/mail/mail.log
|
||||
assert_success
|
||||
assert_output --partial 'loaded'
|
||||
refute_output --partial 'NOT loaded'
|
||||
|
|
|
@ -5,7 +5,7 @@ BATS_TEST_NAME_PREFIX='[ClamAV] '
|
|||
CONTAINER_NAME='dms-test_clamav'
|
||||
|
||||
function setup_file() {
|
||||
init_with_defaults
|
||||
_init_with_defaults
|
||||
|
||||
# Comment for maintainers about `PERMIT_DOCKER=host`:
|
||||
# https://github.com/docker-mailserver/docker-mailserver/pull/2815/files#r991087509
|
||||
|
@ -18,24 +18,24 @@ function setup_file() {
|
|||
--env LOG_LEVEL=trace
|
||||
)
|
||||
|
||||
common_container_setup 'CUSTOM_SETUP_ARGUMENTS'
|
||||
_common_container_setup 'CUSTOM_SETUP_ARGUMENTS'
|
||||
|
||||
# wait for ClamAV to be fully setup or we will get errors on the log
|
||||
repeat_in_container_until_success_or_timeout 60 "${CONTAINER_NAME}" test -e /var/run/clamav/clamd.ctl
|
||||
_repeat_in_container_until_success_or_timeout 60 "${CONTAINER_NAME}" test -e /var/run/clamav/clamd.ctl
|
||||
|
||||
wait_for_service "${CONTAINER_NAME}" postfix
|
||||
wait_for_smtp_port_in_container "${CONTAINER_NAME}"
|
||||
_wait_for_service postfix
|
||||
_wait_for_smtp_port_in_container
|
||||
|
||||
_run_in_container bash -c "nc 0.0.0.0 25 < /tmp/docker-mailserver-test/email-templates/amavis-virus.txt"
|
||||
_run_in_container_bash "nc 0.0.0.0 25 < /tmp/docker-mailserver-test/email-templates/amavis-virus.txt"
|
||||
assert_success
|
||||
|
||||
wait_for_empty_mail_queue_in_container "${CONTAINER_NAME}"
|
||||
_wait_for_empty_mail_queue_in_container
|
||||
}
|
||||
|
||||
function teardown_file() { _default_teardown ; }
|
||||
|
||||
@test "log files exist at /var/log/mail directory" {
|
||||
_run_in_container bash -c "ls -1 /var/log/mail/ | grep -E 'clamav|freshclam|mail.log' | wc -l"
|
||||
_run_in_container_bash "ls -1 /var/log/mail/ | grep -E 'clamav|freshclam|mail.log' | wc -l"
|
||||
assert_success
|
||||
assert_output 3
|
||||
}
|
||||
|
@ -46,7 +46,7 @@ function teardown_file() { _default_teardown ; }
|
|||
}
|
||||
|
||||
@test "freshclam cron is enabled" {
|
||||
_run_in_container bash -c "grep '/usr/bin/freshclam' -r /etc/cron.d"
|
||||
_run_in_container_bash "grep '/usr/bin/freshclam' -r /etc/cron.d"
|
||||
assert_success
|
||||
}
|
||||
|
||||
|
@ -56,6 +56,6 @@ function teardown_file() { _default_teardown ; }
|
|||
}
|
||||
|
||||
@test "rejects virus" {
|
||||
_run_in_container bash -c "grep 'Blocked INFECTED' /var/log/mail/mail.log | grep '<virus@external.tld> -> <user1@localhost.localdomain>'"
|
||||
_run_in_container_bash "grep 'Blocked INFECTED' /var/log/mail/mail.log | grep '<virus@external.tld> -> <user1@localhost.localdomain>'"
|
||||
assert_success
|
||||
}
|
||||
|
|
|
@ -5,7 +5,7 @@ BATS_TEST_NAME_PREFIX='[ClamAV + SA] (disabled) '
|
|||
CONTAINER_NAME='dms-test_clamav-spamassasin_disabled'
|
||||
|
||||
function setup_file() {
|
||||
init_with_defaults
|
||||
_init_with_defaults
|
||||
|
||||
local CUSTOM_SETUP_ARGUMENTS=(
|
||||
--env ENABLE_AMAVIS=1
|
||||
|
@ -14,12 +14,12 @@ function setup_file() {
|
|||
--env AMAVIS_LOGLEVEL=2
|
||||
)
|
||||
|
||||
common_container_setup 'CUSTOM_SETUP_ARGUMENTS'
|
||||
wait_for_smtp_port_in_container "${CONTAINER_NAME}"
|
||||
_common_container_setup 'CUSTOM_SETUP_ARGUMENTS'
|
||||
_wait_for_smtp_port_in_container
|
||||
|
||||
_run_in_container bash -c "nc 0.0.0.0 25 < /tmp/docker-mailserver-test/email-templates/existing-user1.txt"
|
||||
_run_in_container_bash "nc 0.0.0.0 25 < /tmp/docker-mailserver-test/email-templates/existing-user1.txt"
|
||||
assert_success
|
||||
wait_for_empty_mail_queue_in_container "${CONTAINER_NAME}"
|
||||
_wait_for_empty_mail_queue_in_container
|
||||
}
|
||||
|
||||
function teardown_file() { _default_teardown ; }
|
||||
|
@ -30,7 +30,7 @@ function teardown_file() { _default_teardown ; }
|
|||
}
|
||||
|
||||
@test "SA - Amavis integration should not be active" {
|
||||
_run_in_container bash -c "grep -i 'ANTI-SPAM-SA code' /var/log/mail/mail.log | grep 'NOT loaded'"
|
||||
_run_in_container_bash "grep -i 'ANTI-SPAM-SA code' /var/log/mail/mail.log | grep 'NOT loaded'"
|
||||
assert_success
|
||||
}
|
||||
|
||||
|
|
|
@ -10,17 +10,17 @@ function setup_file() {
|
|||
local CUSTOM_SETUP_ARGUMENTS=(
|
||||
--env ENABLE_DNSBL=1
|
||||
)
|
||||
init_with_defaults
|
||||
common_container_setup 'CUSTOM_SETUP_ARGUMENTS'
|
||||
wait_for_smtp_port_in_container "${CONTAINER_NAME}"
|
||||
_init_with_defaults
|
||||
_common_container_setup 'CUSTOM_SETUP_ARGUMENTS'
|
||||
_wait_for_smtp_port_in_container
|
||||
|
||||
local CONTAINER_NAME=${CONTAINER2_NAME}
|
||||
local CUSTOM_SETUP_ARGUMENTS=(
|
||||
--env ENABLE_DNSBL=0
|
||||
)
|
||||
init_with_defaults
|
||||
common_container_setup 'CUSTOM_SETUP_ARGUMENTS'
|
||||
wait_for_smtp_port_in_container "${CONTAINER_NAME}"
|
||||
_init_with_defaults
|
||||
_common_container_setup 'CUSTOM_SETUP_ARGUMENTS'
|
||||
_wait_for_smtp_port_in_container
|
||||
}
|
||||
|
||||
function teardown_file() {
|
||||
|
@ -29,32 +29,32 @@ function teardown_file() {
|
|||
|
||||
# ENABLE_DNSBL=1
|
||||
@test "(enabled) Postfix DNS block list zen.spamhaus.org" {
|
||||
run docker exec "${CONTAINER1_NAME}" postconf smtpd_recipient_restrictions
|
||||
_run_in_container_explicit "${CONTAINER1_NAME}" postconf smtpd_recipient_restrictions
|
||||
assert_output --partial 'reject_rbl_client zen.spamhaus.org'
|
||||
}
|
||||
|
||||
@test "(enabled) Postscreen DNS block lists -> postscreen_dnsbl_action" {
|
||||
run docker exec "${CONTAINER1_NAME}" postconf postscreen_dnsbl_action
|
||||
_run_in_container_explicit "${CONTAINER1_NAME}" postconf postscreen_dnsbl_action
|
||||
assert_output 'postscreen_dnsbl_action = enforce'
|
||||
}
|
||||
|
||||
@test "(enabled) Postscreen DNS block lists -> postscreen_dnsbl_sites" {
|
||||
run docker exec "${CONTAINER1_NAME}" postconf postscreen_dnsbl_sites
|
||||
_run_in_container_explicit "${CONTAINER1_NAME}" postconf postscreen_dnsbl_sites
|
||||
assert_output 'postscreen_dnsbl_sites = zen.spamhaus.org=127.0.0.[2..11]*3 bl.mailspike.net=127.0.0.[2;14;13;12;11;10] b.barracudacentral.org*2 bl.spameatingmonkey.net=127.0.0.2 dnsbl.sorbs.net psbl.surriel.com list.dnswl.org=127.0.[0..255].0*-2 list.dnswl.org=127.0.[0..255].1*-3 list.dnswl.org=127.0.[0..255].[2..3]*-4'
|
||||
}
|
||||
|
||||
# ENABLE_DNSBL=0
|
||||
@test "(disabled) Postfix DNS block list zen.spamhaus.org" {
|
||||
run docker exec "${CONTAINER2_NAME}" postconf smtpd_recipient_restrictions
|
||||
_run_in_container_explicit "${CONTAINER2_NAME}" postconf smtpd_recipient_restrictions
|
||||
refute_output --partial 'reject_rbl_client zen.spamhaus.org'
|
||||
}
|
||||
|
||||
@test "(disabled) Postscreen DNS block lists -> postscreen_dnsbl_action" {
|
||||
run docker exec "${CONTAINER2_NAME}" postconf postscreen_dnsbl_action
|
||||
_run_in_container_explicit "${CONTAINER2_NAME}" postconf postscreen_dnsbl_action
|
||||
assert_output 'postscreen_dnsbl_action = ignore'
|
||||
}
|
||||
|
||||
@test "(disabled) Postscreen DNS block lists -> postscreen_dnsbl_sites" {
|
||||
run docker exec "${CONTAINER2_NAME}" postconf postscreen_dnsbl_sites
|
||||
_run_in_container_explicit "${CONTAINER2_NAME}" postconf postscreen_dnsbl_sites
|
||||
assert_output 'postscreen_dnsbl_sites ='
|
||||
}
|
||||
|
|
|
@ -16,14 +16,14 @@ function setup_file() {
|
|||
# NOTE: May no longer be needed with newer F2B:
|
||||
--ulimit "nofile=$(ulimit -Sn):$(ulimit -Hn)"
|
||||
)
|
||||
init_with_defaults
|
||||
common_container_setup 'CUSTOM_SETUP_ARGUMENTS'
|
||||
wait_for_smtp_port_in_container "${CONTAINER_NAME}"
|
||||
_init_with_defaults
|
||||
_common_container_setup 'CUSTOM_SETUP_ARGUMENTS'
|
||||
_wait_for_smtp_port_in_container
|
||||
|
||||
# Create a container which will send wrong authentications and should get banned
|
||||
CONTAINER_NAME=${CONTAINER2_NAME}
|
||||
init_with_defaults
|
||||
common_container_setup 'CUSTOM_SETUP_ARGUMENTS'
|
||||
_init_with_defaults
|
||||
_common_container_setup 'CUSTOM_SETUP_ARGUMENTS'
|
||||
|
||||
# Set default implicit container fallback for helpers:
|
||||
CONTAINER_NAME=${CONTAINER1_NAME}
|
||||
|
@ -72,26 +72,26 @@ function teardown_file() {
|
|||
# - You could hard-code `sleep 5` on both cases to avoid the alternative assertions,
|
||||
# but the polling + piping into grep approach here reliably minimizes the delay.
|
||||
@test "ban ip on multiple failed login" {
|
||||
CONTAINER1_IP=$(get_container_ip ${CONTAINER1_NAME})
|
||||
CONTAINER1_IP=$(_get_container_ip "${CONTAINER1_NAME}")
|
||||
# Trigger a ban by failing to login twice:
|
||||
_run_in_container_explicit "${CONTAINER2_NAME}" bash -c "nc ${CONTAINER1_IP} 25 < /tmp/docker-mailserver-test/auth/smtp-auth-login-wrong.txt"
|
||||
_run_in_container_explicit "${CONTAINER2_NAME}" bash -c "nc ${CONTAINER1_IP} 25 < /tmp/docker-mailserver-test/auth/smtp-auth-login-wrong.txt"
|
||||
|
||||
# Checking that CONTAINER2_IP is banned in "${CONTAINER1_NAME}"
|
||||
CONTAINER2_IP=$(get_container_ip ${CONTAINER2_NAME})
|
||||
run repeat_in_container_until_success_or_timeout 10 "${CONTAINER_NAME}" bash -c "fail2ban-client status postfix-sasl | grep -F '${CONTAINER2_IP}'"
|
||||
CONTAINER2_IP=$(_get_container_ip "${CONTAINER2_NAME}")
|
||||
run _repeat_in_container_until_success_or_timeout 10 "${CONTAINER_NAME}" /bin/bash -c "fail2ban-client status postfix-sasl | grep -F '${CONTAINER2_IP}'"
|
||||
assert_success
|
||||
assert_output --partial 'Banned IP list:'
|
||||
|
||||
# Checking that CONTAINER2_IP is banned by nftables
|
||||
_run_in_container bash -c 'nft list set inet f2b-table addr-set-postfix-sasl'
|
||||
_run_in_container_bash 'nft list set inet f2b-table addr-set-postfix-sasl'
|
||||
assert_success
|
||||
assert_output --partial "elements = { ${CONTAINER2_IP} }"
|
||||
}
|
||||
|
||||
# NOTE: Depends on previous test case, if no IP was banned at this point, it passes regardless..
|
||||
@test "unban ip works" {
|
||||
CONTAINER2_IP=$(get_container_ip ${CONTAINER2_NAME})
|
||||
CONTAINER2_IP=$(_get_container_ip "${CONTAINER2_NAME}")
|
||||
_run_in_container fail2ban-client set postfix-sasl unbanip "${CONTAINER2_IP}"
|
||||
assert_success
|
||||
|
||||
|
@ -101,7 +101,7 @@ function teardown_file() {
|
|||
refute_output --partial "${CONTAINER2_IP}"
|
||||
|
||||
# Checking that CONTAINER2_IP is unbanned by nftables
|
||||
_run_in_container bash -c 'nft list set inet f2b-table addr-set-postfix-sasl'
|
||||
_run_in_container_bash 'nft list set inet f2b-table addr-set-postfix-sasl'
|
||||
refute_output --partial "${CONTAINER2_IP}"
|
||||
}
|
||||
|
||||
|
|
|
@ -15,11 +15,11 @@ function setup_file() {
|
|||
--env POSTGREY_TEXT="Delayed by Postgrey"
|
||||
)
|
||||
|
||||
init_with_defaults
|
||||
common_container_setup 'CUSTOM_SETUP_ARGUMENTS'
|
||||
_init_with_defaults
|
||||
_common_container_setup 'CUSTOM_SETUP_ARGUMENTS'
|
||||
|
||||
# Postfix needs to be ready on port 25 for nc usage below:
|
||||
wait_for_smtp_port_in_container "${CONTAINER_NAME}"
|
||||
_wait_for_smtp_port_in_container
|
||||
}
|
||||
|
||||
function teardown_file() { _default_teardown ; }
|
||||
|
@ -60,7 +60,7 @@ function teardown_file() { _default_teardown ; }
|
|||
'reason=new' \
|
||||
'client_address=127.0.0.1/32, sender=user@external.tld, recipient=user1@localhost.localdomain'
|
||||
|
||||
repeat_until_success_or_timeout 10 _run_in_container grep \
|
||||
_repeat_until_success_or_timeout 10 _run_in_container grep \
|
||||
'Recipient address rejected: Delayed by Postgrey' \
|
||||
/var/log/mail/mail.log
|
||||
}
|
||||
|
@ -113,7 +113,7 @@ function _send_test_mail() {
|
|||
# This is required for port 10023, otherwise the connection never drops.
|
||||
# It could increase the number of seconds to wait for port 25 to allow for asserting a response,
|
||||
# but that would enforce the delay in tests for port 10023.
|
||||
_run_in_container bash -c "nc -w 0 0.0.0.0 ${PORT} < ${MAIL_TEMPLATE}"
|
||||
_run_in_container_bash "nc -w 0 0.0.0.0 ${PORT} < ${MAIL_TEMPLATE}"
|
||||
}
|
||||
|
||||
function _should_have_log_entry() {
|
||||
|
@ -122,7 +122,7 @@ function _should_have_log_entry() {
|
|||
local TRIPLET=$3
|
||||
|
||||
# Allow some extra time for logs to update to avoids a false-positive failure:
|
||||
run_until_success_or_timeout 10 docker exec "${CONTAINER_NAME}" grep \
|
||||
_run_until_success_or_timeout 10 _exec_in_container grep \
|
||||
"${ACTION}, ${REASON}," \
|
||||
/var/log/mail/mail.log
|
||||
|
||||
|
|
|
@ -6,7 +6,7 @@ CONTAINER1_NAME='dms-test_postscreen_enforce'
|
|||
CONTAINER2_NAME='dms-test_postscreen_sender'
|
||||
|
||||
function setup() {
|
||||
CONTAINER1_IP=$(get_container_ip ${CONTAINER1_NAME})
|
||||
CONTAINER1_IP=$(_get_container_ip ${CONTAINER1_NAME})
|
||||
}
|
||||
|
||||
function setup_file() {
|
||||
|
@ -16,16 +16,16 @@ function setup_file() {
|
|||
local CUSTOM_SETUP_ARGUMENTS=(
|
||||
--env POSTSCREEN_ACTION=enforce
|
||||
)
|
||||
init_with_defaults
|
||||
common_container_setup 'CUSTOM_SETUP_ARGUMENTS'
|
||||
wait_for_smtp_port_in_container "${CONTAINER_NAME}"
|
||||
_init_with_defaults
|
||||
_common_container_setup 'CUSTOM_SETUP_ARGUMENTS'
|
||||
_wait_for_smtp_port_in_container
|
||||
|
||||
# A standard DMS instance to send mail from:
|
||||
# NOTE: None of DMS is actually used for this (just bash + nc).
|
||||
CONTAINER_NAME=${CONTAINER2_NAME}
|
||||
init_with_defaults
|
||||
_init_with_defaults
|
||||
# No need to wait for DMS to be ready for this container:
|
||||
common_container_create
|
||||
_common_container_create
|
||||
run docker start "${CONTAINER_NAME}"
|
||||
assert_success
|
||||
|
||||
|
@ -50,7 +50,7 @@ function teardown_file() {
|
|||
@test "should successfully login (respecting postscreen_greet_wait time)" {
|
||||
# NOTE: Sometimes fails on first attempt (trying too soon?),
|
||||
# Instead of a `run` + asserting partial, Using repeat + internal grep match:
|
||||
repeat_until_success_or_timeout 10 _should_wait_turn_speaking_smtp \
|
||||
_repeat_until_success_or_timeout 10 _should_wait_turn_speaking_smtp \
|
||||
"${CONTAINER2_NAME}" \
|
||||
"${CONTAINER1_IP}" \
|
||||
'/tmp/docker-mailserver-test/auth/smtp-auth-login.txt' \
|
||||
|
|
|
@ -5,7 +5,7 @@ BATS_TEST_NAME_PREFIX='[Spam] (bounced) '
|
|||
CONTAINER_NAME='dms-test_spam-bounced'
|
||||
|
||||
function setup_file() {
|
||||
init_with_defaults
|
||||
_init_with_defaults
|
||||
|
||||
local CUSTOM_SETUP_ARGUMENTS=(
|
||||
--env ENABLE_AMAVIS=1
|
||||
|
@ -14,8 +14,8 @@ function setup_file() {
|
|||
--env SPAMASSASSIN_SPAM_TO_INBOX=0
|
||||
)
|
||||
|
||||
common_container_setup 'CUSTOM_SETUP_ARGUMENTS'
|
||||
wait_for_smtp_port_in_container_to_respond "${CONTAINER_NAME}"
|
||||
_common_container_setup 'CUSTOM_SETUP_ARGUMENTS'
|
||||
_wait_for_smtp_port_in_container_to_respond
|
||||
}
|
||||
|
||||
function teardown_file() { _default_teardown ; }
|
||||
|
@ -31,6 +31,6 @@ function teardown_file() { _default_teardown ; }
|
|||
assert_success
|
||||
|
||||
# message will be added to a queue with varying delay until amavis receives it
|
||||
run repeat_until_success_or_timeout 60 sh -c "docker logs ${CONTAINER_NAME} | grep 'Blocked SPAM {NoBounceInbound,Quarantined}'"
|
||||
run _repeat_until_success_or_timeout 60 sh -c "docker logs ${CONTAINER_NAME} | grep 'Blocked SPAM {NoBounceInbound,Quarantined}'"
|
||||
assert_success
|
||||
}
|
||||
|
|
|
@ -22,20 +22,20 @@ function teardown() { _default_teardown ; }
|
|||
--env SA_SPAM_SUBJECT="SPAM: "
|
||||
--env SPAMASSASSIN_SPAM_TO_INBOX=1
|
||||
)
|
||||
init_with_defaults
|
||||
common_container_setup 'CUSTOM_SETUP_ARGUMENTS'
|
||||
wait_for_smtp_port_in_container "${CONTAINER_NAME}"
|
||||
_init_with_defaults
|
||||
_common_container_setup 'CUSTOM_SETUP_ARGUMENTS'
|
||||
_wait_for_smtp_port_in_container
|
||||
|
||||
# send a spam message
|
||||
_run_in_container bash -c "nc 0.0.0.0 25 < /tmp/docker-mailserver-test/email-templates/amavis-spam.txt"
|
||||
_run_in_container_bash "nc 0.0.0.0 25 < /tmp/docker-mailserver-test/email-templates/amavis-spam.txt"
|
||||
assert_success
|
||||
|
||||
# message will be added to a queue with varying delay until amavis receives it
|
||||
run repeat_until_success_or_timeout 60 bash -c "docker logs ${CONTAINER_NAME} | grep 'Passed SPAM {RelayedTaggedInbound,Quarantined}'"
|
||||
run _repeat_until_success_or_timeout 60 bash -c "docker logs ${CONTAINER_NAME} | grep 'Passed SPAM {RelayedTaggedInbound,Quarantined}'"
|
||||
assert_success
|
||||
|
||||
# spam moved to Junk folder
|
||||
run repeat_until_success_or_timeout 20 bash -c "docker exec ${CONTAINER_NAME} sh -c 'grep \"Subject: SPAM: \" /var/mail/localhost.localdomain/user1/.Junk/new/ -R'"
|
||||
run _repeat_until_success_or_timeout 20 bash -c "docker exec ${CONTAINER_NAME} sh -c 'grep \"Subject: SPAM: \" /var/mail/localhost.localdomain/user1/.Junk/new/ -R'"
|
||||
assert_success
|
||||
}
|
||||
|
||||
|
@ -49,19 +49,19 @@ function teardown() { _default_teardown ; }
|
|||
--env SA_SPAM_SUBJECT="SPAM: "
|
||||
--env SPAMASSASSIN_SPAM_TO_INBOX=1
|
||||
)
|
||||
init_with_defaults
|
||||
common_container_setup 'CUSTOM_SETUP_ARGUMENTS'
|
||||
wait_for_smtp_port_in_container "${CONTAINER_NAME}"
|
||||
_init_with_defaults
|
||||
_common_container_setup 'CUSTOM_SETUP_ARGUMENTS'
|
||||
_wait_for_smtp_port_in_container
|
||||
|
||||
# send a spam message
|
||||
_run_in_container /bin/bash -c "nc 0.0.0.0 25 < /tmp/docker-mailserver-test/email-templates/amavis-spam.txt"
|
||||
assert_success
|
||||
|
||||
# message will be added to a queue with varying delay until amavis receives it
|
||||
run repeat_until_success_or_timeout 60 bash -c "docker logs ${CONTAINER_NAME} | grep 'Passed SPAM {RelayedTaggedInbound,Quarantined}'"
|
||||
run _repeat_until_success_or_timeout 60 bash -c "docker logs ${CONTAINER_NAME} | grep 'Passed SPAM {RelayedTaggedInbound,Quarantined}'"
|
||||
assert_success
|
||||
|
||||
# spam moved to INBOX
|
||||
run repeat_until_success_or_timeout 20 bash -c "docker exec ${CONTAINER_NAME} sh -c 'grep \"Subject: SPAM: \" /var/mail/localhost.localdomain/user1/new/ -R'"
|
||||
run _repeat_until_success_or_timeout 20 bash -c "docker exec ${CONTAINER_NAME} sh -c 'grep \"Subject: SPAM: \" /var/mail/localhost.localdomain/user1/new/ -R'"
|
||||
assert_success
|
||||
}
|
||||
|
|
|
@ -16,10 +16,10 @@ function teardown() { _default_teardown ; }
|
|||
--env ENABLE_SPAMASSASSIN=1
|
||||
--env SA_SPAM_SUBJECT='undef'
|
||||
)
|
||||
init_with_defaults
|
||||
common_container_setup 'CUSTOM_SETUP_ARGUMENTS'
|
||||
_init_with_defaults
|
||||
_common_container_setup 'CUSTOM_SETUP_ARGUMENTS'
|
||||
|
||||
_run_in_container bash -c "grep '\$sa_spam_subject_tag' /etc/amavis/conf.d/20-debian_defaults | grep '= undef'"
|
||||
_run_in_container_bash "grep '\$sa_spam_subject_tag' /etc/amavis/conf.d/20-debian_defaults | grep '= undef'"
|
||||
assert_success
|
||||
}
|
||||
|
||||
|
@ -44,18 +44,18 @@ function teardown() { _default_teardown ; }
|
|||
# NOTE: ulimit required for `ENABLE_SRS=1` until running a newer `postsrsd`
|
||||
--ulimit "nofile=$(ulimit -Sn):$(ulimit -Hn)"
|
||||
)
|
||||
init_with_defaults
|
||||
common_container_setup 'CUSTOM_SETUP_ARGUMENTS'
|
||||
_init_with_defaults
|
||||
_common_container_setup 'CUSTOM_SETUP_ARGUMENTS'
|
||||
|
||||
_run_in_container bash -c "grep '\$sa_tag_level_deflt' /etc/amavis/conf.d/20-debian_defaults | grep '= -5.0'"
|
||||
_run_in_container_bash "grep '\$sa_tag_level_deflt' /etc/amavis/conf.d/20-debian_defaults | grep '= -5.0'"
|
||||
assert_success
|
||||
|
||||
_run_in_container bash -c "grep '\$sa_tag2_level_deflt' /etc/amavis/conf.d/20-debian_defaults | grep '= 2.0'"
|
||||
_run_in_container_bash "grep '\$sa_tag2_level_deflt' /etc/amavis/conf.d/20-debian_defaults | grep '= 2.0'"
|
||||
assert_success
|
||||
|
||||
_run_in_container bash -c "grep '\$sa_kill_level_deflt' /etc/amavis/conf.d/20-debian_defaults | grep '= 3.0'"
|
||||
_run_in_container_bash "grep '\$sa_kill_level_deflt' /etc/amavis/conf.d/20-debian_defaults | grep '= 3.0'"
|
||||
assert_success
|
||||
|
||||
_run_in_container bash -c "grep '\$sa_spam_subject_tag' /etc/amavis/conf.d/20-debian_defaults | grep '= .SPAM: .'"
|
||||
_run_in_container_bash "grep '\$sa_spam_subject_tag' /etc/amavis/conf.d/20-debian_defaults | grep '= .SPAM: .'"
|
||||
assert_success
|
||||
}
|
||||
|
|
|
@ -14,7 +14,7 @@ function setup_file() {
|
|||
# ? optional setup before container is started
|
||||
|
||||
# ? initialize the test helpers
|
||||
init_with_defaults
|
||||
_init_with_defaults
|
||||
|
||||
# ? add custom arguments supplied to `docker run` here
|
||||
local CUSTOM_SETUP_ARGUMENTS=(
|
||||
|
@ -22,7 +22,7 @@ function setup_file() {
|
|||
)
|
||||
|
||||
# ? use a helper to correctly setup the container
|
||||
common_container_setup 'CUSTOM_SETUP_ARGUMENTS'
|
||||
_common_container_setup 'CUSTOM_SETUP_ARGUMENTS'
|
||||
|
||||
# ? optional setup after the container is started
|
||||
}
|
||||
|
@ -34,6 +34,6 @@ function teardown_file() { _default_teardown ; }
|
|||
# ? actual unit tests
|
||||
|
||||
@test "default check" {
|
||||
_run_in_container bash -c "true"
|
||||
_run_in_container_bash "true"
|
||||
assert_success
|
||||
}
|
||||
|
|
|
@ -27,7 +27,7 @@ function setup_file() {
|
|||
# Only interferes (potential test failure) with `assert_output` not `assert_success`?
|
||||
docker pull drwetter/testssl.sh:3.1dev
|
||||
|
||||
# Only used in `should_support_expected_cipherlists()` to set a storage location for `testssl.sh` JSON output:
|
||||
# Only used in `_should_support_expected_cipherlists()` to set a storage location for `testssl.sh` JSON output:
|
||||
# `${BATS_TMPDIR}` maps to `/tmp`: https://bats-core.readthedocs.io/en/v1.8.2/writing-tests.html#special-variables
|
||||
export TLS_RESULTS_DIR="${BATS_TMPDIR}/results"
|
||||
}
|
||||
|
@ -39,38 +39,38 @@ function teardown_file() {
|
|||
function teardown() { _default_teardown ; }
|
||||
|
||||
@test "'TLS_LEVEL=intermediate' + RSA" {
|
||||
configure_and_run_dms_container 'intermediate' 'rsa'
|
||||
should_support_expected_cipherlists
|
||||
_configure_and_run_dms_container 'intermediate' 'rsa'
|
||||
_should_support_expected_cipherlists
|
||||
}
|
||||
|
||||
@test "'TLS_LEVEL=intermediate' + ECDSA" {
|
||||
configure_and_run_dms_container 'intermediate' 'ecdsa'
|
||||
should_support_expected_cipherlists
|
||||
_configure_and_run_dms_container 'intermediate' 'ecdsa'
|
||||
_should_support_expected_cipherlists
|
||||
}
|
||||
|
||||
# Only ECDSA with an RSA fallback is tested.
|
||||
# There isn't a situation where RSA with an ECDSA fallback would make sense.
|
||||
@test "'TLS_LEVEL=intermediate' + ECDSA with RSA fallback" {
|
||||
configure_and_run_dms_container 'intermediate' 'ecdsa' 'rsa'
|
||||
should_support_expected_cipherlists
|
||||
_configure_and_run_dms_container 'intermediate' 'ecdsa' 'rsa'
|
||||
_should_support_expected_cipherlists
|
||||
}
|
||||
|
||||
@test "'TLS_LEVEL=modern' + RSA" {
|
||||
configure_and_run_dms_container 'modern' 'rsa'
|
||||
should_support_expected_cipherlists
|
||||
_configure_and_run_dms_container 'modern' 'rsa'
|
||||
_should_support_expected_cipherlists
|
||||
}
|
||||
|
||||
@test "'TLS_LEVEL=modern' + ECDSA" {
|
||||
configure_and_run_dms_container 'modern' 'ecdsa'
|
||||
should_support_expected_cipherlists
|
||||
_configure_and_run_dms_container 'modern' 'ecdsa'
|
||||
_should_support_expected_cipherlists
|
||||
}
|
||||
|
||||
@test "'TLS_LEVEL=modern' + ECDSA with RSA fallback" {
|
||||
configure_and_run_dms_container 'modern' 'ecdsa' 'rsa'
|
||||
should_support_expected_cipherlists
|
||||
_configure_and_run_dms_container 'modern' 'ecdsa' 'rsa'
|
||||
_should_support_expected_cipherlists
|
||||
}
|
||||
|
||||
function configure_and_run_dms_container() {
|
||||
function _configure_and_run_dms_container() {
|
||||
local TLS_LEVEL=$1
|
||||
local KEY_TYPE=$2
|
||||
local ALT_KEY_TYPE=$3 # Optional parameter
|
||||
|
@ -106,23 +106,23 @@ function configure_and_run_dms_container() {
|
|||
)
|
||||
fi
|
||||
|
||||
init_with_defaults
|
||||
common_container_setup 'CUSTOM_SETUP_ARGUMENTS'
|
||||
wait_for_smtp_port_in_container "${CONTAINER_NAME}"
|
||||
_init_with_defaults
|
||||
_common_container_setup 'CUSTOM_SETUP_ARGUMENTS'
|
||||
_wait_for_smtp_port_in_container
|
||||
}
|
||||
|
||||
function should_support_expected_cipherlists() {
|
||||
function _should_support_expected_cipherlists() {
|
||||
# Make a directory with test user ownership. Avoids Docker creating this with root ownership.
|
||||
# TODO: Can switch to filename prefix for JSON output when this is resolved: https://github.com/drwetter/testssl.sh/issues/1845
|
||||
local RESULTS_PATH="${TLS_RESULTS_DIR}/${TEST_VARIANT}"
|
||||
mkdir -p "${RESULTS_PATH}"
|
||||
|
||||
collect_cipherlists
|
||||
verify_cipherlists
|
||||
_collect_cipherlists
|
||||
_verify_cipherlists
|
||||
}
|
||||
|
||||
# Verify that the collected results match our expected cipherlists:
|
||||
function verify_cipherlists() {
|
||||
function _verify_cipherlists() {
|
||||
# SMTP: Opportunistic STARTTLS Explicit(25)
|
||||
# Needs to test against cipher lists specific to Port 25 ('_p25' parameter)
|
||||
check_cipherlists "${RESULTS_PATH}/port_25.json" '_p25'
|
||||
|
@ -141,7 +141,7 @@ function verify_cipherlists() {
|
|||
}
|
||||
|
||||
# Using `testssl.sh` we can test each port to collect a list of supported cipher suites (ordered):
|
||||
function collect_cipherlists() {
|
||||
function _collect_cipherlists() {
|
||||
# NOTE: An rDNS query for the container IP will resolve to `<container name>.<network name>.`
|
||||
|
||||
# For non-CI test runs, instead of removing prior test files after this test suite completes,
|
||||
|
|
|
@ -14,7 +14,7 @@ function teardown() { _default_teardown ; }
|
|||
# Similar to BATS `setup()` method, but invoked manually after
|
||||
# CONTAINER_NAME has been adjusted for the running testcase.
|
||||
function _initial_setup() {
|
||||
init_with_defaults
|
||||
_init_with_defaults
|
||||
|
||||
# Prepare certificates in the letsencrypt supported file structure:
|
||||
# NOTE: Certbot uses `privkey.pem`.
|
||||
|
@ -41,7 +41,7 @@ function _initial_setup() {
|
|||
--env PERMIT_DOCKER='container'
|
||||
--env SSL_TYPE='letsencrypt'
|
||||
)
|
||||
common_container_setup 'CUSTOM_SETUP_ARGUMENTS'
|
||||
_common_container_setup 'CUSTOM_SETUP_ARGUMENTS'
|
||||
|
||||
# Test that certificate files exist for the configured `hostname`:
|
||||
_should_have_valid_config "${TARGET_DOMAIN}" 'privkey.pem' 'fullchain.pem'
|
||||
|
@ -61,7 +61,7 @@ function _initial_setup() {
|
|||
--env PERMIT_DOCKER='container'
|
||||
--env SSL_TYPE='letsencrypt'
|
||||
)
|
||||
common_container_setup 'CUSTOM_SETUP_ARGUMENTS'
|
||||
_common_container_setup 'CUSTOM_SETUP_ARGUMENTS'
|
||||
|
||||
#test domain has certificate files
|
||||
_should_have_valid_config "${TARGET_DOMAIN}" 'privkey.pem' 'fullchain.pem'
|
||||
|
@ -102,8 +102,8 @@ function _initial_setup() {
|
|||
--env SSL_DOMAIN='*.example.test'
|
||||
--env SSL_TYPE='letsencrypt'
|
||||
)
|
||||
common_container_setup 'CUSTOM_SETUP_ARGUMENTS'
|
||||
wait_for_service "${CONTAINER_NAME}" 'changedetector'
|
||||
_common_container_setup 'CUSTOM_SETUP_ARGUMENTS'
|
||||
_wait_for_service 'changedetector'
|
||||
}
|
||||
|
||||
# Test `acme.json` extraction works at container startup:
|
||||
|
@ -180,7 +180,7 @@ function _should_have_valid_config() {
|
|||
|
||||
# CMD ${1} run in container with output checked to match value of ${2}:
|
||||
function _has_matching_line() {
|
||||
_run_in_container bash -c "${1} | grep '${2}'"
|
||||
_run_in_container_bash "${1} | grep '${2}'"
|
||||
assert_output "${2}"
|
||||
}
|
||||
|
||||
|
@ -207,7 +207,7 @@ function _should_extract_on_changes() {
|
|||
local ACME_JSON=${2}
|
||||
|
||||
cp "${ACME_JSON}" "${TEST_TMP_CONFIG}/letsencrypt/acme.json"
|
||||
wait_until_change_detection_event_completes "${CONTAINER_NAME}"
|
||||
_wait_until_change_detection_event_completes
|
||||
|
||||
# Expected log lines from the changedetector service:
|
||||
run _get_logs_since_last_change_detection "${CONTAINER_NAME}"
|
||||
|
|
|
@ -30,10 +30,10 @@ function setup_file() {
|
|||
--env SSL_ALT_CERT_PATH="${SSL_ALT_CERT_PATH}"
|
||||
)
|
||||
|
||||
init_with_defaults
|
||||
# Override the default set in `common_container_setup`:
|
||||
_init_with_defaults
|
||||
# Override the default set in `_common_container_setup`:
|
||||
export TEST_FQDN="mail.${TEST_DOMAIN}"
|
||||
common_container_setup 'CUSTOM_SETUP_ARGUMENTS'
|
||||
_common_container_setup 'CUSTOM_SETUP_ARGUMENTS'
|
||||
}
|
||||
|
||||
function teardown_file() { _default_teardown ; }
|
||||
|
@ -90,7 +90,7 @@ function teardown_file() { _default_teardown ; }
|
|||
}
|
||||
|
||||
@test "manual cert works correctly" {
|
||||
wait_for_tcp_port_in_container 587 "${CONTAINER_NAME}"
|
||||
_wait_for_tcp_port_in_container 587
|
||||
|
||||
local TEST_COMMAND=(timeout 1 openssl s_client -connect mail.example.test:587 -starttls smtp)
|
||||
local RESULT
|
||||
|
|
|
@ -5,12 +5,12 @@ BATS_TEST_NAME_PREFIX='[Configuration] (overrides) '
|
|||
CONTAINER_NAME='dms-test_config-overrides'
|
||||
|
||||
function setup_file() {
|
||||
init_with_defaults
|
||||
_init_with_defaults
|
||||
|
||||
# Move override configs into main `/tmp/docker-mailserver` config location:
|
||||
mv "${TEST_TMP_CONFIG}/override-configs/"* "${TEST_TMP_CONFIG}/"
|
||||
|
||||
common_container_setup
|
||||
_common_container_setup
|
||||
}
|
||||
|
||||
function teardown_file() { _default_teardown ; }
|
||||
|
|
|
@ -8,7 +8,7 @@ BATS_TEST_NAME_PREFIX='[Dovecot] (Sieve support) '
|
|||
CONTAINER_NAME='dms-test_dovecot-sieve'
|
||||
|
||||
function setup_file() {
|
||||
init_with_defaults
|
||||
_init_with_defaults
|
||||
|
||||
# Move sieve configs into main `/tmp/docker-mailserver` config location:
|
||||
mv "${TEST_TMP_CONFIG}/dovecot-sieve/"* "${TEST_TMP_CONFIG}/"
|
||||
|
@ -21,23 +21,23 @@ function setup_file() {
|
|||
# NOTE: Cannot use ':ro', 'start-mailserver.sh' attempts to 'chown -R' /var/mail:
|
||||
--volume "${TEST_TMP_CONFIG}/dovecot.sieve:/var/mail/localhost.localdomain/user1/.dovecot.sieve"
|
||||
)
|
||||
common_container_setup 'CONTAINER_ARGS_ENV_CUSTOM'
|
||||
_common_container_setup 'CONTAINER_ARGS_ENV_CUSTOM'
|
||||
|
||||
wait_for_smtp_port_in_container "${CONTAINER_NAME}"
|
||||
_wait_for_smtp_port_in_container
|
||||
|
||||
# Single mail sent from 'spam@spam.com' that is handled by User (relocate) and Global (copy) sieves for user1:
|
||||
_run_in_container bash -c "nc 0.0.0.0 25 < /tmp/docker-mailserver-test/email-templates/sieve-spam-folder.txt"
|
||||
_run_in_container_bash "nc 0.0.0.0 25 < /tmp/docker-mailserver-test/email-templates/sieve-spam-folder.txt"
|
||||
# Mail for user2 triggers the sieve-pipe:
|
||||
_run_in_container bash -c "nc 0.0.0.0 25 < /tmp/docker-mailserver-test/email-templates/sieve-pipe.txt"
|
||||
_run_in_container_bash "nc 0.0.0.0 25 < /tmp/docker-mailserver-test/email-templates/sieve-pipe.txt"
|
||||
|
||||
wait_for_empty_mail_queue_in_container "${CONTAINER_NAME}"
|
||||
_wait_for_empty_mail_queue_in_container
|
||||
}
|
||||
|
||||
function teardown_file() { _default_teardown ; }
|
||||
|
||||
# dovecot-sieve/dovecot.sieve
|
||||
@test "User Sieve - should store mail from 'spam@spam.com' into recipient (user1) mailbox 'INBOX.spam'" {
|
||||
_run_in_container bash -c 'ls -A /var/mail/localhost.localdomain/user1/.INBOX.spam/new'
|
||||
_run_in_container_bash 'ls -A /var/mail/localhost.localdomain/user1/.INBOX.spam/new'
|
||||
assert_success
|
||||
_should_output_number_of_lines 1
|
||||
}
|
||||
|
@ -50,7 +50,7 @@ function teardown_file() { _default_teardown ; }
|
|||
|
||||
# dovecot-sieve/sieve-pipe + dovecot-sieve/user2@otherdomain.tld.dovecot.sieve
|
||||
@test "Sieve Pipe - should pipe mail received for user2 into '/tmp/pipe-test.out'" {
|
||||
_run_in_container bash -c 'ls -A /tmp/pipe-test.out'
|
||||
_run_in_container_bash 'ls -A /tmp/pipe-test.out'
|
||||
assert_success
|
||||
_should_output_number_of_lines 1
|
||||
}
|
||||
|
@ -58,6 +58,6 @@ function teardown_file() { _default_teardown ; }
|
|||
# Only test coverage for feature is to check that the service is listening on the expected port:
|
||||
# https://doc.dovecot.org/admin_manual/pigeonhole_managesieve_server/
|
||||
@test "ENV 'ENABLE_MANAGESIEVE' - should have enabled service on port 4190" {
|
||||
_run_in_container bash -c 'nc -z 0.0.0.0 4190'
|
||||
_run_in_container_bash 'nc -z 0.0.0.0 4190'
|
||||
assert_success
|
||||
}
|
||||
|
|
|
@ -12,8 +12,8 @@ function teardown() { _default_teardown ; }
|
|||
export CONTAINER_NAME=${CONTAINER1_NAME}
|
||||
local CUSTOM_SETUP_ARGUMENTS=(--env DOVECOT_INET_PROTOCOLS=)
|
||||
|
||||
init_with_defaults
|
||||
common_container_setup 'CUSTOM_SETUP_ARGUMENTS'
|
||||
_init_with_defaults
|
||||
_common_container_setup 'CUSTOM_SETUP_ARGUMENTS'
|
||||
|
||||
_run_in_container grep '^#listen = \*, ::' /etc/dovecot/dovecot.conf
|
||||
assert_success
|
||||
|
@ -24,8 +24,8 @@ function teardown() { _default_teardown ; }
|
|||
export CONTAINER_NAME=${CONTAINER2_NAME}
|
||||
local CUSTOM_SETUP_ARGUMENTS=(--env DOVECOT_INET_PROTOCOLS=ipv4)
|
||||
|
||||
init_with_defaults
|
||||
common_container_setup 'CUSTOM_SETUP_ARGUMENTS'
|
||||
_init_with_defaults
|
||||
_common_container_setup 'CUSTOM_SETUP_ARGUMENTS'
|
||||
|
||||
_run_in_container grep '^listen = \*$' /etc/dovecot/dovecot.conf
|
||||
assert_success
|
||||
|
@ -36,8 +36,8 @@ function teardown() { _default_teardown ; }
|
|||
export CONTAINER_NAME=${CONTAINER3_NAME}
|
||||
local CUSTOM_SETUP_ARGUMENTS=(--env DOVECOT_INET_PROTOCOLS=ipv6)
|
||||
|
||||
init_with_defaults
|
||||
common_container_setup 'CUSTOM_SETUP_ARGUMENTS'
|
||||
_init_with_defaults
|
||||
_common_container_setup 'CUSTOM_SETUP_ARGUMENTS'
|
||||
|
||||
_run_in_container grep '^listen = \[::\]$' /etc/dovecot/dovecot.conf
|
||||
assert_success
|
||||
|
|
|
@ -5,19 +5,19 @@ BATS_TEST_NAME_PREFIX='[Scripts] (helper functions inside container) '
|
|||
CONTAINER_NAME='dms-test_helper_functions'
|
||||
|
||||
function setup_file() {
|
||||
init_with_defaults
|
||||
common_container_setup
|
||||
_init_with_defaults
|
||||
_common_container_setup
|
||||
}
|
||||
|
||||
function teardown_file() { _default_teardown ; }
|
||||
|
||||
@test "_sanitize_ipv4_to_subnet_cidr" {
|
||||
_run_in_container bash -c "source /usr/local/bin/helpers/index.sh; _sanitize_ipv4_to_subnet_cidr 255.255.255.255/0"
|
||||
_run_in_container_bash "source /usr/local/bin/helpers/index.sh; _sanitize_ipv4_to_subnet_cidr 255.255.255.255/0"
|
||||
assert_output "0.0.0.0/0"
|
||||
|
||||
_run_in_container bash -c "source /usr/local/bin/helpers/index.sh; _sanitize_ipv4_to_subnet_cidr 192.168.255.14/20"
|
||||
_run_in_container_bash "source /usr/local/bin/helpers/index.sh; _sanitize_ipv4_to_subnet_cidr 192.168.255.14/20"
|
||||
assert_output "192.168.240.0/20"
|
||||
|
||||
_run_in_container bash -c "source /usr/local/bin/helpers/index.sh; _sanitize_ipv4_to_subnet_cidr 192.168.255.14/32"
|
||||
_run_in_container_bash "source /usr/local/bin/helpers/index.sh; _sanitize_ipv4_to_subnet_cidr 192.168.255.14/32"
|
||||
assert_output "192.168.255.14/32"
|
||||
}
|
||||
|
|
|
@ -64,11 +64,11 @@ ENV_PROCESS_LIST=(
|
|||
# Disable Dovecot:
|
||||
--env SMTP_ONLY=1
|
||||
)
|
||||
init_with_defaults
|
||||
common_container_setup 'CONTAINER_ARGS_ENV_CUSTOM'
|
||||
_init_with_defaults
|
||||
_common_container_setup 'CONTAINER_ARGS_ENV_CUSTOM'
|
||||
|
||||
# Required for Postfix (when launched by wrapper script which is slow to start)
|
||||
wait_for_smtp_port_in_container "${CONTAINER_NAME}"
|
||||
_wait_for_smtp_port_in_container
|
||||
|
||||
for PROCESS in "${CORE_PROCESS_LIST[@]}"
|
||||
do
|
||||
|
@ -102,10 +102,10 @@ ENV_PROCESS_LIST=(
|
|||
# PR 2730: https://github.com/docker-mailserver/docker-mailserver/commit/672e9cf19a3bb1da309e8cea6ee728e58f905366
|
||||
--ulimit "nofile=$(ulimit -Sn):$(ulimit -Hn)"
|
||||
)
|
||||
init_with_defaults
|
||||
_init_with_defaults
|
||||
mv "${TEST_TMP_CONFIG}/fetchmail/fetchmail.cf" "${TEST_TMP_CONFIG}/fetchmail.cf"
|
||||
# Average time: 6 seconds
|
||||
common_container_setup 'CONTAINER_ARGS_ENV_CUSTOM'
|
||||
_common_container_setup 'CONTAINER_ARGS_ENV_CUSTOM'
|
||||
|
||||
local ENABLED_PROCESS_LIST=(
|
||||
"${CORE_PROCESS_LIST[@]}"
|
||||
|
@ -132,8 +132,8 @@ ENV_PROCESS_LIST=(
|
|||
local CONTAINER_ARGS_ENV_CUSTOM=(
|
||||
--env ENABLE_CLAMAV=1
|
||||
)
|
||||
init_with_defaults
|
||||
common_container_setup 'CONTAINER_ARGS_ENV_CUSTOM'
|
||||
_init_with_defaults
|
||||
_common_container_setup 'CONTAINER_ARGS_ENV_CUSTOM'
|
||||
|
||||
_should_restart_when_killed 'clamd'
|
||||
}
|
||||
|
@ -144,7 +144,7 @@ function _should_restart_when_killed() {
|
|||
|
||||
# Wait until process has been running for at least MIN_PROCESS_AGE:
|
||||
# (this allows us to more confidently check the process was restarted)
|
||||
run_until_success_or_timeout 30 _check_if_process_is_running "${PROCESS}" "${MIN_PROCESS_AGE}"
|
||||
_run_until_success_or_timeout 30 _check_if_process_is_running "${PROCESS}" "${MIN_PROCESS_AGE}"
|
||||
# NOTE: refute_output doesn't have output to compare to when a run failure is due to a timeout
|
||||
assert_success
|
||||
assert_output --partial "${PROCESS}"
|
||||
|
@ -157,13 +157,13 @@ function _should_restart_when_killed() {
|
|||
|
||||
# Wait until original process is not running:
|
||||
# (Ignore restarted process by filtering with MIN_PROCESS_AGE, --fatal-test with `false` stops polling on error):
|
||||
run repeat_until_success_or_timeout --fatal-test "_check_if_process_is_running ${PROCESS} ${MIN_PROCESS_AGE}" 30 false
|
||||
run _repeat_until_success_or_timeout --fatal-test "_check_if_process_is_running ${PROCESS} ${MIN_PROCESS_AGE}" 30 false
|
||||
assert_output --partial "'${PROCESS}' is not running"
|
||||
assert_failure
|
||||
|
||||
# Should be running:
|
||||
# (poll as some processes a slower to restart, such as those run by wrapper scripts adding delay via sleep)
|
||||
run_until_success_or_timeout 30 _check_if_process_is_running "${PROCESS}"
|
||||
_run_until_success_or_timeout 30 _check_if_process_is_running "${PROCESS}"
|
||||
assert_success
|
||||
assert_output --partial "${PROCESS}"
|
||||
}
|
||||
|
|
|
@ -6,7 +6,7 @@ BATS_TEST_NAME_PREFIX='[SMTP] (delivery) '
|
|||
CONTAINER_NAME='dms-test_smtp-delivery'
|
||||
|
||||
function setup_file() {
|
||||
init_with_defaults
|
||||
_init_with_defaults
|
||||
|
||||
local CONTAINER_ARGS_ENV_CUSTOM=(
|
||||
# Required not only for authentication, but delivery in these tests (via nc):
|
||||
|
@ -43,94 +43,94 @@ function setup_file() {
|
|||
mv "${TEST_TMP_CONFIG}/smtp-delivery/postfix-main.cf" "${TEST_TMP_CONFIG}/postfix-main.cf"
|
||||
mv "${TEST_TMP_CONFIG}/smtp-delivery/dovecot.cf" "${TEST_TMP_CONFIG}/dovecot.cf"
|
||||
|
||||
common_container_setup 'CONTAINER_ARGS_ENV_CUSTOM'
|
||||
_common_container_setup 'CONTAINER_ARGS_ENV_CUSTOM'
|
||||
|
||||
_run_in_container setup email add 'added@localhost.localdomain' 'mypassword'
|
||||
assert_success
|
||||
wait_until_change_detection_event_completes "${CONTAINER_NAME}"
|
||||
_wait_until_change_detection_event_completes
|
||||
|
||||
wait_for_smtp_port_in_container "${CONTAINER_NAME}"
|
||||
_wait_for_smtp_port_in_container
|
||||
|
||||
# TODO: Move to clamav tests (For use when ClamAV is enabled):
|
||||
# repeat_in_container_until_success_or_timeout 60 "${CONTAINER_NAME}" test -e /var/run/clamav/clamd.ctl
|
||||
# _run_in_container bash -c "nc 0.0.0.0 25 < /tmp/docker-mailserver-test/email-templates/amavis-virus.txt"
|
||||
# _repeat_in_container_until_success_or_timeout 60 "${CONTAINER_NAME}" test -e /var/run/clamav/clamd.ctl
|
||||
# _run_in_container_bash "nc 0.0.0.0 25 < /tmp/docker-mailserver-test/email-templates/amavis-virus.txt"
|
||||
|
||||
# Required for 'delivers mail to existing alias':
|
||||
_run_in_container bash -c 'nc 0.0.0.0 25 < /tmp/docker-mailserver-test/email-templates/existing-alias-external.txt'
|
||||
_run_in_container_bash 'nc 0.0.0.0 25 < /tmp/docker-mailserver-test/email-templates/existing-alias-external.txt'
|
||||
# Required for 'delivers mail to existing alias with recipient delimiter':
|
||||
_run_in_container bash -c 'nc 0.0.0.0 25 < /tmp/docker-mailserver-test/email-templates/existing-alias-recipient-delimiter.txt'
|
||||
_run_in_container_bash 'nc 0.0.0.0 25 < /tmp/docker-mailserver-test/email-templates/existing-alias-recipient-delimiter.txt'
|
||||
# Required for 'delivers mail to existing catchall':
|
||||
_run_in_container bash -c 'nc 0.0.0.0 25 < /tmp/docker-mailserver-test/email-templates/existing-catchall-local.txt'
|
||||
_run_in_container_bash 'nc 0.0.0.0 25 < /tmp/docker-mailserver-test/email-templates/existing-catchall-local.txt'
|
||||
# Required for 'delivers mail to regexp alias':
|
||||
_run_in_container bash -c 'nc 0.0.0.0 25 < /tmp/docker-mailserver-test/email-templates/existing-regexp-alias-local.txt'
|
||||
_run_in_container_bash 'nc 0.0.0.0 25 < /tmp/docker-mailserver-test/email-templates/existing-regexp-alias-local.txt'
|
||||
|
||||
# Required for 'rejects mail to unknown user':
|
||||
_run_in_container bash -c 'nc 0.0.0.0 25 < /tmp/docker-mailserver-test/email-templates/non-existing-user.txt'
|
||||
_run_in_container_bash 'nc 0.0.0.0 25 < /tmp/docker-mailserver-test/email-templates/non-existing-user.txt'
|
||||
# Required for 'redirects mail to external aliases':
|
||||
_run_in_container bash -c 'nc 0.0.0.0 25 < /tmp/docker-mailserver-test/email-templates/existing-regexp-alias-external.txt'
|
||||
_run_in_container bash -c 'nc 0.0.0.0 25 < /tmp/docker-mailserver-test/email-templates/existing-alias-local.txt'
|
||||
_run_in_container_bash 'nc 0.0.0.0 25 < /tmp/docker-mailserver-test/email-templates/existing-regexp-alias-external.txt'
|
||||
_run_in_container_bash 'nc 0.0.0.0 25 < /tmp/docker-mailserver-test/email-templates/existing-alias-local.txt'
|
||||
# Required for 'rejects spam':
|
||||
_run_in_container bash -c 'nc 0.0.0.0 25 < /tmp/docker-mailserver-test/email-templates/amavis-spam.txt'
|
||||
_run_in_container_bash 'nc 0.0.0.0 25 < /tmp/docker-mailserver-test/email-templates/amavis-spam.txt'
|
||||
|
||||
# Required for 'delivers mail to existing account':
|
||||
_run_in_container bash -c 'nc 0.0.0.0 25 < /tmp/docker-mailserver-test/email-templates/existing-user1.txt'
|
||||
_run_in_container bash -c 'nc 0.0.0.0 25 < /tmp/docker-mailserver-test/email-templates/existing-user2.txt'
|
||||
_run_in_container bash -c 'nc 0.0.0.0 25 < /tmp/docker-mailserver-test/email-templates/existing-user3.txt'
|
||||
_run_in_container bash -c 'nc 0.0.0.0 25 < /tmp/docker-mailserver-test/email-templates/existing-added.txt'
|
||||
_run_in_container bash -c 'nc 0.0.0.0 25 < /tmp/docker-mailserver-test/email-templates/existing-user-and-cc-local-alias.txt'
|
||||
_run_in_container bash -c 'nc 0.0.0.0 25 < /tmp/docker-mailserver-test/email-templates/sieve-spam-folder.txt'
|
||||
_run_in_container bash -c 'nc 0.0.0.0 25 < /tmp/docker-mailserver-test/email-templates/sieve-pipe.txt'
|
||||
_run_in_container bash -c 'sendmail root < /tmp/docker-mailserver-test/email-templates/root-email.txt'
|
||||
_run_in_container_bash 'nc 0.0.0.0 25 < /tmp/docker-mailserver-test/email-templates/existing-user1.txt'
|
||||
_run_in_container_bash 'nc 0.0.0.0 25 < /tmp/docker-mailserver-test/email-templates/existing-user2.txt'
|
||||
_run_in_container_bash 'nc 0.0.0.0 25 < /tmp/docker-mailserver-test/email-templates/existing-user3.txt'
|
||||
_run_in_container_bash 'nc 0.0.0.0 25 < /tmp/docker-mailserver-test/email-templates/existing-added.txt'
|
||||
_run_in_container_bash 'nc 0.0.0.0 25 < /tmp/docker-mailserver-test/email-templates/existing-user-and-cc-local-alias.txt'
|
||||
_run_in_container_bash 'nc 0.0.0.0 25 < /tmp/docker-mailserver-test/email-templates/sieve-spam-folder.txt'
|
||||
_run_in_container_bash 'nc 0.0.0.0 25 < /tmp/docker-mailserver-test/email-templates/sieve-pipe.txt'
|
||||
_run_in_container_bash 'sendmail root < /tmp/docker-mailserver-test/email-templates/root-email.txt'
|
||||
|
||||
wait_for_empty_mail_queue_in_container "${CONTAINER_NAME}"
|
||||
_wait_for_empty_mail_queue_in_container
|
||||
}
|
||||
|
||||
function teardown_file() { _default_teardown ; }
|
||||
|
||||
@test "should successfully authenticate with good password (plain)" {
|
||||
_run_in_container bash -c 'nc -w 5 0.0.0.0 25 < /tmp/docker-mailserver-test/auth/smtp-auth-plain.txt'
|
||||
_run_in_container_bash 'nc -w 5 0.0.0.0 25 < /tmp/docker-mailserver-test/auth/smtp-auth-plain.txt'
|
||||
assert_success
|
||||
assert_output --partial 'Authentication successful'
|
||||
}
|
||||
|
||||
@test "should fail to authenticate with wrong password (plain)" {
|
||||
_run_in_container bash -c 'nc -w 20 0.0.0.0 25 < /tmp/docker-mailserver-test/auth/smtp-auth-plain-wrong.txt'
|
||||
_run_in_container_bash 'nc -w 20 0.0.0.0 25 < /tmp/docker-mailserver-test/auth/smtp-auth-plain-wrong.txt'
|
||||
assert_output --partial 'authentication failed'
|
||||
assert_success
|
||||
}
|
||||
|
||||
@test "should successfully authenticate with good password (login)" {
|
||||
_run_in_container bash -c 'nc -w 5 0.0.0.0 25 < /tmp/docker-mailserver-test/auth/smtp-auth-login.txt'
|
||||
_run_in_container_bash 'nc -w 5 0.0.0.0 25 < /tmp/docker-mailserver-test/auth/smtp-auth-login.txt'
|
||||
assert_success
|
||||
assert_output --partial 'Authentication successful'
|
||||
}
|
||||
|
||||
@test "should fail to authenticate with wrong password (login)" {
|
||||
_run_in_container bash -c 'nc -w 20 0.0.0.0 25 < /tmp/docker-mailserver-test/auth/smtp-auth-login-wrong.txt'
|
||||
_run_in_container_bash 'nc -w 20 0.0.0.0 25 < /tmp/docker-mailserver-test/auth/smtp-auth-login-wrong.txt'
|
||||
assert_output --partial 'authentication failed'
|
||||
assert_success
|
||||
}
|
||||
|
||||
@test "[user: 'added'] should successfully authenticate with good password (plain)" {
|
||||
_run_in_container bash -c 'nc -w 5 0.0.0.0 25 < /tmp/docker-mailserver-test/auth/added-smtp-auth-plain.txt'
|
||||
_run_in_container_bash 'nc -w 5 0.0.0.0 25 < /tmp/docker-mailserver-test/auth/added-smtp-auth-plain.txt'
|
||||
assert_success
|
||||
assert_output --partial 'Authentication successful'
|
||||
}
|
||||
|
||||
@test "[user: 'added'] should fail to authenticate with wrong password (plain)" {
|
||||
_run_in_container bash -c 'nc -w 20 0.0.0.0 25 < /tmp/docker-mailserver-test/auth/added-smtp-auth-plain-wrong.txt'
|
||||
_run_in_container_bash 'nc -w 20 0.0.0.0 25 < /tmp/docker-mailserver-test/auth/added-smtp-auth-plain-wrong.txt'
|
||||
assert_success
|
||||
assert_output --partial 'authentication failed'
|
||||
}
|
||||
|
||||
@test "[user: 'added'] should successfully authenticate with good password (login)" {
|
||||
_run_in_container bash -c 'nc -w 5 0.0.0.0 25 < /tmp/docker-mailserver-test/auth/added-smtp-auth-login.txt'
|
||||
_run_in_container_bash 'nc -w 5 0.0.0.0 25 < /tmp/docker-mailserver-test/auth/added-smtp-auth-login.txt'
|
||||
assert_success
|
||||
assert_output --partial 'Authentication successful'
|
||||
}
|
||||
|
||||
@test "[user: 'added'] should fail to authenticate with wrong password (login)" {
|
||||
_run_in_container bash -c 'nc -w 20 0.0.0.0 25 < /tmp/docker-mailserver-test/auth/added-smtp-auth-login-wrong.txt'
|
||||
_run_in_container_bash 'nc -w 20 0.0.0.0 25 < /tmp/docker-mailserver-test/auth/added-smtp-auth-login-wrong.txt'
|
||||
assert_success
|
||||
assert_output --partial 'authentication failed'
|
||||
}
|
||||
|
@ -141,7 +141,7 @@ function teardown_file() { _default_teardown ; }
|
|||
# postfix/lmtp[1274]: 0EA424ABE7D9: to=<user1@localhost.localdomain>, relay=127.0.0.1[127.0.0.1]:24, delay=0.13, delays=0.07/0.01/0.01/0.05, dsn=2.0.0, status=sent (250 2.0.0 <user1@localhost.localdomain> ixPpB+Zvv2P7BAAAUi6ngw Saved)
|
||||
local LOG_DELIVERED='postfix/lmtp.* status=sent .* Saved)'
|
||||
local FORMAT_LINES="sed 's/.* to=</</g' | sed 's/, relay.*//g' | sort | uniq -c | tr -s ' '"
|
||||
_run_in_container bash -c "grep '${LOG_DELIVERED}' /var/log/mail/mail.log | ${FORMAT_LINES}"
|
||||
_run_in_container_bash "grep '${LOG_DELIVERED}' /var/log/mail/mail.log | ${FORMAT_LINES}"
|
||||
assert_success
|
||||
|
||||
assert_output --partial '1 <added@localhost.localdomain>'
|
||||
|
@ -190,7 +190,7 @@ function teardown_file() { _default_teardown ; }
|
|||
}
|
||||
|
||||
@test "user1 should have received 8 mails" {
|
||||
_run_in_container bash -c "grep Subject /var/mail/localhost.localdomain/user1/new/* | sed 's/.*Subject: //g' | sed 's/\.txt.*//g' | sed 's/VIRUS.*/VIRUS/g' | sort"
|
||||
_run_in_container_bash "grep Subject /var/mail/localhost.localdomain/user1/new/* | sed 's/.*Subject: //g' | sed 's/\.txt.*//g' | sed 's/VIRUS.*/VIRUS/g' | sort"
|
||||
assert_success
|
||||
|
||||
assert_output --partial 'Root Test Message'
|
||||
|
@ -217,7 +217,7 @@ function teardown_file() { _default_teardown ; }
|
|||
}
|
||||
|
||||
@test "redirects mail to external aliases" {
|
||||
_run_in_container bash -c "grep 'Passed CLEAN {RelayedInbound}' /var/log/mail/mail.log | grep -- '-> <external1@otherdomain.tld>'"
|
||||
_run_in_container_bash "grep 'Passed CLEAN {RelayedInbound}' /var/log/mail/mail.log | grep -- '-> <external1@otherdomain.tld>'"
|
||||
assert_success
|
||||
assert_output --partial '<user@external.tld> -> <external1@otherdomain.tld>'
|
||||
_should_output_number_of_lines 2
|
||||
|
@ -250,7 +250,7 @@ function teardown_file() { _default_teardown ; }
|
|||
# Dovecot does not support SMTPUTF8, so while we can send we cannot receive
|
||||
# Better disable SMTPUTF8 support entirely if we can't handle it correctly
|
||||
@test "not advertising smtputf8" {
|
||||
_run_in_container bash -c 'nc 0.0.0.0 25 < /tmp/docker-mailserver-test/email-templates/smtp-ehlo.txt'
|
||||
_run_in_container_bash 'nc 0.0.0.0 25 < /tmp/docker-mailserver-test/email-templates/smtp-ehlo.txt'
|
||||
assert_success
|
||||
refute_output --partial 'SMTPUTF8'
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue