2020-05-02 16:39:51 +00:00
|
|
|
load 'test_helper/common'
|
2021-11-04 20:35:01 +00:00
|
|
|
# Globals referenced from `test_helper/common`:
|
|
|
|
# TEST_NAME
|
|
|
|
|
|
|
|
# Can run tests in parallel?: No
|
|
|
|
# Shared static container name: TEST_NAME
|
2020-05-02 16:39:51 +00:00
|
|
|
|
|
|
|
# Test case
|
|
|
|
# ---------
|
2021-09-20 07:35:03 +00:00
|
|
|
# When SPAMASSASSIN_SPAM_TO_INBOX=0, spam messages must be bounced (rejected).
|
|
|
|
# SPAMASSASSIN_SPAM_TO_INBOX=1 is covered in `mail_spam_junk_folder.bats`.
|
|
|
|
# Original test PR: https://github.com/docker-mailserver/docker-mailserver/pull/1485
|
2020-05-02 16:39:51 +00:00
|
|
|
|
|
|
|
function setup() {
|
2021-09-20 07:35:03 +00:00
|
|
|
run_setup_file_if_necessary
|
2020-05-02 16:39:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function teardown() {
|
2021-09-20 07:35:03 +00:00
|
|
|
docker rm -f "${TEST_NAME}"
|
|
|
|
run_teardown_file_if_necessary
|
2020-05-02 16:39:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function setup_file() {
|
2021-09-20 07:35:03 +00:00
|
|
|
init_with_defaults
|
2020-05-02 16:39:51 +00:00
|
|
|
}
|
|
|
|
|
2021-09-20 07:35:03 +00:00
|
|
|
# Not used
|
|
|
|
# function teardown_file() {
|
|
|
|
# }
|
2020-05-02 16:39:51 +00:00
|
|
|
|
|
|
|
@test "first" {
|
|
|
|
skip 'this test must come first to reliably identify when to run setup_file'
|
|
|
|
}
|
|
|
|
|
2021-09-20 07:35:03 +00:00
|
|
|
@test "checking amavis: spam message is bounced (rejected)" {
|
2021-11-04 20:35:01 +00:00
|
|
|
local TEST_DOCKER_ARGS=(
|
|
|
|
--env ENABLE_SPAMASSASSIN=1
|
|
|
|
--env SPAMASSASSIN_SPAM_TO_INBOX=0
|
|
|
|
)
|
2020-05-02 20:38:37 +00:00
|
|
|
|
2021-11-04 20:35:01 +00:00
|
|
|
common_container_setup 'TEST_DOCKER_ARGS'
|
2020-05-02 20:38:37 +00:00
|
|
|
|
2021-09-20 07:35:03 +00:00
|
|
|
run _should_emit_warning
|
|
|
|
assert_failure
|
|
|
|
|
|
|
|
_should_bounce_spam
|
2020-05-02 20:38:37 +00:00
|
|
|
}
|
|
|
|
|
2021-09-20 07:35:03 +00:00
|
|
|
@test "checking amavis: spam message is bounced (rejected), undefined SPAMASSASSIN_SPAM_TO_INBOX should raise a warning" {
|
|
|
|
# SPAMASSASSIN_SPAM_TO_INBOX=0 is the default. If no explicit ENV value is set, it should log a warning at startup.
|
2020-05-02 16:39:51 +00:00
|
|
|
|
2021-11-04 20:35:01 +00:00
|
|
|
# shellcheck disable=SC2034
|
|
|
|
local TEST_DOCKER_ARGS=(
|
|
|
|
--env ENABLE_SPAMASSASSIN=1
|
|
|
|
)
|
|
|
|
|
|
|
|
common_container_setup 'TEST_DOCKER_ARGS'
|
2020-05-02 16:39:51 +00:00
|
|
|
|
2021-09-20 07:35:03 +00:00
|
|
|
run _should_emit_warning
|
2020-05-02 16:39:51 +00:00
|
|
|
assert_success
|
2021-09-20 07:35:03 +00:00
|
|
|
|
|
|
|
_should_bounce_spam
|
2020-05-02 16:39:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@test "last" {
|
|
|
|
skip 'this test is only there to reliably mark the end for the teardown_file'
|
|
|
|
}
|
2021-09-20 07:35:03 +00:00
|
|
|
|
|
|
|
# This warning should only be raised when the env SPAMASSASSIN_SPAM_TO_INBOX has no explicit value set
|
|
|
|
function _should_emit_warning() {
|
|
|
|
sh -c "docker logs ${TEST_NAME} | grep 'Spam messages WILL NOT BE DELIVERED'"
|
|
|
|
}
|
|
|
|
|
|
|
|
function _should_bounce_spam() {
|
|
|
|
wait_for_smtp_port_in_container_to_respond "${TEST_NAME}"
|
|
|
|
|
|
|
|
# send a spam message
|
|
|
|
run docker exec "${TEST_NAME}" /bin/sh -c "nc 0.0.0.0 25 < /tmp/docker-mailserver-test/email-templates/amavis-spam.txt"
|
|
|
|
assert_success
|
|
|
|
|
|
|
|
run repeat_until_success_or_timeout 20 sh -c "docker logs ${TEST_NAME} | grep 'Blocked SPAM {NoBounceInbound,Quarantined}'"
|
|
|
|
assert_success
|
|
|
|
}
|