use new filters in tests

This commit is contained in:
georglauterbach 2024-01-16 20:50:55 +01:00
parent 51a3b3f5f3
commit 6503f24b61
No known key found for this signature in database
GPG key ID: F367F7C43C118578
8 changed files with 51 additions and 82 deletions

View file

@ -38,8 +38,7 @@ function teardown_file() { _default_teardown ; }
} }
@test 'should be identified by Amavis' { @test 'should be identified by Amavis' {
_run_in_container grep -i 'Found secondary av scanner ClamAV-clamscan' /var/log/mail/mail.log _service_log_should_contain_string 'mail' 'Found secondary av scanner ClamAV-clamscan'
assert_success
} }
@test 'freshclam cron is enabled' { @test 'freshclam cron is enabled' {
@ -53,6 +52,6 @@ function teardown_file() { _default_teardown ; }
} }
@test 'rejects virus' { @test 'rejects virus' {
_run_in_container_bash "grep 'Blocked INFECTED' /var/log/mail/mail.log | grep '<virus@external.tld> -> <user1@localhost.localdomain>'" _service_log_should_contain_string 'mail' 'Blocked INFECTED'
assert_success assert_output --partial '<virus@external.tld> -> <user1@localhost.localdomain>'
} }

View file

@ -25,16 +25,14 @@ function setup_file() {
function teardown_file() { _default_teardown ; } function teardown_file() { _default_teardown ; }
@test "ClamAV - Amavis integration should not be active" { @test "ClamAV - Amavis integration should not be active" {
_run_in_container grep -i 'Found secondary av scanner ClamAV-clamscan' /var/log/mail/mail.log _service_log_should_not_contain_string 'mail' 'Found secondary av scanner ClamAV-clamscan'
assert_failure
} }
@test "SA - Amavis integration should not be active" { @test "SA - Amavis integration should not be active" {
_run_in_container_bash "grep -i 'ANTI-SPAM-SA code' /var/log/mail/mail.log | grep 'NOT loaded'" _service_log_should_contain_string 'mail' 'ANTI-SPAM-SA code'
assert_success assert_output --partial 'NOT loaded'
} }
@test "SA - should not have been called" { @test "SA - should not have been called" {
_run_in_container grep -i 'connect to /var/run/clamav/clamd.ctl failed' /var/log/mail/mail.log _service_log_should_not_contain_string 'mail' 'connect to /var/run/clamav/clamd.ctl failed'
assert_failure
} }

View file

@ -272,10 +272,10 @@ function teardown_file() { _default_teardown ; }
_nc_wrapper 'nc/rspamd_imap_move_to_junk.txt' '0.0.0.0 143' _nc_wrapper 'nc/rspamd_imap_move_to_junk.txt' '0.0.0.0 143'
sleep 1 # wait for the transaction to finish sleep 1 # wait for the transaction to finish
_run_in_container cat /var/log/mail/mail.log _service_log_should_contain_string 'mail' 'imapsieve: Matched static mailbox rule \[1\]'
assert_success _service_log_should_not_contain_string 'mail' 'imapsieve: Matched static mailbox rule \[2\]'
assert_output --partial 'imapsieve: Matched static mailbox rule [1]'
refute_output --partial 'imapsieve: Matched static mailbox rule [2]' _filter_service_log 'mail' '.'
for LINE in "${LEARN_SPAM_LINES[@]}"; do for LINE in "${LEARN_SPAM_LINES[@]}"; do
assert_output --partial "${LINE}" assert_output --partial "${LINE}"
done done
@ -286,9 +286,9 @@ function teardown_file() { _default_teardown ; }
_nc_wrapper 'nc/rspamd_imap_move_to_inbox.txt' '0.0.0.0 143' _nc_wrapper 'nc/rspamd_imap_move_to_inbox.txt' '0.0.0.0 143'
sleep 1 # wait for the transaction to finish sleep 1 # wait for the transaction to finish
_run_in_container cat /var/log/mail/mail.log _service_log_should_contain_string 'mail' 'imapsieve: Matched static mailbox rule \[2\]'
assert_success
assert_output --partial 'imapsieve: Matched static mailbox rule [2]' _filter_service_log 'mail' '.'
for LINE in "${LEARN_HAM_LINES[@]}"; do for LINE in "${LEARN_HAM_LINES[@]}"; do
assert_output --partial "${LINE}" assert_output --partial "${LINE}"
done done

View file

@ -54,7 +54,7 @@ function teardown_file() {
_nc_wrapper 'emails/nc_raw/dsn/authenticated.txt' '0.0.0.0 587' _nc_wrapper 'emails/nc_raw/dsn/authenticated.txt' '0.0.0.0 587'
_wait_for_empty_mail_queue_in_container _wait_for_empty_mail_queue_in_container
_run_in_container grep "${LOG_DSN}" /var/log/mail/mail.log _filter_service_log 'mail' "${LOG_DSN}"
_should_output_number_of_lines 3 _should_output_number_of_lines 3
} }
@ -70,15 +70,14 @@ function teardown_file() {
# #
# Although external requests are discarded, anyone who has requested a DSN # Although external requests are discarded, anyone who has requested a DSN
# will still receive it, but it will come from the sending mail server, not this one. # will still receive it, but it will come from the sending mail server, not this one.
_run_in_container grep "${LOG_DSN}" /var/log/mail/mail.log _service_log_should_not_contain_string 'mail' "${LOG_DSN}"
assert_failure
# These ports are excluded via master.cf. # These ports are excluded via master.cf.
_nc_wrapper 'emails/nc_raw/dsn/authenticated.txt' '0.0.0.0 465' _nc_wrapper 'emails/nc_raw/dsn/authenticated.txt' '0.0.0.0 465'
_nc_wrapper 'emails/nc_raw/dsn/authenticated.txt' '0.0.0.0 587' _nc_wrapper 'emails/nc_raw/dsn/authenticated.txt' '0.0.0.0 587'
_wait_for_empty_mail_queue_in_container _wait_for_empty_mail_queue_in_container
_run_in_container grep "${LOG_DSN}" /var/log/mail/mail.log _service_log_should_contain_string 'mail' "${LOG_DSN}"
_should_output_number_of_lines 2 _should_output_number_of_lines 2
} }
@ -92,6 +91,5 @@ function teardown_file() {
# DSN requests are rejected regardless of origin. # DSN requests are rejected regardless of origin.
# This is usually a bad idea, as you won't get them either. # This is usually a bad idea, as you won't get them either.
_run_in_container grep "${LOG_DSN}" /var/log/mail/mail.log _service_log_should_not_contain_string 'mail' "${LOG_DSN}"
assert_failure
} }

