Exemplo n.º 1
0
    def test_positive_delete_scap_content_with_title(self):
        """Delete a scap content with title as parameter

        :id: aa4ca830-3250-4517-b40c-0256cdda5e0a

        :setup:

            1. Oscap should be enabled.
            2. Oscap-cli hammer plugin installed.

        :steps:

            1. Login to hammer shell.
            2. Execute "scap-content" command with "delete" as sub-command.
            3. Pass name as parameter.

        :expectedresults: The scap-content is deleted successfully.

        :CaseAutomation: Automated

        :CaseImportance: Critical
        """
        scap_content = make_scapcontent(
            {'scap-file': settings.oscap.content_path})
        Scapcontent.delete({'title': scap_content['title']})
        with pytest.raises(CLIReturnCodeError):
            Scapcontent.info({'title': scap_content['title']})
Exemplo n.º 2
0
    def test_positive_delete_scap_policy_with_name(self):
        """Delete the scap policy with name as parameter

        :id: 6c167e7b-cbdd-4059-808c-04c686ba9fe8

        :setup:

            1. Oscap should be enabled.
            2. Oscap-cli hammer plugin installed.
            3. Atleast 1 policy.

        :steps:

            1. Login to hammer shell.
            2. Execute "policy" command with "delete" as sub-command.
            3. Pass name as parameter.

        :expectedresults: The scap policy is deleted successfully.
        """
        name = gen_string('alphanumeric')
        scap_policy = make_scap_policy({
            'name': name,
            'scap-content-id': self.scap_id_rhel6,
            'scap-content-profile-id': self.scap_profile_id_rhel6,
            'period': OSCAP_PERIOD['weekly'].lower(),
            'weekday': OSCAP_WEEKDAY['friday'].lower(),
        })
        self.assertEqual(scap_policy['name'], name)
        Scappolicy.delete({'name': name})
        with self.assertRaises(CLIReturnCodeError):
            Scapcontent.info({'name': scap_policy['name']})
Exemplo n.º 3
0
    def test_positive_delete_scap_content_with_id(self):
        """Delete a scap content with id as parameter

        :id: 11ae7652-65e0-4751-b1e0-246b27919238

        :setup:

            1. Oscap should be enabled.
            2. Oscap-cli hammer plugin installed.

        :steps:

            1. Login to hammer shell.
            2. Execute "scap-content" command with "delete" as sub-command.
            3. Pass ID as parameter.

        :expectedresults: The scap-content is deleted successfully.

        :CaseImportance: Critical
        """
        scap_content = make_scapcontent({
            'scap-file': '/tmp/{0}'.format(self.file_name)})
        Scapcontent.delete({'id': scap_content['id']})
        with self.assertRaises(CLIReturnCodeError):
            Scapcontent.info({'id': scap_content['id']})
Exemplo n.º 4
0
    def test_positive_delete_scap_content_with_title(self):
        """Delete a scap content with title as parameter

        :id: aa4ca830-3250-4517-b40c-0256cdda5e0a

        :setup:

            1. Oscap should be enabled.
            2. Oscap-cli hammer plugin installed.

        :steps:

            1. Login to hammer shell.
            2. Execute "scap-content" command with "delete" as sub-command.
            3. Pass name as parameter.

        :expectedresults: The scap-content is deleted successfully.

        :caseautomation: automated

        :CaseImportance: Critical
        """
        scap_content = make_scapcontent({
            'scap-file': '/tmp/{0}'.format(self.file_name)})
        Scapcontent.delete({'title': scap_content['title']})
        with self.assertRaises(CLIReturnCodeError):
            Scapcontent.info({'title': scap_content['title']})
Exemplo n.º 5
0
    def test_positive_delete_scap_policy_with_name(self):
        """Delete the scap policy with name as parameter

        :id: 6c167e7b-cbdd-4059-808c-04c686ba9fe8

        :setup:

            1. Oscap should be enabled.
            2. Oscap-cli hammer plugin installed.
            3. Atleast 1 policy.

        :steps:

            1. Login to hammer shell.
            2. Execute "policy" command with "delete" as sub-command.
            3. Pass name as parameter.

        :expectedresults: The scap policy is deleted successfully.
        """
        name = gen_string('alphanumeric')
        scap_policy = make_scap_policy(
            {
                'name': name,
                'deploy-by': 'puppet',
                'scap-content-id': self.scap_id_rhel7,
                'scap-content-profile-id': self.scap_profile_id_rhel7,
                'period': OSCAP_PERIOD['weekly'].lower(),
                'weekday': OSCAP_WEEKDAY['friday'].lower(),
            }
        )
        assert scap_policy['name'] == name
        Scappolicy.delete({'name': name})
        with pytest.raises(CLIReturnCodeError):
            Scapcontent.info({'name': scap_policy['name']})
