Changeset - 226882a5ed41
[Not reviewed]
0 4 0
Branko Majic (branko) - 4 years ago 2020-01-06 23:56:34
branko@majic.rs
MAR-148: Fixed tests for the mail_server role:

- Implement small workaround for sieve-connect invocations (due to
special treatment of 255 exit code by Testinfra itself).
- Fixed a couple of newline-related errors coming from command
outputs.
4 files changed with 32 insertions and 21 deletions:
0 comments (0 inline, 0 general)
roles/mail_server/molecule/default/tests/test_client2.py
Show inline comments
 
@@ -236,10 +236,21 @@ def test_sieve_authentication_requires_tls(host):
 
    assert "PLAIN LOGIN" not in command.stdout
 

	
 
    # STARTTLS
 
    command = host.run("echo 'johnpassword' | sieve-connect -u john.doe@domain1 --password 0 --server parameters-mandatory --port 4190 --list")
 
    # @TODO: In case of failed login (authentication rejected),
 
    #        sieve-connect will return error code 255. However,
 
    #        internally Testinfra treats error code as if it is a
 
    #        signal from the SSH (over which the command is being run)
 
    #        that the SSH itself has failed, and throws a runtime
 
    #        exception. The use of || //bin/false is a workaround for
 
    #        now. It would be a good idea to get in contact with
 
    #        Testinfra maintainer and raise an issue around
 
    #        this. There are more similar uses of sieve-connect in the
 
    #        test files, don't forget to update those as well if some
 
    #        kind of better solution pops-up.
 
    command = host.run("echo 'johnpassword' | sieve-connect -u john.doe@domain1 --password 0 --server parameters-mandatory --port 4190 --list || /bin/false")
 
    assert command.rc == 0
 

	
 
    command = host.run("echo 'johnpassword' | sieve-connect -u john.doe@domain1 --password 0 --server parameters-optional --port 4190 --list")
 
    command = host.run("echo 'johnpassword' | sieve-connect -u john.doe@domain1 --password 0 --server parameters-optional --port 4190 --list || /bin/false")
 
    assert command.rc == 0
 

	
 

	
 
@@ -289,17 +300,17 @@ def test_dovecot_sieve(host):
 
    """
 

	
 
    # Test valid users.
 
    command = host.run('echo johnpassword | sieve-connect --list -s parameters-mandatory -p 4190 -u john.doe@domain1 --password 0')
 
    command = host.run('echo johnpassword | sieve-connect --list -s parameters-mandatory -p 4190 -u john.doe@domain1 --password 0 || /bin/false')
 
    assert command.rc == 0
 

	
 
    command = host.run('echo janepassword | sieve-connect --list -s parameters-optional -p 4190 -u jane.doe@domain2 --password 0')
 
    command = host.run('echo janepassword | sieve-connect --list -s parameters-optional -p 4190 -u jane.doe@domain2 --password 0 || /bin/false')
 
    assert command.rc == 0
 

	
 
    # Test invalid users.
 
    command = host.run('echo johnpassword | sieve-connect --list -s parameters-mandatory -p 4190 -u john.doe@domain2 --password 0')
 
    command = host.run('echo johnpassword | sieve-connect --list -s parameters-mandatory -p 4190 -u john.doe@domain2 --password 0 || /bin/false' )
 
    assert command.rc != 0
 
    assert "Authentication refused by server" in command.stderr
 

	
 
    command = host.run('echo janepassword | sieve-connect --list -s parameters-optional -p 4190 -u jane.doe@domain1 --password 0')
 
    command = host.run('echo janepassword | sieve-connect --list -s parameters-optional -p 4190 -u jane.doe@domain1 --password 0 || /bin/false')
 
    assert command.rc != 0
 
    assert "Authentication refused by server" in command.stderr
roles/mail_server/molecule/default/tests/test_default.py
Show inline comments
 
@@ -162,11 +162,11 @@ def test_postfix_ldap_configuration(host):
 
        # Test for valid domains.
 
        command = host.run("postmap -q domain1 ldap:/etc/postfix/ldap-virtual-mailbox-domains.cf")
 
        assert command.rc == 0
 
        assert command.stdout == "domain1"
 
        assert command.stdout == "domain1\n"
 

	
 
        command = host.run("postmap -q domain2 ldap:/etc/postfix/ldap-virtual-mailbox-domains.cf")
 
        assert command.rc == 0
 
        assert command.stdout == "domain2"
 
        assert command.stdout == "domain2\n"
 

	
 
        # Test for invalid domains.
 
        command = host.run("postmap -q domain3 ldap:/etc/postfix/ldap-virtual-mailbox-domains.cf")
 
@@ -176,11 +176,11 @@ def test_postfix_ldap_configuration(host):
 
        # Test for valid mail addresses.
 
        command = host.run("postmap -q 'john.doe@domain1' ldap:/etc/postfix/ldap-virtual-mailbox-maps.cf")
 
        assert command.rc == 0
 
        assert command.stdout == 'john.doe@domain1'
 
        assert command.stdout == 'john.doe@domain1\n'
 

	
 
        command = host.run("postmap -q 'jane.doe@domain2' ldap:/etc/postfix/ldap-virtual-mailbox-maps.cf")
 
        assert command.rc == 0
 
        assert command.stdout == 'jane.doe@domain2'
 
        assert command.stdout == 'jane.doe@domain2\n'
 

	
 
        # Test for invalid mail addresses.
 
        command = host.run("postmap -q 'jane.doe@domain1' ldap:/etc/postfix/ldap-virtual-mailbox-maps.cf")
 
@@ -199,11 +199,11 @@ def test_postfix_ldap_configuration(host):
 
        # Test for valid mail aliases.
 
        command = host.run("postmap -q postmaster@domain1 ldap:/etc/postfix/ldap-virtual-alias-maps.cf")
 
        assert command.rc == 0
 
        assert command.stdout == "john.doe@domain1"
 
        assert command.stdout == "john.doe@domain1\n"
 

	
 
        command = host.run("postmap -q webmaster@domain2 ldap:/etc/postfix/ldap-virtual-alias-maps.cf")
 
        assert command.rc == 0
 
        assert command.stdout == "jane.doe@domain2"
 
        assert command.stdout == "jane.doe@domain2\n"
 

	
 
        # Test for invalid mail aliases.
 
        command = host.run("postmap -q postmaster@domain2 ldap:/etc/postfix/ldap-virtual-alias-maps.cf")
 
@@ -232,7 +232,7 @@ def test_postfix_delivery_to_dovecot(host):
 
    Tests if mail received by Postfix is properly delivered to Dovecot.
 
    """
 

	
 
    hostname = host.run('hostname').stdout
 
    hostname = host.run('hostname').stdout.strip()
 

	
 
    message_id = str(uuid.uuid4())
 

	
