Refactor security checklist test to another class

This will allow security checks to be logically separate from other
functional tests, and adhere to a similar design pattern that is
used in other charm tests (see nova [0]) for an example. It will also
highight which security checks are currently passing, and which are not.

[0] https://github.com/openstack-charmers/zaza-openstack-tests/blob/35840a66d6788dc4899847747ee7523895f46e1b/zaza/openstack/charm_tests/nova/tests.py#L485-L529

Partial-Bug: #1883196
This commit is contained in:
Garrett Thompson
2021-02-09 19:47:40 -08:00
parent 6cbcd0b126
commit 83e5dc798c
@@ -407,17 +407,6 @@ class OpenStackDashboardTests(test_utils.OpenStackBaseTest,
self.assertEqual(e.code, 404, msg)
logging.info('OK')
def test_501_security_checklist_action(self):
"""Verify expected result on a default install.
Ported from amulet tests.
"""
logging.info("Testing security-checklist")
unit_name = zaza_model.get_lead_unit_name('openstack-dashboard')
action = zaza_model.run_action(unit_name, 'security-checklist')
assert action.data.get(u"status") == "failed", \
"Security check is expected to not pass by default"
def test_900_restart_on_config_change(self):
"""Verify that the specified services are restarted on config changed.
@@ -520,3 +509,45 @@ class OpenStackDashboardPolicydTests(policyd.BasePolicydSpecialization,
result = client.get(_url)
if result.status_code == 403:
raise policyd.PolicydOperationFailedException("Not authenticated")
class SecurityTests(test_utils.OpenStackBaseTest,
OpenStackDashboardBase):
"""Openstack-dashboard security tests."""
@classmethod
def setUpClass(cls):
"""Run class setup for running openstack-dashboard SecurityTests."""
super(SecurityTests, cls).setUpClass()
def test_security_checklist(self):
"""Verify expected state with security checklist."""
logging.info("Testing security checklist.")
expected_failures = [
'csrf_cookie_set',
'disable_password_reveal',
'disallow-iframe-embed',
'password-validator-is-not-default',
'securie_proxy_ssl_header_is_set',
'session_cookie-httponly',
'session-cookie-store',
]
expected_passes = [
'disable_password_autocomplete',
'enforce-password-check',
'validate-file-ownership',
'validate-file-permissions'
]
logging.info('Running `security-checklist` action'
' on {} leader'.format(self.application_name))
test_utils.audit_assertions(
zaza_model.run_action_on_leader(
self.application_name,
'security-checklist',
model_name=self.model_name,
action_params={}),
expected_passes,
expected_failures,
expected_to_pass=False)