diff --git a/roles/mail_server/molecule/default/tests/test_client2.py b/roles/mail_server/molecule/default/tests/test_client2.py index 4fd73af06e42c29d1f176471dd35ac460e76d2fc..6e70bb5b6f92d63bef532b68cc34b2eb078661dd 100644 --- a/roles/mail_server/molecule/default/tests/test_client2.py +++ b/roles/mail_server/molecule/default/tests/test_client2.py @@ -1,6 +1,8 @@ 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