2022-11-26 11:37:58 +13:00
|
|
|
load "${REPOSITORY_ROOT}/test/helper/setup"
|
|
|
|
load "${REPOSITORY_ROOT}/test/helper/common"
|
2022-10-14 09:48:28 +02:00
|
|
|
|
2023-01-09 08:54:04 +01:00
|
|
|
BATS_TEST_NAME_PREFIX='[ClamAV] '
|
2023-01-03 18:58:09 +13:00
|
|
|
CONTAINER_NAME='dms-test_clamav'
|
2022-10-14 09:48:28 +02:00
|
|
|
|
|
|
|
function setup_file() {
|
2023-01-22 00:05:28 +01:00
|
|
|
_init_with_defaults
|
2022-11-26 10:59:14 +13: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-22 00:05:28 +01:00
|
|
|
_common_container_setup 'CUSTOM_SETUP_ARGUMENTS'
|
2022-10-14 09:48:28 +02:00
|
|
|
|
|
|
|
# wait for ClamAV to be fully setup or we will get errors on the log
|
2023-01-22 00:05:28 +01:00
|
|
|
_repeat_in_container_until_success_or_timeout 60 "${CONTAINER_NAME}" test -e /var/run/clamav/clamd.ctl
|
2022-10-14 09:48:28 +02:00
|
|
|
|
2023-01-22 00:05:28 +01:00
|
|
|
_wait_for_service postfix
|
|
|
|
_wait_for_smtp_port_in_container
|
2024-01-11 10:34:08 +01:00
|
|
|
_send_email --from 'virus@external.tld' --data 'amavis/virus.txt'
|
2023-01-22 00:05:28 +01:00
|
|
|
_wait_for_empty_mail_queue_in_container
|
2022-10-14 09:48:28 +02:00
|
|
|
}
|
|
|
|
|
2022-11-26 10:59:14 +13:00
|
|
|
function teardown_file() { _default_teardown ; }
|
2022-10-14 09:48:28 +02:00
|
|
|
|
2024-01-03 01:17:54 +01:00
|
|
|
@test 'log files exist at /var/log/mail directory' {
|
2024-01-06 17:07:00 +01:00
|
|
|
_run_in_container_bash "ls -1 /var/log/mail/ | grep -c -E 'clamav|freshclam|mail.log'"
|
2022-10-14 09:48:28 +02:00
|
|
|
assert_success
|
|
|
|
assert_output 3
|
|
|
|
}
|
|
|
|
|
2024-01-03 01:17:54 +01:00
|
|
|
@test 'should be identified by Amavis' {
|
2024-01-24 23:06:05 +01:00
|
|
|
_service_log_should_contain_string 'mail' 'Found secondary av scanner ClamAV-clamscan'
|
2022-10-14 09:48:28 +02:00
|
|
|
}
|
|
|
|
|
2024-01-03 01:17:54 +01:00
|
|
|
@test 'freshclam cron is enabled' {
|
2023-01-22 00:05:28 +01:00
|
|
|
_run_in_container_bash "grep '/usr/bin/freshclam' -r /etc/cron.d"
|
2022-10-14 09:48:28 +02:00
|
|
|
assert_success
|
|
|
|
}
|
|
|
|
|
2024-01-03 01:17:54 +01:00
|
|
|
@test 'env CLAMAV_MESSAGE_SIZE_LIMIT is set correctly' {
|
2022-11-26 10:59:14 +13:00
|
|
|
_run_in_container grep -q '^MaxFileSize 30M$' /etc/clamav/clamd.conf
|
2022-10-14 09:48:28 +02:00
|
|
|
assert_success
|
|
|
|
}
|
|
|
|
|
2024-01-03 01:17:54 +01:00
|
|
|
@test 'rejects virus' {
|
2024-01-24 23:06:05 +01:00
|
|
|
_service_log_should_contain_string 'mail' 'Blocked INFECTED'
|
|
|
|
assert_output --partial '<virus@external.tld> -> <user1@localhost.localdomain>'
|
2022-10-14 09:48:28 +02:00
|
|
|
}
|