Files
@ 24033bb8b1a5
Branch filter:
Location: majic-ansible-roles/roles/xmpp_server/molecule/default/tests/test_default.py
24033bb8b1a5
9.3 KiB
text/x-python
MAR-173: Added test for validating the list of enabled modules in Prosody.
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 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 | import os
import testinfra.utils.ansible_runner
testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner(
os.environ['MOLECULE_INVENTORY_FILE']).get_hosts('parameters-*')
def test_supporting_packages_installed(host):
"""
Tests if all the necessary supporting packages have been
installed.
"""
assert host.package('python-apt').is_installed
assert host.package('lua-ldap').is_installed
def test_prosody_apt_key(host):
"""
Tests if Prosody repository signing key has been imported.
"""
keys = host.run("apt-key adv --fingerprint --fingerprint prosody")
assert "107D 65A0 A148 C237 FDF0 0AB4 7393 D7E6 74D9 DBB5" in keys.stdout
assert "44AB 6DD0 6DA4 6979 CFAF 997F 9B1B 8278 6C8F 28BA" in keys.stdout
def test_prosody_repository(host):
"""
Tests if Prosody repository has been added.
"""
repository = host.file("/etc/apt/sources.list.d/packages_prosody_im_debian.list")
distribution_release = host.ansible("setup")["ansible_facts"]["ansible_distribution_release"]
expected_content = "deb http://packages.prosody.im/debian %s main\n" % distribution_release
assert repository.is_file
assert repository.user == 'root'
assert repository.group == 'root'
assert repository.mode == 0o644
assert repository.content_string == expected_content
def test_prosody_user(host):
"""
Tests if Prosody user has been set-up correctly to access TLS material.
"""
assert 'ssl-cert' in host.user('prosody').groups
def test_prosody_modules_directory(host):
"""
Tests if directory for storing additional Prosody modules is set-up
correctly.
"""
directory = host.file('/usr/local/lib/prosody/modules')
assert directory.is_directory
assert directory.user == 'root'
assert directory.group == 'root'
assert directory.mode == 0o755
def test_prosody_mod_auth_ldap(host):
"""
Tests if Prosody module mod_auth_ldap has been deployed correctly.
"""
module = host.file('/usr/local/lib/prosody/modules/mod_auth_ldap.lua')
assert module.is_file
assert module.user == 'root'
assert module.group == 'root'
assert module.mode == 0o644
assert 'module:provides("auth", provider);' in module.content_string
assert 'mod_auth_ldap' in module.content_string
def test_prosody_configuration_file(host):
"""
Tests if Prosody configuration file has correct permissions.
"""
with host.sudo():
config = host.file('/etc/prosody/prosody.cfg.lua')
assert config.is_file
assert config.user == 'root'
assert config.group == 'prosody'
assert config.mode == 0o640
def test_services(host):
"""
Tests if services are enabled and running.
"""
service = host.service('prosody')
assert service.is_enabled
assert service.is_running
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/30-xmpp.conf')
assert config.is_file
assert config.user == 'root'
assert config.group == 'root'
assert config.mode == 0o640
def test_xmpp_server_dh_parameters_file(host):
"""
Tests if the Diffie-Hellman parameter file has been generated
correctly.
"""
fqdn = host.run('hostname -f').stdout.strip()
dhparam_file_path = '/etc/ssl/private/%s_xmpp.dh.pem' % fqdn
with host.sudo():
dhparam_file = host.file(dhparam_file_path)
assert dhparam_file.is_file
assert dhparam_file.user == 'root'
assert dhparam_file.group == 'prosody'
assert dhparam_file.mode == 0o640
dhparam_info = host.run("openssl dhparam -noout -text -in %s", dhparam_file_path)
assert "DH Parameters: (2048 bit)" in dhparam_info.stdout
def test_prosody_tls_files(host):
"""
Tests if Prosody TLS private key and certificage have been deployed
correctly.
"""
hostname = host.run('hostname -f').stdout.strip()
with host.sudo():
tls_file = host.file('/etc/ssl/private/%s_xmpp.key' % hostname)
assert tls_file.is_file
assert tls_file.user == 'root'
assert tls_file.group == 'prosody'
assert tls_file.mode == 0o640
assert tls_file.content_string == open("tests/data/x509/server/%s_xmpp.key.pem" % hostname, "r").read().rstrip()
tls_file = host.file('/etc/ssl/certs/%s_xmpp.pem' % hostname)
assert tls_file.is_file
assert tls_file.user == 'root'
assert tls_file.group == 'root'
assert tls_file.mode == 0o644
assert tls_file.content_string == open("tests/data/x509/server/%s_xmpp.cert.pem" % hostname, "r").read().rstrip()
def test_certificate_validity_check_configuration(host):
"""
Tests if certificate validity check configuration file has been deployed
correctly.
"""
hostname = host.run('hostname').stdout.strip()
config = host.file('/etc/check_certificate/%s_xmpp.conf' % hostname)
assert config.is_file
assert config.user == 'root'
assert config.group == 'root'
assert config.mode == 0o644
assert config.content_string == "/etc/ssl/certs/%s_xmpp.pem" % hostname
def test_xmpp_server_uses_correct_dh_parameters(host):
"""
Tests if the HTTP server uses the generated Diffie-Hellman parameter.
"""
fqdn = host.run('hostname -f').stdout.strip()
# Use first defined domain for testing.
domain = host.ansible.get_variables()['xmpp_domains'][0]
with host.sudo():
expected_dhparam = host.file('/etc/ssl/private/%s_xmpp.dh.pem' % fqdn).content_string.rstrip()
connection = host.run("gnutls-cli --no-ca-verification --starttls-proto=xmpp --port 5222 "
"--priority 'NONE:+VERS-TLS1.2:+CTYPE-X509:+COMP-NULL:+SIGN-RSA-SHA384:+DHE-RSA:+SHA384:+AEAD:+AES-256-GCM' --verbose %s", domain)
output = connection.stdout
begin_marker = "-----BEGIN DH PARAMETERS-----"
end_marker = "-----END DH PARAMETERS-----"
used_dhparam = output[output.find(begin_marker):output.find(end_marker) + len(end_marker)]
assert used_dhparam == expected_dhparam
def test_tls_connectivity(host):
"""
Tests if it is possible to connect to the XMPP server using
STARTTLS/TLS.
"""
# Use first defined domain for testing.
domain = host.ansible.get_variables()['xmpp_domains'][0]
starttls = host.run('echo "test" | openssl s_client -quiet -starttls xmpp -xmpphost %s -connect localhost:5222', domain)
assert starttls.rc == 0
assert 'jabber:client' in starttls.stdout
assert 'not-well-formed' in starttls.stdout
tls = host.run('echo "test" | openssl s_client -quiet -connect %s:5223', domain)
assert tls.rc == 0
assert 'jabber:client' in starttls.stdout
assert 'not-well-formed' in starttls.stdout
s2s = host.run('echo "test" | openssl s_client -quiet -starttls xmpp-server -xmpphost %s -connect localhost:5222', domain)
assert s2s.rc == 0
assert 'jabber:client' in s2s.stdout
assert 'not-well-formed' in s2s.stdout
def test_backports_repository(host):
"""
Tests if backports repository has been added.
"""
repository = host.file("/etc/apt/sources.list.d/backports.list")
distribution_release = host.ansible("setup")["ansible_facts"]["ansible_distribution_release"]
expected_content = "deb http://ftp.debian.org/debian %s-backports main\n" % distribution_release
assert repository.is_file
assert repository.user == 'root'
assert repository.group == 'root'
assert repository.mode == 0o644
assert repository.content_string == expected_content
def test_lua_ldap_pin_and_version(host):
"""
Tests if lua-ldap package has been correctly pinned to the
backports repository.
"""
distribution_major_version = host.ansible("setup")["ansible_facts"]["ansible_distribution_major_version"]
backports_version_suffix = "bpo%s" % distribution_major_version
pin_configuration_file = host.file("/etc/apt/preferences.d/lua-ldap")
lua_ldap = host.package("lua-ldap")
assert pin_configuration_file.is_file
assert pin_configuration_file.user == 'root'
assert pin_configuration_file.group == 'root'
assert pin_configuration_file.mode == 0o644
assert backports_version_suffix in lua_ldap.version
def test_prosody_configuration_validity(host):
"""
Tests the Prosody configuration file using the 'prosodyctl check'
command.
"""
with host.sudo():
check_config = host.run("prosodyctl check config")
assert check_config.rc == 0, check_config.stdout
def test_enabled_modules(host):
"""
Tests if correct modules have been enabled.
"""
expected_modules = [
"admin_adhoc",
"announce",
"dialback",
"disco",
"legacyauth",
"pep",
"ping",
"posix",
"private",
"register",
"roster",
"saslauth",
"time",
"tls",
"uptime",
"vcard",
"version",
]
with host.sudo():
module_list_command = host.run("/usr/local/bin/list_prosody_modules.lua")
enabled_modules = sorted(module_list_command.stdout.strip().splitlines())
assert enabled_modules == expected_modules
# @TODO: Tests which were not implemented due to lack of out-of-box tools:
#
# - Proxy capability.
# - MUC.
# - Server administration through XMPP.
|