2023-01-03 05:58:09 +00:00
|
|
|
load "${REPOSITORY_ROOT}/test/helper/setup"
|
|
|
|
load "${REPOSITORY_ROOT}/test/helper/common"
|
2020-05-02 16:39:51 +00:00
|
|
|
|
2023-01-29 12:29:25 +00:00
|
|
|
# Tests originally contributed in PR: https://github.com/docker-mailserver/docker-mailserver/pull/1485
|
|
|
|
# That introduced both ENV: SPAMASSASSIN_SPAM_TO_INBOX and MOVE_SPAM_TO_JUNK
|
2020-05-02 16:39:51 +00:00
|
|
|
|
2023-01-29 12:29:25 +00:00
|
|
|
BATS_TEST_NAME_PREFIX='[Spam - Amavis] ENV SPAMASSASSIN_SPAM_TO_INBOX '
|
|
|
|
CONTAINER1_NAME='dms-test_spam-amavis_bounced'
|
|
|
|
CONTAINER2_NAME='dms-test_spam-amavis_env-move-spam-to-junk-0'
|
|
|
|
CONTAINER3_NAME='dms-test_spam-amavis_env-move-spam-to-junk-1'
|
2022-05-30 00:53:30 +00:00
|
|
|
|
2023-01-29 12:29:25 +00:00
|
|
|
function teardown() { _default_teardown ; }
|
2020-05-02 16:39:51 +00:00
|
|
|
|
2023-01-29 12:29:25 +00:00
|
|
|
@test "(disabled) spam message should be bounced (rejected)" {
|
2023-01-03 05:58:09 +00:00
|
|
|
export CONTAINER_NAME=${CONTAINER1_NAME}
|
2023-01-29 12:29:25 +00:00
|
|
|
|
2023-01-03 05:58:09 +00:00
|
|
|
local CUSTOM_SETUP_ARGUMENTS=(
|
|
|
|
--env ENABLE_AMAVIS=1
|
|
|
|
--env ENABLE_SPAMASSASSIN=1
|
2023-01-29 12:29:25 +00:00
|
|
|
--env SPAMASSASSIN_SPAM_TO_INBOX=0
|
2023-01-03 05:58:09 +00:00
|
|
|
--env PERMIT_DOCKER=container
|
|
|
|
)
|
2023-01-21 23:05:28 +00:00
|
|
|
_init_with_defaults
|
|
|
|
_common_container_setup 'CUSTOM_SETUP_ARGUMENTS'
|
2020-05-02 16:39:51 +00:00
|
|
|
|
2023-01-29 12:29:25 +00:00
|
|
|
_should_send_spam_message
|
|
|
|
_should_be_received_by_amavis 'Blocked SPAM {NoBounceInbound,Quarantined}'
|
2020-05-02 16:55:29 +00:00
|
|
|
}
|
|
|
|
|
2023-01-29 12:29:25 +00:00
|
|
|
@test "(enabled + MOVE_SPAM_TO_JUNK=0) should deliver spam message into INBOX" {
|
2023-01-03 05:58:09 +00:00
|
|
|
export CONTAINER_NAME=${CONTAINER2_NAME}
|
2023-01-29 12:29:25 +00:00
|
|
|
|
2023-01-03 05:58:09 +00:00
|
|
|
local CUSTOM_SETUP_ARGUMENTS=(
|
|
|
|
--env ENABLE_AMAVIS=1
|
|
|
|
--env ENABLE_SPAMASSASSIN=1
|
2023-01-29 12:29:25 +00:00
|
|
|
--env SA_SPAM_SUBJECT="SPAM: "
|
|
|
|
--env SPAMASSASSIN_SPAM_TO_INBOX=1
|
2023-01-03 05:58:09 +00:00
|
|
|
--env MOVE_SPAM_TO_JUNK=0
|
|
|
|
--env PERMIT_DOCKER=container
|
2023-01-29 12:29:25 +00:00
|
|
|
)
|
|
|
|
_init_with_defaults
|
|
|
|
_common_container_setup 'CUSTOM_SETUP_ARGUMENTS'
|
|
|
|
|
|
|
|
_should_send_spam_message
|
|
|
|
_should_be_received_by_amavis 'Passed SPAM {RelayedTaggedInbound,Quarantined}'
|
|
|
|
|
|
|
|
# Should move delivered spam to INBOX
|
|
|
|
_should_receive_spam_at '/var/mail/localhost.localdomain/user1/new/'
|
|
|
|
}
|
|
|
|
|
|
|
|
@test "(enabled + MOVE_SPAM_TO_JUNK=1) should deliver spam message into Junk folder" {
|
|
|
|
export CONTAINER_NAME=${CONTAINER3_NAME}
|
|
|
|
|
|
|
|
local CUSTOM_SETUP_ARGUMENTS=(
|
|
|
|
--env ENABLE_AMAVIS=1
|
|
|
|
--env ENABLE_SPAMASSASSIN=1
|
2023-01-03 05:58:09 +00:00
|
|
|
--env SA_SPAM_SUBJECT="SPAM: "
|
|
|
|
--env SPAMASSASSIN_SPAM_TO_INBOX=1
|
2023-01-29 12:29:25 +00:00
|
|
|
--env MOVE_SPAM_TO_JUNK=1
|
|
|
|
--env PERMIT_DOCKER=container
|
2023-01-03 05:58:09 +00:00
|
|
|
)
|
2023-01-21 23:05:28 +00:00
|
|
|
_init_with_defaults
|
|
|
|
_common_container_setup 'CUSTOM_SETUP_ARGUMENTS'
|
2023-01-29 12:29:25 +00:00
|
|
|
|
|
|
|
_should_send_spam_message
|
|
|
|
_should_be_received_by_amavis 'Passed SPAM {RelayedTaggedInbound,Quarantined}'
|
|
|
|
|
|
|
|
# Should move delivered spam to Junk folder
|
|
|
|
_should_receive_spam_at '/var/mail/localhost.localdomain/user1/.Junk/new/'
|
|
|
|
}
|
|
|
|
|
|
|
|
function _should_send_spam_message() {
|
2023-01-21 23:05:28 +00:00
|
|
|
_wait_for_smtp_port_in_container
|
2023-02-22 09:26:04 +00:00
|
|
|
_wait_for_tcp_port_in_container 10024 # port 10024 is for Amavis
|
2023-02-24 09:44:18 +00:00
|
|
|
_send_email 'email-templates/amavis-spam'
|
2023-01-29 12:29:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function _should_be_received_by_amavis() {
|
|
|
|
local MATCH_CONTENT=${1}
|
2020-05-02 16:55:29 +00:00
|
|
|
|
2022-05-30 00:53:30 +00:00
|
|
|
# message will be added to a queue with varying delay until amavis receives it
|
2023-01-29 12:29:25 +00:00
|
|
|
_run_in_container_bash "timeout 60 tail -F /var/log/mail/mail.log | grep --max-count 1 '${MATCH_CONTENT}'"
|
2020-05-02 16:55:29 +00:00
|
|
|
assert_success
|
2023-01-29 12:29:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function _should_receive_spam_at() {
|
|
|
|
local MAIL_DIR=${1}
|
2020-05-02 16:55:29 +00:00
|
|
|
|
2023-01-29 12:29:25 +00:00
|
|
|
# spam moved into MAIL_DIR
|
|
|
|
_repeat_in_container_until_success_or_timeout 20 "${CONTAINER_NAME}" grep -R 'Subject: SPAM: ' "${MAIL_DIR}"
|
2020-05-02 16:39:51 +00:00
|
|
|
assert_success
|
|
|
|
}
|