rename: `--unchecked` -> `--expect-rejection`
ref: https://github.com/docker-mailserver/docker-mailserver/pull/3747#discussion_r1446059805 I also added a bit more context to the function description and I added comments inside the function to help better understand what's going on.
This commit is contained in:
parent
97ff44c533
commit
3c55b42f47
|
@ -137,11 +137,11 @@ function _send_email() {
|
||||||
# test file and need to assert certain log entries for each mail individually.
|
# test file and need to assert certain log entries for each mail individually.
|
||||||
#
|
#
|
||||||
# The first argument has to be the name of the variable that the e-mail ID is stored
|
# The first argument has to be the name of the variable that the e-mail ID is stored
|
||||||
# in. The second argument **can** be the flag `--unchecked`; if this flag is supplied,
|
# in. The second argument **can** be the flag `--expect-rejection`. If this flag is supplied,
|
||||||
# the function uses `_send_email_unchecked` instead of `_send_email`. This avoids the
|
# the function does not check whether the whole mail delivery transaction was successful and
|
||||||
# `assert_success`. Be warned though this is only required in special situations where
|
# it will also query the queue ID differently. Be warned though that it must still be possible
|
||||||
# it is still possible to `grep` for the Message-ID that Postfix generated, -
|
# to `grep` for the Message-ID that Postfix generated in the mail log; otherwise this function
|
||||||
# otherwise this function fails. The rest of the arguments are the same as `_send_email`.
|
# fails. The rest of the arguments are the same as `_send_email`.
|
||||||
#
|
#
|
||||||
# ## Attention
|
# ## Attention
|
||||||
#
|
#
|
||||||
|
@ -172,18 +172,25 @@ function _send_email_and_get_id() {
|
||||||
local MESSAGE_ID_REGEX="[0-9]{14}\\.${QUEUE_ID_REGEX}"
|
local MESSAGE_ID_REGEX="[0-9]{14}\\.${QUEUE_ID_REGEX}"
|
||||||
|
|
||||||
_wait_for_empty_mail_queue_in_container
|
_wait_for_empty_mail_queue_in_container
|
||||||
if [[ ${1} == --unchecked ]]; then
|
if [[ ${1} == --expect-rejection ]]; then
|
||||||
shift 1
|
shift 1
|
||||||
local OUTPUT=$(_send_email_unchecked "${@}")
|
local OUTPUT=$(_send_email_unchecked "${@}")
|
||||||
|
# Because we expect the mail to be rejected, we have to query the mail log
|
||||||
|
# instead of `swaks`, because `swaks` cannot provide us with a queue ID when
|
||||||
|
# mail is rejected (we see something like this instead: `<** 554 5.7.1 Gtube pattern`).
|
||||||
QUEUE_ID=$(_exec_in_container tac /var/log/mail.log \
|
QUEUE_ID=$(_exec_in_container tac /var/log/mail.log \
|
||||||
| grep -E "postfix/smtpd.*: ${QUEUE_ID_REGEX}: client=" \
|
| grep -E "postfix/smtpd.*: ${QUEUE_ID_REGEX}: client=" \
|
||||||
| grep -E -m 1 -o '[A-Z0-9]{9,12}' || :)
|
| grep -E -m 1 -o '[A-Z0-9]{9,12}' || :)
|
||||||
else
|
else
|
||||||
local OUTPUT=$(_send_email "${@}")
|
local OUTPUT=$(_send_email "${@}")
|
||||||
|
# When mail is expected to be delivered, we can use the output of `swaks`
|
||||||
|
# to easily query the queue ID.
|
||||||
QUEUE_ID=$(grep -F 'queued as' <<< "${OUTPUT}" | grep -E -o "${QUEUE_ID_REGEX}$")
|
QUEUE_ID=$(grep -F 'queued as' <<< "${OUTPUT}" | grep -E -o "${QUEUE_ID_REGEX}$")
|
||||||
fi
|
fi
|
||||||
_wait_for_empty_mail_queue_in_container
|
_wait_for_empty_mail_queue_in_container
|
||||||
|
|
||||||
|
assert_not_equal "${QUEUE_ID}" ''
|
||||||
|
|
||||||
MESSAGE_ID=$(_exec_in_container tac /var/log/mail.log \
|
MESSAGE_ID=$(_exec_in_container tac /var/log/mail.log \
|
||||||
| grep -E "message-id=<${MESSAGE_ID_REGEX}@" \
|
| grep -E "message-id=<${MESSAGE_ID_REGEX}@" \
|
||||||
| grep -E -m 1 -o "${MESSAGE_ID_REGEX}" || :)
|
| grep -E -m 1 -o "${MESSAGE_ID_REGEX}" || :)
|
||||||
|
|
|
@ -50,10 +50,10 @@ function setup_file() {
|
||||||
# 1. The first one should pass just fine
|
# 1. The first one should pass just fine
|
||||||
_send_email_and_get_id MAIL_ID_PASS
|
_send_email_and_get_id MAIL_ID_PASS
|
||||||
# 2. The second one should be rejected (GTUBE pattern)
|
# 2. The second one should be rejected (GTUBE pattern)
|
||||||
_send_email_and_get_id MAIL_ID_REJECT --unchecked --body "XJS${GTUBE_SUFFIX}"
|
_send_email_and_get_id MAIL_ID_REJECT --expect-rejection --body "XJS${GTUBE_SUFFIX}"
|
||||||
# 3. The third one should be rejected due to a virus (ClamAV EICAR pattern)
|
# 3. The third one should be rejected due to a virus (ClamAV EICAR pattern)
|
||||||
# shellcheck disable=SC2016
|
# shellcheck disable=SC2016
|
||||||
_send_email_and_get_id MAIL_ID_VIRUS --unchecked \
|
_send_email_and_get_id MAIL_ID_VIRUS --expect-rejection \
|
||||||
--body 'X5O!P%@AP[4\PZX54(P^)7CC)7}$EICAR-STANDARD-ANTIVIRUS-TEST-FILE!$H+H*'
|
--body 'X5O!P%@AP[4\PZX54(P^)7CC)7}$EICAR-STANDARD-ANTIVIRUS-TEST-FILE!$H+H*'
|
||||||
# 4. The fourth one will receive an added header (GTUBE pattern)
|
# 4. The fourth one will receive an added header (GTUBE pattern)
|
||||||
_send_email_and_get_id MAIL_ID_HEADER --body "YJS${GTUBE_SUFFIX}"
|
_send_email_and_get_id MAIL_ID_HEADER --body "YJS${GTUBE_SUFFIX}"
|
||||||
|
|
Loading…
Reference in New Issue