Files
@ ff510f233909
Branch filter:
Location: majic-ansible-roles/roles/mail_forwarder/molecule/default/tests/test_mandatory.py - annotation
ff510f233909
2.1 KiB
text/x-python
MAR-132: Added support for Debian 9 (Stretch) to php_website role:
- Implemented the necessary changes related to differences between PHP
versions and related paths (PHP 5 vs PHP 7).
- Set the shell for application system account explicitly (workaround
for Debian bug 865762 in Stretch).
- Updated Molecule tests to cover Debian 9.
- Updated Molecule test preparation playbook to account for a number
of differences between Jessie and Stretch (mainly related to mailing
functionality).
- Use more specific host groups in tests.
- Renamed a couple of variables in test for sending out mails to make
it clearer what is being looked up as part of regex matching.
- Updated Molecule tests where certain paths depend on what Debian
release they are ran against.
- Split-up Jessie-specific tests into separate file.
- Implemented the necessary changes related to differences between PHP
versions and related paths (PHP 5 vs PHP 7).
- Set the shell for application system account explicitly (workaround
for Debian bug 865762 in Stretch).
- Updated Molecule tests to cover Debian 9.
- Updated Molecule test preparation playbook to account for a number
of differences between Jessie and Stretch (mainly related to mailing
functionality).
- Use more specific host groups in tests.
- Renamed a couple of variables in test for sending out mails to make
it clearer what is being looked up as part of regex matching.
- Updated Molecule tests where certain paths depend on what Debian
release they are ran against.
- Split-up Jessie-specific tests into separate file.
13982172ed2e f774e938a4ed 01f4b619cfa6 f774e938a4ed f774e938a4ed f774e938a4ed f774e938a4ed f774e938a4ed 13982172ed2e f774e938a4ed f774e938a4ed fb5e4e372902 f774e938a4ed f774e938a4ed f774e938a4ed f774e938a4ed fb5e4e372902 f774e938a4ed f774e938a4ed f774e938a4ed f774e938a4ed fb5e4e372902 f774e938a4ed f774e938a4ed f774e938a4ed f774e938a4ed fb5e4e372902 f774e938a4ed fb5e4e372902 f774e938a4ed fb5e4e372902 f774e938a4ed fb5e4e372902 fb5e4e372902 f774e938a4ed f774e938a4ed f774e938a4ed f774e938a4ed fb5e4e372902 fb5e4e372902 f774e938a4ed f774e938a4ed fb5e4e372902 fb5e4e372902 f774e938a4ed f774e938a4ed f774e938a4ed f774e938a4ed f774e938a4ed f774e938a4ed f774e938a4ed fb5e4e372902 f774e938a4ed f774e938a4ed f774e938a4ed f774e938a4ed f774e938a4ed fb5e4e372902 f774e938a4ed f774e938a4ed f774e938a4ed 01f4b619cfa6 01f4b619cfa6 01f4b619cfa6 fb5e4e372902 fb5e4e372902 23a9ea4219dc 23a9ea4219dc f774e938a4ed f774e938a4ed | import os
import re
import time
import testinfra.utils.ansible_runner
testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner(
os.environ['MOLECULE_INVENTORY_FILE']).get_hosts(['parameters-mandatory'])
def test_smtp_relay_truststore_file(host):
"""
Tests if SMTP relay truststore has correct content.
"""
truststore = host.file('/etc/ssl/certs/smtp_relay_truststore.pem')
assert truststore.content == open("tests/data/x509/truststore.pem", "r").read().rstrip()
def test_smtp_mailname(host):
"""
Tests if SMTP mailname configuration file has correct content.
"""
hostname = host.run('hostname').stdout
mailname = host.file('/etc/mailname')
assert mailname.content == hostname
def test_postfix_main_cf_file_content(host):
"""
Tests if the Postfix main configuration file content is correct.
"""
hostname = host.run('hostname').stdout
config = host.file('/etc/postfix/main.cf')
config_lines = config.content.split("\n")
assert "myhostname = %s" % hostname in config_lines
assert "mydestination = %s, %s, localhost.localdomain, localhost" % (hostname, hostname) in config_lines
assert "relayhost = " in config_lines
assert "mynetworks = 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128" in config_lines
assert "smtp_tls_security_level" not in config.content
assert "smtp_tls_CAfile" not in config.content
assert "smtp_host_lookup = dns, native" in config_lines
def test_direct_mail_sending(host):
"""
Tests if mails are sent correctly directly without relay if relay has not
been configured.
"""
send = host.run('swaks --suppress-data --to root@domain1 --server localhost')
assert send.rc == 0
message_id = re.search('Ok: queued as (.*)', send.stdout).group(1)
# Wait for a little while for message to be processed.
time.sleep(5)
with host.sudo():
mail_log = host.file('/var/log/mail.log')
# Pattern used to verify the mail was sent directly on default port.
pattern = "%s: to=<root@domain1>, relay=domain1\[[^]]*\]:25.*status=sent" % message_id
assert re.search(pattern, mail_log.content) is not None
|