Skip to content

Commit

Permalink
make oscap tests run on rhel9 backend
Browse files Browse the repository at this point in the history
  • Loading branch information
pondrejk committed Apr 10, 2024
1 parent a13c05d commit 6cb4c72
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 41 deletions.
1 change: 1 addition & 0 deletions conf/oscap.yaml.template
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ OSCAP:
CONTENT_PATH: /usr/share/xml/scap/ssg/content/ssg-rhel7-ds.xml
# see: robottelo/constants/__init__.py OSCAP_PROFILE
PROFILE: security7
CONTENT_DIR: /usr/share/xml/scap/ssg/content
20 changes: 13 additions & 7 deletions pytest_fixtures/component/oscap.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,26 +20,32 @@ def tailoring_file_path(session_target_sat):


@pytest.fixture(scope="session")
def oscap_content_path(session_target_sat):
def oscap_content_source(session_target_sat):
"""Get scap content file path"""
return f'{settings.oscap.content_dir}/ssg-rhel{session_target_sat.os_distribution_version.split(".")[0]}-ds.xml'


@pytest.fixture(scope="session")
def oscap_content_path(session_target_sat, oscap_content_source):
"""Download scap content from satellite and return local path of it."""
local_file = robottelo_tmp_dir.joinpath(PurePath(settings.oscap.content_path).name)
session_target_sat.get(remote_path=settings.oscap.content_path, local_path=str(local_file))
local_file = robottelo_tmp_dir.joinpath(PurePath(oscap_content_source).name)
session_target_sat.get(remote_path=oscap_content_source, local_path=str(local_file))
return local_file


@pytest.fixture(scope="module")
def scap_content(import_ansible_roles, module_target_sat):
def scap_content(import_ansible_roles, module_target_sat, oscap_content_source):
title = f"rhel-content-{gen_string('alpha')}"
scap_info = module_target_sat.cli_factory.scapcontent(
{'title': title, 'scap-file': f'{settings.oscap.content_path}'}
{'title': title, 'scap-file': f'{oscap_content_source}'}
)
scap_id = scap_info['id']
scap_info = entities.ScapContents(id=scap_id).read()

scap_profile_id = [
profile['id']
for profile in scap_info.scap_content_profiles
if OSCAP_PROFILE[settings.oscap.profile] in profile['title']
if OSCAP_PROFILE[f'security{module_target_sat.os_distribution_version.split(".")[0]}']
in profile['title']
][0]
return {
"title": title,
Expand Down
5 changes: 5 additions & 0 deletions robottelo/constants/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1574,6 +1574,7 @@ class Colored(Box):
'rhel6_content': 'Red Hat rhel6 default content',
'rhel7_content': 'Red Hat rhel7 default content',
'rhel8_content': 'Red Hat rhel8 default content',
'rhel9_content': 'Red Hat rhel9 default content',
'rhel_firefox': 'Red Hat firefox default content',
}

Expand All @@ -1590,6 +1591,8 @@ class Colored(Box):
),
'security6': 'Standard System Security Profile for Red Hat Enterprise Linux 6',
'security7': 'Standard System Security Profile for Red Hat Enterprise Linux 7',
'security8': 'Standard System Security Profile for Red Hat Enterprise Linux 8',
'security9': 'CCN Red Hat Enterprise Linux 9 - Basic',
'cbrhel6': 'PCI-DSS v3.2.1 Control Baseline for Red Hat Enterprise Linux 6',
'cbrhel7': 'PCI-DSS v3.2.1 Control Baseline for Red Hat Enterprise Linux 7',
'cbrhel8': 'PCI-DSS v3.2.1 Control Baseline for Red Hat Enterprise Linux 8',
Expand Down Expand Up @@ -2060,6 +2063,8 @@ class Colored(Box):
EXPIRED_MANIFEST = 'expired-manifest.zip'

# Data File Paths


class DataFile(Box):
"""The boxed Data directory class with its attributes pointing to the Data directory files"""

Expand Down
58 changes: 35 additions & 23 deletions tests/foreman/cli/test_oscap.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
from nailgun import entities
import pytest

