Changeset - 315128d98063
[Not reviewed]
0 3 0
Branko Majic (branko) - 4 years ago 2020-09-16 15:52:59
branko@majic.rs
MAR-158: Deduplicate tests in web server role:

- Deduplicate test for certificate validity check configuration
deployment.
- Deduplicate test for checking if TLS is enabled or not.
3 files changed with 28 insertions and 50 deletions:
0 comments (0 inline, 0 general)
roles/web_server/molecule/default/tests/test_default.py
Show inline comments
 
@@ -300,3 +300,31 @@ def test_nginx_tls_files(host):
 
        assert tls_file.group == 'root'
 
        assert tls_file.mode == 0o644
 
        assert tls_file.content_string == open("tests/data/x509/server/%s_https.cert.pem" % hostname, "r").read().rstrip()
 

	
 

	
 
def test_certificate_validity_check_configuration(host):
 
    """
 
    Tests if certificate validity check configuration file has been deployed
 
    correctly.
 
    """
 

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

	
 
    config = host.file('/etc/check_certificate/%s_https.conf' % hostname)
 
    assert config.is_file
 
    assert config.user == 'root'
 
    assert config.group == 'root'
 
    assert config.mode == 0o644
 
    assert config.content_string == "/etc/ssl/certs/%s_https.pem" % hostname
 

	
 

	
 
def test_tls_enabled(host):
 
    """
 
    Tests if TLS has been enabled.
 
    """
 

	
 
    hostname = host.run('hostname').stdout.strip()
 
    fqdn = hostname[:hostname.rfind('-')]
 

	
 
    tls = host.run('wget -q -O - https://%s/', fqdn)
 
    assert tls.rc == 0
roles/web_server/molecule/default/tests/test_mandatory.py
Show inline comments
 
@@ -7,31 +7,6 @@ testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner(
 
    os.environ['MOLECULE_INVENTORY_FILE']).get_hosts('parameters-mandatory')
 

	
 

	
 
def test_certificate_validity_check_configuration(host):
 
    """
 
    Tests if certificate validity check configuration file has been deployed
 
    correctly.
 
    """
 

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

	
 
    config = host.file('/etc/check_certificate/%s_https.conf' % hostname)
 
    assert config.is_file
 
    assert config.user == 'root'
 
    assert config.group == 'root'
 
    assert config.mode == 0o644
 
    assert config.content_string == "/etc/ssl/certs/%s_https.pem" % hostname
 

	
 

	
 
def test_tls_enabled(host):
 
    """
 
    Tests if TLS has been enabled.
 
    """
 

	
 
    tls = host.run('wget -q -O - https://parameters-mandatory/')
 
    assert tls.rc == 0
 

	
 

	
 
def test_tls_version(host):
 
    """
 
    Tests if only the configured TLS protocol versions are allowed by
roles/web_server/molecule/default/tests/test_optional.py
Show inline comments
 
@@ -7,31 +7,6 @@ testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner(
 
    os.environ['MOLECULE_INVENTORY_FILE']).get_hosts('parameters-optional')
 

	
 

	
 
def test_certificate_validity_check_configuration(host):
 
    """
 
    Tests if certificate validity check configuration file has been deployed
 
    correctly.
 
    """
 

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

	
 
    config = host.file('/etc/check_certificate/%s_https.conf' % hostname)
 
    assert config.is_file
 
    assert config.user == 'root'
 
    assert config.group == 'root'
 
    assert config.mode == 0o644
 
    assert config.content_string == "/etc/ssl/certs/%s_https.pem" % hostname
 

	
 

	
 
def test_tls_enabled(host):
 
    """
 
    Tests if TLS has been enabled.
 
    """
 

	
 
    tls = host.run('wget -q -O - https://parameters-optional/')
 
    assert tls.rc == 0
 

	
 

	
 
def test_tls_version(host):
 
    """
 
    Tests if only the configured TLS protocol versions are allowed by
0 comments (0 inline, 0 general)