def test_positive_crud_tailoringfile(self, module_org, module_location, tailoring_file_path): """Perform end to end testing for oscap tailoring files component :id: 2441988f-2054-49f7-885e-3675336f712f :expectedresults: All expected CRUD actions finished successfully :CaseImportance: Critical """ name = gen_string('alpha') new_name = gen_string('alpha') original_filename = gen_string('alpha') scap = entities.TailoringFile( name=name, scap_file=tailoring_file_path, organization=[module_org], location=[module_location], ).create() assert entities.TailoringFile().search(query={'search': f'name={name}'}) result = entities.TailoringFile(id=scap.id).read() assert result.name == name assert result.location[0].id == module_location.id assert result.organization[0].id == module_org.id scap = entities.TailoringFile( id=scap.id, name=new_name, original_filename=f'{original_filename}' ).update() result = entities.TailoringFile(id=scap.id).read() assert result.name == new_name assert result.original_filename == original_filename assert entities.TailoringFile().search(query={'search': f'name={new_name}'}) entities.TailoringFile(id=scap.id).delete() assert not entities.TailoringFile().search(query={'search': f'name={new_name}'})
def tailoring_file(module_org, module_location, tailoring_file_path): """ Create Tailoring file.""" tf_name = gen_string('alpha') entity = entities.TailoringFile().search( query={'search': f'name="{tf_name}"'}) if not entity: result = entities.TailoringFile( name=f"{tf_name}", scap_file=f"{tailoring_file_path}", organization=[module_org], location=[module_location], ).create() else: result = entities.TailoringFile(id=entity[0].id).read() tailor_profile_id = result.tailoring_file_profiles[0]['id'] return (result, tailor_profile_id)
def tailoring_file(module_org, module_location, tailoring_file_path): """ Create Tailoring file.""" tailoring_file_name = f"tailoring-file-{gen_string('alpha')}" tf_info = entities.TailoringFile( name=f"{tailoring_file_name}", scap_file=f"{tailoring_file_path['local']}", organization=[module_org], location=[module_location], ).create() return { "name": tailoring_file_name, "tailoring_file_id": tf_info['id'], "tailoring_file_profile_id": tf_info.tailoring_file_profiles[0]['id'], }
def test_positive_end_to_end(session, tailoring_file_path, default_org, default_location): """Perform end to end testing for tailoring file component :id: 9aebccb8-6837-4583-8a8a-8883480ab688 :expectedresults: All expected CRUD actions finished successfully :CaseLevel: Integration """ name = gen_string('alpha') new_name = gen_string('alpha') with session: session.organization.select(org_name=default_org.name) session.location.select(loc_name=default_location.name) session.oscaptailoringfile.create({ 'file_upload.name': name, 'file_upload.scap_file': tailoring_file_path['local'], 'organizations.resources.assigned': [default_org.name], 'locations.resources.assigned': [default_location.name], }) assert session.oscaptailoringfile.search(name)[0]['Name'] == name tailroingfile_values = session.oscaptailoringfile.read(name) assert tailroingfile_values['file_upload']['name'] == name assert (tailroingfile_values['file_upload']['uploaded_scap_file'] == tailoring_file_path['local'].rsplit('/', 1)[-1]) assert default_org.name in tailroingfile_values['organizations'][ 'resources']['assigned'] assert default_location.name in tailroingfile_values['locations'][ 'resources']['assigned'] session.oscaptailoringfile.update(name, {'file_upload.name': new_name}) assert session.oscaptailoringfile.search( new_name)[0]['Name'] == new_name assert not session.oscaptailoringfile.search(name) session.oscaptailoringfile.delete(new_name) assert not entities.TailoringFile().search( query={'search': f'name={new_name}'})
def test_positive_end_to_end( session, module_host_group, default_location, default_org, oscap_content_path, tailoring_file_path, import_ansible_roles, ): """Perform end to end testing for oscap policy component :id: 39c26f89-3147-4f27-bf5e-810f0ba721d8 :expectedresults: All expected CRUD actions finished successfully :CaseLevel: Integration :CaseImportance: Critical """ name = '{} {}'.format(gen_string('alpha'), gen_string('alpha')) new_name = gen_string('alpha') description = gen_string('alpha') oscap_content_title = gen_string('alpha') tailoring_name = gen_string('alpha') profile_type = OSCAP_PROFILE['security7'] tailoring_type = OSCAP_PROFILE['tailoring_rhel7'] # Upload oscap content file entities.ScapContents( title=oscap_content_title, scap_file=oscap_content_path, organization=[default_org], location=[default_location], ).create() # Upload tailoring file entities.TailoringFile( name=tailoring_name, scap_file=tailoring_file_path['local'], organization=[default_org], location=[default_location], ).create() with session: session.organization.select(org_name=default_org.name) session.location.select(loc_name=default_location.name) # Create new oscap policy with assigned content and tailoring file session.oscappolicy.create( { 'deployment_options.deploy_by': 'ansible', 'policy_attributes.name': name, 'policy_attributes.description': description, 'scap_content.scap_content_resource': oscap_content_title, 'scap_content.xccdf_profile': profile_type, 'scap_content.tailoring_file': tailoring_name, 'scap_content.xccdf_profile_tailoring_file': tailoring_type, 'schedule.period': 'Monthly', 'schedule.period_selection.day_of_month': '5', 'locations.resources.assigned': [default_location.name], 'organizations.resources.assigned': [default_org.name], 'host_group.resources.assigned': [module_host_group.name], } ) assert session.oscappolicy.search(name)[0]['Name'] == name # Check that created entity has expected values oscappolicy_values = session.oscappolicy.read(name) assert oscappolicy_values['deployment_options']['deploy_by'] == 'ansible' assert oscappolicy_values['general']['name'] == name assert oscappolicy_values['general']['description'] == description assert oscappolicy_values['scap_content']['scap_content'] == oscap_content_title assert oscappolicy_values['scap_content']['xccdf_profile'] == profile_type assert oscappolicy_values['scap_content']['tailoring_file'] == tailoring_name assert oscappolicy_values['scap_content']['xccdf_profile_tailoring_file'] == tailoring_type assert oscappolicy_values['schedule']['period'] == 'Monthly' assert oscappolicy_values['schedule']['period_selection']['day_of_month'] == '5' assert default_location.name in oscappolicy_values['locations']['resources']['assigned'] assert default_org.name in oscappolicy_values['organizations']['resources']['assigned'] assert oscappolicy_values['host_group']['resources']['assigned'] == [module_host_group.name] # Update oscap policy with new name session.oscappolicy.update(name, {'general.name': new_name}) oscappolicy_values = session.oscappolicy.read(new_name) assert oscappolicy_values['general']['name'] == new_name assert not session.oscappolicy.search(name) # Delete oscap policy entity session.oscappolicy.delete(new_name) assert not session.oscappolicy.search(new_name)