apply PR feedback

This commit is contained in:
georglauterbach 2024-01-06 22:15:26 +01:00
parent d7dd8405d3
commit ab1c72a458
No known key found for this signature in database
GPG Key ID: F367F7C43C118578
3 changed files with 28 additions and 21 deletions

View File

@ -11,9 +11,8 @@
# a custom email, create a file at `test/files/<TEST FILE>`, # a custom email, create a file at `test/files/<TEST FILE>`,
# and provide `<TEST FILE>` as an argument to this function. # and provide `<TEST FILE>` as an argument to this function.
# #
# Parameters include all options that one can supply to `swaks` # Parameters include all options that one can supply to `swaks` itself.
# itself. The `--data` parameter expects a relative path from `emails/` # The `--data` parameter expects a relative path from `emails/`.
# where the contents will be implicitly provided to `swaks` via STDIN.
# #
# This functions performs **no** implicit `assert_success` to check whether # This functions performs **no** implicit `assert_success` to check whether
# the e-mail transaction was successful. If this is not desirable, use # the e-mail transaction was successful. If this is not desirable, use
@ -24,9 +23,8 @@
# This function assumes `CONTAINER_NAME` to be properly set (to the container # This function assumes `CONTAINER_NAME` to be properly set (to the container
# name the command should be executed in)! # name the command should be executed in)!
# #
# This function will just send the email in an "asynchronous" fashion, i.e. it will # This function will send the email in an "asynchronous" fashion,
# send the email but it will not make sure the mail queue is empty after the mail # it will return without waiting for the Postfix mail queue to be emptied.
# has been sent.
function _send_email_unchecked() { function _send_email_unchecked() {
[[ -v CONTAINER_NAME ]] || return 1 [[ -v CONTAINER_NAME ]] || return 1
@ -38,6 +36,7 @@ function _send_email_unchecked() {
local PORT=25 local PORT=25
# Extra options for `swaks` that aren't covered by the default options above: # Extra options for `swaks` that aren't covered by the default options above:
local ADDITIONAL_SWAKS_OPTIONS=() local ADDITIONAL_SWAKS_OPTIONS=()
local DATA_WAS_SUPPLIED=0
while [[ ${#} -gt 0 ]]; do while [[ ${#} -gt 0 ]]; do
case "${1}" in case "${1}" in
@ -55,21 +54,31 @@ function _send_email_unchecked() {
ADDITIONAL_SWAKS_OPTIONS+=("'${2}'") ADDITIONAL_SWAKS_OPTIONS+=("'${2}'")
fi fi
shift 2 shift 2
DATA_WAS_SUPPLIED=1
;; ;;
( * ) ADDITIONAL_SWAKS_OPTIONS+=("'${1}'") ; shift 1 ;; ( * ) ADDITIONAL_SWAKS_OPTIONS+=("'${1}'") ; shift 1 ;;
esac esac
done done
if [[ ${DATA_WAS_SUPPLIED} -eq 0 ]]; then
# Fallback template without implicit `Message-Id` + `X-Mailer` headers:
# NOTE: It is better to let Postfix generate the `Message-Id` header and append that
# as it contains the queue ID for tracking logs and is returned to in swaks output.
ADDITIONAL_SWAKS_OPTIONS+=('--data')
ADDITIONAL_SWAKS_OPTIONS+=("'Date: %DATE%\nTo: %TO_ADDRESS%\nFrom: %FROM_ADDRESS%\nSubject: test %DATE%\n%NEW_HEADERS%\n%BODY%\n'")
fi
echo "swaks --server '${SERVER}' --port '${PORT}' --ehlo '${EHLO}' --from '${FROM}' --to '${TO}' ${ADDITIONAL_SWAKS_OPTIONS[*]}" >/tmp/lol
_run_in_container_bash "swaks --server '${SERVER}' --port '${PORT}' --ehlo '${EHLO}' --from '${FROM}' --to '${TO}' ${ADDITIONAL_SWAKS_OPTIONS[*]}" _run_in_container_bash "swaks --server '${SERVER}' --port '${PORT}' --ehlo '${EHLO}' --from '${FROM}' --to '${TO}' ${ADDITIONAL_SWAKS_OPTIONS[*]}"
} }
# Sends a mail from localhost (127.0.0.1) to a container. To send # Sends a mail from localhost (127.0.0.1) to a container. To send a custom email:
# a custom email, create a file at `test/files/<TEST FILE>`,
# and provide `<TEST FILE>` as an argument to this function.
# #
# Parameters include all options that one can supply to `swaks` # 1. Create a file at `test/files/<TEST FILE>`
# itself. The `--data` parameter expects a relative path from `emails/` # 2. Provide `<TEST FILE>` as an argument to this function.
# where the contents will be implicitly provided to `swaks` via STDIN. #
# Parameters include all options that one can supply to `swaks` itself.
# The `--data` parameter expects a relative path from `emails/`.
# #
# This functions performs an implicit `assert_success` to check whether # This functions performs an implicit `assert_success` to check whether
# the e-mail transaction was successful. If this is not desirable, use # the e-mail transaction was successful. If this is not desirable, use
@ -77,12 +86,7 @@ function _send_email_unchecked() {
# #
# ## Attention # ## Attention
# #
# This function assumes `CONTAINER_NAME` to be properly set (to the container # Please see the 'Attention' section of `_send_email_unchecked`,
# name the command should be executed in)!
#
# This function will just send the email in an "asynchronous" fashion, i.e. it will
# send the email but it will not make sure the mail queue is empty after the mail
# has been sent.
function _send_email() { function _send_email() {
_send_email_unchecked "${@}" _send_email_unchecked "${@}"
assert_success assert_success

View File

@ -207,7 +207,7 @@ function _should_have_correct_mail_headers() {
# (eg: OVERRIDE_HOSTNAME or `--hostname mail --domainname example.test`) # (eg: OVERRIDE_HOSTNAME or `--hostname mail --domainname example.test`)
local EXPECTED_HOSTNAME=${3:-${EXPECTED_FQDN}} local EXPECTED_HOSTNAME=${3:-${EXPECTED_FQDN}}
_send_email --from 'user@external.tld' --data "Date: %DATE%\nTo: %TO_ADDRESS%\nFrom: %FROM_ADDRESS%\nSubject: test %DATE%\n%NEW_HEADERS%\n%BODY%\n" _send_email --from 'user@external.tld'
_wait_for_empty_mail_queue_in_container _wait_for_empty_mail_queue_in_container
_count_files_in_directory_in_container '/var/mail/localhost.localdomain/user1/new/' '1' _count_files_in_directory_in_container '/var/mail/localhost.localdomain/user1/new/' '1'

View File

@ -88,7 +88,10 @@ function setup_file() {
_send_email --to user2@otherdomain.tld _send_email --to user2@otherdomain.tld
_send_email --to user3@localhost.localdomain _send_email --to user3@localhost.localdomain
_send_email --to added@localhost.localdomain --header 'Subject: Test Message existing-added' _send_email --to added@localhost.localdomain --header 'Subject: Test Message existing-added'
_send_email --to user1@localhost.localdomain --header 'Subject: Test Message existing-user-and-cc-local-alias' _send_email \
--to user1@localhost.localdomain \
--header 'Subject: Test Message existing-user-and-cc-local-alias' \
--cc 'alias2@localhost.localdomain'
_send_email --data 'sieve/spam-folder.txt' _send_email --data 'sieve/spam-folder.txt'
_send_email --to user2@otherdomain.tld --data 'sieve/pipe.txt' _send_email --to user2@otherdomain.tld --data 'sieve/pipe.txt'
_run_in_container_bash 'sendmail root < /tmp/docker-mailserver-test/emails/sendmail/root-email.txt' _run_in_container_bash 'sendmail root < /tmp/docker-mailserver-test/emails/sendmail/root-email.txt'
@ -96,7 +99,7 @@ function setup_file() {
} }
function _unsuccessful() { function _unsuccessful() {
_send_email_unchecked --port 465 --auth "${1}" --auth-user "${2}" --auth-password wrongpassword _send_email_unchecked --port 465 --auth "${1}" --auth-user "${2}" --auth-password wrongpassword --quit-after AUTH
assert_failure assert_failure
assert_output --partial 'authentication failed' assert_output --partial 'authentication failed'
assert_output --partial 'No authentication type succeeded' assert_output --partial 'No authentication type succeeded'