Files
@ c8d4251a6ea5
Branch filter:
Location: majic-ansible-roles/roles/ldap_server/molecule/default/tests/test_default.py
c8d4251a6ea5
5.0 KiB
text/x-python
MAR-131: Added support for specifying Python version in wsgi_website role:
- Introduced additional role parameter for specifying the Python
version.
- Updated tests to verify new functionality.
- Fixed existing tests to account for differences between Python 2 and
Python 3 - including changes to WSGI test applications.
- Updated documentation, documenting new parameter and fixing one
minor typo.
- Updated release notes.
- Bumped default version of Gunicorn/futures used.
- Introduced additional role parameter for specifying the Python
version.
- Updated tests to verify new functionality.
- Fixed existing tests to account for differences between Python 2 and
Python 3 - including changes to WSGI test applications.
- Updated documentation, documenting new parameter and fixing one
minor typo.
- Updated release notes.
- Bumped default version of Gunicorn/futures used.
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 | import os
import testinfra.utils.ansible_runner
testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner(
os.environ['MOLECULE_INVENTORY_FILE']).get_hosts(['parameters-mandatory', 'parameters-optional'])
def test_installed_packages(host):
"""
Tests if all the necessary packages have been installed.
"""
assert host.package('slapd').is_installed
assert host.package('python-ldap').is_installed
def test_ldap_user_group(host):
"""
Tests if LDAP server user is part of group that allows it to traverse TLS
private keys directory.
"""
assert "ssl-cert" in host.user('openldap').groups
def test_ldap_server_service_sockets_and_ports(host):
"""
Tests if LDAP server has been configured to listen on correct sockets.
"""
assert host.socket('tcp://389').is_listening
assert host.socket('tcp://636').is_listening
assert host.socket('unix:///var/run/slapd/ldapi').is_listening
def test_ldap_server_service(host):
"""
Tests if the LDAP service is enabled and running.
"""
service = host.service('slapd')
assert service.is_enabled
assert service.is_running
def test_syslog_configuration(host):
"""
Tests if syslog configuration file has been deployed, and log file was
created correctly (and is being logged to).
"""
config = host.file('/etc/rsyslog.d/slapd.conf')
assert config.is_file
assert config.user == 'root'
assert config.group == 'root'
assert config.mode == 0o644
with host.sudo():
log = host.file('/var/log/slapd.log')
assert log.is_file
assert 'slapd' in log.content
def test_log_rotation_configuration(host):
"""
Tests if log rotation configuration file has been deployed correctly and has
valid syntax.
"""
config = host.file('/etc/logrotate.d/slapd')
assert config.is_file
assert config.user == 'root'
assert config.group == 'root'
assert config.mode == 0o644
with host.sudo():
assert host.run('logrotate /etc/logrotate.d/slapd').rc == 0
def test_misc_schema_presence(host):
"""
Tests if the misc LDAP schema has been imported.
"""
with host.sudo():
misc_schema = host.run('ldapsearch -H ldapi:/// -Q -LLL -Y EXTERNAL -b cn=config dn')
assert misc_schema.rc == 0
assert 'dn: cn={4}misc,cn=schema,cn=config' in misc_schema.stdout
def test_memberof_module(host):
"""
Tests if the memberof overlay has been enabled for the main database.
"""
with host.sudo():
memberof = host.run('ldapsearch -H ldapi:/// -Q -LLL -Y EXTERNAL -b cn=config dn')
assert memberof.rc == 0
assert 'dn: olcOverlay={0}memberof,olcDatabase={1}mdb,cn=config' in memberof.stdout
def test_basic_directory_structure(host):
"""
Tests if the base LDAP directory structure has been set-up correctly.
"""
with host.sudo():
ous = ["people", "groups", "services"]
for ou in ous:
entry = host.run('ldapsearch -H ldapi:/// -Q -LLL -Y EXTERNAL -s base -b ou=%s,dc=local' % ou)
assert entry.rc == 0
assert entry.stdout == """dn: ou=%(ou)s,dc=local
objectClass: organizationalUnit
ou: %(ou)s""" % {'ou': ou}
def test_mail_service_entries(host):
"""
Tests if the mail service entries have been set-up correctly.
"""
with host.sudo():
entry = host.run('ldapsearch -H ldapi:/// -Q -LLL -Y EXTERNAL -s base -b ou=mail,ou=services,dc=local')
assert entry.rc == 0
assert entry.stdout == """dn: ou=mail,ou=services,dc=local
objectClass: organizationalUnit
ou: mail"""
entry = host.run('ldapsearch -H ldapi:/// -Q -LLL -Y EXTERNAL -s base -b ou=domains,ou=mail,ou=services,dc=local')
assert entry.rc == 0
assert entry.stdout == """dn: ou=domains,ou=mail,ou=services,dc=local
objectClass: organizationalUnit
ou: domains"""
entry = host.run('ldapsearch -H ldapi:/// -Q -LLL -Y EXTERNAL -s base -b ou=aliases,ou=mail,ou=services,dc=local')
assert entry.rc == 0
assert entry.stdout == """dn: ou=aliases,ou=mail,ou=services,dc=local
objectClass: organizationalUnit
ou: aliases"""
def test_firewall_configuration_file(host):
"""
Tests if firewall configuration file has been deployed correctly.
"""
with host.sudo():
config = host.file('/etc/ferm/conf.d/10-ldap.conf')
assert config.is_file
assert config.user == 'root'
assert config.group == 'root'
assert config.mode == 0o640
def test_admin_password(host):
"""
Tests if administrator password has been set correctly.
"""
login = host.run("ldapwhoami -H ldapi:/// -x -w adminpassword -D cn=admin,dc=local")
assert login.rc == 0
assert login.stdout == "dn:cn=admin,dc=local"
def test_temporary_admin_password_file_not_present(host):
"""
Tests if the file that temporarily contains the LDAP adminstrator password
has been removed.
"""
with host.sudo():
assert not host.file('/root/.ldap_admin_password').exists
|