add `--data <FILE>` instead of implictly using last argument
This commit is contained in:
parent
1a65775943
commit
74b7d9dc1a
|
@ -11,8 +11,10 @@
|
|||
# a custom email, create a file at `test/files/<TEST FILE>`,
|
||||
# and provide `<TEST FILE>` as an argument to this function.
|
||||
#
|
||||
# @param ${1} = template file (path) name without .txt suffix
|
||||
# @param ... = options that `swaks` accepts
|
||||
# Parameters include all options that one can supply to `swaks`
|
||||
# itself. What differs is the parameter `--data`: this functions
|
||||
# takes a file path without prefixes or the need to handle STDIN.
|
||||
#
|
||||
#
|
||||
# ## Attention
|
||||
#
|
||||
|
@ -30,24 +32,29 @@ function _send_email() {
|
|||
local TO='user1@localhost.localdomain'
|
||||
local SERVER='0.0.0.0'
|
||||
local PORT=25
|
||||
local MORE_SWAKS_OPTIONS=()
|
||||
local ADDITIONAL_SWAKS_OPTIONS=()
|
||||
local FINAL_SWAKS_OPTIONS=()
|
||||
|
||||
while [[ ${#} -gt 1 ]]; do
|
||||
while [[ ${#} -gt 0 ]]; do
|
||||
case "${1}" in
|
||||
( '--helo' ) HELO=${2:?--helo given but no argument} ; shift 2 ;;
|
||||
( '--from' ) FROM=${2:?--from given but no argument} ; shift 2 ;;
|
||||
( '--to' ) TO=${2:?--to given but no argument} ; shift 2 ;;
|
||||
( '--server' ) SERVER=${2:?--server given but no argument} ; shift 2 ;;
|
||||
( '--port' ) PORT=${2:?--port given but no argument} ; shift 2 ;;
|
||||
( * ) MORE_SWAKS_OPTIONS+=("${1}") ; shift 1 ;;
|
||||
( '--data' )
|
||||
local TEMPLATE_FILE="/tmp/docker-mailserver-test/emails/${2:?--data given but no argument provided}.txt"
|
||||
FINAL_SWAKS_OPTIONS+=('--data')
|
||||
FINAL_SWAKS_OPTIONS+=('-')
|
||||
FINAL_SWAKS_OPTIONS+=('<')
|
||||
FINAL_SWAKS_OPTIONS+=("${TEMPLATE_FILE}")
|
||||
shift 2
|
||||
;;
|
||||
( * ) ADDITIONAL_SWAKS_OPTIONS+=("${1}") ; shift 1 ;;
|
||||
esac
|
||||
done
|
||||
|
||||
local TEMPLATE_FILE="/tmp/docker-mailserver-test/emails/${1:?Must provide name of template file}.txt"
|
||||
|
||||
echo "CONTAINER: ${CONTAINER_NAME} | COMMAND: swaks --server ${SERVER} --port ${PORT} --helo ${HELO} --from ${FROM} --to ${TO} ${MORE_SWAKS_OPTIONS[*]} --data - < ${TEMPLATE_FILE}" >/tmp/log
|
||||
|
||||
_run_in_container_bash "swaks --server ${SERVER} --port ${PORT} --helo ${HELO} --from ${FROM} --to ${TO} ${MORE_SWAKS_OPTIONS[*]} --data - < ${TEMPLATE_FILE}"
|
||||
_run_in_container_bash "swaks --server ${SERVER} --port ${PORT} --ehlo ${EHLO} --from ${FROM} --to ${TO} ${ADDITIONAL_SWAKS_OPTIONS[*]} ${FINAL_SWAKS_OPTIONS[*]}"
|
||||
}
|
||||
|
||||
# Like `_send_email` with two major differences:
|
||||
|
|
|
@ -225,11 +225,11 @@ function teardown_file() { _default_teardown ; }
|
|||
sleep 10
|
||||
|
||||
# send some big emails
|
||||
_send_email --to 'quotauser@otherdomain.tld' 'quota-exceeded'
|
||||
_send_email --to 'quotauser@otherdomain.tld' --data 'quota-exceeded'
|
||||
assert_success
|
||||
_send_email --to 'quotauser@otherdomain.tld' 'quota-exceeded'
|
||||
_send_email --to 'quotauser@otherdomain.tld' --data 'quota-exceeded'
|
||||
assert_success
|
||||
_send_email --to 'quotauser@otherdomain.tld' 'quota-exceeded'
|
||||
_send_email --to 'quotauser@otherdomain.tld' --data 'quota-exceeded'
|
||||
assert_success
|
||||
# check for quota warn message existence
|
||||
run _repeat_until_success_or_timeout 20 _exec_in_container grep -R 'Subject: quota warning' /var/mail/otherdomain.tld/quotauser/new/
|
||||
|
|
|
@ -26,10 +26,10 @@ 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 --data 'sieve/spam-folder'
|
||||
assert_success
|
||||
# Mail for user2 triggers the sieve-pipe:
|
||||
_send_email --to 'user2@otherdomain.tld' 'sieve/pipe'
|
||||
_send_email --to 'user2@otherdomain.tld' --data 'sieve/pipe'
|
||||
assert_success
|
||||
|
||||
_wait_for_empty_mail_queue_in_container
|
||||
|
|
|
@ -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 --data 'existing/user1'
|
||||
assert_success
|
||||
_wait_for_empty_mail_queue_in_container
|
||||
|
||||
|
@ -48,7 +48,7 @@ function teardown() { _default_teardown ; }
|
|||
_common_container_setup 'CUSTOM_SETUP_ARGUMENTS'
|
||||
_wait_for_smtp_port_in_container
|
||||
|
||||
_send_email 'existing/user1'
|
||||
_send_email --data 'existing/user1'
|
||||
assert_success
|
||||
_wait_for_empty_mail_queue_in_container
|
||||
|
||||
|
|
|
@ -14,7 +14,7 @@ function setup_file() {
|
|||
function teardown_file() { _default_teardown ; }
|
||||
|
||||
@test 'normal delivery works' {
|
||||
_send_email 'existing/user1'
|
||||
_send_email --data 'existing/user1'
|
||||
assert_success
|
||||
_count_files_in_directory_in_container /var/mail/localhost.localdomain/user1/new 1
|
||||
}
|
||||
|
|
|
@ -25,7 +25,7 @@ function setup_file() {
|
|||
|
||||
_wait_for_service postfix
|
||||
_wait_for_smtp_port_in_container
|
||||
_send_email --from 'virus@external.tld' 'amavis/virus'
|
||||
_send_email --from 'virus@external.tld' --data 'amavis/virus'
|
||||
assert_success
|
||||
_wait_for_empty_mail_queue_in_container
|
||||
}
|
||||
|
|
|
@ -18,7 +18,7 @@ function setup_file() {
|
|||
_common_container_setup 'CUSTOM_SETUP_ARGUMENTS'
|
||||
_wait_for_smtp_port_in_container
|
||||
|
||||
_send_email 'existing/user1'
|
||||
_send_email --data 'existing/user1'
|
||||
assert_success
|
||||
_wait_for_empty_mail_queue_in_container
|
||||
}
|
||||
|
|
|
@ -51,7 +51,7 @@ function teardown_file() { _default_teardown ; }
|
|||
_reload_postfix
|
||||
|
||||
# Send test mail (it should fail to deliver):
|
||||
_send_email --from 'user@external.tld' 'postgrey'
|
||||
_send_email --from 'user@external.tld' --data 'postgrey'
|
||||
assert_failure
|
||||
assert_output --partial 'Recipient address rejected: Delayed by Postgrey'
|
||||
|
||||
|
@ -67,7 +67,7 @@ function teardown_file() { _default_teardown ; }
|
|||
# Wait until `$POSTGREY_DELAY` seconds pass before trying again:
|
||||
sleep 3
|
||||
# Retry delivering test mail (it should be trusted this time):
|
||||
_send_email --from 'user@external.tld' 'postgrey'
|
||||
_send_email --from 'user@external.tld' --data 'postgrey'
|
||||
assert_success
|
||||
|
||||
# Confirm postgrey permitted delivery (triplet is now trusted):
|
||||
|
|
|
@ -52,11 +52,11 @@ function teardown_file() {
|
|||
|
||||
@test "should successfully pass postscreen and get postfix greeting message (respecting postscreen_greet_wait time)" {
|
||||
# Send from mail client container (CONTAINER2_NAME) to DMS server container (CONTAINER1_NAME):
|
||||
CONTAINER_NAME=${CONTAINER2_NAME} _send_email --server "${CONTAINER1_IP}" 'postscreen'
|
||||
CONTAINER_NAME=${CONTAINER2_NAME} _send_email --server "${CONTAINER1_IP}" --data 'postscreen'
|
||||
assert_success
|
||||
|
||||
# TODO: Implement support for separate client and server containers:
|
||||
# local MAIL_ID=$(_send_email_and_get_id 'postscreen')
|
||||
# local MAIL_ID=$(_send_email_and_get_id --data 'postscreen')
|
||||
# _print_mail_log_for_id "${MAIL_ID}"
|
||||
# assert_output --partial "stored mail into mailbox 'INBOX'"
|
||||
|
||||
|
|
|
@ -45,10 +45,10 @@ 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_email_and_get_id --from 'rspamd-pass@example.test' 'rspamd/pass')
|
||||
export MAIL_ID2=$(_send_email_and_get_id --from 'rspamd-spam@example.test' 'rspamd/spam')
|
||||
export MAIL_ID3=$(_send_email_and_get_id --from 'rspamd-virus@example.test' 'rspamd/virus')
|
||||
export MAIL_ID4=$(_send_email_and_get_id --from 'rspamd-spam-header@example.test' 'rspamd/spam-header')
|
||||
export MAIL_ID1=$(_send_email_and_get_id --from 'rspamd-pass@example.test' --data 'rspamd/pass')
|
||||
export MAIL_ID2=$(_send_email_and_get_id --from 'rspamd-spam@example.test' --data 'rspamd/spam')
|
||||
export MAIL_ID3=$(_send_email_and_get_id --from 'rspamd-virus@example.test' --data 'rspamd/virus')
|
||||
export MAIL_ID4=$(_send_email_and_get_id --from 'rspamd-spam-header@example.test' --data 'rspamd/spam-header')
|
||||
|
||||
for ID in MAIL_ID{1,2,3,4}; do
|
||||
[[ -n ${!ID} ]] || { echo "${ID} is empty - aborting!" ; return 1 ; }
|
||||
|
|
|
@ -95,7 +95,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 --from 'spam@external.tld' 'amavis/spam'
|
||||
_send_email --from 'spam@external.tld' --data 'amavis/spam'
|
||||
}
|
||||
|
||||
function _should_be_received_by_amavis() {
|
||||
|
|
|
@ -207,7 +207,7 @@ function _should_have_correct_mail_headers() {
|
|||
# (eg: OVERRIDE_HOSTNAME or `--hostname mail --domainname example.test`)
|
||||
local EXPECTED_HOSTNAME=${3:-${EXPECTED_FQDN}}
|
||||
|
||||
_send_email --from 'user@external.tld' 'existing/user1'
|
||||
_send_email --from 'user@external.tld' --data 'existing/user1'
|
||||
_wait_for_empty_mail_queue_in_container
|
||||
_count_files_in_directory_in_container '/var/mail/localhost.localdomain/user1/new/' '1'
|
||||
|
||||
|
|
|
@ -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 --data '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)
|
||||
|
|
|
@ -29,7 +29,7 @@ function teardown_file() { _default_teardown ; }
|
|||
--port 587 -tls --auth LOGIN \
|
||||
--auth-user user1@localhost.localdomain \
|
||||
--auth-password mypassword \
|
||||
'privacy'
|
||||
--data 'privacy'
|
||||
assert_success
|
||||
|
||||
_run_until_success_or_timeout 120 _exec_in_container_bash '[[ -d /var/mail/localhost.localdomain/user1/new ]]'
|
||||
|
|
|
@ -63,33 +63,33 @@ function setup_file() {
|
|||
|
||||
# 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
|
||||
# _send_email --from 'virus@external.tld' 'amavis/virus'
|
||||
# _send_email --from 'virus@external.tld' --data 'amavis/virus'
|
||||
|
||||
# Required for 'delivers mail to existing alias':
|
||||
_send_email --to alias1@localhost.localdomain 'existing/alias-external'
|
||||
_send_email --to alias1@localhost.localdomain --data 'existing/alias-external'
|
||||
# Required for 'delivers mail to existing alias with recipient delimiter':
|
||||
_send_email --to alias1~test@localhost.localdomain 'existing/alias-recipient-delimiter'
|
||||
_send_email --to alias1~test@localhost.localdomain --data 'existing/alias-recipient-delimiter'
|
||||
# Required for 'delivers mail to existing catchall':
|
||||
_send_email --to wildcard@localdomain2.com 'existing/catchall-local'
|
||||
_send_email --to wildcard@localdomain2.com --data 'existing/catchall-local'
|
||||
# Required for 'delivers mail to regexp alias':
|
||||
_send_email --to test123@localhost.localdomain 'existing/regexp-alias-local'
|
||||
_send_email --to test123@localhost.localdomain --data 'existing/regexp-alias-local'
|
||||
|
||||
# Required for 'rejects mail to unknown user':
|
||||
_send_email --to nouser@localhost.localdomain 'non-existing-user'
|
||||
_send_email --to nouser@localhost.localdomain --data 'non-existing-user'
|
||||
# Required for 'redirects mail to external aliases':
|
||||
_send_email --to bounce-always@localhost.localdomain 'existing/regexp-alias-external'
|
||||
_send_email --to alias2@localhost.localdomain 'existing/alias-local'
|
||||
_send_email --to bounce-always@localhost.localdomain --data 'existing/regexp-alias-external'
|
||||
_send_email --to alias2@localhost.localdomain --data 'existing/alias-local'
|
||||
# Required for 'rejects spam':
|
||||
_send_email --from 'spam@external.tld' 'amavis/spam'
|
||||
_send_email --from 'spam@external.tld' --data 'amavis/spam'
|
||||
|
||||
# Required for 'delivers mail to existing account':
|
||||
_send_email 'existing/user1'
|
||||
_send_email --to user2@otherdomain.tld 'existing/user2'
|
||||
_send_email --to user3@localhost.localdomain 'existing/user3'
|
||||
_send_email --to added@localhost.localdomain 'existing/added'
|
||||
_send_email --to user1@localhost.localdomain 'existing/user-and-cc-local-alias'
|
||||
_send_email 'sieve/spam-folder'
|
||||
_send_email --to user2@otherdomain.tld 'sieve/pipe'
|
||||
_send_email --data 'existing/user1'
|
||||
_send_email --to user2@otherdomain.tld --data 'existing/user2'
|
||||
_send_email --to user3@localhost.localdomain --data 'existing/user3'
|
||||
_send_email --to added@localhost.localdomain --data 'existing/added'
|
||||
_send_email --to user1@localhost.localdomain --data 'existing/user-and-cc-local-alias'
|
||||
_send_email --data 'sieve/spam-folder'
|
||||
_send_email --to user2@otherdomain.tld --data 'sieve/pipe'
|
||||
_run_in_container_bash 'sendmail root < /tmp/docker-mailserver-test/emails/sendmail/root-email.txt'
|
||||
}
|
||||
|
||||
|
|
|
@ -40,7 +40,7 @@ function teardown_file() { _default_teardown ; }
|
|||
--to user@destination.test \
|
||||
--auth-user user@origin.test \
|
||||
--auth-password secret \
|
||||
'smtp-only'
|
||||
--data 'smtp-only'
|
||||
_wait_for_empty_mail_queue_in_container
|
||||
|
||||
# this seemingly succeeds, but looking at the logs, it doesn't
|
||||
|
|
|
@ -333,7 +333,7 @@ function teardown() {
|
|||
--auth-password secret \
|
||||
--helo mail \
|
||||
--from ldap@localhost.localdomain \
|
||||
'auth/ldap-smtp-auth-spoofed'
|
||||
--data 'auth/ldap-smtp-auth-spoofed'
|
||||
assert_output --partial 'Sender address rejected: not owned by user'
|
||||
}
|
||||
|
||||
|
@ -345,7 +345,7 @@ function teardown() {
|
|||
--helo mail \
|
||||
--from postmaster@localhost.localdomain \
|
||||
--to some.user@localhost.localdomain \
|
||||
'auth/ldap-smtp-auth-spoofed-alias'
|
||||
--data 'auth/ldap-smtp-auth-spoofed-alias'
|
||||
assert_output --partial 'End data with'
|
||||
}
|
||||
|
||||
|
@ -361,7 +361,7 @@ function teardown() {
|
|||
--helo mail \
|
||||
--from randomspoofedaddress@localhost.localdomain \
|
||||
--to some.user@localhost.localdomain \
|
||||
'auth/ldap-smtp-auth-spoofed-sender-with-filter-exception'
|
||||
--data 'auth/ldap-smtp-auth-spoofed-sender-with-filter-exception'
|
||||
assert_output --partial 'Sender address rejected: not owned by user'
|
||||
}
|
||||
|
||||
|
|
|
@ -297,7 +297,7 @@ EOF
|
|||
--auth-password mypassword \
|
||||
--helo mail \
|
||||
--from user2@localhost.localdomain \
|
||||
'auth/added-smtp-auth-spoofed'
|
||||
--data 'auth/added-smtp-auth-spoofed'
|
||||
assert_output --partial 'Sender address rejected: not owned by user'
|
||||
}
|
||||
|
||||
|
@ -313,7 +313,7 @@ EOF
|
|||
--auth-password mypassword \
|
||||
--helo mail \
|
||||
--from alias1@localhost.localdomain \
|
||||
'auth/added-smtp-auth-spoofed-alias'
|
||||
--data 'auth/added-smtp-auth-spoofed-alias'
|
||||
assert_success
|
||||
assert_output --partial 'End data with'
|
||||
}
|
||||
|
|
|
@ -20,7 +20,7 @@ function setup_file() {
|
|||
function teardown_file() { _default_teardown ; }
|
||||
|
||||
@test 'should successfully deliver mail' {
|
||||
_send_email 'existing/user1'
|
||||
_send_email --data 'existing/user1'
|
||||
_wait_for_empty_mail_queue_in_container
|
||||
|
||||
# Should be successfully sent (received) by Postfix:
|
||||
|
@ -72,4 +72,3 @@ function teardown_file() { _default_teardown ; }
|
|||
_run_in_container grep -i 'connect to 127.0.0.1:10023: Connection refused' /var/log/mail/mail.log
|
||||
assert_failure
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue