Files
@ 277c561f3f52
Branch filter:
Location: majic-ansible-roles/roles/mail_server/tests/test_default.py - annotation
277c561f3f52
7.4 KiB
text/x-python
MAR-28: Impelmented general and SMTP-related tests for mail_server:
- Increased amount of memory in test instances to 768MB.
- Fixed playbook for runs against client test instances.
- Fixed typos and invalid settings in test playbook.
- Switched to expanded syntax in tasks used for deploying TLS keys and
certificates in order to avoid mangling of TAB characters.
- Fixed missing permissions set-up for Postfix main configuration file.
- Fixed deployment of Postfix master.cf configuration file to take into account
configurable virtual mail user.
- Implemented tests covering SMTP functionality.
- Increased amount of memory in test instances to 768MB.
- Fixed playbook for runs against client test instances.
- Fixed typos and invalid settings in test playbook.
- Switched to expanded syntax in tasks used for deploying TLS keys and
certificates in order to avoid mangling of TAB characters.
- Fixed missing permissions set-up for Postfix main configuration file.
- Fixed deployment of Postfix master.cf configuration file to take into account
configurable virtual mail user.
- Implemented tests covering SMTP functionality.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 | 277c561f3f52 277c561f3f52 0004ec73b902 0004ec73b902 277c561f3f52 0004ec73b902 277c561f3f52 277c561f3f52 277c561f3f52 277c561f3f52 277c561f3f52 277c561f3f52 277c561f3f52 277c561f3f52 277c561f3f52 277c561f3f52 277c561f3f52 277c561f3f52 277c561f3f52 277c561f3f52 277c561f3f52 277c561f3f52 277c561f3f52 277c561f3f52 277c561f3f52 277c561f3f52 277c561f3f52 277c561f3f52 277c561f3f52 277c561f3f52 277c561f3f52 277c561f3f52 277c561f3f52 277c561f3f52 277c561f3f52 277c561f3f52 277c561f3f52 277c561f3f52 277c561f3f52 277c561f3f52 277c561f3f52 277c561f3f52 277c561f3f52 277c561f3f52 277c561f3f52 277c561f3f52 277c561f3f52 277c561f3f52 277c561f3f52 277c561f3f52 277c561f3f52 277c561f3f52 277c561f3f52 277c561f3f52 277c561f3f52 277c561f3f52 277c561f3f52 277c561f3f52 277c561f3f52 277c561f3f52 277c561f3f52 277c561f3f52 277c561f3f52 277c561f3f52 277c561f3f52 277c561f3f52 277c561f3f52 277c561f3f52 277c561f3f52 277c561f3f52 277c561f3f52 277c561f3f52 277c561f3f52 277c561f3f52 277c561f3f52 277c561f3f52 277c561f3f52 277c561f3f52 277c561f3f52 277c561f3f52 277c561f3f52 277c561f3f52 277c561f3f52 277c561f3f52 277c561f3f52 277c561f3f52 277c561f3f52 277c561f3f52 277c561f3f52 277c561f3f52 277c561f3f52 277c561f3f52 277c561f3f52 277c561f3f52 277c561f3f52 277c561f3f52 277c561f3f52 277c561f3f52 277c561f3f52 277c561f3f52 277c561f3f52 277c561f3f52 277c561f3f52 277c561f3f52 277c561f3f52 277c561f3f52 277c561f3f52 277c561f3f52 277c561f3f52 277c561f3f52 277c561f3f52 277c561f3f52 277c561f3f52 277c561f3f52 277c561f3f52 277c561f3f52 277c561f3f52 277c561f3f52 277c561f3f52 277c561f3f52 277c561f3f52 277c561f3f52 277c561f3f52 277c561f3f52 277c561f3f52 277c561f3f52 277c561f3f52 277c561f3f52 277c561f3f52 277c561f3f52 277c561f3f52 277c561f3f52 277c561f3f52 277c561f3f52 277c561f3f52 277c561f3f52 277c561f3f52 277c561f3f52 277c561f3f52 277c561f3f52 277c561f3f52 277c561f3f52 277c561f3f52 277c561f3f52 277c561f3f52 277c561f3f52 277c561f3f52 277c561f3f52 277c561f3f52 277c561f3f52 277c561f3f52 277c561f3f52 277c561f3f52 277c561f3f52 277c561f3f52 277c561f3f52 277c561f3f52 277c561f3f52 277c561f3f52 277c561f3f52 277c561f3f52 277c561f3f52 277c561f3f52 277c561f3f52 277c561f3f52 277c561f3f52 277c561f3f52 277c561f3f52 277c561f3f52 277c561f3f52 277c561f3f52 277c561f3f52 277c561f3f52 277c561f3f52 277c561f3f52 277c561f3f52 277c561f3f52 277c561f3f52 277c561f3f52 277c561f3f52 277c561f3f52 277c561f3f52 277c561f3f52 277c561f3f52 277c561f3f52 277c561f3f52 277c561f3f52 277c561f3f52 277c561f3f52 277c561f3f52 277c561f3f52 277c561f3f52 277c561f3f52 277c561f3f52 277c561f3f52 277c561f3f52 277c561f3f52 277c561f3f52 277c561f3f52 277c561f3f52 277c561f3f52 277c561f3f52 277c561f3f52 277c561f3f52 277c561f3f52 277c561f3f52 277c561f3f52 277c561f3f52 277c561f3f52 277c561f3f52 277c561f3f52 277c561f3f52 277c561f3f52 277c561f3f52 277c561f3f52 277c561f3f52 277c561f3f52 277c561f3f52 277c561f3f52 277c561f3f52 277c561f3f52 0004ec73b902 277c561f3f52 277c561f3f52 277c561f3f52 277c561f3f52 0004ec73b902 277c561f3f52 277c561f3f52 277c561f3f52 277c561f3f52 0004ec73b902 277c561f3f52 277c561f3f52 277c561f3f52 277c561f3f52 | import re
import testinfra.utils.ansible_runner
testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner(
'.molecule/ansible_inventory').get_hosts(['parameters-mandatory', 'parameters-optiona'])
def test_installed_packages(Package):
"""
Tests if the necessary packages have been installed.
"""
assert Package('rsync').is_installed
assert Package('dovecot-imapd').is_installed
assert Package('dovecot-ldap').is_installed
assert Package('dovecot-sieve').is_installed
assert Package('dovecot-managesieved').is_installed
assert Package('postfix').is_installed
assert Package('postfix-ldap').is_installed
assert Package('swaks').is_installed
assert Package('clamav-milter').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_postfix_user(User):
"""
Tests if Postfix user has been added to correct group for traversing the TLS
private key directory.
"""
assert "ssl-cert" in User('postfix').groups
def test_dovecot_user(User):
"""
Tests if Dovecot user has been added to correct group for traversing the TLS
private key directory.
"""
assert "ssl-cert" in User('dovecot').groups
def test_clamav_milter_configuration(File):
"""
Tests if ClamAV Milter configuration has been deployed correctly.
"""
config = File('/etc/clamav/clamav-milter.conf')
assert config.is_file
assert config.user == 'root'
assert config.group == 'root'
assert config.mode == 0o644
def test_clamav_milter(Command):
"""
Tests if ClamAV milter is blocking viruses.
"""
server_did_not_accept_mail = 26
eicar = 'X5O!P%@AP[4\PZX54(P^)7CC)7}$EICAR-STANDARD-ANTIVIRUS-TEST-FILE!$H+H*'
send_mail = Command("swaks --to john.doe@domain1 --server localhost --attach '%s'" % eicar)
assert send_mail.rc == server_did_not_accept_mail
assert 'Your message has been rejected due to a possible virus' in send_mail.stdout
def test_postfix_chroot_directories(File):
"""
Tests if Postfix chroot directories have been set-up with correct
permissions.
"""
directory = File('/var/spool/postfix/var')
assert directory.is_directory
assert directory.user == 'root'
assert directory.group == 'root'
assert directory.mode == 0o755
directory = File('/var/spool/postfix/var/run')
assert directory.is_directory
assert directory.user == 'root'
assert directory.group == 'root'
assert directory.mode == 0o755
directory = File('/var/spool/postfix/var/run/clamav')
assert directory.is_directory
assert directory.user == 'clamav'
assert directory.group == 'clamav'
assert directory.mode == 0o755
def test_ldap_tls_truststore_file(File):
"""
Tests if the LDAP TLS truststore file has been deployed correctly.
"""
tls_file = File('/etc/ssl/certs/mail_ldap_tls_truststore.pem')
assert tls_file.is_file
assert tls_file.user == 'root'
assert tls_file.group == 'root'
assert tls_file.mode == 0o644
assert tls_file.content == open("tests/data/x509/ca.cert.pem", "r").read().rstrip()
tls_file = File('/var/spool/postfix/etc/ssl/certs/mail_ldap_tls_truststore.pem')
assert tls_file.is_file
assert tls_file.user == 'root'
assert tls_file.group == 'root'
assert tls_file.mode == 0o644
assert tls_file.content == open("tests/data/x509/ca.cert.pem", "r").read().rstrip()
def test_mailname_file(File):
"""
Tests the system mail name file permissions.
"""
mailname = File('/etc/mailname')
assert mailname.is_file
assert mailname.user == 'root'
assert mailname.group == 'root'
assert mailname.mode == 0o644
def test_postfix_ldap_configuration_files(File):
"""
Tests if Postfix LDAP configuration files have been deployed correctly.
"""
for config_file_path in ['/etc/postfix/ldap-virtual-alias-maps.cf',
'/etc/postfix/ldap-virtual-mailbox-domains.cf',
'/etc/postfix/ldap-virtual-mailbox-maps.cf']:
config = File(config_file_path)
assert config.is_file
assert config.user == 'root'
assert config.group == 'postfix'
assert config.mode == 0o640
def test_postfix_ldap_configuration(Command, Sudo):
"""
Tests if LDAP configuration can be used to fetch correct query results.
"""
with Sudo():
# Test for valid domains.
command = Command("postmap -q domain1 ldap:/etc/postfix/ldap-virtual-mailbox-domains.cf")
assert command.rc == 0
assert command.stdout == "domain1"
command = Command("postmap -q domain2 ldap:/etc/postfix/ldap-virtual-mailbox-domains.cf")
assert command.rc == 0
assert command.stdout == "domain2"
# Test for invalid domains.
command = Command("postmap -q domain3 ldap:/etc/postfix/ldap-virtual-mailbox-domains.cf")
assert command.rc == 1
assert command.stdout == ""
# Test for valid mail addresses.
command = Command("postmap -q 'john.doe@domain1' ldap:/etc/postfix/ldap-virtual-mailbox-maps.cf")
assert command.rc == 0
assert command.stdout == 'john.doe@domain1'
command = Command("postmap -q 'jane.doe@domain2' ldap:/etc/postfix/ldap-virtual-mailbox-maps.cf")
assert command.rc == 0
assert command.stdout == 'jane.doe@domain2'
# Test for invalid mail addresses.
command = Command("postmap -q 'jane.doe@domain1' ldap:/etc/postfix/ldap-virtual-mailbox-maps.cf")
assert command.rc == 1
assert command.stdout == ''
command = Command("postmap -q 'john.doe@domain2' ldap:/etc/postfix/ldap-virtual-mailbox-maps.cf")
assert command.rc == 1
assert command.stdout == ''
# Test for valid mail aliases.
command = Command("postmap -q postmaster@domain1 ldap:/etc/postfix/ldap-virtual-alias-maps.cf")
assert command.rc == 0
assert command.stdout == "john.doe@domain1"
command = Command("postmap -q webmaster@domain2 ldap:/etc/postfix/ldap-virtual-alias-maps.cf")
assert command.rc == 0
assert command.stdout == "jane.doe@domain2"
# Test for invalid mail aliases.
command = Command("postmap -q postmaster@domain2 ldap:/etc/postfix/ldap-virtual-alias-maps.cf")
assert command.rc == 1
assert command.stdout == ""
command = Command("postmap -q webmaster@domain1 ldap:/etc/postfix/ldap-virtual-alias-maps.cf")
assert command.rc == 1
assert command.stdout == ""
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_postfix_delivery_to_dovecot(Command, File, Sudo):
"""
Tests if mail received by Postfix is properly delivered to Dovecot.
"""
# Virtual account.
send = Command('swaks --suppress-data --to john.doe@domain1 --server parameters-mandatory')
assert send.rc == 0
message_id = re.search('Ok: queued as (.*)', send.stdout).group(1)
with Sudo():
mail_log = File('/var/log/mail.log')
pattern = "dovecot: lda\(john.doe@domain1\): msgid=<[^.]*.%s@[^>]*>: saved mail to INBOX" % message_id
assert re.search(pattern, mail_log.content) is not None
|