Files @ 17cf34f73ca6
Branch filter:

Location: majic-ansible-roles/roles/database/tests/test_default.py

branko
MAR-28: Implemented additional tests for mail_server role:

- Deploy a number of tools on clients in order to test SMTP, IMAP, and Sieve
services.
- Added one more user to LDAP directory for testing group restrictions.
- Deploy CA certificate on all testing machines for TLS validation purposes.
- Use different custom-configured cipher for mail server ciphers.
- Fixed invalid postmaster address for parameters-optional host.
- Deploy configuration files for use with Imap-CLI on client test machines.
- Updated testing of SMTP server to include checks for users that do not belong
to mail group.
- Extended some SMTP-related tests to cover both test servers.
- Some small fixes in SMTP-related tests for expected output from commands.
- Implemented tests covering Dovecot (IMAP + Sieve) functionality.
- Implemented tests for running/enabled services.
- Implemented tests for ClamAV.
- Implemented tests for firewall and connectivity.
- Implemented tests for Postfix TLS configuration.
- TODO: Tests for Sieve TLS configuration have not been written yet due to
limitation of available tools.
import testinfra.utils.ansible_runner

testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner(
    '.molecule/ansible_inventory').get_hosts('all')


def test_database_created(Command, Sudo):
    """
    Tests if database has been created.
    """

    with Sudo():
        show_databases = Command("mysql -BNe \"show databases like 'testdb'\"")

        assert show_databases.rc == 0
        assert show_databases.stdout == "testdb"


def test_database_user_login(Command):
    """
    Tests database user login.
    """

    login = Command("mysql -utestdb -ptestdbpassword -BNe 'show databases'")

    assert login.rc == 0


def test_database_user_permissions(Command, Sudo):
    """
    Tests if database user has been granted correct permissions on the database.
    """

    visible_databases = Command("mysql -utestdb -ptestdbpassword -BNe 'show databases'")

    assert visible_databases.rc == 0
    assert visible_databases.stdout == "information_schema\ntestdb"

    with Sudo():
        permissions = Command("mysql -BNe 'show grants for testdb@localhost'")
        assert len(permissions.stdout.split("\n")) == 2
        assert "GRANT USAGE ON *.* TO 'testdb'@'localhost' IDENTIFIED BY PASSWORD '*676852B7FAE972722AD20D6E74781D6B1A100544'" in permissions.stdout.split("\n")
        assert "GRANT ALL PRIVILEGES ON `testdb`.* TO 'testdb'@'localhost'" in permissions.stdout.split("\n")