tests: improve _send_email (#3105)

This commit is contained in:
Georg Lauterbach 2023-02-24 10:44:18 +01:00 committed by GitHub
parent 199e3c7721
commit ae05e6a7c3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
19 changed files with 88 additions and 93 deletions

View file

@ -26,9 +26,9 @@ function setup_file() {
_wait_for_smtp_port_in_container
# Single mail sent from 'spam@spam.com' that is handled by User (relocate) and Global (copy) sieves for user1:
_send_email 'sieve-spam-folder'
_send_email 'email-templates/sieve-spam-folder'
# Mail for user2 triggers the sieve-pipe:
_send_email 'sieve-pipe'
_send_email 'email-templates/sieve-pipe'
_wait_for_empty_mail_queue_in_container
}

View file

@ -26,7 +26,7 @@ function teardown() { _default_teardown ; }
_common_container_setup 'CUSTOM_SETUP_ARGUMENTS'
_wait_for_smtp_port_in_container
_send_email 'existing-user1'
_send_email 'email-templates/existing-user1'
_wait_for_empty_mail_queue_in_container
# Mail received should be stored as `u.1` (one file per message)
@ -47,7 +47,7 @@ function teardown() { _default_teardown ; }
_common_container_setup 'CUSTOM_SETUP_ARGUMENTS'
_wait_for_smtp_port_in_container
_send_email 'existing-user1'
_send_email 'email-templates/existing-user1'
_wait_for_empty_mail_queue_in_container
# Mail received should be stored in `m.1` (1 or more messages)

View file

@ -14,7 +14,7 @@ function setup_file() {
function teardown_file() { _default_teardown ; }
@test 'normal delivery works' {
_send_email 'existing-user1'
_send_email 'email-templates/existing-user1'
_count_files_in_directory_in_container /var/mail/localhost.localdomain/user1/new 1
}
@ -26,8 +26,7 @@ function teardown_file() { _default_teardown ; }
}
@test "(IMAP) special-use folders should be created when necessary" {
_run_in_container_bash "nc -w 8 0.0.0.0 143 < /tmp/docker-mailserver-test/nc_templates/imap_special_use_folders.txt"
assert_success
_send_email 'nc_templates/imap_special_use_folders' '-w 8 0.0.0.0 143'
assert_output --partial 'Drafts'
assert_output --partial 'Junk'
assert_output --partial 'Trash'

View file

@ -26,7 +26,9 @@ function setup_file() {
_common_container_setup 'CUSTOM_SETUP_ARGUMENTS'
}
function teardown_file() { _default_teardown ; }
function teardown_file() {
docker rm -f "${CONTAINER1_NAME}" "${CONTAINER2_NAME}"
}
@test '(Amavis enabled) configuration should be correct' {
export CONTAINER_NAME=${CONTAINER1_NAME}

View file

@ -25,7 +25,7 @@ function setup_file() {
_wait_for_service postfix
_wait_for_smtp_port_in_container
_send_email 'amavis-virus'
_send_email 'email-templates/amavis-virus'
_wait_for_empty_mail_queue_in_container
}

View file

@ -17,7 +17,7 @@ function setup_file() {
_common_container_setup 'CUSTOM_SETUP_ARGUMENTS'
_wait_for_smtp_port_in_container
_send_email 'existing-user1'
_send_email 'email-templates/existing-user1'
_wait_for_empty_mail_queue_in_container
}

View file

@ -74,8 +74,8 @@ function teardown_file() {
@test "ban ip on multiple failed login" {
CONTAINER1_IP=$(_get_container_ip "${CONTAINER1_NAME}")
# Trigger a ban by failing to login twice:
_run_in_container_explicit "${CONTAINER2_NAME}" bash -c "nc ${CONTAINER1_IP} 465 < /tmp/docker-mailserver-test/auth/smtp-auth-login-wrong.txt"
_run_in_container_explicit "${CONTAINER2_NAME}" bash -c "nc ${CONTAINER1_IP} 465 < /tmp/docker-mailserver-test/auth/smtp-auth-login-wrong.txt"
CONTAINER_NAME=${CONTAINER2_NAME} _send_email 'auth/smtp-auth-login-wrong' "${CONTAINER1_IP} 465"
CONTAINER_NAME=${CONTAINER2_NAME} _send_email 'auth/smtp-auth-login-wrong' "${CONTAINER1_IP} 465"
# Checking that CONTAINER2_IP is banned in "${CONTAINER1_NAME}"
CONTAINER2_IP=$(_get_container_ip "${CONTAINER2_NAME}")

View file

@ -37,9 +37,8 @@ function teardown_file() {
docker rm -f "${CONTAINER1_NAME}" "${CONTAINER2_NAME}"
}
@test "should fail send when talking out of turn" {
_run_in_container_explicit "${CONTAINER2_NAME}" bash -c "nc ${CONTAINER1_IP} 25 < /tmp/docker-mailserver-test/email-templates/postscreen.txt"
assert_success
@test 'should fail send when talking out of turn' {
CONTAINER_NAME=${CONTAINER2_NAME} _send_email 'email-templates/postscreen' "${CONTAINER1_IP} 25"
assert_output --partial 'Protocol error'
# Expected postscreen log entry:
@ -62,7 +61,7 @@ function teardown_file() {
}
# When postscreen is active, it prevents the usual method of piping a file through nc:
# (Won't work: _run_in_container_explicit "${CLIENT_CONTAINER_NAME}" bash -c "nc ${TARGET_CONTAINER_IP} 25 < ${SMTP_TEMPLATE}")
# (Won't work: CONTAINER_NAME=${CLIENT_CONTAINER_NAME} _send_email "${SMTP_TEMPLATE}" "${TARGET_CONTAINER_IP} 25")
# The below workaround respects `postscreen_greet_wait` time (default 6 sec), talking to the mail-server in turn:
# https://www.postfix.org/postconf.5.html#postscreen_greet_wait
function _should_wait_turn_speaking_smtp() {

View file

@ -31,9 +31,9 @@ function setup_file() {
# We will send 3 emails: the first one should pass just fine; the second one should
# be rejected due to spam; the third one should be rejected due to a virus.
export MAIL_ID1=$(_send_mail_and_get_id 'existing-user1')
export MAIL_ID2=$(_send_mail_and_get_id 'rspamd-spam')
export MAIL_ID3=$(_send_mail_and_get_id 'rspamd-virus')
export MAIL_ID1=$(_send_email_and_get_id 'email-templates/existing-user1')
export MAIL_ID2=$(_send_email_and_get_id 'email-templates/rspamd-spam')
export MAIL_ID3=$(_send_email_and_get_id 'email-templates/rspamd-virus')
# add a nested option to a module
_exec_in_container_bash "echo -e 'complicated {\n anOption = someValue;\n}' >/etc/rspamd/override.d/testmodule_complicated.conf"

View file

@ -72,7 +72,7 @@ function teardown() { _default_teardown ; }
function _should_send_spam_message() {
_wait_for_smtp_port_in_container
_wait_for_tcp_port_in_container 10024 # port 10024 is for Amavis
_send_email 'amavis-spam'
_send_email 'email-templates/amavis-spam'
}
function _should_be_received_by_amavis() {

View file

@ -206,7 +206,7 @@ function _should_have_correct_mail_headers() {
# (eg: OVERRIDE_HOSTNAME or `--hostname mail --domainname example.test`)
local EXPECTED_HOSTNAME=${3:-${EXPECTED_FQDN}}
_send_email 'existing-user1'
_send_email 'email-templates/existing-user1'
_wait_for_empty_mail_queue_in_container
_count_files_in_directory_in_container '/var/mail/localhost.localdomain/user1/new/' '1'

View file

@ -38,7 +38,7 @@ function teardown_file() { _default_teardown ; }
@test "delivers mail to existing account" {
_wait_for_smtp_port_in_container
_send_email 'existing-user1' # send a test email
_send_email 'email-templates/existing-user1' # send a test email
# Verify delivery was successful, log line should look similar to:
# postfix/lmtp[1274]: 0EA424ABE7D9: to=<user1@localhost.localdomain>, relay=127.0.0.1[127.0.0.1]:24, delay=0.13, delays=0.07/0.01/0.01/0.05, dsn=2.0.0, status=sent (250 2.0.0 <user1@localhost.localdomain> ixPpB+Zvv2P7BAAAUi6ngw Saved)

View file

@ -55,40 +55,41 @@ function setup_file() {
_wait_for_tcp_port_in_container 10024
_wait_for_smtp_port_in_container_to_respond
# see https://github.com/docker-mailserver/docker-mailserver/pull/3105#issuecomment-1441055103
# Amavis may still not be ready to receive mail, sleep a little to avoid connection failures:
sleep 1
sleep 5
### Send mail to queue for delivery ###
# TODO: Move to clamav tests (For use when ClamAV is enabled):
# _repeat_in_container_until_success_or_timeout 60 "${CONTAINER_NAME}" test -e /var/run/clamav/clamd.ctl
# _run_in_container_bash "nc 0.0.0.0 25 < /tmp/docker-mailserver-test/email-templates/amavis-virus.txt"
# _send_email 'email-templates/amavis-virus'
# Required for 'delivers mail to existing alias':
_send_email 'existing-alias-external'
_send_email 'email-templates/existing-alias-external'
# Required for 'delivers mail to existing alias with recipient delimiter':
_send_email 'existing-alias-recipient-delimiter'
_send_email 'email-templates/existing-alias-recipient-delimiter'
# Required for 'delivers mail to existing catchall':
_send_email 'existing-catchall-local'
_send_email 'email-templates/existing-catchall-local'
# Required for 'delivers mail to regexp alias':
_send_email 'existing-regexp-alias-local'
_send_email 'email-templates/existing-regexp-alias-local'
# Required for 'rejects mail to unknown user':
_send_email 'non-existing-user'
_send_email 'email-templates/non-existing-user'
# Required for 'redirects mail to external aliases':
_send_email 'existing-regexp-alias-external'
_send_email 'existing-alias-local'
_send_email 'email-templates/existing-regexp-alias-external'
_send_email 'email-templates/existing-alias-local'
# Required for 'rejects spam':
_send_email 'amavis-spam'
_send_email 'email-templates/amavis-spam'
# Required for 'delivers mail to existing account':
_send_email 'existing-user1'
_send_email 'existing-user2'
_send_email 'existing-user3'
_send_email 'existing-added'
_send_email 'existing-user-and-cc-local-alias'
_send_email 'sieve-spam-folder'
_send_email 'sieve-pipe'
_send_email 'email-templates/existing-user1'
_send_email 'email-templates/existing-user2'
_send_email 'email-templates/existing-user3'
_send_email 'email-templates/existing-added'
_send_email 'email-templates/existing-user-and-cc-local-alias'
_send_email 'email-templates/sieve-spam-folder'
_send_email 'email-templates/sieve-pipe'
_run_in_container_bash 'sendmail root < /tmp/docker-mailserver-test/email-templates/root-email.txt'
}
@ -102,50 +103,43 @@ function setup_file() {
}
@test "should successfully authenticate with good password (plain)" {
_run_in_container_bash 'nc -w 5 0.0.0.0 465 < /tmp/docker-mailserver-test/auth/smtp-auth-plain.txt'
assert_success
_send_email 'auth/smtp-auth-plain' '-w 5 0.0.0.0 465'
assert_output --partial 'Authentication successful'
}
@test "should fail to authenticate with wrong password (plain)" {
_run_in_container_bash 'nc -w 20 0.0.0.0 465 < /tmp/docker-mailserver-test/auth/smtp-auth-plain-wrong.txt'
_send_email 'auth/smtp-auth-plain-wrong' '-w 20 0.0.0.0 465'
assert_output --partial 'authentication failed'
assert_success
}
@test "should successfully authenticate with good password (login)" {
_run_in_container_bash 'nc -w 5 0.0.0.0 465 < /tmp/docker-mailserver-test/auth/smtp-auth-login.txt'
assert_success
_send_email 'auth/smtp-auth-login' '-w 5 0.0.0.0 465'
assert_output --partial 'Authentication successful'
}
@test "should fail to authenticate with wrong password (login)" {
_run_in_container_bash 'nc -w 20 0.0.0.0 465 < /tmp/docker-mailserver-test/auth/smtp-auth-login-wrong.txt'
_send_email 'auth/smtp-auth-login-wrong' '-w 20 0.0.0.0 465'
assert_output --partial 'authentication failed'
assert_success
}
@test "[user: 'added'] should successfully authenticate with good password (plain)" {
_run_in_container_bash 'nc -w 5 0.0.0.0 465 < /tmp/docker-mailserver-test/auth/added-smtp-auth-plain.txt'
assert_success
_send_email 'auth/added-smtp-auth-plain' '-w 5 0.0.0.0 465'
assert_output --partial 'Authentication successful'
}
@test "[user: 'added'] should fail to authenticate with wrong password (plain)" {
_run_in_container_bash 'nc -w 20 0.0.0.0 465 < /tmp/docker-mailserver-test/auth/added-smtp-auth-plain-wrong.txt'
assert_success
_send_email 'auth/added-smtp-auth-plain-wrong' '-w 20 0.0.0.0 465'
assert_output --partial 'authentication failed'
}
@test "[user: 'added'] should successfully authenticate with good password (login)" {
_run_in_container_bash 'nc -w 5 0.0.0.0 465 < /tmp/docker-mailserver-test/auth/added-smtp-auth-login.txt'
_send_email 'auth/added-smtp-auth-login' '-w 5 0.0.0.0 465'
assert_success
assert_output --partial 'Authentication successful'
}
@test "[user: 'added'] should fail to authenticate with wrong password (login)" {
_run_in_container_bash 'nc -w 20 0.0.0.0 465 < /tmp/docker-mailserver-test/auth/added-smtp-auth-login-wrong.txt'
assert_success
_send_email 'auth/added-smtp-auth-login-wrong' '-w 20 0.0.0.0 465'
assert_output --partial 'authentication failed'
}
@ -264,8 +258,7 @@ function setup_file() {
# Dovecot does not support SMTPUTF8, so while we can send we cannot receive
# Better disable SMTPUTF8 support entirely if we can't handle it correctly
@test "not advertising smtputf8" {
_run_in_container_bash 'nc 0.0.0.0 25 < /tmp/docker-mailserver-test/email-templates/smtp-ehlo.txt'
assert_success
_send_email 'email-templates/smtp-ehlo'
refute_output --partial 'SMTPUTF8'
}

View file

@ -32,7 +32,7 @@ function teardown_file() { _default_teardown ; }
assert_success
# it looks as if someone tries to send mail to another domain outside of DMS
_send_email 'smtp-only'
_send_email 'email-templates/smtp-only'
_wait_for_empty_mail_queue_in_container
# this seemingly succeeds, but looking at the logs, it doesn't