Exemplo n.º 6
0
    def test_negative_info_scap_content(self):
        """View info of scap content with invalid ID as parameter

        :id: 86f44fb1-2e2b-4004-83c1-4a62162ebea9

        :setup:

            1. Oscap should be enabled.
            2. Default content should already be populated.
            3. Oscap-cli hammer plugin installed.

        :steps:

            1. Login to hammer shell as admin.
            2. Execute the "scap-content" command with info as sub-command.
            3. Pass invalid "ID" of scap-content as argument.

        :expectedresults: The info of the scap-content is not listed.

        :caseautomation: automated

        :CaseImportance: Critical
        """
        scap_id = gen_string('alphanumeric')
        with self.assertRaises(CLIReturnCodeError):
            Scapcontent.info({'id': scap_id})
Exemplo n.º 7
0
    def test_positive_delete_scap_content_with_id(self):
        """Delete a scap content with id as parameter

        :id: 11ae7652-65e0-4751-b1e0-246b27919238

        :setup:

            1. Oscap should be enabled.
            2. Oscap-cli hammer plugin installed.

        :steps:

            1. Login to hammer shell.
            2. Execute "scap-content" command with "delete" as sub-command.
            3. Pass ID as parameter.

        :expectedresults: The scap-content is deleted successfully.

        :CaseImportance: Critical
        """
        scap_content = make_scapcontent(
            {'scap-file': settings.oscap.content_path})
        Scapcontent.delete({'id': scap_content['id']})
        with pytest.raises(CLIReturnCodeError):
            Scapcontent.info({'id': scap_content['id']})
Exemplo n.º 8
0
    def test_positive_update_scap_content_with_newtitle(self):
        """Update scap content title

        :id: 2c32e94a-237d-40b9-8a3b-fca2ef26fe79

        :setup:

            1. Oscap should be enabled.
            2. Oscap-cli hammer plugin installed.

        :steps:

            1. Login to hammer shell.
            2. Execute "scap-content" command with "update" as sub-command.
            3. Pass valid parameters and newtitle parameter.

        :expectedresults: The scap-content is updated successfully.

        :CaseImportance: Critical
        """
        title = gen_string('alpha')
        new_title = gen_string('alpha')
        scap_content = make_scapcontent({
            'title': title,
            'scap-file': '/tmp/{0}'.format(self.file_name)})
        self.assertEqual(scap_content['title'], title)
        result = Scapcontent.update({
            'title': title,
            'new-title': new_title})
        if bz_bug_is_open(1496810):
            result = Scapcontent.info({'title': new_title})
        self.assertEqual(result['title'], new_title)
Exemplo n.º 9
0
    def test_positive_update_scap_content_with_newtitle(self):
        """Update scap content title

        :id: 2c32e94a-237d-40b9-8a3b-fca2ef26fe79

        :setup:

            1. Oscap should be enabled.
            2. Oscap-cli hammer plugin installed.

        :steps:

            1. Login to hammer shell.
            2. Execute "scap-content" command with "update" as sub-command.
            3. Pass valid parameters and newtitle parameter.

        :expectedresults: The scap-content is updated successfully.

        :CaseImportance: Critical

        :BZ: 1490302
        """
        title = gen_string('alpha')
        new_title = gen_string('alpha')
        scap_content = make_scapcontent({
            'title':
            title,
            'scap-file':
            settings.oscap.content_path
        })
        assert scap_content['title'] == title
        Scapcontent.update({'title': title, 'new-title': new_title})
        result = Scapcontent.info({'title': new_title}, output_format='json')
        assert result['title'] == new_title
Exemplo n.º 10
0
    def test_positive_view_scap_content_info_admin(self):
        """View info of scap content with admin account

        :id: 539ea982-0701-43f5-bb91-e566e6687e35

        :setup:

            1. Oscap should be enabled.
            2. Default content should already be populated.
            3. Oscap-cli hammer plugin installed.

        :steps:

            1. Login to hammer shell as admin.
            2. Execute the "scap-content" command with info as sub-command.
            3. Pass valid "ID" of scap-content as argument.

        :expectedresults: The info of the scap-content is listed.

        :CaseImportance: Critical
        """
        title = gen_string('alpha')
        make_scapcontent({
            'title': title,
            'scap-file': settings.oscap.content_path
        })
        result = Scapcontent.info({'title': title})
        assert result['title'] == title
