From 74b7d9dc1a60334e437f3ce46ee0781cb2a6a788 Mon Sep 17 00:00:00 2001 From: georglauterbach <44545919+georglauterbach@users.noreply.github.com> Date: Tue, 2 Jan 2024 00:15:44 +0100 Subject: [PATCH] add `--data ` instead of implictly using last argument --- test/helper/sending.bash | 27 ++++++++++------ .../parallel/set1/dovecot/dovecot_quotas.bats | 6 ++-- .../parallel/set1/dovecot/dovecot_sieve.bats | 4 +-- .../set1/dovecot/mailbox_format_dbox.bats | 4 +-- .../set1/dovecot/special_use_folders.bats | 2 +- .../parallel/set1/spam_virus/clamav.bats | 2 +- .../disabled_clamav_spamassassin.bats | 2 +- .../set1/spam_virus/postgrey_enabled.bats | 4 +-- .../parallel/set1/spam_virus/postscreen.bats | 4 +-- .../parallel/set1/spam_virus/rspamd_full.bats | 8 ++--- .../set1/spam_virus/spam_junk_folder.bats | 2 +- .../container_configuration/hostname.bats | 2 +- test/tests/parallel/set3/mta/lmtp_ip.bats | 2 +- test/tests/parallel/set3/mta/privacy.bats | 2 +- .../parallel/set3/mta/smtp_delivery.bats | 32 +++++++++---------- test/tests/parallel/set3/mta/smtponly.bats | 2 +- test/tests/serial/mail_with_ldap.bats | 6 ++-- test/tests/serial/tests.bats | 4 +-- test/tests/serial/vmail-id.bats | 3 +- 19 files changed, 62 insertions(+), 56 deletions(-) diff --git a/test/helper/sending.bash b/test/helper/sending.bash index ffdd7515..7c52e3bb 100644 --- a/test/helper/sending.bash +++ b/test/helper/sending.bash @@ -11,8 +11,10 @@ # a custom email, create a file at `test/files/`, # and provide `` 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: diff --git a/test/tests/parallel/set1/dovecot/dovecot_quotas.bats b/test/tests/parallel/set1/dovecot/dovecot_quotas.bats index 7f22ac22..81cf9bc1 100644 --- a/test/tests/parallel/set1/dovecot/dovecot_quotas.bats +++ b/test/tests/parallel/set1/dovecot/dovecot_quotas.bats @@ -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/ diff --git a/test/tests/parallel/set1/dovecot/dovecot_sieve.bats b/test/tests/parallel/set1/dovecot/dovecot_sieve.bats index c122b95c..e3e076a5 100644 --- a/test/tests/parallel/set1/dovecot/dovecot_sieve.bats +++ b/test/tests/parallel/set1/dovecot/dovecot_sieve.bats @@ -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 diff --git a/test/tests/parallel/set1/dovecot/mailbox_format_dbox.bats b/test/tests/parallel/set1/dovecot/mailbox_format_dbox.bats index 6061b2a8..033a5bde 100644 --- a/test/tests/parallel/set1/dovecot/mailbox_format_dbox.bats +++ b/test/tests/parallel/set1/dovecot/mailbox_format_dbox.bats @@ -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 diff --git a/test/tests/parallel/set1/dovecot/special_use_folders.bats b/test/tests/parallel/set1/dovecot/special_use_folders.bats index d44f8204..fe1f554e 100644 --- a/test/tests/parallel/set1/dovecot/special_use_folders.bats +++ b/test/tests/parallel/set1/dovecot/special_use_folders.bats @@ -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 } diff --git a/test/tests/parallel/set1/spam_virus/clamav.bats b/test/tests/parallel/set1/spam_virus/clamav.bats index 1abf9aa6..9232f90f 100644 --- a/test/tests/parallel/set1/spam_virus/clamav.bats +++ b/test/tests/parallel/set1/spam_virus/clamav.bats @@ -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 } diff --git a/test/tests/parallel/set1/spam_virus/disabled_clamav_spamassassin.bats b/test/tests/parallel/set1/spam_virus/disabled_clamav_spamassassin.bats index 4e3ee013..f2474cc0 100644 --- a/test/tests/parallel/set1/spam_virus/disabled_clamav_spamassassin.bats +++ b/test/tests/parallel/set1/spam_virus/disabled_clamav_spamassassin.bats @@ -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 } diff --git a/test/tests/parallel/set1/spam_virus/postgrey_enabled.bats b/test/tests/parallel/set1/spam_virus/postgrey_enabled.bats index de0d9c37..14d276ca 100644 --- a/test/tests/parallel/set1/spam_virus/postgrey_enabled.bats +++ b/test/tests/parallel/set1/spam_virus/postgrey_enabled.bats @@ -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): diff --git a/test/tests/parallel/set1/spam_virus/postscreen.bats b/test/tests/parallel/set1/spam_virus/postscreen.bats index 5a9bff68..c92b3ed2 100644 --- a/test/tests/parallel/set1/spam_virus/postscreen.bats +++ b/test/tests/parallel/set1/spam_virus/postscreen.bats @@ -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'" diff --git a/test/tests/parallel/set1/spam_virus/rspamd_full.bats b/test/tests/parallel/set1/spam_virus/rspamd_full.bats index dbb71a7b..2e610d72 100644 --- a/test/tests/parallel/set1/spam_virus/rspamd_full.bats +++ b/test/tests/parallel/set1/spam_virus/rspamd_full.bats @@ -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 ; } diff --git a/test/tests/parallel/set1/spam_virus/spam_junk_folder.bats b/test/tests/parallel/set1/spam_virus/spam_junk_folder.bats index 888e2614..fea23b0b 100644 --- a/test/tests/parallel/set1/spam_virus/spam_junk_folder.bats +++ b/test/tests/parallel/set1/spam_virus/spam_junk_folder.bats @@ -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() { diff --git a/test/tests/parallel/set3/container_configuration/hostname.bats b/test/tests/parallel/set3/container_configuration/hostname.bats index 2cd66477..f5774eef 100644 --- a/test/tests/parallel/set3/container_configuration/hostname.bats +++ b/test/tests/parallel/set3/container_configuration/hostname.bats @@ -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' diff --git a/test/tests/parallel/set3/mta/lmtp_ip.bats b/test/tests/parallel/set3/mta/lmtp_ip.bats index fd055161..d8be42d9 100644 --- a/test/tests/parallel/set3/mta/lmtp_ip.bats +++ b/test/tests/parallel/set3/mta/lmtp_ip.bats @@ -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=, 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 ixPpB+Zvv2P7BAAAUi6ngw Saved) diff --git a/test/tests/parallel/set3/mta/privacy.bats b/test/tests/parallel/set3/mta/privacy.bats index 2122f8d0..4d4d82ba 100644 --- a/test/tests/parallel/set3/mta/privacy.bats +++ b/test/tests/parallel/set3/mta/privacy.bats @@ -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 ]]' diff --git a/test/tests/parallel/set3/mta/smtp_delivery.bats b/test/tests/parallel/set3/mta/smtp_delivery.bats index d0080d67..0fb30bdb 100644 --- a/test/tests/parallel/set3/mta/smtp_delivery.bats +++ b/test/tests/parallel/set3/mta/smtp_delivery.bats @@ -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' } diff --git a/test/tests/parallel/set3/mta/smtponly.bats b/test/tests/parallel/set3/mta/smtponly.bats index 35337f28..db5b5058 100644 --- a/test/tests/parallel/set3/mta/smtponly.bats +++ b/test/tests/parallel/set3/mta/smtponly.bats @@ -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 diff --git a/test/tests/serial/mail_with_ldap.bats b/test/tests/serial/mail_with_ldap.bats index 167192e7..4903e8d4 100644 --- a/test/tests/serial/mail_with_ldap.bats +++ b/test/tests/serial/mail_with_ldap.bats @@ -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' } diff --git a/test/tests/serial/tests.bats b/test/tests/serial/tests.bats index 2840a2ad..505b0242 100644 --- a/test/tests/serial/tests.bats +++ b/test/tests/serial/tests.bats @@ -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' } diff --git a/test/tests/serial/vmail-id.bats b/test/tests/serial/vmail-id.bats index 60706a62..32c889a5 100644 --- a/test/tests/serial/vmail-id.bats +++ b/test/tests/serial/vmail-id.bats @@ -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 } -