import testinfra.utils.ansible_runner testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner( '.molecule/ansible_inventory').get_hosts(['parameters-mandatory', 'parameters-optional']) def test_installed_packages(Package): """ Tests if the necessary packages have been installed. """ assert Package('postfix').is_installed assert Package('procmail').is_installed assert Package('swaks').is_installed def test_removed_packages(Package): """ Tests if certain packages have been removed from the system. """ assert not Package('exim4').is_installed def test_smtp_relay_truststore_file(File): """ Tests if SMTP relay truststore has correct permissions """ truststore = File('/etc/ssl/certs/smtp_relay_truststore.pem') assert truststore.is_file assert truststore.user == 'root' assert truststore.group == 'root' assert truststore.mode == 0o644 def test_smtp_mailname(File): """ Tests if SMTP mailname configuration file has correct permissions. """ mailname = File('/etc/mailname') assert mailname.is_file assert mailname.user == 'root' assert mailname.group == 'root' assert mailname.mode == 0o644 def test_postfix_main_cf_file(File): """ Tests Postfix main configuration file permissions. """ config = File('/etc/postfix/main.cf') assert config.is_file assert config.user == 'root' assert config.group == 'root' assert config.mode == 0o644 def test_services(Service): """ Tests if all the necessary services are enabled and running. """ service = Service('postfix') assert service.is_running assert service.is_enabled def test_firewall_configuration_file(File, Sudo): """ Tests if firewall configuration file has correct permissions. """ with Sudo(): config = File('/etc/ferm/conf.d/20-mail.conf') assert config.is_file assert config.user == 'root' assert config.group == 'root' assert config.mode == 0o640