Files @ 3dd7f39302f8
Branch filter:

Location: majic-ansible-roles/roles/xmpp_server/tests/test_mandatory.py - annotation

branko
MAR-29: Implemented tests for php_website role:

- Install some additional tools for testing everything.
- Updated test playbook to change allowed extensions for running PHP scripts on
parameters-optional.
- Updated error page to use correct extension for parameters-optional test
instance.
- Expanded rewrite configuration slightly for parameters-optional.
- Install libmariadb-client-lgpl-dev-compat to test mysql_config symlink
creation.
- Deploy a number of PHP pages used for testing if pages are served correctly.
- Set file permissions on deployed PHP FPM pool configuraiton files.
- Use expanded syntax when deploying TLS keys/certificates in order to avoid
issues with TAB mangling.
- Fixed set-up of Strict-Transport-Security header when HTTPS enforcement is
disabled.
- Added a number of PHP and static test pages.
- Wrote tests covering full functionality of the role.
import testinfra.utils.ansible_runner


testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner(
    '.molecule/ansible_inventory').get_hosts('parameters-mandatory.domain1')


def test_prosody_tls_files(File, Sudo):
    """
    Tests if Prosody TLS private key and certificage have been deployed
    correctly.
    """

    with Sudo():

        tls_file = File('/etc/ssl/private/parameters-mandatory.domain1_xmpp.key')
        assert tls_file.is_file
        assert tls_file.user == 'root'
        assert tls_file.group == 'prosody'
        assert tls_file.mode == 0o640
        assert tls_file.content == open("tests/data/x509/parameters-mandatory.domain1_xmpp.key", "r").read().rstrip()

        tls_file = File('/etc/ssl/certs/parameters-mandatory.domain1_xmpp.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/parameters-mandatory.domain1_xmpp.pem", "r").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-mandatory.domain1_xmpp.conf')
    assert config.is_file
    assert config.user == 'root'
    assert config.group == 'root'
    assert config.mode == 0o644
    assert config.content == "/etc/ssl/certs/parameters-mandatory.domain1_xmpp.pem"


def test_prosody_configuration_file_content(File, Sudo):
    """
    Tests if Prosody configuration file has correct content.
    """

    with Sudo():

        config = File('/etc/prosody/prosody.cfg.lua')

        assert "admins = { \"john.doe@domain1\",  }" in config.content
        assert "key = \"/etc/ssl/private/parameters-mandatory.domain1_xmpp.key\";" in config.content
        assert "certificate = \"/etc/ssl/certs/parameters-mandatory.domain1_xmpp.pem\";" in config.content
        assert "ldap_server = \"ldap-server\"" in config.content
        assert "ldap_rootdn = \"cn=prosody,ou=services,dc=local\"" in config.content
        assert "ldap_password = \"prosodypassword\"" in config.content
        assert "ldap_filter = \"(&(mail=$user@$host)(memberOf=cn=xmpp,ou=groups,dc=local))\"" in config.content
        assert "ldap_base = \"ou=people,dc=local\"" in config.content

        assert """VirtualHost "domain1"
Component "conference.domain1" "muc"
  restrict_room_creation = "local"
Component "proxy.domain1" "proxy65"
  proxy65_acl = { "domain1" }""" in config.content