Files
@ 01f4b619cfa6
Branch filter:
Location: majic-ansible-roles/roles/ldap_server/tests/test_optional.py
01f4b619cfa6
6.1 KiB
text/x-python
MAR-27: Update mail_forwarder role/tests:
- Install swaks on mail-server instance for testing SMTP.
- Install procmail via mail_forwarder role (needed to be explicit for Debian
Stretch).
- Introduce small sleep when mails are sent to localhost for delivery to remote
hosts before checking the logs in order to allow Postfix to process the
queue.
- Install swaks on mail-server instance for testing SMTP.
- Install procmail via mail_forwarder role (needed to be explicit for Debian
Stretch).
- Introduce small sleep when mails are sent to localhost for delivery to remote
hosts before checking the logs in order to allow Postfix to process the
queue.
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 | import testinfra.utils.ansible_runner
testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner(
'.molecule/ansible_inventory').get_hosts('parameters-optional')
def test_base_entry(Command, Sudo):
"""
Tests if the base entry has been created correctly.
"""
with Sudo():
base_dn = Command("ldapsearch -H ldapi:/// -Q -LLL -Y EXTERNAL -b dc=local -s base")
assert base_dn.rc == 0
assert "dc: local" in base_dn.stdout.split("\n")
assert "o: Example" in base_dn.stdout.split("\n")
def test_log_level(Command, Sudo):
"""
Tests if the logging level has been set correctly.
"""
with Sudo():
log_level = Command('ldapsearch -H ldapi:/// -Q -LLL -Y EXTERNAL -b cn=config -s base olcLogLevel')
assert log_level.rc == 0
assert 'olcLogLevel: 0' in log_level.stdout
def test_ldap_tls_private_key_file(File, Sudo):
"""
Tests if the TLS private key has been deployed correctly.
"""
with Sudo():
key = File('/etc/ssl/private/parameters-optional_ldap.key')
assert key.is_file
assert key.user == 'root'
assert key.group == 'openldap'
assert key.mode == 0o640
assert key.content == open('tests/data/x509/parameters-optional.key.pem').read().rstrip()
def test_ldap_tls_certificate_file(File, Sudo):
"""
Tests if the TLS certificate has been deployed correctly.
"""
with Sudo():
cert = File('/etc/ssl/certs/parameters-optional_ldap.pem')
assert cert.is_file
assert cert.user == 'root'
assert cert.group == 'root'
assert cert.mode == 0o644
assert cert.content == open('tests/data/x509/parameters-optional.cert.pem').read().rstrip()
def test_certificate_validity_check_configuration(File):
"""
Tests if certificate validity check configuration file has been deployed
correctly.
"""
config = File('/etc/check_certificate/parameters-optional_ldap.conf')
assert config.is_file
assert config.user == 'root'
assert config.group == 'root'
assert config.mode == 0o644
assert config.content == "/etc/ssl/certs/parameters-optional_ldap.pem"
def test_tls_configuration(Command):
"""
Tests if the TLS has been configured correctly and works.
"""
ldap_starttls = Command('ldapwhoami -Z -x -H ldap://parameters-optional/')
assert ldap_starttls.rc == 0
assert ldap_starttls.stdout == 'anonymous'
ldap_tls = Command('ldapwhoami -x -H ldaps://parameters-optional/')
assert ldap_tls.rc == 0
assert ldap_tls.stdout == 'anonymous'
old_tls_versions_disabled = Command("echo 'Q' | openssl s_client -no_tls1_2 -connect parameters-optional:636")
assert old_tls_versions_disabled.rc == 0
assert "CONNECTED" in old_tls_versions_disabled.stdout
cipher = Command("echo 'Q' | openssl s_client -cipher ECDHE-RSA-AES128-SHA256 -connect parameters-optional:636")
assert cipher.rc == 0
assert "ECDHE-RSA-AES128-SHA256" in cipher.stdout
cipher = Command("echo 'Q' | openssl s_client -tls1_1 -cipher ECDHE-RSA-AES128-SHA -connect parameters-optional:636")
assert cipher.rc == 0
assert "ECDHE-RSA-AES128-SHA" in cipher.stdout
def test_ssf_configuration(Command, Sudo):
"""
Tests if the SSF olcSecurity configuration has been set-up correctly.
"""
with Sudo():
ssf = Command('ldapsearch -H ldapi:/// -Q -LLL -Y EXTERNAL -b cn=config olcSecurity')
assert ssf.rc == 0
assert "olcSecurity: ssf=0" in ssf.stdout
def test_permissions(Command, Sudo):
"""
Tests if LDAP directory permissions have been set-up correctly.
"""
with Sudo():
permissions = Command("ldapsearch -o ldif-wrap=no -H ldapi:/// -Q -LLL -Y EXTERNAL -b 'olcDatabase={1}mdb,cn=config' -s base olcAccess olcAccess")
expected_permissions = "olcAccess: {0}to * " \
"by dn.exact=gidNumber=0+uidNumber=0,cn=peercred,cn=external,cn=auth manage " \
"by self write by * read by dn=\"cn=admin,dc=local\" write " \
"by * none"
assert permissions.rc == 0
assert expected_permissions in permissions.stdout
def test_services_login_entries(Command, Sudo):
"""
Tests if the service/consumer login entries have been set correctly.
"""
with Sudo():
entries = Command("ldapsearch -H ldapi:/// -Q -LLL -Y EXTERNAL -s one -b ou=services,dc=local '(objectClass=simpleSecurityObject)'")
assert entries.rc == 0
assert entries.stdout == """dn: cn=consumer1,ou=services,dc=local
objectClass: applicationProcess
objectClass: simpleSecurityObject
userPassword:: Y29uc3VtZXIxcGFzc3dvcmQ=
cn: consumer1
dn: cn=consumer2,ou=services,dc=local
objectClass: applicationProcess
objectClass: simpleSecurityObject
userPassword:: Y29uc3VtZXIycGFzc3dvcmQ=
cn: consumer2"""
def test_group_entries(Command, Sudo):
"""
Tests that no group entries have been created out-of-the-box.
"""
with Sudo():
entries = Command("ldapsearch -H ldapi:/// -Q -LLL -Y EXTERNAL -s one -b ou=groups,dc=local '(objectClass=groupOfUniqueNames)'")
assert entries.rc == 0
assert entries.stdout == """dn: cn=group1,ou=groups,dc=local
objectClass: groupOfUniqueNames
uniqueMember: cn=NONE
cn: group1
dn: cn=group2,ou=groups,dc=local
objectClass: groupOfUniqueNames
uniqueMember: cn=NONE
cn: group2"""
def test_user_supplied_entries(Command, Sudo):
"""
Tests if user-supplied entries are created correctly.
"""
with Sudo():
john_doe = Command("ldapsearch -H ldapi:/// -Q -LLL -Y EXTERNAL -s base -b uid=john,dc=local")
assert john_doe.rc == 0
assert john_doe.stdout == """dn: uid=john,dc=local
objectClass: inetOrgPerson
objectClass: simpleSecurityObject
userPassword:: am9obnBhc3N3b3Jk
cn: John Doe
sn: Doe
uid: john"""
jane_doe = Command("ldapsearch -H ldapi:/// -Q -LLL -Y EXTERNAL -s base -b uid=jane,dc=local")
assert jane_doe.rc == 0
assert jane_doe.stdout == """dn: uid=jane,dc=local
objectClass: inetOrgPerson
objectClass: simpleSecurityObject
userPassword:: amFuZXBhc3N3b3Jk
cn: Jane Doe
sn: Doe
uid: jane"""
|