Changeset - 774d8236fa12
[Not reviewed]
0 1 0
Branko Majic (branko) - 4 years ago 2021-01-12 22:24:31
branko@majic.rs
MAR-163: Refactor the test_imap_authentication_requires_tls test:

- Parametrise the tests.
- Reduce code duplication.
- Make the host.run invocation slightly safer (currently it does not
matter, but it looks nicer this way).
1 file changed with 12 insertions and 16 deletions:
0 comments (0 inline, 0 general)
roles/mail_server/molecule/default/tests/test_client2.py
Show inline comments
 
import os
 
import re
 

	
 
import pytest
 

	
 
import testinfra.utils.ansible_runner
 

	
 

	
 
@@ -188,35 +190,29 @@ def test_dovecot_inbox_separator(host):
 
    assert pattern_dot_separator.search(status.stdout) is not None
 

	
 

	
 
def test_imap_authentication_requires_tls(host):
 
@pytest.mark.parametrize("server", [
 
    "parameters-mandatory",
 
    "parameters-optional"
 
])
 
def test_imap_authentication_requires_tls(host, server):
 
    """
 
    Tests if IMAP authentication requires TLS.
 
    """
 

	
 
    # No TLS.
 
    command = host.run("echo -e 'a0001 CAPABILITY\na0002 LOGOUT' | nc parameters-mandatory 143")
 
    assert command.rc == 0
 
    assert "LOGINDISABLED" in command.stdout
 
    capabilities_command = "a0001 CAPABILITY\na0002 LOGOUT"
 

	
 
    command = host.run("echo -e 'a0001 CAPABILITY\na0002 LOGOUT' | nc parameters-optional 143")
 
    # No TLS.
 
    command = host.run("echo %s | nc %s 143", capabilities_command, server)
 
    assert command.rc == 0
 
    assert "LOGINDISABLED" in command.stdout
 

	
 
    # STARTTLS.
 
    command = host.run("echo -e 'a0001 CAPABILITY\na0002 LOGOUT' | openssl s_client -quiet -connect parameters-mandatory:143 -starttls imap")
 
    assert command.rc == 0
 
    assert "LOGINDISABLED" not in command.stdout
 

	
 
    command = host.run("echo -e 'a0001 CAPABILITY\na0002 LOGOUT' | openssl s_client -quiet -connect parameters-optional:143 -starttls imap")
 
    command = host.run("echo %s | openssl s_client -quiet -connect %s:143 -starttls imap", capabilities_command, server)
 
    assert command.rc == 0
 
    assert "LOGINDISABLED" not in command.stdout
 

	
 
    # TLS.
 
    command = host.run("echo -e 'a0001 CAPABILITY\na0002 LOGOUT' | openssl s_client -quiet -connect parameters-mandatory:993")
 
    assert command.rc == 0
 
    assert "LOGINDISABLED" not in command.stdout
 

	
 
    command = host.run("echo -e 'a0001 CAPABILITY\na0002 LOGOUT' | openssl s_client -quiet -connect parameters-optional:993")
 
    command = host.run("echo %s | openssl s_client -quiet -connect %s:993", capabilities_command, server)
 
    assert command.rc == 0
 
    assert "LOGINDISABLED" not in command.stdout
 

	
0 comments (0 inline, 0 general)