Exemplo n.º 1
0
    def test_positive_crud_scap_policy(self, module_org, module_location,
                                       scap_content, tailoring_file):
        """Perform end to end testing for oscap policy component

        :id: d0706e49-2a00-4495-86ea-1b53a6776b6f

        :expectedresults: All expected CRUD actions finished successfully

        :CaseLevel: Integration

        :CaseImportance: High
        """
        name = gen_string('alpha')
        new_name = gen_string('alpha')
        description = gen_string('alpha')
        hostgroup = entities.HostGroup(location=[module_location],
                                       organization=[module_org]).create()
        # Create new oscap policy with assigned content and tailoring file
        policy = entities.CompliancePolicies(
            name=name,
            deploy_by='puppet',
            description=description,
            scap_content_id=scap_content["scap_id"],
            scap_content_profile_id=scap_content["scap_profile_id"],
            tailoring_file_id=tailoring_file["tailoring_file_id"],
            tailoring_file_profile_id=tailoring_file[
                "tailoring_file_profile_id"],
            period="monthly",
            day_of_month="5",
            hostgroup=[hostgroup],
            location=[module_location],
            organization=[module_org],
        ).create()
        assert entities.CompliancePolicies().search(
            query={'search': f'name="{name}"'})
        # Check that created entity has expected values
        assert policy.deploy_by == 'puppet'
        assert policy.name == name
        assert policy.description == description
        assert str(policy.scap_content_id) == str(scap_content["scap_id"])
        assert str(policy.scap_content_profile_id) == str(
            scap_content["scap_profile_id"])
        assert str(policy.tailoring_file_id) == str(
            tailoring_file["tailoring_file_id"])
        assert policy.period == "monthly"
        assert int(policy.day_of_month) == 5
        assert str(policy.hostgroup[0].id) == str(hostgroup.id)
        assert str(policy.organization[0].id) == str(module_org.id)
        assert str(policy.location[0].id) == str(module_location.id)
        # Update oscap policy with new name
        policy = entities.CompliancePolicies(id=policy.id,
                                             name=new_name).update()
        assert policy.name == new_name
        assert not entities.CompliancePolicies().search(
            query={'search': f'name="{name}"'})
        # Delete oscap policy entity
        entities.CompliancePolicies(id=policy.id).delete()
        assert not entities.CompliancePolicies().search(
            query={'search': f'name="{new_name}"'})
Exemplo n.º 2
0
    def scap(content_type, content_name):
        """This function is used for deleting old scap contents and policy
        and it use create_policy for creating new policies.

        :param content_type: Search result of scap-content or compliance-policy entity.
        :param str content_name: Name assigned to searched entity.
        """
        for entity in range(len(content_type)):
            if content_name == "updated_scap_content":
                if updated_scap_content[entity].title == scap_content_name[0]:
                    create_policy(updated_scap_content[entity],
                                  compliance_policies[0])
                elif updated_scap_content[entity].title == scap_content_name[
                        1]:
                    create_policy(updated_scap_content[entity],
                                  compliance_policies[1])
            elif content_name == "policies_search":
                entities.CompliancePolicies(
                    id=policies_search[entity].id).delete()
            elif content_name == "scap_content_search":
                entities.ScapContents(
                    id=scap_content_search[entity].id).delete()
Exemplo n.º 3
0
    def create_policy(scap_content, policy_name):
        """This function is used for creating scap policy

        :param scap_content: Name of scap-content to be used while creating policy.
        :param str policy_name: Name of policy to be created.
        """
        org = entities.Organization().search(
            query={'search': 'name="{}"'.format("Default Organization")})[0]
        loc = entities.Location().search(
            query={'search': 'name="Default Location"'})[0]
        scap_content_profile_id = entities.ScapContents(
            id=scap_content.id).read().scap_content_profiles[0]['id']
        entities.CompliancePolicies(
            name=policy_name,
            scap_content_id=scap_content.id,
            scap_content_profile_id=scap_content_profile_id,
            deploy_by='puppet',
            organization=[org],
            location=[loc],
            period='weekly',
            weekday='monday',
        ).create()
Exemplo n.º 4
0
def update_scap_content():
    """ The purpose of this function is to perform deletion of old scap-contents
        and then uploading new scap-contents. It also deletes scap-policies and creates
         new scap-policies with new scap-contents. """
    def create_policy(scap_content, policy_name):
        """This function is used for creating scap policy

        :param scap_content: Name of scap-content to be used while creating policy.
        :param str policy_name: Name of policy to be created.
        """
        org = entities.Organization().search(
            query={'search': 'name="{}"'.format("Default Organization")})[0]
        loc = entities.Location().search(
            query={'search': 'name="Default Location"'})[0]
        scap_content_profile_id = entities.ScapContents(
            id=scap_content.id).read().scap_content_profiles[0]['id']
        entities.CompliancePolicies(
            name=policy_name,
            scap_content_id=scap_content.id,
            scap_content_profile_id=scap_content_profile_id,
            deploy_by='puppet',
            organization=[org],
            location=[loc],
            period='weekly',
            weekday='monday',
        ).create()

    def scap(content_type, content_name):
        """This function is used for deleting old scap contents and policy
        and it use create_policy for creating new policies.

        :param content_type: Search result of scap-content or compliance-policy entity.
        :param str content_name: Name assigned to searched entity.
        """
        for entity in range(len(content_type)):
            if content_name == "updated_scap_content":
                if updated_scap_content[entity].title == scap_content_name[0]:
                    create_policy(updated_scap_content[entity],
                                  compliance_policies[0])
                elif updated_scap_content[entity].title == scap_content_name[
                        1]:
                    create_policy(updated_scap_content[entity],
                                  compliance_policies[1])
            elif content_name == "policies_search":
                entities.CompliancePolicies(
                    id=policies_search[entity].id).delete()
            elif content_name == "scap_content_search":
                entities.ScapContents(
                    id=scap_content_search[entity].id).delete()

    compliance_policies = ['RHEL 7 policy', 'RHEL 6 policy']
    scap_content_name = [
        'Red Hat rhel7 default content', 'Red Hat rhel6 default content'
    ]
    scap_content_search = entities.ScapContents().search()
    policies_search = entities.CompliancePolicies().search()
    scap(policies_search, "policies_search")
    scap(scap_content_search, "scap_content_search")
    run('foreman-rake foreman_openscap:bulk_upload:default')
    updated_scap_content = entities.ScapContents().search()
    scap(updated_scap_content, "updated_scap_content")