Changeset - 6f3bc2a8facd
[Not reviewed]
0 3 0
Branko Majic (branko) - 3 years ago 2020-12-22 17:27:30
branko@majic.rs
MAR-175: Add test for local mail delivery and drop use of procmail.
3 files changed with 37 insertions and 1 deletions:
0 comments (0 inline, 0 general)
roles/mail_server/molecule/default/prepare.yml
Show inline comments
 
@@ -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
roles/mail_server/molecule/default/tests/test_default.py
Show inline comments
 
@@ -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<queue_id>[^:]+): 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=<localuser@localhost>, 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
roles/mail_server/templates/main.cf.j2
Show inline comments
 
@@ -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
0 comments (0 inline, 0 general)