1
0
mirror of https://github.com/tomav/docker-mailserver.git synced 2024-06-30 21:21:31 +02:00
docker-mailserver/test/mail_spam_bounced.bats
Brennan Kinney b1a74bd47a
tests(feat): Refactor test_helper/common.bash common_container methods (#2275)
These are improvements for better supporting the requirements of other tests.

- Opted for passing an array reference instead of an ENV file. This seems to be a better approach and supports more than just ENV changes.
- Likewise, shifted to a `create` + `start` approach, instead of `docker run` for added flexibility.
- Using `TEST_TMP_CONFIG` instead of `PRIVATE_CONFIG` to make the difference in usage with config volume in tests more clear.
- Changed the config volume from read-only volume mount to be read-write instead, which seems required for other tests.
- Added notes about logged failures from a read-only config volume during container startup.
- Added `TEST_CA_CERT` as a default CA cert path for the test files volume. This can be used by default by openssl methods.
2021-11-05 09:35:01 +13:00

84 lines
2.2 KiB
Bash

load 'test_helper/common'
# Globals referenced from `test_helper/common`:
# TEST_NAME
# Can run tests in parallel?: No
# Shared static container name: TEST_NAME
# Test case
# ---------
# 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
function setup() {
run_setup_file_if_necessary
}
function teardown() {
docker rm -f "${TEST_NAME}"
run_teardown_file_if_necessary
}
function setup_file() {
init_with_defaults
}
# Not used
# function teardown_file() {
# }
@test "first" {
skip 'this test must come first to reliably identify when to run setup_file'
}
@test "checking amavis: spam message is bounced (rejected)" {
local TEST_DOCKER_ARGS=(
--env ENABLE_SPAMASSASSIN=1
--env SPAMASSASSIN_SPAM_TO_INBOX=0
)
common_container_setup 'TEST_DOCKER_ARGS'
run _should_emit_warning
assert_failure
_should_bounce_spam
}
@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.
# shellcheck disable=SC2034
local TEST_DOCKER_ARGS=(
--env ENABLE_SPAMASSASSIN=1
)
common_container_setup 'TEST_DOCKER_ARGS'
run _should_emit_warning
assert_success
_should_bounce_spam
}
@test "last" {
skip 'this test is only there to reliably mark the end for the teardown_file'
}
# 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
}