roles/mail_server/molecule/default/tests/test_mandatory.py
Show inline comments
 
@@ -12,7 +12,7 @@ def test_smtp_tls_files(host):
 
    Tests if SMTP TLS private key has been deployed correctly.
 
    """
 

	
 
    hostname = host.run('hostname').stdout
 
    hostname = host.run('hostname').stdout.strip()
 

	
 
    with host.sudo():
 

	
 
@@ -51,7 +51,7 @@ def test_certificate_validity_check_configuration(host):
 
    correctly.
 
    """
 

	
 
    hostname = host.run('hostname').stdout
 
    hostname = host.run('hostname').stdout.strip()
 

	
 
    config = host.file('/etc/check_certificate/%s_smtp.conf' % hostname)
 
    assert config.is_file
 
@@ -74,7 +74,7 @@ def test_mailname_file_content(host):
 
    """
 

	
 
    mailname = host.file('/etc/mailname')
 
    hostname = host.run('hostname').stdout
 
    hostname = host.run('hostname').stdout.strip()
 

	
 
    assert mailname.content == hostname
 

	
 
@@ -84,7 +84,7 @@ def test_postfix_main_cf_file_content(host):
 
    Tests if the Postfix main configuration file content is correct.
 
    """
 

	
 
    hostname = host.run('hostname').stdout
 
    hostname = host.run('hostname').stdout.strip()
 

	
 
    config = host.file('/etc/postfix/main.cf')
 
    config_lines = config.content.split("\n")
roles/mail_server/molecule/default/tests/test_optional.py
Show inline comments
 
@@ -14,7 +14,7 @@ def test_smtp_tls_files(host):
 
    Tests if SMTP TLS private key has been deployed correctly.
 
    """
 

	
 
    hostname = host.run('hostname').stdout
 
    hostname = host.run('hostname').stdout.strip()
 

	
 
    with host.sudo():
 

	
 
@@ -53,7 +53,7 @@ def test_certificate_validity_check_configuration(host):
 
    correctly.
 
    """
 

	
 
    hostname = host.run('hostname').stdout
 
    hostname = host.run('hostname').stdout.strip()
 

	
 
    config = host.file('/etc/check_certificate/%s_smtp.conf' % hostname)
 
    assert config.is_file
 
@@ -76,7 +76,7 @@ def test_mailname_file_content(host):
 
    """
 

	
 
    mailname = host.file('/etc/mailname')
 
    hostname = host.run('hostname').stdout
 
    hostname = host.run('hostname').stdout.strip()
 

	
 
    assert mailname.content == hostname
 

	
 
@@ -94,7 +94,7 @@ def test_postfix_main_cf_file_content(host):
 
    elif distribution_release == "stretch":
 
        allow_relay_from_ip = "10.31.127.22"
 

	
 
    hostname = host.run('hostname').stdout
 
    hostname = host.run('hostname').stdout.strip()
 

	
 
    config = host.file('/etc/postfix/main.cf')
 
    config_lines = config.content.split("\n")
0 comments (0 inline, 0 general)