mirror of
https://github.com/docker-mailserver/docker-mailserver.git
synced 2024-01-19 02:48:50 +00:00
tests: refactor 4 more tests (#3018)
This commit is contained in:
parent
d7dee5d8a4
commit
0fd7c362da
|
@ -60,7 +60,7 @@ function __handle_container_name() {
|
||||||
printf '%s' "${CONTAINER_NAME}"
|
printf '%s' "${CONTAINER_NAME}"
|
||||||
return 0
|
return 0
|
||||||
else
|
else
|
||||||
echo 'ERROR: (helper/common.sh) Container name was either provided explicitly without the required `dms-test_` prefix, or CONTAINER_NAME is not set for implicit usage' >&2
|
echo 'ERROR: (helper/common.sh) Container name was either provided explicitly without the required "dms-test_" prefix, or CONTAINER_NAME is not set for implicit usage' >&2
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
@ -119,6 +119,27 @@ function _exec_in_container_bash() { _exec_in_container /bin/bash -c "${@}" ; }
|
||||||
# @param ... = Bash command to execute
|
# @param ... = Bash command to execute
|
||||||
function _run_in_container_bash() { _run_in_container /bin/bash -c "${@}" ; }
|
function _run_in_container_bash() { _run_in_container /bin/bash -c "${@}" ; }
|
||||||
|
|
||||||
|
# Run a command in Bash and filter the output given a regex.
|
||||||
|
#
|
||||||
|
# @param ${1} = command to run in Bash
|
||||||
|
# @param ${2} = regex to filter [OPTIONAL]
|
||||||
|
#
|
||||||
|
# ## Attention
|
||||||
|
#
|
||||||
|
# The regex is given to `grep -E`, so make sure it is compatible.
|
||||||
|
#
|
||||||
|
# ## Note
|
||||||
|
#
|
||||||
|
# If no regex is provided, this function will default to one that strips
|
||||||
|
# empty lines and Bash comments from the output.
|
||||||
|
function _run_in_container_bash_and_filter_output() {
|
||||||
|
local COMMAND=${1:?Command must be provided}
|
||||||
|
local FILTER_REGEX=${2:-^[[:space:]]*$|^ *#}
|
||||||
|
|
||||||
|
_run_in_container_bash "${COMMAND} | grep -E -v '${FILTER_REGEX}'"
|
||||||
|
assert_success
|
||||||
|
}
|
||||||
|
|
||||||
# ? << Functions to execute commands inside a container
|
# ? << Functions to execute commands inside a container
|
||||||
# ! -------------------------------------------------------------------
|
# ! -------------------------------------------------------------------
|
||||||
# ? >> Functions about executing commands with timeouts
|
# ? >> Functions about executing commands with timeouts
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
HELO mail.localhost
|
HELO mail.example.test
|
||||||
MAIL FROM: test@localhost
|
MAIL FROM: test@localhost
|
||||||
RCPT TO: user2@external.tld
|
RCPT TO: user2@external.tld
|
||||||
DATA
|
DATA
|
||||||
|
|
|
@ -1,43 +1,33 @@
|
||||||
load "${REPOSITORY_ROOT}/test/test_helper/common"
|
load "${REPOSITORY_ROOT}/test/helper/common"
|
||||||
|
load "${REPOSITORY_ROOT}/test/helper/setup"
|
||||||
# Test case
|
|
||||||
# ---------
|
|
||||||
# When ENABLE_QUOTAS is explicitly disabled (ENABLE_QUOTAS=0), dovecot quota must not be enabled.
|
|
||||||
|
|
||||||
|
BATS_TEST_NAME_PREFIX='[Quotas Disabled] '
|
||||||
|
CONTAINER_NAME='dms-test_quotas-disabled'
|
||||||
|
|
||||||
function setup_file() {
|
function setup_file() {
|
||||||
local PRIVATE_CONFIG
|
_init_with_defaults
|
||||||
PRIVATE_CONFIG=$(duplicate_config_for_container .)
|
local CUSTOM_SETUP_ARGUMENTS=(--env ENABLE_QUOTAS=0)
|
||||||
|
_common_container_setup 'CUSTOM_SETUP_ARGUMENTS'
|
||||||
docker run -d --name mail_no_quotas \
|
|
||||||
-v "${PRIVATE_CONFIG}":/tmp/docker-mailserver \
|
|
||||||
-v "$(pwd)/test/test-files":/tmp/docker-mailserver-test:ro \
|
|
||||||
-e ENABLE_QUOTAS=0 \
|
|
||||||
-h mail.my-domain.com -t "${NAME}"
|
|
||||||
|
|
||||||
wait_for_finished_setup_in_container mail_no_quotas
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function teardown_file() {
|
function teardown_file() { _default_teardown ; }
|
||||||
docker rm -f mail_no_quotas
|
|
||||||
}
|
|
||||||
|
|
||||||
@test "checking dovecot: (ENABLE_QUOTAS=0) quota plugin is disabled" {
|
@test "(Dovecot) quota plugin is disabled" {
|
||||||
run docker exec mail_no_quotas /bin/sh -c "grep '\$mail_plugins quota' /etc/dovecot/conf.d/10-mail.conf"
|
_run_in_container_bash_and_filter_output 'cat /etc/dovecot/conf.d/10-mail.conf'
|
||||||
|
refute_output --partial 'quota'
|
||||||
|
|
||||||
|
_run_in_container_bash_and_filter_output 'cat /etc/dovecot/conf.d/20-imap.conf'
|
||||||
|
refute_output --partial 'imap_quota'
|
||||||
|
|
||||||
|
_run_in_container_bash "[[ -f /etc/dovecot/conf.d/90-quota.conf ]]"
|
||||||
assert_failure
|
assert_failure
|
||||||
|
|
||||||
run docker exec mail_no_quotas /bin/sh -c "grep '\$mail_plugins imap_quota' /etc/dovecot/conf.d/20-imap.conf"
|
_run_in_container_bash "[[ -f /etc/dovecot/conf.d/90-quota.conf.disab ]]"
|
||||||
assert_failure
|
|
||||||
|
|
||||||
run docker exec mail_no_quotas ls /etc/dovecot/conf.d/90-quota.conf
|
|
||||||
assert_failure
|
|
||||||
|
|
||||||
run docker exec mail_no_quotas ls /etc/dovecot/conf.d/90-quota.conf.disab
|
|
||||||
assert_success
|
assert_success
|
||||||
}
|
}
|
||||||
|
|
||||||
@test "checking postfix: (ENABLE_QUOTAS=0) dovecot quota absent in postconf" {
|
@test "(Postfix) Dovecot quota absent in postconf" {
|
||||||
run docker exec mail_no_quotas /bin/bash -c "postconf | grep 'check_policy_service inet:localhost:65265'"
|
_run_in_container postconf
|
||||||
assert_failure
|
assert_success
|
||||||
|
refute_output --partial "check_policy_service inet:localhost:65265'"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,64 +1,44 @@
|
||||||
load "${REPOSITORY_ROOT}/test/test_helper/common"
|
load "${REPOSITORY_ROOT}/test/helper/common"
|
||||||
|
load "${REPOSITORY_ROOT}/test/helper/setup"
|
||||||
|
|
||||||
|
BATS_TEST_NAME_PREFIX='[SMTP-Only] '
|
||||||
|
CONTAINER_NAME='dms-test_env-smtp-only'
|
||||||
|
|
||||||
function setup_file() {
|
function setup_file() {
|
||||||
docker run --rm -d --name mail_smtponly \
|
_init_with_defaults
|
||||||
-v "$(pwd)/test/test-files":/tmp/docker-mailserver-test:ro \
|
|
||||||
-e SMTP_ONLY=1 \
|
|
||||||
-e PERMIT_DOCKER=network \
|
|
||||||
-e OVERRIDE_HOSTNAME=mail.my-domain.com \
|
|
||||||
-t "${NAME}"
|
|
||||||
|
|
||||||
wait_for_finished_setup_in_container mail_smtponly
|
local CUSTOM_SETUP_ARGUMENTS=(
|
||||||
wait_for_smtp_port_in_container mail_smtponly
|
--env SMTP_ONLY=1
|
||||||
|
--env PERMIT_DOCKER=network
|
||||||
|
)
|
||||||
|
|
||||||
|
_common_container_setup 'CUSTOM_SETUP_ARGUMENTS'
|
||||||
|
|
||||||
|
_wait_for_smtp_port_in_container
|
||||||
}
|
}
|
||||||
|
|
||||||
function teardown_file() {
|
function teardown_file() { _default_teardown ; }
|
||||||
docker rm -f mail_smtponly
|
|
||||||
}
|
|
||||||
|
|
||||||
#
|
@test "Dovecot quota absent in postconf" {
|
||||||
# configuration checks
|
_run_in_container postconf
|
||||||
#
|
|
||||||
|
|
||||||
@test "checking configuration: hostname/domainname override" {
|
|
||||||
run docker exec mail_smtponly /bin/bash -c "cat /etc/mailname | grep my-domain.com"
|
|
||||||
assert_success
|
assert_success
|
||||||
|
refute_output --partial "check_policy_service inet:localhost:65265'"
|
||||||
}
|
}
|
||||||
|
|
||||||
#
|
# TODO: needs complete rework when proper DNS container is running for tests
|
||||||
# imap
|
@test "sending mail should work" {
|
||||||
#
|
skip 'TODO: This test is absolutely broken and needs reworking!'
|
||||||
|
|
||||||
@test "checking configuration: dovecot quota absent in postconf (disabled using SMTP_ONLY)" {
|
|
||||||
run docker exec mail_smtponly /bin/bash -c "postconf | grep 'check_policy_service inet:localhost:65265'"
|
|
||||||
assert_failure
|
|
||||||
}
|
|
||||||
|
|
||||||
#
|
|
||||||
# smtp
|
|
||||||
#
|
|
||||||
|
|
||||||
@test "checking smtp_only: mail send should work" {
|
|
||||||
run docker exec mail_smtponly /bin/sh -c "postconf smtp_host_lookup=no"
|
|
||||||
assert_success
|
assert_success
|
||||||
|
|
||||||
_reload_postfix mail_smtponly
|
|
||||||
|
|
||||||
wait_for_smtp_port_in_container mail_smtponly
|
# it looks as if someone tries to send mail to another domain outside of DMS
|
||||||
run docker exec mail_smtponly /bin/sh -c "nc 0.0.0.0 25 < /tmp/docker-mailserver-test/email-templates/smtp-only.txt"
|
_run_in_container_bash "nc 0.0.0.0 25 < /tmp/docker-mailserver-test/email-templates/smtp-only.txt"
|
||||||
assert_success
|
assert_success
|
||||||
run docker exec mail_smtponly /bin/sh -c 'grep -cE "to=<user2\@external.tld>.*status\=sent" /var/log/mail/mail.log'
|
_wait_for_empty_mail_queue_in_container
|
||||||
|
|
||||||
|
# this seemingly succeeds, but looking at the logs, it doesn't
|
||||||
|
_run_in_container_bash 'grep -cE "to=<user2\@external.tld>.*status\=sent" /var/log/mail/mail.log'
|
||||||
|
# this is absolutely useless! `grep -c` count 0 but also returns 0; the mail was never properly sent!
|
||||||
[[ ${status} -ge 0 ]]
|
[[ ${status} -ge 0 ]]
|
||||||
}
|
}
|
||||||
|
|
||||||
#
|
|
||||||
# PERMIT_DOCKER=network
|
|
||||||
#
|
|
||||||
|
|
||||||
@test "checking PERMIT_DOCKER=network: opendmarc/opendkim config" {
|
|
||||||
run docker exec mail_smtponly /bin/sh -c "cat /etc/opendmarc/ignore.hosts | grep '172.16.0.0/12'"
|
|
||||||
assert_success
|
|
||||||
|
|
||||||
run docker exec mail_smtponly /bin/sh -c "cat /etc/opendkim/TrustedHosts | grep '172.16.0.0/12'"
|
|
||||||
assert_success
|
|
||||||
}
|
|
||||||
|
|
|
@ -1,40 +1,38 @@
|
||||||
load "${REPOSITORY_ROOT}/test/test_helper/common"
|
load "${REPOSITORY_ROOT}/test/helper/common"
|
||||||
|
load "${REPOSITORY_ROOT}/test/helper/setup"
|
||||||
|
|
||||||
setup_file() {
|
BATS_TEST_NAME_PREFIX='[Special Use Folders] '
|
||||||
local PRIVATE_CONFIG
|
CONTAINER_NAME='dms-test_special-use-folders'
|
||||||
PRIVATE_CONFIG=$(duplicate_config_for_container .)
|
|
||||||
|
|
||||||
docker run -d --name mail_special_use_folders \
|
function setup_file() {
|
||||||
-v "${PRIVATE_CONFIG}":/tmp/docker-mailserver \
|
_init_with_defaults
|
||||||
-v "$(pwd)/test/test-files":/tmp/docker-mailserver-test:ro \
|
local CUSTOM_SETUP_ARGUMENTS=(--env PERMIT_DOCKER=host)
|
||||||
-e ENABLE_CLAMAV=0 \
|
_common_container_setup 'CUSTOM_SETUP_ARGUMENTS'
|
||||||
-e ENABLE_SPAMASSASSIN=0 \
|
_wait_for_smtp_port_in_container
|
||||||
-e PERMIT_DOCKER=host \
|
|
||||||
-h mail.my-domain.com -t "${NAME}"
|
|
||||||
|
|
||||||
wait_for_smtp_port_in_container mail_special_use_folders
|
|
||||||
}
|
}
|
||||||
|
|
||||||
teardown_file() {
|
function teardown_file() { _default_teardown ; }
|
||||||
docker rm -f mail_special_use_folders
|
|
||||||
}
|
|
||||||
|
|
||||||
@test "checking normal delivery" {
|
@test "normal delivery works" {
|
||||||
run docker exec mail_special_use_folders /bin/sh -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
|
assert_success
|
||||||
|
|
||||||
# shellcheck disable=SC2016
|
_count_files_in_directory_in_container /var/mail/localhost.localdomain/user1/new 1
|
||||||
repeat_until_success_or_timeout 30 docker exec mail_special_use_folders /bin/sh -c '[ $(ls /var/mail/localhost.localdomain/user1/new | wc -l) -eq 1 ]'
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@test "checking special-use folders not yet created" {
|
@test "(IMAP) special-use folders should not exist yet" {
|
||||||
run docker exec mail_special_use_folders /bin/bash -c "ls -A /var/mail/localhost.localdomain/user1 | grep -E '.Drafts|.Sent|.Trash' | wc -l"
|
_run_in_container find /var/mail/localhost.localdomain/user1 -maxdepth 1 -type d
|
||||||
assert_success
|
assert_success
|
||||||
assert_output 0
|
refute_output --partial '.Drafts'
|
||||||
|
refute_output --partial '.Sent'
|
||||||
|
refute_output --partial '.Trash'
|
||||||
}
|
}
|
||||||
|
|
||||||
@test "checking special-use folders available in IMAP" {
|
@test "(IMAP) special-use folders should be created when necessary" {
|
||||||
run docker exec mail_special_use_folders /bin/sh -c "nc -w 8 0.0.0.0 143 < /tmp/docker-mailserver-test/nc_templates/imap_special_use_folders.txt | grep -E 'Drafts|Junk|Trash|Sent' | wc -l"
|
_run_in_container_bash "nc -w 8 0.0.0.0 143 < /tmp/docker-mailserver-test/nc_templates/imap_special_use_folders.txt"
|
||||||
assert_success
|
assert_success
|
||||||
assert_output 4
|
assert_output --partial 'Drafts'
|
||||||
|
assert_output --partial 'Junk'
|
||||||
|
assert_output --partial 'Trash'
|
||||||
|
assert_output --partial 'Sent'
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,29 +1,23 @@
|
||||||
load "${REPOSITORY_ROOT}/test/test_helper/common"
|
load "${REPOSITORY_ROOT}/test/helper/common"
|
||||||
|
load "${REPOSITORY_ROOT}/test/helper/setup"
|
||||||
|
|
||||||
setup_file() {
|
BATS_TEST_NAME_PREFIX='[Timezone] '
|
||||||
local PRIVATE_CONFIG
|
CONTAINER_NAME='dms-test_timezone'
|
||||||
PRIVATE_CONFIG=$(duplicate_config_for_container .)
|
|
||||||
|
|
||||||
docker run -d --name mail_time \
|
function setup_file() {
|
||||||
-v "${PRIVATE_CONFIG}":/tmp/docker-mailserver \
|
_init_with_defaults
|
||||||
-v "$(pwd)/test/test-files":/tmp/docker-mailserver-test:ro \
|
local CUSTOM_SETUP_ARGUMENTS=(--env TZ='Asia/Jakarta')
|
||||||
-e TZ='Asia/Jakarta' \
|
_common_container_setup 'CUSTOM_SETUP_ARGUMENTS'
|
||||||
-e LOG_LEVEL=debug \
|
|
||||||
-h mail.my-domain.com -t "${NAME}"
|
|
||||||
|
|
||||||
wait_for_smtp_port_in_container mail_time
|
|
||||||
}
|
}
|
||||||
|
|
||||||
teardown_file() {
|
function teardown_file() { _default_teardown ; }
|
||||||
docker rm -f mail_time
|
|
||||||
}
|
|
||||||
|
|
||||||
@test "checking time: setting the time with TZ works correctly" {
|
@test "setting the time with TZ works correctly" {
|
||||||
run docker exec mail_time cat /etc/timezone
|
_run_in_container cat /etc/timezone
|
||||||
assert_success
|
assert_success
|
||||||
assert_output 'Asia/Jakarta'
|
assert_output 'Asia/Jakarta'
|
||||||
|
|
||||||
run docker exec mail_time date '+%Z'
|
_run_in_container date '+%Z'
|
||||||
assert_success
|
assert_success
|
||||||
assert_output 'WIB'
|
assert_output 'WIB'
|
||||||
}
|
}
|
||||||
|
|
|
@ -84,3 +84,12 @@ teardown_file() {
|
||||||
assert_output --partial "550 5.5.1 Protocol error"
|
assert_output --partial "550 5.5.1 Protocol error"
|
||||||
[[ ${status} -ge 0 ]]
|
[[ ${status} -ge 0 ]]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@test "checking PERMIT_DOCKER=network: opendmarc/opendkim config" {
|
||||||
|
skip 'TODO: this test was taken from mail_smtponly, where it did not actually belong to'
|
||||||
|
run docker exec mail_smtponly /bin/sh -c "cat /etc/opendmarc/ignore.hosts | grep '172.16.0.0/12'"
|
||||||
|
assert_success
|
||||||
|
|
||||||
|
run docker exec mail_smtponly /bin/sh -c "cat /etc/opendkim/TrustedHosts | grep '172.16.0.0/12'"
|
||||||
|
assert_success
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue