2022-11-25 22:37:58 +00:00
|
|
|
load "${REPOSITORY_ROOT}/test/helper/setup"
|
|
|
|
load "${REPOSITORY_ROOT}/test/helper/common"
|
2022-10-14 07:48:28 +00:00
|
|
|
|
2023-01-09 07:54:04 +00:00
|
|
|
BATS_TEST_NAME_PREFIX='[ClamAV] '
|
2023-01-03 05:58:09 +00:00
|
|
|
CONTAINER_NAME='dms-test_clamav'
|
2022-10-14 07:48:28 +00:00
|
|
|
|
|
|
|
function setup_file() {
|
2023-01-21 23:05:28 +00:00
|
|
|
_init_with_defaults
|
2022-11-25 21:59:14 +00:00
|
|
|
|
|
|
|
# Comment for maintainers about `PERMIT_DOCKER=host`:
|
|
|
|
# https://github.com/docker-mailserver/docker-mailserver/pull/2815/files#r991087509
|
|
|
|
local CUSTOM_SETUP_ARGUMENTS=(
|
|
|
|
--env ENABLE_CLAMAV=1
|
|
|
|
--env ENABLE_AMAVIS=1
|
|
|
|
--env PERMIT_DOCKER=host
|
|
|
|
--env AMAVIS_LOGLEVEL=2
|
|
|
|
--env CLAMAV_MESSAGE_SIZE_LIMIT=30M
|
|
|
|
--env LOG_LEVEL=trace
|
|
|
|
)
|
|
|
|
|
2023-01-21 23:05:28 +00:00
|
|
|
_common_container_setup 'CUSTOM_SETUP_ARGUMENTS'
|
2022-10-14 07:48:28 +00:00
|
|
|
|
|
|
|
# wait for ClamAV to be fully setup or we will get errors on the log
|
2023-01-21 23:05:28 +00:00
|
|
|
_repeat_in_container_until_success_or_timeout 60 "${CONTAINER_NAME}" test -e /var/run/clamav/clamd.ctl
|
2022-10-14 07:48:28 +00:00
|
|
|
|
2023-01-21 23:05:28 +00:00
|
|
|
_wait_for_service postfix
|
|
|
|
_wait_for_smtp_port_in_container
|
2022-10-14 07:48:28 +00:00
|
|
|
|
2023-01-21 23:05:28 +00:00
|
|
|
_run_in_container_bash "nc 0.0.0.0 25 < /tmp/docker-mailserver-test/email-templates/amavis-virus.txt"
|
2022-10-14 07:48:28 +00:00
|
|
|
assert_success
|
|
|
|
|
2023-01-21 23:05:28 +00:00
|
|
|
_wait_for_empty_mail_queue_in_container
|
2022-10-14 07:48:28 +00:00
|
|
|
}
|
|
|
|
|
2022-11-25 21:59:14 +00:00
|
|
|
function teardown_file() { _default_teardown ; }
|
2022-10-14 07:48:28 +00:00
|
|
|
|
2023-01-09 07:54:04 +00:00
|
|
|
@test "log files exist at /var/log/mail directory" {
|
2023-01-21 23:05:28 +00:00
|
|
|
_run_in_container_bash "ls -1 /var/log/mail/ | grep -E 'clamav|freshclam|mail.log' | wc -l"
|
2022-10-14 07:48:28 +00:00
|
|
|
assert_success
|
|
|
|
assert_output 3
|
|
|
|
}
|
|
|
|
|
2023-01-09 07:54:04 +00:00
|
|
|
@test "should be identified by Amavis" {
|
2022-11-25 21:59:14 +00:00
|
|
|
_run_in_container grep -i 'Found secondary av scanner ClamAV-clamscan' /var/log/mail/mail.log
|
2022-10-14 07:48:28 +00:00
|
|
|
assert_success
|
|
|
|
}
|
|
|
|
|
2023-01-09 07:54:04 +00:00
|
|
|
@test "freshclam cron is enabled" {
|
2023-01-21 23:05:28 +00:00
|
|
|
_run_in_container_bash "grep '/usr/bin/freshclam' -r /etc/cron.d"
|
2022-10-14 07:48:28 +00:00
|
|
|
assert_success
|
|
|
|
}
|
|
|
|
|
2023-01-09 07:54:04 +00:00
|
|
|
@test "env CLAMAV_MESSAGE_SIZE_LIMIT is set correctly" {
|
2022-11-25 21:59:14 +00:00
|
|
|
_run_in_container grep -q '^MaxFileSize 30M$' /etc/clamav/clamd.conf
|
2022-10-14 07:48:28 +00:00
|
|
|
assert_success
|
|
|
|
}
|
|
|
|
|
2023-01-09 07:54:04 +00:00
|
|
|
@test "rejects virus" {
|
2023-01-21 23:05:28 +00:00
|
|
|
_run_in_container_bash "grep 'Blocked INFECTED' /var/log/mail/mail.log | grep '<virus@external.tld> -> <user1@localhost.localdomain>'"
|
2022-10-14 07:48:28 +00:00
|
|
|
assert_success
|
|
|
|
}
|