mirror of
https://github.com/docker-mailserver/docker-mailserver.git
synced 2025-08-04 10:05:00 +02:00
tests(chore): Rename test files to serial and parallel types
- `test_helper.bats` needs more work than this PR provides to be compatible with parallel tests, so must remain as a serial test for now. - `spam_bounced.bats` had failures as a serial test, but works well converted to a parallel test in a future commit.
This commit is contained in:
parent
2bc4078e35
commit
59127e2b25
41 changed files with 0 additions and 0 deletions
79
test/tests/parallel/set1/clamav.bats
Normal file
79
test/tests/parallel/set1/clamav.bats
Normal file
|
@ -0,0 +1,79 @@
|
|||
load 'test_helper/common'
|
||||
|
||||
TEST_NAME_PREFIX='ClamAV:'
|
||||
CONTAINER_NAME='dms-test-clamav'
|
||||
RUN_COMMAND=('run' 'docker' 'exec' "${CONTAINER_NAME}")
|
||||
|
||||
function setup_file() {
|
||||
local PRIVATE_CONFIG
|
||||
PRIVATE_CONFIG=$(duplicate_config_for_container . "${CONTAINER_NAME}")
|
||||
|
||||
docker run --rm --detach --tty \
|
||||
--name "${CONTAINER_NAME}" \
|
||||
--hostname mail.my-domain.com \
|
||||
--volume "${PRIVATE_CONFIG}:/tmp/docker-mailserver" \
|
||||
--volume "${PWD}/test/test-files:/tmp/docker-mailserver-test:ro" \
|
||||
--env ENABLE_AMAVIS=1 \
|
||||
--env AMAVIS_LOGLEVEL=2 \
|
||||
--env ENABLE_CLAMAV=1 \
|
||||
--env ENABLE_UPDATE_CHECK=0 \
|
||||
--env ENABLE_SPAMASSASSIN=0 \
|
||||
--env ENABLE_FAIL2BAN=0 \
|
||||
--env PERMIT_DOCKER=host \
|
||||
--env CLAMAV_MESSAGE_SIZE_LIMIT=30M \
|
||||
--env LOG_LEVEL=debug \
|
||||
"${IMAGE_NAME}"
|
||||
|
||||
wait_for_finished_setup_in_container "${CONTAINER_NAME}"
|
||||
|
||||
# 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
|
||||
|
||||
wait_for_service "${CONTAINER_NAME}" postfix
|
||||
wait_for_smtp_port_in_container "${CONTAINER_NAME}"
|
||||
|
||||
"${RUN_COMMAND[@]}" bash -c "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}"
|
||||
}
|
||||
|
||||
function teardown_file() {
|
||||
docker rm -f "${CONTAINER_NAME}"
|
||||
}
|
||||
|
||||
@test "${TEST_NAME_PREFIX} process clamd is running" {
|
||||
"${RUN_COMMAND[@]}" bash -c "ps aux --forest | grep -v grep | grep '/usr/sbin/clamd'"
|
||||
assert_success
|
||||
}
|
||||
|
||||
@test "${TEST_NAME_PREFIX} log files exist at /var/log/mail directory" {
|
||||
"${RUN_COMMAND[@]}" bash -c "ls -1 /var/log/mail/ | grep -E 'clamav|freshclam|mail.log'| wc -l"
|
||||
assert_success
|
||||
assert_output 3
|
||||
}
|
||||
|
||||
@test "${TEST_NAME_PREFIX} should be identified by Amavis" {
|
||||
"${RUN_COMMAND[@]}" grep -i 'Found secondary av scanner ClamAV-clamscan' /var/log/mail/mail.log
|
||||
assert_success
|
||||
}
|
||||
|
||||
@test "${TEST_NAME_PREFIX} freshclam cron is enabled" {
|
||||
"${RUN_COMMAND[@]}" bash -c "grep '/usr/bin/freshclam' -r /etc/cron.d"
|
||||
assert_success
|
||||
}
|
||||
|
||||
@test "${TEST_NAME_PREFIX} env CLAMAV_MESSAGE_SIZE_LIMIT is set correctly" {
|
||||
"${RUN_COMMAND[@]}" grep -q '^MaxFileSize 30M$' /etc/clamav/clamd.conf
|
||||
assert_success
|
||||
}
|
||||
|
||||
@test "${TEST_NAME_PREFIX} rejects virus" {
|
||||
"${RUN_COMMAND[@]}" bash -c "grep 'Blocked INFECTED' /var/log/mail/mail.log | grep '<virus@external.tld> -> <user1@localhost.localdomain>'"
|
||||
assert_success
|
||||
}
|
||||
|
||||
@test "${TEST_NAME_PREFIX} process clamd restarts when killed" {
|
||||
"${RUN_COMMAND[@]}" bash -c "pkill clamd && sleep 10 && ps aux --forest | grep -v grep | grep '/usr/sbin/clamd'"
|
||||
assert_success
|
||||
}
|
28
test/tests/parallel/set1/default_relay_host.bats
Normal file
28
test/tests/parallel/set1/default_relay_host.bats
Normal file
|
@ -0,0 +1,28 @@
|
|||
load 'test_helper/common'
|
||||
|
||||
function setup() {
|
||||
local PRIVATE_CONFIG
|
||||
PRIVATE_CONFIG=$(duplicate_config_for_container relay-hosts)
|
||||
|
||||
docker run -d --name mail_with_default_relay \
|
||||
-v "${PRIVATE_CONFIG}":/tmp/docker-mailserver \
|
||||
-v "$(pwd)/test/test-files":/tmp/docker-mailserver-test:ro \
|
||||
-e DEFAULT_RELAY_HOST=default.relay.host.invalid:25 \
|
||||
-e PERMIT_DOCKER=host \
|
||||
-h mail.my-domain.com -t "${NAME}"
|
||||
|
||||
wait_for_finished_setup_in_container mail_with_default_relay
|
||||
}
|
||||
|
||||
function teardown() {
|
||||
docker rm -f mail_with_default_relay
|
||||
}
|
||||
|
||||
#
|
||||
# default relay host
|
||||
#
|
||||
|
||||
@test "checking default relay host: default relay host is added to main.cf" {
|
||||
run docker exec mail_with_default_relay /bin/sh -c 'grep -e "^relayhost =" /etc/postfix/main.cf'
|
||||
assert_output 'relayhost = default.relay.host.invalid:25'
|
||||
}
|
49
test/tests/parallel/set2/spam_bounced.bats
Normal file
49
test/tests/parallel/set2/spam_bounced.bats
Normal file
|
@ -0,0 +1,49 @@
|
|||
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 teardown() {
|
||||
docker rm -f "${TEST_NAME}"
|
||||
}
|
||||
|
||||
function setup_file() {
|
||||
init_with_defaults
|
||||
}
|
||||
|
||||
# Not used
|
||||
# function teardown_file() {
|
||||
# }
|
||||
|
||||
@test "checking amavis: spam message is bounced (rejected)" {
|
||||
# shellcheck disable=SC2034
|
||||
local TEST_DOCKER_ARGS=(
|
||||
--env ENABLE_SPAMASSASSIN=1
|
||||
--env PERMIT_DOCKER=container
|
||||
--env SPAMASSASSIN_SPAM_TO_INBOX=0
|
||||
)
|
||||
|
||||
common_container_setup 'TEST_DOCKER_ARGS'
|
||||
|
||||
_should_bounce_spam
|
||||
}
|
||||
|
||||
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
|
||||
|
||||
# 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 ${TEST_NAME} | grep 'Blocked SPAM {NoBounceInbound,Quarantined}'"
|
||||
assert_success
|
||||
}
|
54
test/tests/parallel/set3/dovecot_inet_protocol.bats
Normal file
54
test/tests/parallel/set3/dovecot_inet_protocol.bats
Normal file
|
@ -0,0 +1,54 @@
|
|||
load 'test_helper/common'
|
||||
|
||||
function setup_file() {
|
||||
local PRIVATE_CONFIG
|
||||
export ALL IPV4 IPV6
|
||||
|
||||
PRIVATE_CONFIG=$(duplicate_config_for_container . "${IPV4}")
|
||||
ALL="mail_dovecot_all_protocols"
|
||||
IPV4="mail_dovecot_ipv4"
|
||||
IPV6="mail_dovecot_ipv6"
|
||||
|
||||
docker run --rm -d --name "${ALL}" \
|
||||
-v "${PRIVATE_CONFIG}":/tmp/docker-mailserver \
|
||||
-e DOVECOT_INET_PROTOCOLS= \
|
||||
-h mail.my-domain.com \
|
||||
-t "${NAME}"
|
||||
|
||||
docker run --rm -d --name "${IPV4}" \
|
||||
-v "${PRIVATE_CONFIG}":/tmp/docker-mailserver \
|
||||
-e DOVECOT_INET_PROTOCOLS=ipv4 \
|
||||
-h mail.my-domain.com \
|
||||
-t "${NAME}"
|
||||
|
||||
docker run --rm -d --name "${IPV6}" \
|
||||
-v "${PRIVATE_CONFIG}":/tmp/docker-mailserver \
|
||||
-e DOVECOT_INET_PROTOCOLS=ipv6 \
|
||||
-h mail.my-domain.com \
|
||||
-t "${NAME}"
|
||||
}
|
||||
|
||||
@test 'checking dovecot IP configuration' {
|
||||
wait_for_finished_setup_in_container "${ALL}"
|
||||
run docker exec "${ALL}" grep '^#listen = \*, ::' /etc/dovecot/dovecot.conf
|
||||
assert_success
|
||||
assert_output '#listen = *, ::'
|
||||
}
|
||||
|
||||
@test 'checking dovecot IPv4 configuration' {
|
||||
wait_for_finished_setup_in_container "${IPV4}"
|
||||
run docker exec "${IPV4}" grep '^listen = \*$' /etc/dovecot/dovecot.conf
|
||||
assert_success
|
||||
assert_output 'listen = *'
|
||||
}
|
||||
|
||||
@test 'checking dovecot IPv6 configuration' {
|
||||
wait_for_finished_setup_in_container "${IPV6}"
|
||||
run docker exec "${IPV6}" grep '^listen = \[::\]$' /etc/dovecot/dovecot.conf
|
||||
assert_success
|
||||
assert_output 'listen = [::]'
|
||||
}
|
||||
|
||||
function teardown_file {
|
||||
docker rm -f "${ALL}" "${IPV4}" "${IPV6}"
|
||||
}
|
30
test/tests/parallel/set3/helper-functions.bats
Normal file
30
test/tests/parallel/set3/helper-functions.bats
Normal file
|
@ -0,0 +1,30 @@
|
|||
load 'test_helper/common'
|
||||
|
||||
function setup_file() {
|
||||
local PRIVATE_CONFIG
|
||||
PRIVATE_CONFIG=$(duplicate_config_for_container .)
|
||||
|
||||
docker run -d --name mail_helper_functions \
|
||||
--cap-add=NET_ADMIN \
|
||||
-v "${PRIVATE_CONFIG}":/tmp/docker-mailserver \
|
||||
-v "$(pwd)/test/test-files":/tmp/docker-mailserver-test:ro \
|
||||
-e ENABLE_FETCHMAIL=1 \
|
||||
-h mail.my-domain.com -t "${NAME}"
|
||||
|
||||
wait_for_finished_setup_in_container mail_helper_functions
|
||||
}
|
||||
|
||||
function teardown_file() {
|
||||
docker rm -f mail_helper_functions
|
||||
}
|
||||
|
||||
@test "check helper functions (network.sh): _sanitize_ipv4_to_subnet_cidr" {
|
||||
run docker exec mail_helper_functions bash -c "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 docker exec mail_helper_functions bash -c "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 docker exec mail_helper_functions bash -c "source /usr/local/bin/helpers/index.sh; _sanitize_ipv4_to_subnet_cidr 192.168.255.14/32"
|
||||
assert_output "192.168.255.14/32"
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue