setup: improve Amavis setup routine (#3079)

* improve Amavis setup routine

see https://github.com/docker-mailserver/docker-mailserver/pull/3046#issuecomment-1423718811
This commit is contained in:
Georg Lauterbach 2023-02-18 19:22:20 +01:00 committed by GitHub
parent f5d325bdc1
commit 40e10d755d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 55 additions and 10 deletions

View file

@ -85,9 +85,6 @@ virtual_mailbox_domains = /etc/postfix/vhost
virtual_mailbox_maps = texthash:/etc/postfix/vmailbox
virtual_alias_maps = texthash:/etc/postfix/virtual
# Additional option for filtering
content_filter = smtp-amavis:[127.0.0.1]:10024
# Milters used by DKIM
milter_protocol = 6
milter_default_action = accept

View file

@ -73,14 +73,14 @@ function _setup_amavis
if [[ ${ENABLE_AMAVIS} -eq 1 ]]
then
_log 'debug' 'Setting up Amavis'
cat /etc/dms/postfix/master.d/postfix-amavis.cf >>/etc/postfix/master.cf
postconf 'content_filter = smtp-amavis:[127.0.0.1]:10024'
sed -i \
"s|^#\$myhostname = \"mail.example.com\";|\$myhostname = \"${HOSTNAME}\";|" \
/etc/amavis/conf.d/05-node_id
else
_log 'debug' "Removing Amavis from Postfix's configuration"
sed -i 's|content_filter =.*|content_filter =|' /etc/postfix/main.cf
_log 'debug' 'Disabling Amavis cron job'
mv /etc/cron.d/amavisd-new /etc/cron.d/amavisd-new.disabled
chmod 0 /etc/cron.d/amavisd-new.disabled

View file

@ -2,23 +2,52 @@ load "${REPOSITORY_ROOT}/test/helper/common"
load "${REPOSITORY_ROOT}/test/helper/setup"
BATS_TEST_NAME_PREFIX='[Amavis + SA] '
CONTAINER_NAME='dms-test_amavis'
CONTAINER1_NAME='dms-test_amavis_enabled'
CONTAINER2_NAME='dms-test_amavis_disabled'
function setup_file() {
_init_with_defaults
export CONTAINER_NAME
CONTAINER_NAME=${CONTAINER1_NAME}
_init_with_defaults
local CUSTOM_SETUP_ARGUMENTS=(
--env ENABLE_AMAVIS=1
--env AMAVIS_LOGLEVEL=2
--env ENABLE_SPAMASSASSIN=1
)
_common_container_setup 'CUSTOM_SETUP_ARGUMENTS'
CONTAINER_NAME=${CONTAINER2_NAME}
_init_with_defaults
local CUSTOM_SETUP_ARGUMENTS=(
--env ENABLE_AMAVIS=0
--env ENABLE_SPAMASSASSIN=0
)
_common_container_setup 'CUSTOM_SETUP_ARGUMENTS'
}
function teardown_file() { _default_teardown ; }
@test 'SpamAssassin integration should be active' {
@test '(Amavis enabled) configuration should be correct' {
export CONTAINER_NAME=${CONTAINER1_NAME}
_run_in_container postconf -h content_filter
assert_success
assert_line 'smtp-amavis:[127.0.0.1]:10024'
_run_in_container grep 'smtp-amavis' /etc/postfix/master.cf
assert_success
_run_in_container grep -F '127.0.0.1:10025' /etc/postfix/master.cf
assert_success
_run_in_container_bash '[[ -f /etc/cron.d/amavisd-new.disabled ]]'
assert_failure
_run_in_container_bash '[[ -f /etc/cron.d/amavisd-new ]]'
assert_success
}
@test '(Amavis enabled) SA integration should be active' {
export CONTAINER_NAME=${CONTAINER1_NAME}
# give Amavis just a bit of time to print out its full debug log
run _repeat_in_container_until_success_or_timeout 5 "${CONTAINER_NAME}" grep 'ANTI-SPAM-SA' /var/log/mail/mail.log
assert_success
@ -26,7 +55,9 @@ function teardown_file() { _default_teardown ; }
refute_output --partial 'NOT loaded'
}
@test 'SA ENV should update Amavis config' {
@test '(Amavis enabled) SA ENV should update Amavis config' {
export CONTAINER_NAME=${CONTAINER1_NAME}
local AMAVIS_DEFAULTS_FILE='/etc/amavis/conf.d/20-debian_defaults'
_run_in_container grep '\$sa_tag_level_deflt' "${AMAVIS_DEFAULTS_FILE}"
assert_success
@ -44,3 +75,20 @@ function teardown_file() { _default_teardown ; }
assert_success
assert_output --partial "= '***SPAM*** ';"
}
@test '(Amavis disabled) configuration should be correct' {
export CONTAINER_NAME=${CONTAINER2_NAME}
_run_in_container postconf -h content_filter
assert_success
refute_output --partial 'smtp-amavis:[127.0.0.1]:10024'
_run_in_container grep 'smtp-amavis' /etc/postfix/master.cf
assert_failure
_run_in_container grep -F '127.0.0.1:10025' /etc/postfix/master.cf
assert_failure
_run_in_container_bash '[[ -f /etc/cron.d/amavisd-new.disabled ]]'
assert_success
_run_in_container_bash '[[ -f /etc/cron.d/amavisd-new ]]'
assert_failure
}