Exemplo n.º 11
0
    def test_positive_update_scap_content_with_newtitle(self):
        """Update scap content title

        :id: 2c32e94a-237d-40b9-8a3b-fca2ef26fe79

        :setup:

            1. Oscap should be enabled.
            2. Oscap-cli hammer plugin installed.

        :steps:

            1. Login to hammer shell.
            2. Execute "scap-content" command with "update" as sub-command.
            3. Pass valid parameters and newtitle parameter.

        :expectedresults: The scap-content is updated successfully.

        :CaseImportance: Critical
        """
        title = gen_string('alpha')
        new_title = gen_string('alpha')
        scap_content = make_scapcontent({
            'title':
            title,
            'scap-file':
            '/tmp/{0}'.format(self.file_name)
        })
        self.assertEqual(scap_content['title'], title)
        result = Scapcontent.update({'title': title, 'new-title': new_title})
        if bz_bug_is_open(1496810):
            result = Scapcontent.info({'title': new_title},
                                      output_format='json')
        self.assertEqual(result['title'], new_title)
Exemplo n.º 12
0
def update_scap_content(module_org):
    """ Update default scap contents"""
    for content in rhel8_content, rhel7_content, rhel6_content:
        content = Scapcontent.info({'title': content}, output_format='json')
        organization_ids = [content_org['id'] for content_org in content.get('organizations', [])]
        organization_ids.append(module_org.id)
        Scapcontent.update({'title': content['title'], 'organization-ids': organization_ids})
Exemplo n.º 13
0
    def test_positive_view_scap_content_info_admin(self):
        """View info of scap content with admin account

        :id: 539ea982-0701-43f5-bb91-e566e6687e35

        :setup:

            1. Oscap should be enabled.
            2. Default content should already be populated.
            3. Oscap-cli hammer plugin installed.

        :steps:

            1. Login to hammer shell as admin.
            2. Execute the "scap-content" command with info as sub-command.
            3. Pass valid "ID" of scap-content as argument.

        :expectedresults: The info of the scap-content is listed.

        :CaseImportance: Critical
        """
        title = gen_string('alpha')
        make_scapcontent({
            'title': title,
            'scap-file': '/tmp/{0}'.format(self.file_name)})
        result = Scapcontent.info({'title': title})
        self.assertEqual(result['title'], title)
Exemplo n.º 14
0
    def test_negative_info_scap_content(self):
        """View info of scap content with invalid ID as parameter

        :id: 86f44fb1-2e2b-4004-83c1-4a62162ebea9

        :setup:

            1. Oscap should be enabled.
            2. Default content should already be populated.
            3. Oscap-cli hammer plugin installed.

        :steps:

            1. Login to hammer shell as admin.
            2. Execute the "scap-content" command with info as sub-command.
            3. Pass invalid "ID" of scap-content as argument.

        :expectedresults: The info of the scap-content is not listed.

        :CaseImportance: Critical
        """
        invalid_scap_id = gen_string('alpha')
        with pytest.raises(CLIReturnCodeError):
            Scapcontent.info({'id': invalid_scap_id})
Exemplo n.º 15
0
    def fetch_scap_and_profile_id(cls, scap_name, scap_profile):
        """Extracts the scap ID and scap profile id

        :param scap_name: Scap title
        :param scap_profile: Scap profile you want to select

        :returns: scap_id and scap_profile_id
        """
        default_content = Scapcontent.info({'title': scap_name}, output_format='json')
        scap_id = default_content['id']
        scap_profile_ids = [
            profile['id']
            for profile in default_content['scap-content-profiles']
            if scap_profile in profile['title']
        ]
        return scap_id, scap_profile_ids
Exemplo n.º 16
0
    def fetch_scap_and_profile_id(cls, scap_name, scap_profile):
        """Extracts the scap ID and scap profile id

        :param scap_name: Scap title
        :param scap_profile: Scap profile you want to select

        :returns: scap_id and scap_profile_id
        """
        default_content = Scapcontent.info({'title': scap_name})
        scap_id = default_content['id']
        scap_profile_ids = [
            profile['id']
            for profile in default_content['scap-content-profiles']
            if scap_profile in profile['title']
        ]
        return scap_id, scap_profile_ids