View file

@ -174,33 +174,28 @@ function _successful() {
} }
@test "delivers mail to existing alias" { @test "delivers mail to existing alias" {
_run_in_container grep 'to=<user1@localhost.localdomain>, orig_to=<alias1@localhost.localdomain>' /var/log/mail/mail.log _service_log_should_contain_string 'mail' 'to=<user1@localhost.localdomain>, orig_to=<alias1@localhost.localdomain>'
assert_success
assert_output --partial 'status=sent' assert_output --partial 'status=sent'
_should_output_number_of_lines 1 _should_output_number_of_lines 1
} }
@test "delivers mail to existing alias with recipient delimiter" { @test "delivers mail to existing alias with recipient delimiter" {
_run_in_container grep 'to=<user1~test@localhost.localdomain>, orig_to=<alias1~test@localhost.localdomain>' /var/log/mail/mail.log _service_log_should_contain_string 'mail' 'to=<user1~test@localhost.localdomain>, orig_to=<alias1~test@localhost.localdomain>'
assert_success
assert_output --partial 'status=sent' assert_output --partial 'status=sent'
_should_output_number_of_lines 1 _should_output_number_of_lines 1
_run_in_container grep 'to=<user1~test@localhost.localdomain>' /var/log/mail/mail.log _service_log_should_contain_string 'mail' 'to=<user1~test@localhost.localdomain>'
assert_success
refute_output --partial 'status=bounced' refute_output --partial 'status=bounced'
} }
@test "delivers mail to existing catchall" { @test "delivers mail to existing catchall" {
_run_in_container grep 'to=<user1@localhost.localdomain>, orig_to=<wildcard@localdomain2.com>' /var/log/mail/mail.log _service_log_should_contain_string 'mail' 'to=<user1@localhost.localdomain>, orig_to=<wildcard@localdomain2.com>'
assert_success
assert_output --partial 'status=sent' assert_output --partial 'status=sent'
_should_output_number_of_lines 1 _should_output_number_of_lines 1
} }
@test "delivers mail to regexp alias" { @test "delivers mail to regexp alias" {
_run_in_container grep 'to=<user1@localhost.localdomain>, orig_to=<test123@localhost.localdomain>' /var/log/mail/mail.log _service_log_should_contain_string 'mail' 'to=<user1@localhost.localdomain>, orig_to=<test123@localhost.localdomain>'
assert_success
assert_output --partial 'status=sent' assert_output --partial 'status=sent'
_should_output_number_of_lines 1 _should_output_number_of_lines 1
} }
@ -227,23 +222,20 @@ function _successful() {
} }
@test "rejects mail to unknown user" { @test "rejects mail to unknown user" {
_run_in_container grep '<nouser@localhost.localdomain>: Recipient address rejected: User unknown in virtual mailbox table' /var/log/mail/mail.log _service_log_should_contain_string 'mail' '<nouser@localhost.localdomain>: Recipient address rejected: User unknown in virtual mailbox table'
assert_success
_should_output_number_of_lines 1 _should_output_number_of_lines 1
} }
@test "redirects mail to external aliases" { @test "redirects mail to external aliases" {
_run_in_container_bash "grep 'Passed CLEAN {RelayedInbound}' /var/log/mail/mail.log | grep -- '-> <external1@otherdomain.tld>'" _service_log_should_contain_string 'mail' 'Passed CLEAN {RelayedInbound}'
assert_success run bash -c "grep '<user@external.tld> -> <external1@otherdomain.tld>' <<< '${output}'"
assert_output --partial '<user@external.tld> -> <external1@otherdomain.tld>'
_should_output_number_of_lines 2 _should_output_number_of_lines 2
# assert_output --partial 'external.tld=user@example.test> -> <external1@otherdomain.tld>' # assert_output --partial 'external.tld=user@example.test> -> <external1@otherdomain.tld>'
} }
# TODO: Add a test covering case SPAMASSASSIN_SPAM_TO_INBOX=1 (default) # TODO: Add a test covering case SPAMASSASSIN_SPAM_TO_INBOX=1 (default)
@test "rejects spam" { @test "rejects spam" {
_run_in_container grep 'Blocked SPAM {NoBounceInbound,Quarantined}' /var/log/mail/mail.log _service_log_should_contain_string 'mail' 'Blocked SPAM {NoBounceInbound,Quarantined}'
assert_success
assert_output --partial '<spam@external.tld> -> <user1@localhost.localdomain>' assert_output --partial '<spam@external.tld> -> <user1@localhost.localdomain>'
_should_output_number_of_lines 1 _should_output_number_of_lines 1

View file

@ -33,11 +33,9 @@ function teardown_file() { _default_teardown ; }
assert_success assert_success
} }
@test '/var/log/mail/mail.log is error-free' { @test 'Mail log is error-free' {
_run_in_container grep 'non-null host address bits in' /var/log/mail/mail.log _service_log_should_not_contain_string 'mail' 'non-null host address bits in'
assert_failure _service_log_should_not_contain_string 'mail' ': error:'
_run_in_container grep ': error:' /var/log/mail/mail.log
assert_failure
} }
@test '(Manage Sieve) disabled per default' { @test '(Manage Sieve) disabled per default' {

View file

@ -182,23 +182,15 @@ function teardown_file() { _default_teardown ; }
assert_success assert_success
} }
@test "system: /var/log/mail/mail.log is error free" { @test "system: Mail log is error free" {
_run_in_container grep 'non-null host address bits in' /var/log/mail/mail.log _service_log_should_not_contain_string 'mail' 'non-null host address bits in'
assert_failure _service_log_should_not_contain_string 'mail' 'mail system configuration error'
_run_in_container grep 'mail system configuration error' /var/log/mail/mail.log _service_log_should_not_contain_string 'mail' ': error:'
assert_failure _service_log_should_not_contain_string 'mail' 'is not writable'
_run_in_container grep ': error:' /var/log/mail/mail.log _service_log_should_not_contain_string 'mail' 'permission denied'
assert_failure _service_log_should_not_contain_string 'mail' '\(!\)connect'
_run_in_container grep -i 'is not writable' /var/log/mail/mail.log _service_log_should_not_contain_string 'mail' 'using backwards-compatible default setting'
assert_failure _service_log_should_not_contain_string 'mail' 'connect to 127.0.0.1:10023: Connection refused'
_run_in_container grep -i 'permission denied' /var/log/mail/mail.log
assert_failure
_run_in_container grep -i '(!)connect' /var/log/mail/mail.log
assert_failure
_run_in_container grep -i 'using backwards-compatible default setting' /var/log/mail/mail.log
assert_failure
_run_in_container grep -i 'connect to 127.0.0.1:10023: Connection refused' /var/log/mail/mail.log
assert_failure
} }
@test "system: /var/log/auth.log is error free" { @test "system: /var/log/auth.log is error free" {
@ -212,7 +204,8 @@ function teardown_file() { _default_teardown ; }
} }
@test "system: amavis decoders installed and available" { @test "system: amavis decoders installed and available" {
_run_in_container_bash "grep -E '.*(Internal decoder|Found decoder) for\s+\..*' /var/log/mail/mail.log*|grep -Eo '(mail|Z|gz|bz2|xz|lzma|lrz|lzo|lz4|rpm|cpio|tar|deb|rar|arj|arc|zoo|doc|cab|tnef|zip|kmz|7z|jar|swf|lha|iso|exe)' | sort | uniq" _service_log_should_contain_string 'mail' '.*(Internal decoder|Found decoder) for\s+\..*'
run bash -c "grep -Eo '(mail|Z|gz|bz2|xz|lzma|lrz|lzo|lz4|rpm|cpio|tar|deb|rar|arj|arc|zoo|doc|cab|tnef|zip|kmz|7z|jar|swf|lha|iso|exe)' <<< '${output}' | sort | uniq"
assert_success assert_success
# Support for doc and zoo removed in buster # Support for doc and zoo removed in buster
cat <<'EOF' | assert_output cat <<'EOF' | assert_output

View file

@ -24,8 +24,7 @@ function teardown_file() { _default_teardown ; }
_wait_for_empty_mail_queue_in_container _wait_for_empty_mail_queue_in_container
# Should be successfully sent (received) by Postfix: # Should be successfully sent (received) by Postfix:
_run_in_container grep 'to=<user1@localhost.localdomain>' /var/log/mail/mail.log _service_log_should_contain_string 'mail' 'to=<user1@localhost.localdomain>'
assert_success
assert_output --partial 'status=sent' assert_output --partial 'status=sent'
_should_output_number_of_lines 1 _should_output_number_of_lines 1
@ -41,35 +40,27 @@ function teardown_file() { _default_teardown ; }
# This test case is shared with tests.bats, but provides context on errors + some minor edits # This test case is shared with tests.bats, but provides context on errors + some minor edits
# TODO: Could improve in future with keywords from https://github.com/docker-mailserver/docker-mailserver/pull/3550#issuecomment-1738509088 # TODO: Could improve in future with keywords from https://github.com/docker-mailserver/docker-mailserver/pull/3550#issuecomment-1738509088
# Potentially via a helper that allows an optional fixed number of errors to be present if they were intentional # Potentially via a helper that allows an optional fixed number of errors to be present if they were intentional
@test '/var/log/mail/mail.log is error free' { @test 'Mail log is error free' {
# Postfix: https://serverfault.com/questions/934703/postfix-451-4-3-0-temporary-lookup-failure # Postfix: https://serverfault.com/questions/934703/postfix-451-4-3-0-temporary-lookup-failure
_run_in_container grep 'non-null host address bits in' /var/log/mail/mail.log _service_log_should_not_contain_string 'mail' 'non-null host address bits in'
assert_failure
# Postfix delivery failure: https://github.com/docker-mailserver/docker-mailserver/issues/230 # Postfix delivery failure: https://github.com/docker-mailserver/docker-mailserver/issues/230
_run_in_container grep 'mail system configuration error' /var/log/mail/mail.log _service_log_should_not_contain_string 'mail' 'mail system configuration error'
assert_failure
# Unknown error source: https://github.com/docker-mailserver/docker-mailserver/pull/85 # Unknown error source: https://github.com/docker-mailserver/docker-mailserver/pull/85
_run_in_container grep -i ': error:' /var/log/mail/mail.log _service_log_should_not_contain_string 'mail' ': error:'
assert_failure
# Unknown error source: https://github.com/docker-mailserver/docker-mailserver/pull/320 # Unknown error source: https://github.com/docker-mailserver/docker-mailserver/pull/320
_run_in_container grep -i 'not writable' /var/log/mail/mail.log _service_log_should_not_contain_string 'mail' 'not writable'
assert_failure _service_log_should_not_contain_string 'mail' 'permission denied'
_run_in_container grep -i 'permission denied' /var/log/mail/mail.log
assert_failure
# Amavis: https://forum.howtoforge.com/threads/postfix-smtp-error-caused-by-clamav-cant-connect-to-a-unix-socket-var-run-clamav-clamd-ctl.81002/ # Amavis: https://forum.howtoforge.com/threads/postfix-smtp-error-caused-by-clamav-cant-connect-to-a-unix-socket-var-run-clamav-clamd-ctl.81002/
_run_in_container grep -i '(!)connect' /var/log/mail/mail.log _service_log_should_not_contain_string 'mail' '\(!\)connect'
assert_failure
# Postfix: https://github.com/docker-mailserver/docker-mailserver/pull/2597 # Postfix: https://github.com/docker-mailserver/docker-mailserver/pull/2597
_run_in_container grep -i 'using backwards-compatible default setting' /var/log/mail/mail.log _service_log_should_not_contain_string 'mail' 'using backwards-compatible default setting'
assert_failure
# Postgrey: https://github.com/docker-mailserver/docker-mailserver/pull/612#discussion_r117635774 # Postgrey: https://github.com/docker-mailserver/docker-mailserver/pull/612#discussion_r117635774
_run_in_container grep -i 'connect to 127.0.0.1:10023: Connection refused' /var/log/mail/mail.log _service_log_should_not_contain_string 'mail' 'connect to 127.0.0.1:10023: Connection refused'
assert_failure
} }