-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[TODO]: Tests - test_helper.bats
refactor mailqueue test cases
#3768
Comments
Using the Postfix queue in a controlled manner (block delivery so mail is held in queue until we decide to decide to release it via This comment isn't specific to this issue, but collects enough information on the subject to go forward with an implementation, which may be useful elsewhere in testing (if the Queue ID is important, it is much easier to retrieve assuming mail is accepted for delivery). Presently we use docker-mailserver/test/helper/common.bash Lines 319 to 328 in aba218e
# Equivalent output of mailq command:
$ postqueue -p
-Queue ID- --Size-- ----Arrival Time---- -Sender/Recipient-------
8551B132C2* 802 Wed Jan 10 00:32:03 someone@external.test
hello@example.test
C293F132B1* 802 Wed Jan 10 00:29:19 someone-else@external.test
hello@example.test
AC00D132B3* 802 Wed Jan 10 00:29:48 someone@external.test
bye@example.test
-- 2 Kbytes in 3 Requests.
# JSON output supported:
$ postqueue -j
{"queue_name": "active", "queue_id": "8551B132C2", "arrival_time": 1704846723, "message_size": 802, "forced_expire": false, "sender": "someone@external.test", "recipients": [{"address": "hello@example.test"}]}
{"queue_name": "active", "queue_id": "C293F132B1", "arrival_time": 1704846559, "message_size": 802, "forced_expire": false, "sender": "someone-else@external.test", "recipients": [{"address": "hello@example.test"}]}
{"queue_name": "active", "queue_id": "AC00D132B3", "arrival_time": 1704846588, "message_size": 802, "forced_expire": false, "sender": "someone@external.test", "recipients": [{"address": "bye@example.test"}]} # Use jaq query on the JSON to match a specific sender and return their queue_id:
$ postqueue -j | jaq -r 'select(.sender == "someone-else@external.test") | .queue_id'
C293F132B1
# `postqueue -i <QUEUE ID>` triggers delivery of deferred queue item,
# This uses jaq to find a JSONL entry with a recipient we expect, then returns the queue id:
$ postqueue -i $(postqueue -j | jaq -r 'select(.recipients[].address == "bye@example.test") | .queue_id')
# Mail was released from queue:
$ postqueue -j
{"queue_name": "active", "queue_id": "8551B132C2", "arrival_time": 1704846723, "message_size": 802, "forced_expire": false, "sender": "someone@external.test", "recipients": [{"address": "hello@example.test"}]}
{"queue_name": "active", "queue_id": "C293F132B1", "arrival_time": 1704846559, "message_size": 802, "forced_expire": false, "sender": "someone-else@external.test", "recipients": [{"address": "hello@example.test"}]} So if we want to hold mail in the queue for postconf defer_transports=local,lmtp Mail has to reach that point of making it to the point it's queued for delivery to the transport I think. If that's not viable because mail is rejected earlier, you may only be able to track mail in the logs where getting the Queue ID is less convenient. Definition of a transport
Likewise
$ grep -E 'lmtp|virtual' /etc/postfix/master.cf
virtual unix - n n - - virtual
lmtp unix - - n - - lmtp
# Won't hold mail in queue:
$ postconf defer_transports=virtual
# Will hold mail for Dovecot in queue:
$ postconf defer_transports=lmtp
# Will hold mail for local agent (@$myhostname) in queue:
$ postconf defer_transports=local
$ grep -E 'local|relay' /etc/postfix/master.cf
local unix - n n - - local
relay unix - - n - - smtp
$ postconf | grep -E '_transport = (smtp|local|relay|lmtp|virtual)'
default_transport = smtp
local_transport = local:$myhostname
relay_transport = relay
virtual_transport = lmtp:unix:/var/run/dovecot/lmtp Extra insightsWe can use transport maps config to direct mail for a recipient to a particular transport (here is equivalent for matching on sender), or redirect all incoming mail to a specific fallback transport instead. If the transport is omitted it'll be selected by the appropriate address class. We can add our own custom transport to
The
# Take the two fields needed and prefix the queue directory
postqueue -j | jaq -r \
--arg queue_dir "$(postconf -h queue_directory)" \
'[$queue_dir, .queue_name, .queue_id] | join("/")'
# Output would be 1 or more queue items like this
/var/spool/postfix/deferred/0BBAB132FA
# Pass path to postcat to view the queued items info / content:
postcat /var/spool/postfix/deferred/0BBAB132FA |
Description
This was identified during recent review feedback, that the test cases could probably be refactored:
Presently it's skipped for being unreliable like some other tests have been (Dovecot Quota). The test file also needs to be adapted to our newer test format.
We can configure Postfix to defer mail to a transport, keeping it stuck in the queue until we decide to flush it. This is the main focus of the test-case which relied on unreliable means to try fill the queue up momentarily.
docker-mailserver/test/tests/serial/test_helper.bats
Lines 183 to 192 in aba218e
docker-mailserver/test/tests/serial/test_helper.bats
Lines 215 to 221 in aba218e
The text was updated successfully, but these errors were encountered: