Files @ f428e318d2ca
Branch filter:

Location: majic-ansible-roles/roles/xmpp_server/molecule/default/tests/test_default.py

branko
MAR-162: Make the https_tls_certificate and https_tls_key parameters mandatory in wsgi_website role:

- Dropped the defaults from wsgi_server role.
- Updated group variables in role tests.
- Changed the key/certificate file extensions to be more descriptive.
- Updated role reference documentation.
- Updated usage instructions to include the mandatory parameters.
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-sec').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


# @TODO: Tests which were not implemented due to lack of out-of-box tools:
#
# - Proxy capability.
# - MUC.
# - Server administration through XMPP.