mirror of
https://github.com/docker-mailserver/docker-mailserver.git
synced 2024-01-19 02:48:50 +00:00
672e9cf19a
* tests: Ensure excessive FD limits are avoided Processes that run as daemons (`postsrsd` and `fail2ban-server`) initialize by closing all FDs (File Descriptors). This behaviour queries that maximum limit and iterates through the entire range even if only a few FDs are open. In some environments (Docker, limit configured by distro) this can be a range exceeding 1 billion (from kernel default of 1024 soft, 4096 hard), causing an 8 minute delay with heavy CPU activity. `postsrsd` has since been updated to use `close_range()` syscall, and `fail2ban` will now iterate through `/proc/self/fd` (open FDs) which should resolve the performance hit. Until those updates reach our Docker image, we need to workaround it with `--ulimit` option. NOTE: If `docker.service` on a distro sets `LimitNOFILE=` to approx 1 million or lower, it should not be an issue. On distros such as Fedora 36, it is `LimitNOFILE=infinity` (approx 1 billion) that causes excessive delays. * chore: Use Docker host limits instead Typically on modern distros with systemd, this should equate to 1024 (soft) and 512K (hard) limits. A distro may override the built-in global defaults systemd sets via setting `DefaultLimitNOFILE=` in `/etc/systemd/user.conf` and `/etc/systemd/system.conf`. * tests(fix): Better prevent non-deterministic failures - `no_containers.bats` tests the external script `setup.sh` (without `-c`). It's expected that no existing DMS container is running - otherwise it may attempt to use that container and fail. Detect this and fail early via `setup_file()` step. - `mail_hostname.bats` had a odd timing failure with teardown due to the last tests bringing the containers down earlier (`docker stop` paired with the `docker run --rm`). Adding a moment of delay via `sleep` helps avoid that false positive scenario.
66 lines
2.3 KiB
Bash
66 lines
2.3 KiB
Bash
load 'test_helper/common'
|
|
|
|
function setup() {
|
|
local PRIVATE_CONFIG
|
|
|
|
PRIVATE_CONFIG=$(duplicate_config_for_container .)
|
|
docker run -d --name mail_undef_spam_subject \
|
|
-v "${PRIVATE_CONFIG}":/tmp/docker-mailserver \
|
|
-v "$(pwd)/test/test-files":/tmp/docker-mailserver-test:ro \
|
|
-e ENABLE_SPAMASSASSIN=1 \
|
|
-e SA_SPAM_SUBJECT="undef" \
|
|
--hostname mail.my-domain.com \
|
|
--tty \
|
|
"${NAME}"
|
|
|
|
CONTAINER='mail_undef_spam_subject_2'
|
|
PRIVATE_CONFIG=$(duplicate_config_for_container . "${CONTAINER}")
|
|
docker run -d \
|
|
-v "${PRIVATE_CONFIG}":/tmp/docker-mailserver \
|
|
-v "$(pwd)/test/test-files":/tmp/docker-mailserver-test:ro \
|
|
-v "$(pwd)/test/onedir":/var/mail-state \
|
|
-e ENABLE_CLAMAV=1 \
|
|
-e SPOOF_PROTECTION=1 \
|
|
-e ENABLE_SPAMASSASSIN=1 \
|
|
-e REPORT_RECIPIENT=user1@localhost.localdomain \
|
|
-e REPORT_SENDER=report1@mail.my-domain.com \
|
|
-e SA_TAG=-5.0 \
|
|
-e SA_TAG2=2.0 \
|
|
-e SA_KILL=3.0 \
|
|
-e SA_SPAM_SUBJECT="SPAM: " \
|
|
-e VIRUSMAILS_DELETE_DELAY=7 \
|
|
-e ENABLE_SRS=1 \
|
|
-e SASL_PASSWD="external-domain.com username:password" \
|
|
-e ENABLE_MANAGESIEVE=1 \
|
|
-e PERMIT_DOCKER=host \
|
|
--name "${CONTAINER}" \
|
|
--hostname mail.my-domain.com \
|
|
--tty \
|
|
--ulimit "nofile=$(ulimit -Sn):$(ulimit -Hn)" \
|
|
"${NAME}"
|
|
|
|
wait_for_finished_setup_in_container mail_undef_spam_subject
|
|
wait_for_finished_setup_in_container "${CONTAINER}"
|
|
}
|
|
|
|
function teardown() {
|
|
docker rm -f mail_undef_spam_subject "${CONTAINER}"
|
|
}
|
|
|
|
@test "checking spamassassin: docker env variables are set correctly (custom)" {
|
|
run docker exec "${CONTAINER}" /bin/sh -c "grep '\$sa_tag_level_deflt' /etc/amavis/conf.d/20-debian_defaults | grep '= -5.0'"
|
|
assert_success
|
|
|
|
run docker exec "${CONTAINER}" /bin/sh -c "grep '\$sa_tag2_level_deflt' /etc/amavis/conf.d/20-debian_defaults | grep '= 2.0'"
|
|
assert_success
|
|
|
|
run docker exec "${CONTAINER}" /bin/sh -c "grep '\$sa_kill_level_deflt' /etc/amavis/conf.d/20-debian_defaults | grep '= 3.0'"
|
|
assert_success
|
|
|
|
run docker exec "${CONTAINER}" /bin/sh -c "grep '\$sa_spam_subject_tag' /etc/amavis/conf.d/20-debian_defaults | grep '= .SPAM: .'"
|
|
assert_success
|
|
|
|
run docker exec mail_undef_spam_subject /bin/sh -c "grep '\$sa_spam_subject_tag' /etc/amavis/conf.d/20-debian_defaults | grep '= undef'"
|
|
assert_success
|
|
}
|