Exemplo n.º 17
0
def scap_content():
    oscap_content_path = settings.oscap.content_path
    _, file_name = os.path.split(oscap_content_path)
    title = 'rhel-content-{0}'.format(gen_string('alpha'))
    ssh.upload_file(local_file=oscap_content_path,
                    remote_file="/tmp/{0}".format(file_name))
    scap_info = make_scapcontent({
        'title': title,
        'scap-file': '/tmp/{0}'.format(file_name)
    })
    scap_id = scap_info['id']
    scap_info = Scapcontent.info({'id': scap_id}, output_format='json')

    scap_profile_id = [
        profile['id'] for profile in scap_info['scap-content-profiles']
        if OSCAP_PROFILE['common'] in profile['title']
    ][0]
    return scap_id, scap_profile_id
Exemplo n.º 18
0
def scap_content():
    oscap_content_path = settings.oscap.content_path
    _, file_name = os.path.split(oscap_content_path)
    title = 'rhel-content-{0}'.format(gen_string('alpha'))
    ssh.upload_file(
        local_file=oscap_content_path,
        remote_file="/tmp/{0}".format(file_name)
    )
    scap_info = make_scapcontent({
        'title': title,
        'scap-file': '/tmp/{0}'.format(file_name)
    })
    scap_id = scap_info['id']
    scap_info = Scapcontent.info({'id': scap_id}, output_format='json')

    scap_profile_id = [
        profile['id']
        for profile in scap_info['scap-content-profiles']
        if OSCAP_PROFILE['common'] in profile['title']
    ][0]
    return scap_id, scap_profile_id
Exemplo n.º 19
0
    def test_positive_associate_scap_policy_with_tailoringfiles(
            self, deploy, scap_content, tailoring_file_path):
        """Associate tailoring file by name/id to scap policy with all deployments

        :id: d0f9b244-b92d-4889-ba6a-8973ea05bf43

        :parametrized: yes

        :steps:

            1. Login to hammer shell.
            2. Execute "policy" command with "create" as sub-command.
            3. Pass valid parameters.
            4. Associate tailoring file by name/id with policy

        :expectedresults: The policy is created and associated successfully.
        """
        tailoring_file_a = make_tailoringfile(
            {'scap-file': tailoring_file_path['satellite']})
        tailoring_file_profile_a_id = tailoring_file_a[
            'tailoring-file-profiles'][0]['id']
        tailoring_file_b = make_tailoringfile(
            {'scap-file': tailoring_file_path['satellite']})
        tailoring_file_profile_b_id = tailoring_file_b[
            'tailoring-file-profiles'][0]['id']

        scap_policy = make_scap_policy({
            'scap-content-id':
            scap_content["scap_id"],
            'deploy-by':
            deploy,
            'scap-content-profile-id':
            scap_content["scap_profile_id"],
            'period':
            OSCAP_PERIOD['weekly'].lower(),
            'weekday':
            OSCAP_WEEKDAY['friday'].lower(),
            'tailoring-file':
            tailoring_file_a['name'],
            'tailoring-file-profile-id':
            tailoring_file_profile_a_id,
        })
        assert scap_policy['deployment-option'] == deploy
        assert scap_policy['tailoring-file-id'] == tailoring_file_a['id']
        assert scap_policy[
            'tailoring-file-profile-id'] == tailoring_file_profile_a_id

        Scappolicy.update({
            'name':
            scap_policy['name'],
            'tailoring-file':
            tailoring_file_b['name'],
            'tailoring-file-profile-id':
            tailoring_file_profile_b_id,
        })
        scap_info = Scappolicy.info({'name': scap_policy['name']})
        assert scap_info['tailoring-file-id'] == tailoring_file_b['id']
        assert scap_info[
            'tailoring-file-profile-id'] == tailoring_file_profile_b_id

        Scappolicy.delete({'name': scap_policy['name']})
        with pytest.raises(CLIReturnCodeError):
            Scapcontent.info({'name': scap_policy['name']})

        scap_policy = make_scap_policy({
            'scap-content-id':
            scap_content["scap_id"],
            'deploy-by':
            deploy,
            'scap-content-profile-id':
            scap_content["scap_profile_id"],
            'period':
            OSCAP_PERIOD['weekly'].lower(),
            'weekday':
            OSCAP_WEEKDAY['friday'].lower(),
            'tailoring-file-id':
            tailoring_file_a['id'],
            'tailoring-file-profile-id':
            tailoring_file_profile_a_id,
        })
        assert scap_policy['deployment-option'] == deploy
        assert scap_policy['tailoring-file-id'] == tailoring_file_a['id']
        assert scap_policy[
            'tailoring-file-profile-id'] == tailoring_file_profile_a_id

        Scappolicy.update({
            'id':
            scap_policy['id'],
            'tailoring-file-id':
            tailoring_file_b['id'],
            'tailoring-file-profile-id':
            tailoring_file_profile_b_id,
        })
        scap_info = Scappolicy.info({'id': scap_policy['id']})
        assert scap_info['tailoring-file-id'] == tailoring_file_b['id']
        assert scap_info[
            'tailoring-file-profile-id'] == tailoring_file_profile_b_id

        Scappolicy.delete({'id': scap_policy['id']})
        with pytest.raises(CLIReturnCodeError):
            Scapcontent.info({'name': scap_policy['name']})