from robottelo.config import settings
from robottelo.constants import OSCAP_DEFAULT_CONTENT, OSCAP_PERIOD, OSCAP_WEEKDAY
from robottelo.exceptions import CLIFactoryError, CLIReturnCodeError
from robottelo.utils.datafactory import (
Expand Down Expand Up @@ -67,8 +66,10 @@ def test_positive_list_default_content_with_admin(self, module_target_sat):
:CaseImportance: Medium
"""
scap_contents = [content['title'] for content in module_target_sat.cli.Scapcontent.list()]
for title in OSCAP_DEFAULT_CONTENT.values():
assert title in scap_contents
assert (
f'Red Hat rhel{module_target_sat.os_distribution_version.split(".")[0]} default content'
in scap_contents
)

@pytest.mark.tier1
def test_negative_list_default_content_with_viewer_role(
Expand Down Expand Up @@ -105,7 +106,7 @@ def test_negative_list_default_content_with_viewer_role(
).info({'title': scap_content['title']})

@pytest.mark.tier1
def test_positive_view_scap_content_info_admin(self, module_target_sat):
def test_positive_view_scap_content_info_admin(self, module_target_sat, oscap_content_source):
"""View info of scap content with admin account
:id: 539ea982-0701-43f5-bb91-e566e6687e35
Expand All @@ -128,7 +129,7 @@ def test_positive_view_scap_content_info_admin(self, module_target_sat):
"""
title = gen_string('alpha')
module_target_sat.cli_factory.scapcontent(
{'title': title, 'scap-file': settings.oscap.content_path}
{'title': title, 'scap-file': oscap_content_source}
)
result = module_target_sat.cli.Scapcontent.info({'title': title})
assert result['title'] == title
Expand Down Expand Up @@ -161,7 +162,9 @@ def test_negative_info_scap_content(self, module_target_sat):

@pytest.mark.parametrize('title', **parametrized(valid_data_list()))
@pytest.mark.tier1
def test_positive_create_scap_content_with_valid_title(self, title, module_target_sat):
def test_positive_create_scap_content_with_valid_title(
self, title, module_target_sat, oscap_content_source
):
"""Create scap-content with valid title
:id: 68e9fbe2-e3c3-48e7-a774-f1260a3b7f4f
Expand All @@ -187,12 +190,14 @@ def test_positive_create_scap_content_with_valid_title(self, title, module_targe
:CaseImportance: Medium
"""
scap_content = module_target_sat.cli_factory.scapcontent(
{'title': title, 'scap-file': settings.oscap.content_path}
{'title': title, 'scap-file': oscap_content_source}
)
assert scap_content['title'] == title

@pytest.mark.tier1
def test_negative_create_scap_content_with_same_title(self, module_target_sat):
def test_negative_create_scap_content_with_same_title(
self, module_target_sat, oscap_content_source
):
"""Create scap-content with same title
:id: a8cbacc9-456a-4f6f-bd0e-4d1167a8b401
Expand Down Expand Up @@ -221,17 +226,19 @@ def test_negative_create_scap_content_with_same_title(self, module_target_sat):
"""
title = gen_string('alpha')
scap_content = module_target_sat.cli_factory.scapcontent(
{'title': title, 'scap-file': settings.oscap.content_path}
{'title': title, 'scap-file': oscap_content_source}
)
assert scap_content['title'] == title
with pytest.raises(CLIFactoryError):
module_target_sat.cli_factory.scapcontent(
{'title': title, 'scap-file': settings.oscap.content_path}
{'title': title, 'scap-file': oscap_content_source}
)

@pytest.mark.parametrize('title', **parametrized(invalid_names_list()))
@pytest.mark.tier1
def test_negative_create_scap_content_with_invalid_title(self, title, module_target_sat):
def test_negative_create_scap_content_with_invalid_title(
self, title, module_target_sat, oscap_content_source
):
"""Create scap-content with invalid title
:id: 90a2590e-a6ff-41f1-9e0a-67d4b16435c0
Expand All @@ -256,13 +263,13 @@ def test_negative_create_scap_content_with_invalid_title(self, title, module_tar
"""
with pytest.raises(CLIFactoryError):
module_target_sat.cli_factory.scapcontent(
{'title': title, 'scap-file': settings.oscap.content_path}
{'title': title, 'scap-file': oscap_content_source}
)

@pytest.mark.parametrize('name', **parametrized(valid_data_list()))
@pytest.mark.tier1
def test_positive_create_scap_content_with_valid_originalfile_name(
self, name, module_target_sat
self, name, module_target_sat, oscap_content_source
):
"""Create scap-content with valid original file name
Expand All @@ -288,14 +295,14 @@ def test_positive_create_scap_content_with_valid_originalfile_name(
"""
title = gen_string('alpha')
scap_content = module_target_sat.cli_factory.scapcontent(
{'original-filename': name, 'scap-file': settings.oscap.content_path, 'title': title}
{'original-filename': name, 'scap-file': oscap_content_source, 'title': title}
)
assert scap_content['original-filename'] == name

@pytest.mark.parametrize('name', **parametrized(invalid_names_list()))
@pytest.mark.tier1
def test_negative_create_scap_content_with_invalid_originalfile_name(
self, name, module_target_sat
self, name, module_target_sat, oscap_content_source
):
"""Create scap-content with invalid original file name
Expand Down Expand Up @@ -323,7 +330,7 @@ def test_negative_create_scap_content_with_invalid_originalfile_name(
"""
with pytest.raises(CLIFactoryError):
module_target_sat.cli_factory.scapcontent(
{'original-filename': name, 'scap-file': settings.oscap.content_path}
{'original-filename': name, 'scap-file': oscap_content_source}
)

@pytest.mark.parametrize('title', **parametrized(valid_data_list()))
Expand Down Expand Up @@ -354,7 +361,9 @@ def test_negative_create_scap_content_without_dsfile(self, title, module_target_
module_target_sat.cli_factory.scapcontent({'title': title})

@pytest.mark.tier1
def test_positive_update_scap_content_with_newtitle(self, module_target_sat):
def test_positive_update_scap_content_with_newtitle(
self, module_target_sat, oscap_content_source
):
"""Update scap content title
:id: 2c32e94a-237d-40b9-8a3b-fca2ef26fe79
Expand All @@ -379,15 +388,15 @@ def test_positive_update_scap_content_with_newtitle(self, module_target_sat):
title = gen_string('alpha')
new_title = gen_string('alpha')
scap_content = module_target_sat.cli_factory.scapcontent(
{'title': title, 'scap-file': settings.oscap.content_path}
{'title': title, 'scap-file': oscap_content_source}
)
assert scap_content['title'] == title
module_target_sat.cli.Scapcontent.update({'title': title, 'new-title': new_title})
result = module_target_sat.cli.Scapcontent.info({'title': new_title}, output_format='json')
assert result['title'] == new_title

@pytest.mark.tier1
def test_positive_delete_scap_content_with_id(self, module_target_sat):
def test_positive_delete_scap_content_with_id(self, module_target_sat, oscap_content_source):
"""Delete a scap content with id as parameter
:id: 11ae7652-65e0-4751-b1e0-246b27919238
Expand All @@ -409,14 +418,14 @@ def test_positive_delete_scap_content_with_id(self, module_target_sat):
"""
title = gen_string('alpha')
scap_content = module_target_sat.cli_factory.scapcontent(
{'scap-file': settings.oscap.content_path, 'title': title}
{'scap-file': oscap_content_source, 'title': title}
)
module_target_sat.cli.Scapcontent.delete({'id': scap_content['id']})
with pytest.raises(CLIReturnCodeError):
module_target_sat.cli.Scapcontent.info({'id': scap_content['id']})

@pytest.mark.tier1
def test_positive_delete_scap_content_with_title(self, module_target_sat):
def test_positive_delete_scap_content_with_title(self, module_target_sat, oscap_content_source):
"""Delete a scap content with title as parameter
:id: aa4ca830-3250-4517-b40c-0256cdda5e0a
Expand All @@ -440,7 +449,7 @@ def test_positive_delete_scap_content_with_title(self, module_target_sat):
"""
title = gen_string('alpha')
scap_content = module_target_sat.cli_factory.scapcontent(
{'scap-file': settings.oscap.content_path, 'title': title}
{'scap-file': oscap_content_source, 'title': title}
)
module_target_sat.cli.Scapcontent.delete({'title': scap_content['title']})
with pytest.raises(CLIReturnCodeError):
Expand Down Expand Up @@ -920,7 +929,10 @@ def test_positive_update_scap_policy_with_content(self, scap_content, module_tar
)
assert scap_policy['scap-content-id'] == scap_content["scap_id"]
scap_id, scap_profile_id = self.fetch_scap_and_profile_id(
OSCAP_DEFAULT_CONTENT['rhel_firefox'], module_target_sat
OSCAP_DEFAULT_CONTENT[
f'rhel{module_target_sat.os_distribution_version.split(".")[0]}_content'
],
module_target_sat,
)
module_target_sat.cli.Scappolicy.update(
{'name': name, 'scap-content-id': scap_id, 'scap-content-profile-id': scap_profile_id}
Expand Down
11 changes: 0 additions & 11 deletions tests/foreman/ui/test_oscapcontent.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,13 @@
:CaseImportance: High
"""
import os

import pytest

from robottelo.config import robottelo_tmp_dir, settings
from robottelo.constants import DataFile
from robottelo.utils.datafactory import gen_string


@pytest.fixture(scope='module')
def oscap_content_path(module_target_sat):
_, file_name = os.path.split(settings.oscap.content_path)

local_file = robottelo_tmp_dir.joinpath(file_name)
module_target_sat.get(remote_path=settings.oscap.content_path, local_path=str(local_file))
return local_file


@pytest.mark.skip_if_open("BZ:2167937")
@pytest.mark.skip_if_open("BZ:2133151")
@pytest.mark.tier1
Expand Down

0 comments on commit 6cb4c72

Please sign in to comment.