mirror of
https://github.com/docker-mailserver/docker-mailserver
synced 2024-12-18 23:14:11 +01:00
ed1e1ebbd3
* move log/filter functions into own file * add ShellCheck global directives * use new function for tracking logs The new function, called `_send_email_with_mid`, aligns with suggestions from @polarethene and is heavily simplified compared to its predecessor `_send_email_and_get_id`. New helpers will be introduced to filter logs according to the MID constructed in this function. * new filters for searching logs with MID * use new filters (and sending) functions * add new helper for asserting non-existence of log message * use new filters in tests * Apply suggestions from code review - `_mid` / `MID` => `_msgid` / `MSG_ID` - Revised documentation / tooltip comments * Apply suggestions from code review * fix tests * use more distinct names for MSG_ID headers * update `_filter_service_log` to not use `-i -E` Moreover, I added a function to print the whole mail log. Appropriate comments were added to this function to indicate that one should only use this function when necessary. * adjust helpers to new helper filter * follow-up of previous commit * add CHANGELOG entry * Apply suggestions from code review * chore: Update OAuth2 to use new log helper * Apply suggestions from code review Co-authored-by: Brennan Kinney <5098581+polarathene@users.noreply.github.com> * added explicit `_regexp` filters for logs * Apply suggestions from code review --------- Co-authored-by: Brennan Kinney <5098581+polarathene@users.noreply.github.com>
67 lines
2.7 KiB
Bash
67 lines
2.7 KiB
Bash
load "${REPOSITORY_ROOT}/test/helper/setup"
|
|
load "${REPOSITORY_ROOT}/test/helper/common"
|
|
|
|
BATS_TEST_NAME_PREFIX='[Postscreen] '
|
|
CONTAINER1_NAME='dms-test_postscreen_enforce'
|
|
CONTAINER2_NAME='dms-test_postscreen_sender'
|
|
|
|
function setup() {
|
|
CONTAINER1_IP=$(_get_container_ip "${CONTAINER1_NAME}")
|
|
}
|
|
|
|
function setup_file() {
|
|
export CONTAINER_NAME
|
|
|
|
CONTAINER_NAME=${CONTAINER1_NAME}
|
|
local CUSTOM_SETUP_ARGUMENTS=(
|
|
--env POSTSCREEN_ACTION=enforce
|
|
)
|
|
_init_with_defaults
|
|
_common_container_setup 'CUSTOM_SETUP_ARGUMENTS'
|
|
_wait_for_smtp_port_in_container
|
|
|
|
# A standard DMS instance to send mail from:
|
|
# NOTE: None of DMS is actually used for this (just bash + nc).
|
|
CONTAINER_NAME=${CONTAINER2_NAME}
|
|
_init_with_defaults
|
|
# No need to wait for DMS to be ready for this container:
|
|
_common_container_create
|
|
run docker start "${CONTAINER_NAME}"
|
|
assert_success
|
|
|
|
# Set default implicit container fallback for helpers:
|
|
CONTAINER_NAME=${CONTAINER1_NAME}
|
|
}
|
|
|
|
function teardown_file() {
|
|
docker rm -f "${CONTAINER1_NAME}" "${CONTAINER2_NAME}"
|
|
}
|
|
|
|
# `POSTSCREEN_ACTION=enforce` (DMS default) should reject delivery with a 550 SMTP reply
|
|
# A legitimate mail client should speak SMTP by waiting it's turn, which postscreen defaults enforce (only on port 25)
|
|
# https://www.postfix.org/postconf.5.html#postscreen_greet_wait
|
|
#
|
|
# Use `nc` to send all SMTP commands at once instead (emulate a misbehaving client that should be rejected)
|
|
# NOTE: Postscreen only runs on port 25, avoid implicit ports in test methods
|
|
@test 'should fail send when talking out of turn' {
|
|
CONTAINER_NAME=${CONTAINER2_NAME} _nc_wrapper 'emails/nc_raw/postscreen.txt' "${CONTAINER1_IP} 25"
|
|
# Expected postscreen log entry:
|
|
assert_output --partial 'Protocol error'
|
|
|
|
_run_in_container cat /var/log/mail.log
|
|
assert_output --partial 'COMMAND PIPELINING'
|
|
assert_output --partial 'DATA without valid RCPT'
|
|
}
|
|
|
|
@test "should successfully pass postscreen and get postfix greeting message (respecting postscreen_greet_wait time)" {
|
|
# Configure `send_email()` to send from the mail client container (CONTAINER2_NAME) via ENV override,
|
|
# mail is sent to the DMS server container (CONTAINER1_NAME) via `--server` parameter:
|
|
CONTAINER_NAME=${CONTAINER2_NAME} _send_email --expect-rejection --server "${CONTAINER1_IP}" --port 25 --data 'postscreen.txt'
|
|
# TODO: Use _send_email_with_msgid when proper resolution of domain names is possible:
|
|
# CONTAINER_NAME=${CONTAINER2_NAME} _send_email_with_msgid 'msgid-postscreen' --server "${CONTAINER1_IP}" --data 'postscreen.txt'
|
|
# _print_mail_log_for_msgid 'msgid-postscreen'
|
|
# assert_output --partial "stored mail into mailbox 'INBOX'"
|
|
|
|
_service_log_should_contain_string 'mail' 'PASS NEW'
|
|
}
|