Exemplo n.º 20
0
    def configure_puppet_test(cls):
        """Sets up the whole provisioning environment needed for Puppet based
        end-to-end tests like OSCAP etc

        :returns: A dict of entities to help with provisioning
        """
        cls.rhel6_content = OSCAP_DEFAULT_CONTENT['rhel6_content']
        cls.rhel7_content = OSCAP_DEFAULT_CONTENT['rhel7_content']
        cls.rhel8_content = OSCAP_DEFAULT_CONTENT['rhel8_content']
        sat6_hostname = settings.server.hostname
        proxy = Proxy.list({'search': sat6_hostname})[0]
        p_features = set(proxy.get('features').split(', '))
        if {'Puppet', 'Ansible', 'Openscap'}.issubset(p_features):
            cls.proxy_id = proxy.get('id')
        else:
            raise ProxyError(
                'Some features like Puppet, DHCP, Openscap, Ansible are not present'
            )
        ak_name_8 = gen_string('alpha')
        ak_name_7 = gen_string('alpha')
        ak_name_6 = gen_string('alpha')
        repo_values = [
            {
                'repo': settings.sattools_repo['rhel8'],
                'akname': ak_name_8
            },
            {
                'repo': settings.sattools_repo['rhel7'],
                'akname': ak_name_7
            },
            {
                'repo': settings.sattools_repo['rhel6'],
                'akname': ak_name_6
            },
        ]
        # Create new organization and environment.
        org = entities.Organization(name=gen_string('alpha')).create()
        cls.puppet_env = (entities.Environment().search(
            query={'search': 'name=production'})[0].read())
        cls.puppet_env.organization.append(org)
        cls.puppet_env = cls.puppet_env.update(['organization'])
        smart_proxy = (entities.SmartProxy().search(
            query={'search': f'name={sat6_hostname}'})[0].read())
        smart_proxy.import_puppetclasses(environment=cls.puppet_env.name)
        env = entities.LifecycleEnvironment(organization=org,
                                            name=gen_string('alpha')).create()
        # Create content view
        content_view = entities.ContentView(organization=org,
                                            name=gen_string('alpha')).create()
        # Create activation keys for rhel6, rhel7 and rhel8.
        for repo in repo_values:
            activation_key = entities.ActivationKey(name=repo.get('akname'),
                                                    environment=env,
                                                    organization=org).create()
            # Setup org for a custom repo for RHEL6, RHEL7 and RHEL8.
            setup_org_for_a_custom_repo({
                'url': repo.get('repo'),
                'organization-id': org.id,
                'content-view-id': content_view.id,
                'lifecycle-environment-id': env.id,
                'activationkey-id': activation_key.id,
            })

        for content in cls.rhel8_content, cls.rhel7_content, cls.rhel6_content:
            content = Scapcontent.info({'title': content},
                                       output_format='json')
            organization_ids = [
                content_org['id']
                for content_org in content.get('organizations', [])
            ]
            organization_ids.append(org.id)
            Scapcontent.update({
                'title': content['title'],
                'organization-ids': organization_ids
            })

        return {
            'org_name': org.name,
            'cv_name': content_view.name,
            'sat6_hostname': settings.server.hostname,
            'ak_name': {
                'rhel8': ak_name_8,
                'rhel7': ak_name_7,
                'rhel6': ak_name_6
            },
            'env_name': env.name,
        }