From 6f3bc2a8facd447fcc13346e4d0d5c9eb429e13a 2020-12-22 17:27:30 From: Branko Majic Date: 2020-12-22 17:27:30 Subject: [PATCH] MAR-175: Add test for local mail delivery and drop use of procmail. --- diff --git a/roles/mail_server/molecule/default/prepare.yml b/roles/mail_server/molecule/default/prepare.yml index c84fb778856ad4b0ae36f012761da8de1d73571d..4ee505cd304c0f302931511173b77ebd13b228f6 100644 --- a/roles/mail_server/molecule/default/prepare.yml +++ b/roles/mail_server/molecule/default/prepare.yml @@ -226,3 +226,16 @@ values: - uid=john,ou=people,dc=local - uid=jane,ou=people,dc=local + +- hosts: parameters-mandatory,parameters-optional + become: true + tasks: + + - name: Create group for user used for local mail delivery testing + group: + name: localuser + + - name: Create user for local mail delivery testing + user: + name: localuser + group: localuser diff --git a/roles/mail_server/molecule/default/tests/test_default.py b/roles/mail_server/molecule/default/tests/test_default.py index c4f7547a7693bb517f656fd99e0ad8be1318036c..3d78fac856373848b8efa7c35d263aad923bca4b 100644 --- a/roles/mail_server/molecule/default/tests/test_default.py +++ b/roles/mail_server/molecule/default/tests/test_default.py @@ -482,3 +482,27 @@ def test_smtp_tls_connectivity(host): tls = host.run('echo "QUIT" | openssl s_client -quiet -starttls smtp -connect %s:587', fqdn) assert tls.rc == 0 assert '221 2.0.0 Bye' in starttls.stdout + + +def test_postfix_local_delivery(host): + """ + Tests if mail received by Postfix is properly delivered to local + account's mail spool. + """ + + message_id = str(uuid.uuid4()) + + send = host.run('swaks --header %s --suppress-data --to localuser@localhost --server localhost', "Message-Id: <%s>" % message_id) + assert send.rc == 0 + + with host.sudo(): + mail_log = host.file('/var/log/mail.log') + + pattern = r"postfix/cleanup\[\d+\]: (?P[^:]+): message-id=<%s>" % message_id + match_result = re.search(pattern, mail_log.content_string) + assert match_result is not None + + queue_id = match_result.group('queue_id') + pattern = r"postfix/local\[\d+\]: %s: to=, relay=local,.*, status=sent \(delivered to mailbox\)" % queue_id + match_result = re.search(pattern, mail_log.content_string) + assert match_result is not None, queue_id diff --git a/roles/mail_server/templates/main.cf.j2 b/roles/mail_server/templates/main.cf.j2 index bf9d1f0326339af0a6c6e9b118b7bdaf1c839bc6..abbfb2621eb144bfe165cdae3ae6d790940909b0 100644 --- a/roles/mail_server/templates/main.cf.j2 +++ b/roles/mail_server/templates/main.cf.j2 @@ -39,7 +39,6 @@ mydestination = {{ inventory_hostname }}, {{ inventory_hostname_short }}, localh relayhost = mynetworks = 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128{% for network in smtp_allow_relay_from %} {{ network }}{% endfor %} -mailbox_command = procmail -a "$EXTENSION" mailbox_size_limit = 0 recipient_delimiter = + inet_interfaces = all