2023-01-15 05:33:31 +00:00
|
|
|
load "${REPOSITORY_ROOT}/test/helper/common"
|
|
|
|
load "${REPOSITORY_ROOT}/test/helper/setup"
|
|
|
|
|
|
|
|
# Originally contributed Jan 2017:
|
|
|
|
# https://github.com/docker-mailserver/docker-mailserver/pull/461
|
|
|
|
# Refactored with additional insights:
|
|
|
|
# https://github.com/docker-mailserver/docker-mailserver/pull/3004
|
|
|
|
|
|
|
|
# NOTE: Purpose of feature is to use an ENV instead of providing a `postfix-main.cf`
|
|
|
|
# to configure a URI for sending mail to an alternative LMTP server.
|
|
|
|
# TODO: A more appropriate test if keeping this feature would be to run Dovecot via a
|
|
|
|
# separate container to deliver mail to, and verify it was stored in the expected mail dir.
|
|
|
|
|
2023-01-21 23:05:28 +00:00
|
|
|
BATS_TEST_NAME_PREFIX='[ENV] (POSTFIX_DAGENT) '
|
2023-01-15 05:33:31 +00:00
|
|
|
CONTAINER_NAME='dms-test_env_postfix-dagent'
|
|
|
|
|
|
|
|
function setup_file() {
|
|
|
|
export LMTP_URI='lmtp:127.0.0.1:24'
|
2023-01-21 23:05:28 +00:00
|
|
|
_init_with_defaults
|
2019-08-16 17:36:03 +00:00
|
|
|
|
2023-01-15 05:33:31 +00:00
|
|
|
local CONTAINER_ARGS_ENV_CUSTOM=(
|
|
|
|
--env PERMIT_DOCKER='container'
|
|
|
|
--env POSTFIX_DAGENT="${LMTP_URI}"
|
|
|
|
)
|
|
|
|
|
|
|
|
# Configure LMTP service listener in `/etc/dovecot/conf.d/10-master.conf` to instead listen on TCP port 24:
|
|
|
|
mv "${TEST_TMP_CONFIG}/dovecot-lmtp/user-patches.sh" "${TEST_TMP_CONFIG}/"
|
|
|
|
|
2023-01-21 23:05:28 +00:00
|
|
|
_common_container_setup 'CONTAINER_ARGS_ENV_CUSTOM'
|
2019-08-16 17:36:03 +00:00
|
|
|
}
|
|
|
|
|
2023-01-15 05:33:31 +00:00
|
|
|
function teardown_file() { _default_teardown ; }
|
|
|
|
|
|
|
|
@test "should have updated the value of 'main.cf:virtual_transport'" {
|
|
|
|
_run_in_container grep "virtual_transport = ${LMTP_URI}" /etc/postfix/main.cf
|
2019-08-16 17:36:03 +00:00
|
|
|
assert_success
|
|
|
|
}
|
|
|
|
|
2023-01-15 05:33:31 +00:00
|
|
|
@test "delivers mail to existing account" {
|
2023-01-21 23:05:28 +00:00
|
|
|
_wait_for_smtp_port_in_container
|
2023-02-24 09:44:18 +00:00
|
|
|
_send_email 'email-templates/existing-user1' # send a test email
|
2020-10-18 13:44:01 +00:00
|
|
|
|
2023-01-15 05:33:31 +00:00
|
|
|
# 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)
|
tests(fix): `lmtp_ip.bats` improve partial failure output (#3552)
Instead of exit status of `124` (_signifies timeout_), it should fail with `1` (failure) like the others. Handled via using `_run_in_container_bash()` (_`timeout` failure `124` does not propagate and is treated as `1` instead_).
In this case we are waiting on the status of the mail being sent, the pattern provided to `grep` is too specific and results in a timeout. Instead since we only expect the one log entry, match any status and assert the expected pattern afterwards.
This provides a more helpful failure output that informs us that mail was at least processed by Postfix, but the sent status is not what we expected.
### Before
```
✗ [ENV] (POSTFIX_DAGENT) delivers mail to existing account [60327]
(from function `assert_success' in file test/test_helper/bats-assert/src/assert_success.bash, line 42,
in test file test/tests/parallel/set3/mta/lmtp_ip.bats, line 47)
`assert_success' failed
-- command failed --
status : 124
output :
--
```
### After
```
✗ [ENV] (POSTFIX_DAGENT) delivers mail to existing account [1425]
(from function `assert_output' in file test/test_helper/bats-assert/src/assert_output.bash, line 178,
in test file test/tests/parallel/set3/mta/lmtp_ip.bats, line 48)
`assert_output --regexp "${MATCH_LOG_LINE}=sent .* Saved)"' failed
-- regular expression does not match output --
regexp : postfix/lmtp.* status=sent .* Saved)
output : Sep 28 04:12:52 mail postfix/lmtp[721]: 23701B575: to=<user1@localhost.localdomain>, relay=127.0.0.1[127.0.0.1]:24, delay=0.08, delays=0.07/0/0.01/0, dsn=4.2.0, status=deferred (host 127.0.0.1[127.0.0.1] said: 451 4.2.0 <user1@localhost.localdomain> Internal error occurred. Refer to server log for more information. [2023-09-28 04:12:52] (in reply to end of DATA command))
--
```
The expected pattern is logged as `assert_success` confirms a valid match for the log line of interest was found, and we have the mismatched value to debug the failure against.
2023-09-28 21:17:57 +00:00
|
|
|
local MATCH_LOG_LINE='postfix/lmtp.* status'
|
|
|
|
_run_in_container_bash "timeout 60 tail -F /var/log/mail/mail.log | grep --max-count 1 '${MATCH_LOG_LINE}'"
|
2019-08-16 17:36:03 +00:00
|
|
|
assert_success
|
tests(fix): `lmtp_ip.bats` improve partial failure output (#3552)
Instead of exit status of `124` (_signifies timeout_), it should fail with `1` (failure) like the others. Handled via using `_run_in_container_bash()` (_`timeout` failure `124` does not propagate and is treated as `1` instead_).
In this case we are waiting on the status of the mail being sent, the pattern provided to `grep` is too specific and results in a timeout. Instead since we only expect the one log entry, match any status and assert the expected pattern afterwards.
This provides a more helpful failure output that informs us that mail was at least processed by Postfix, but the sent status is not what we expected.
### Before
```
✗ [ENV] (POSTFIX_DAGENT) delivers mail to existing account [60327]
(from function `assert_success' in file test/test_helper/bats-assert/src/assert_success.bash, line 42,
in test file test/tests/parallel/set3/mta/lmtp_ip.bats, line 47)
`assert_success' failed
-- command failed --
status : 124
output :
--
```
### After
```
✗ [ENV] (POSTFIX_DAGENT) delivers mail to existing account [1425]
(from function `assert_output' in file test/test_helper/bats-assert/src/assert_output.bash, line 178,
in test file test/tests/parallel/set3/mta/lmtp_ip.bats, line 48)
`assert_output --regexp "${MATCH_LOG_LINE}=sent .* Saved)"' failed
-- regular expression does not match output --
regexp : postfix/lmtp.* status=sent .* Saved)
output : Sep 28 04:12:52 mail postfix/lmtp[721]: 23701B575: to=<user1@localhost.localdomain>, relay=127.0.0.1[127.0.0.1]:24, delay=0.08, delays=0.07/0/0.01/0, dsn=4.2.0, status=deferred (host 127.0.0.1[127.0.0.1] said: 451 4.2.0 <user1@localhost.localdomain> Internal error occurred. Refer to server log for more information. [2023-09-28 04:12:52] (in reply to end of DATA command))
--
```
The expected pattern is logged as `assert_success` confirms a valid match for the log line of interest was found, and we have the mismatched value to debug the failure against.
2023-09-28 21:17:57 +00:00
|
|
|
# Assertion of full pattern here (instead of via grep) is a bit more helpful for debugging partial failures:
|
|
|
|
assert_output --regexp "${MATCH_LOG_LINE}=sent .* Saved)"
|
2019-08-16 17:36:03 +00:00
|
|
|
}
|