diff --git a/conf/oscap.yaml.template b/conf/oscap.yaml.template index f23ec46ffb9..53a28fc9fe4 100644 --- a/conf/oscap.yaml.template +++ b/conf/oscap.yaml.template @@ -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 diff --git a/pytest_fixtures/component/oscap.py b/pytest_fixtures/component/oscap.py index 786788914f2..f0bb642f396 100644 --- a/pytest_fixtures/component/oscap.py +++ b/pytest_fixtures/component/oscap.py @@ -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, diff --git a/robottelo/constants/__init__.py b/robottelo/constants/__init__.py index 8bda8f3e777..3da68f4cacc 100644 --- a/robottelo/constants/__init__.py +++ b/robottelo/constants/__init__.py @@ -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', } @@ -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', @@ -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""" diff --git a/tests/foreman/cli/test_oscap.py b/tests/foreman/cli/test_oscap.py index c198e5fa636..f01f8e15869 100644 --- a/tests/foreman/cli/test_oscap.py +++ b/tests/foreman/cli/test_oscap.py @@ -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 ( @@ -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( @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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())) @@ -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 @@ -379,7 +388,7 @@ 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}) @@ -387,7 +396,7 @@ def test_positive_update_scap_content_with_newtitle(self, module_target_sat): 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 @@ -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 @@ -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): @@ -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} diff --git a/tests/foreman/ui/test_oscapcontent.py b/tests/foreman/ui/test_oscapcontent.py index 5669fb9e854..cb580c4c857 100644 --- a/tests/foreman/ui/test_oscapcontent.py +++ b/tests/foreman/ui/test_oscapcontent.py @@ -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