Exemplo n.º 1
0
 def create_ldap(self, ad_data):
     """Fetch necessary properties from settings and Create ldap auth source"""
     org = entities.Organization().create()
     loc = entities.Location(organization=[org]).create()
     ad_data = ad_data()
     yield dict(
         org=org,
         loc=loc,
         sat_url=f'https://{settings.server.hostname}',
         ldap_user_name=ad_data['ldap_user_name'],
         ldap_user_passwd=ad_data['ldap_user_passwd'],
         authsource=entities.AuthSourceLDAP(
             onthefly_register=True,
             account=ad_data['ldap_user_name'],
             account_password=ad_data['ldap_user_passwd'],
             base_dn=ad_data['base_dn'],
             groups_base=ad_data['group_base_dn'],
             attr_firstname=LDAP_ATTR['firstname'],
             attr_lastname=LDAP_ATTR['surname'],
             attr_login=LDAP_ATTR['login_ad'],
             server_type=LDAP_SERVER_TYPE['API']['ad'],
             attr_mail=LDAP_ATTR['mail'],
             name=gen_string('alpha'),
             host=ad_data['ldap_hostname'],
             tls=False,
             port='389',
             location=[loc],
             organization=[org],
         ).create(),
     )
     for user in entities.User().search(
             query={'search': f'login={ad_data["ldap_user_name"]}'}):
         user.delete()
     org.delete()
     loc.delete()
Exemplo n.º 2
0
def test_post_verify_usergroup_membership(request):
    """After upgrade, check the LDAP user's(that we created before the upgrade) existence and
    their functionality.

    :steps:
        1. verify ldap user(created before upgrade) is part of user group.
        2. Update ldap auth.

    :expectedresults: After upgrade, user group membership should remain the same and LDAP
    auth update should work.
    """
    pre_test_name = [
        mark.kwargs['depend_on'].__name__ for mark in request.node.own_markers
        if 'depend_on' in mark.kwargs
    ][0]
    user_group = entities.UserGroup().search(
        query={'search': f'name={pre_test_name}_user_group'})
    authsource = entities.AuthSourceLDAP().search(
        query={'search': f'name={pre_test_name}_server'})[0]
    request.addfinalizer(authsource.delete)
    request.addfinalizer(user_group[0].delete)
    user = entities.User().search(
        query={'search': f'login={settings.ldap.username}'})[0]
    request.addfinalizer(user.delete)
    assert user.read().id == user_group[0].read().user[0].id
Exemplo n.º 3
0
    def test_post_verify_usergroup_membership(self, request, dependent_scenario_name):
        """After upgrade, check the LDAP user created before the upgrade still exists and its
         update functionality should work.

        :id: postupgrade-7545fc6a-bd57-4403-90c8-c68a7a3b5bca

        :steps:
            1. verify ldap user(created before upgrade) is part of user group.
            2. Update ldap auth.

        :expectedresults: After upgrade, user group membership should remain the same and LDAP
        auth update should work.
        """
        pre_test_name = dependent_scenario_name
        user_group = entities.UserGroup().search(
            query={'search': f'name={pre_test_name}_user_group'}
        )
        authsource = entities.AuthSourceLDAP().search(
            query={'search': f'name={pre_test_name}_server'}
        )[0]
        request.addfinalizer(authsource.delete)
        request.addfinalizer(user_group[0].delete)
        user = entities.User().search(query={'search': f'login={settings.ldap.username}'})[0]
        request.addfinalizer(user.delete)
        assert user.read().id == user_group[0].read().user[0].id
Exemplo n.º 4
0
 def create_ldap(self):
     """Fetch necessary properties from settings and Create ldap auth source"""
     org = entities.Organization().create()
     loc = entities.Location(organization=[org]).create()
     yield dict(
         org=org,
         loc=loc,
         sat_url='https://{}'.format(settings.server.hostname),
         ldap_user_name=settings.ldap.username,
         ldap_user_passwd=settings.ldap.password,
         authsource=entities.AuthSourceLDAP(
             onthefly_register=True,
             account=settings.ldap.username,
             account_password=settings.ldap.password,
             base_dn=settings.ldap.basedn,
             groups_base=settings.ldap.grpbasedn,
             attr_firstname=LDAP_ATTR['firstname'],
             attr_lastname=LDAP_ATTR['surname'],
             attr_login=LDAP_ATTR['login_ad'],
             server_type=LDAP_SERVER_TYPE['API']['ad'],
             attr_mail=LDAP_ATTR['mail'],
             name=gen_string('alpha'),
             host=settings.ldap.hostname,
             tls=False,
             port='389',
             location=[loc],
             organization=[org],
         ).create(),
     )
     for user in entities.User().search(
             query={'search': 'login={}'.format(settings.ldap.username)}):
         user.delete()
     org.delete()
     loc.delete()
Exemplo n.º 5
0
    def setUpClass(cls):  # noqa
        super(ActiveDirectoryUserTestCase, cls).setUpClass()
        cls.ldap_user_name = settings.ldap.username
        cls.ldap_user_passwd = settings.ldap.password
        cls.base_dn = settings.ldap.basedn
        cls.group_base_dn = settings.ldap.grpbasedn
        cls.ldap_hostname = settings.ldap.hostname
        cls.usergroup_name = gen_string('alpha')

        authsource_attrs = entities.AuthSourceLDAP(
            onthefly_register=True,
            account=cls.ldap_user_name,
            account_password=cls.ldap_user_passwd,
            base_dn=cls.base_dn,
            groups_base=cls.group_base_dn,
            attr_firstname=LDAP_ATTR['firstname'],
            attr_lastname=LDAP_ATTR['surname'],
            attr_login=LDAP_ATTR['login_ad'],
            server_type=LDAP_SERVER_TYPE['API']['ad'],
            attr_mail=LDAP_ATTR['mail'],
            name=gen_string('alpha'),
            host=cls.ldap_hostname,
            tls=False,
            port='389',
        ).create()
        cls.ldap_server_name = authsource_attrs.name
Exemplo n.º 6
0
 def setUpClass(cls):
     """Fetch necessary properties from settings and Create ldap auth source"""
     super(FreeIPAUserTestCase, cls).setUpClass()
     cls.org = entities.Organization().create()
     cls.loc = entities.Location(organization=[cls.org]).create()
     cls.sat_url = 'https://{}'.format(settings.server.hostname)
     cls.username = settings.ipa.user_ipa
     cls.ldap_user_name = settings.ipa.username_ipa
     cls.ldap_user_passwd = settings.ipa.password_ipa
     cls.authsource = entities.AuthSourceLDAP(
         onthefly_register=True,
         account=cls.ldap_user_name,
         account_password=cls.ldap_user_passwd,
         base_dn=settings.ipa.basedn_ipa,
         groups_base=settings.ipa.grpbasedn_ipa,
         attr_firstname=LDAP_ATTR['firstname'],
         attr_lastname=LDAP_ATTR['surname'],
         attr_login=LDAP_ATTR['login'],
         server_type=LDAP_SERVER_TYPE['API']['ipa'],
         attr_mail=LDAP_ATTR['mail'],
         name=gen_string('alpha'),
         host=settings.ipa.hostname_ipa,
         tls=False,
         port='389',
         location=[cls.loc],
         organization=[cls.org],
     ).create()
Exemplo n.º 7
0
def ldap_auth_source(request, module_org, module_loc, ad_data, ipa_data):
    if request.param.lower() == 'ad':
        # entity create with AD settings
        entities.AuthSourceLDAP(
            onthefly_register=True,
            account=ad_data['ldap_user_name'],
            account_password=ad_data['ldap_user_passwd'],
            base_dn=ad_data['base_dn'],
            groups_base=ad_data['group_base_dn'],
            attr_firstname=LDAP_ATTR['firstname'],
            attr_lastname=LDAP_ATTR['surname'],
            attr_login=LDAP_ATTR['login_ad'],
            server_type=LDAP_SERVER_TYPE['API']['ad'],
            attr_mail=LDAP_ATTR['mail'],
            name=gen_string('alpha'),
            host=ad_data['ldap_hostname'],
            tls=False,
            port='389',
            organization=[module_org],
            location=[module_loc],
        ).create()
        ldap_data = ad_data
    elif request.param.lower() == 'ipa':
        # entity create with IPA settings
        entities.AuthSourceLDAP(
            onthefly_register=True,
            account=ipa_data['ldap_user_cn'],
            account_password=ipa_data['ldap_user_passwd'],
            base_dn=ipa_data['base_dn'],
            groups_base=ipa_data['group_base_dn'],
            attr_firstname=LDAP_ATTR['firstname'],
            attr_lastname=LDAP_ATTR['surname'],
            attr_login=LDAP_ATTR['login'],
            server_type=LDAP_SERVER_TYPE['API']['ipa'],
            attr_mail=LDAP_ATTR['mail'],
            name=gen_string('alpha'),
            host=ipa_data['ldap_hostname'],
            tls=False,
            port='389',
            organization=[module_org],
            location=[module_loc],
        ).create()
        ldap_data = ipa_data
    else:
        # default auth server settings
        raise Exception('Incorrect auth source parameter used')
    yield ldap_data
Exemplo n.º 8
0
def ldap_auth_name():
    """Return some random ldap name, and attempt to delete all ldap when test starts.
    """
    ldap = entities.AuthSourceLDAP().search()
    for ldap_auth in range(len(ldap)):
        ldap[ldap_auth].delete()
    ldap_name = gen_string('alphanumeric')
    yield ldap_name
Exemplo n.º 9
0
def ldap_tear_down():
    """Teardown the all ldap settings user, usergroup and ldap delete"""
    yield
    ldap_auth_sources = entities.AuthSourceLDAP().search()
    for ldap_auth in ldap_auth_sources:
        users = entities.User(auth_source=ldap_auth).search()
        for user in users:
            user.delete()
        ldap_auth.delete()
Exemplo n.º 10
0
 def _clean_up_previous_ldap(self):
     """clean up the all ldap settings user, usergroup and ldap delete"""
     ldap = entities.AuthSourceLDAP().search()
     for ldap_auth in range(len(ldap)):
         users = entities.User(auth_source=ldap[ldap_auth]).search()
         for user in range(len(users)):
             users[user].delete()
         ldap[ldap_auth].delete()
     user_groups = entities.UserGroup().search()
     for user_group in user_groups:
         user_group.delete()
Exemplo n.º 11
0
def test_positive_endtoend(auth_source_type, module_org, module_location,
                           ad_data, ipa_data):
    """Create/update/delete LDAP authentication with AD using names of different types

    :id: e3607c97-7c48-4cf6-b119-2bfd895d9325

    :expectedresults: Whether creating/updating/deleting LDAP Auth with AD/IPA is successful.

    :parametrized: yes

    :CaseImportance: Critical
    """
    for server_name in generate_strings_list():
        if auth_source_type == 'AD':
            auth_source_data = ad_data()
            auth_type_attr = LDAP_ATTR[f'login_{auth_source_type.lower()}']
        elif auth_source_type == 'IPA':
            auth_source_data = ipa_data
            auth_source_data['ldap_user_name'] = auth_source_data[
                'ldap_user_cn']
            auth_type_attr = LDAP_ATTR['login']
        authsource = entities.AuthSourceLDAP(
            onthefly_register=True,
            account=auth_source_data['ldap_user_cn'],
            account_password=auth_source_data['ldap_user_passwd'],
            base_dn=auth_source_data['base_dn'],
            groups_base=auth_source_data['group_base_dn'],
            attr_firstname=LDAP_ATTR['firstname'],
            attr_lastname=LDAP_ATTR['surname'],
            attr_login=auth_type_attr,
            server_type=LDAP_SERVER_TYPE['API'][auth_source_type.lower()],
            attr_mail=LDAP_ATTR['mail'],
            name=server_name,
            host=auth_source_data['ldap_hostname'],
            tls=False,
            port='389',
            organization=[module_org],
            location=[module_location],
        ).create()

        assert authsource.name == server_name
        for new_name in generate_strings_list():
            authsource.name = new_name
            authsource = authsource.update(['name'])
            assert authsource.name == new_name
        authsource.delete()
        with pytest.raises(HTTPError):
            authsource.read()
Exemplo n.º 12
0
def auth_source_open_ldap(module_org, module_loc, open_ldap_data):
    return entities.AuthSourceLDAP(
        onthefly_register=True,
        account=open_ldap_data.username,
        account_password=open_ldap_data.password,
        base_dn=open_ldap_data.base_dn,
        attr_firstname=LDAP_ATTR['firstname'],
        attr_lastname=LDAP_ATTR['surname'],
        attr_login=LDAP_ATTR['login'],
        server_type=LDAP_SERVER_TYPE['API']['posix'],
        attr_mail=LDAP_ATTR['mail'],
        name=gen_string('alpha'),
        host=open_ldap_data.hostname,
        tls=False,
        port='389',
        organization=[module_org],
        location=[module_loc],
    ).create()
Exemplo n.º 13
0
    def test_pre_create_usergroup_with_ldap_user(self, request):
        """Create Usergroup in preupgrade version.

        :id: preupgrade-4b11d883-f523-4f38-b65a-650ecd90335c

        :steps:
            1. Create ldap auth pre upgrade.
            2. Login with ldap User in satellite and logout.
            3. Create usergroup and assign ldap user to it.

        :expectedresults: The usergroup, with ldap user as member, should be created successfully.
        """
        authsource = entities.AuthSourceLDAP(
            onthefly_register=True,
            account=settings.ldap.username,
            account_password=settings.ldap.password,
            base_dn=settings.ldap.basedn,
            groups_base=settings.ldap.grpbasedn,
            attr_firstname=LDAP_ATTR['firstname'],
            attr_lastname=LDAP_ATTR['surname'],
            attr_login=LDAP_ATTR['login_ad'],
            server_type=LDAP_SERVER_TYPE['API']['ad'],
            attr_mail=LDAP_ATTR['mail'],
            name=request.node.name + "_server",
            host=settings.ldap.hostname,
            tls=False,
            port='389',
        ).create()
        assert authsource.name == request.node.name + "_server"
        sc = ServerConfig(
            auth=(settings.ldap.username, settings.ldap.password),
            url=f'https://{settings.server.hostname}',
            verify=False,
        )

        with pytest.raises(HTTPError):
            entities.User(sc).search()
        user_group = entities.UserGroup(name=request.node.name +
                                        "_user_group").create()
        user = entities.User().search(
            query={'search': f'login={settings.ldap.username}'})[0]
        user_group.user = [user]
        user_group = user_group.update(['user'])
        assert user.login == user_group.user[0].read().login
Exemplo n.º 14
0
def auth_source_ipa(module_org, module_location, ipa_data):
    return entities.AuthSourceLDAP(
        onthefly_register=True,
        account=ipa_data['ldap_user_cn'],
        account_password=ipa_data['ldap_user_passwd'],
        base_dn=ipa_data['base_dn'],
        groups_base=ipa_data['group_base_dn'],
        attr_firstname=LDAP_ATTR['firstname'],
        attr_lastname=LDAP_ATTR['surname'],
        attr_login=LDAP_ATTR['login'],
        server_type=LDAP_SERVER_TYPE['API']['ipa'],
        attr_mail=LDAP_ATTR['mail'],
        name=gen_string('alpha'),
        host=ipa_data['ldap_hostname'],
        tls=False,
        port='389',
        organization=[module_org],
        location=[module_location],
    ).create()
Exemplo n.º 15
0
    def test_pre_create_usergroup_with_ldap_user(self):
        """Create Usergroup in preupgrade version.

        :steps:
            1. Create ldap auth pre upgrade.
            2. Login with ldap User in satellite and logout.
            3. Create usergroup and assign ldap user to it.

        :expectedresults: The usergroup, with ldap user as member, should be created successfully.
        """
        authsource = entities.AuthSourceLDAP(
            onthefly_register=True,
            account=self.ldap_user_name,
            account_password=self.ldap_user_passwd,
            base_dn=self.base_dn,
            groups_base=self.group_base_dn,
            attr_firstname=LDAP_ATTR['firstname'],
            attr_lastname=LDAP_ATTR['surname'],
            attr_login=LDAP_ATTR['login_ad'],
            server_type=LDAP_SERVER_TYPE['API']['ad'],
            attr_mail=LDAP_ATTR['mail'],
            name=self.server_name,
            host=self.ldap_hostname,
            tls=False,
            port='389',
        ).create()
        self.assertEqual(authsource.name, self.server_name)
        sc = ServerConfig(auth=(self.ldap_user_name, self.ldap_user_passwd),
                          url=self.sat_url,
                          verify=False)
        with self.assertRaises(HTTPError):
            entities.User(sc).search()
        user_group = entities.UserGroup(
            name=self.preupgrade_usergroup).create()
        user = entities.User().search(
            query={'search': 'login={}'.format(self.ldap_user_name)})[0]
        user_group.user = [user]
        user_group = user_group.update(['user'])
        self.assertEqual(user.login, user_group.user[0].read().login)
Exemplo n.º 16
0
    def test_positive_endtoend_withad(self):
        """Create/update/delete LDAP authentication with AD using names of different types

        :id: e3607c97-7c48-4cf6-b119-2bfd895d9325

        :expectedresults: Whether creating/updating/deleting LDAP Auth with AD is successful.

        :CaseImportance: Critical
        """
        for server_name in generate_strings_list():
            with self.subTest(server_name):
                authsource = entities.AuthSourceLDAP(
                    onthefly_register=True,
                    account=self.ldap_user_name,
                    account_password=self.ldap_user_passwd,
                    base_dn=self.base_dn,
                    groups_base=self.group_base_dn,
                    attr_firstname=LDAP_ATTR['firstname'],
                    attr_lastname=LDAP_ATTR['surname'],
                    attr_login=LDAP_ATTR['login_ad'],
                    server_type=LDAP_SERVER_TYPE['API']['ad'],
                    attr_mail=LDAP_ATTR['mail'],
                    name=server_name,
                    host=self.ldap_hostname,
                    tls=False,
                    port='389',
                    location=[self.loc],
                    organization=[self.org],
                ).create()
                self.assertEqual(authsource.name, server_name)
                for new_name in generate_strings_list():
                    with self.subTest(new_name):
                        authsource.name = new_name
                        authsource = authsource.update(['name'])
                        self.assertEqual(authsource.name, new_name)
                authsource.delete()
                with self.assertRaises(HTTPError):
                    authsource.read()
Exemplo n.º 17
0
def ldap_auth_source(request, module_org, module_location, ad_data, ipa_data,
                     open_ldap_data):
    auth_type = request.param.lower()
    if 'ad' in auth_type:
        ad_data = ad_data('2019') if '2019' in auth_type else ad_data()
        # entity create with AD settings
        auth_source = entities.AuthSourceLDAP(
            onthefly_register=True,
            account=ad_data['ldap_user_name'],
            account_password=ad_data['ldap_user_passwd'],
            base_dn=ad_data['base_dn'],
            groups_base=ad_data['group_base_dn'],
            attr_firstname=LDAP_ATTR['firstname'],
            attr_lastname=LDAP_ATTR['surname'],
            attr_login=LDAP_ATTR['login_ad'],
            server_type=LDAP_SERVER_TYPE['API']['ad'],
            attr_mail=LDAP_ATTR['mail'],
            name=gen_string('alpha'),
            host=ad_data['ldap_hostname'],
            tls=False,
            port='389',
            organization=[module_org],
            location=[module_location],
        ).create()
        ldap_data = ad_data
    elif auth_type == 'ipa':
        # entity create with IPA settings
        auth_source = entities.AuthSourceLDAP(
            onthefly_register=True,
            account=ipa_data['ldap_user_cn'],
            account_password=ipa_data['ldap_user_passwd'],
            base_dn=ipa_data['base_dn'],
            groups_base=ipa_data['group_base_dn'],
            attr_firstname=LDAP_ATTR['firstname'],
            attr_lastname=LDAP_ATTR['surname'],
            attr_login=LDAP_ATTR['login'],
            server_type=LDAP_SERVER_TYPE['API']['ipa'],
            attr_mail=LDAP_ATTR['mail'],
            name=gen_string('alpha'),
            host=ipa_data['ldap_hostname'],
            tls=False,
            port='389',
            organization=[module_org],
            location=[module_location],
        ).create()
        ldap_data = ipa_data
    elif auth_type == 'openldap':
        # entity create with OpenLdap settings
        auth_source = entities.AuthSourceLDAP(
            onthefly_register=True,
            account=open_ldap_data['ldap_user_cn'],
            account_password=open_ldap_data['ldap_user_passwd'],
            base_dn=open_ldap_data['base_dn'],
            groups_base=open_ldap_data['group_base_dn'],
            attr_firstname=LDAP_ATTR['firstname'],
            attr_lastname=LDAP_ATTR['surname'],
            attr_login=LDAP_ATTR['login'],
            server_type=LDAP_SERVER_TYPE['API']['posix'],
            attr_mail=LDAP_ATTR['mail'],
            name=gen_string('alpha'),
            host=open_ldap_data['ldap_hostname'],
            tls=False,
            port='389',
            organization=[module_org],
            location=[module_location],
        ).create()
        ldap_data = open_ldap_data
    else:
        raise Exception('Incorrect auth source parameter used')
    ldap_data['auth_type'] = auth_type
    if ldap_data['auth_type'] == 'ipa':
        ldap_data['server_type'] = LDAP_SERVER_TYPE['UI']['ipa']
        ldap_data['attr_login'] = LDAP_ATTR['login']
    elif ldap_data['auth_type'] == 'ad':
        ldap_data['server_type'] = LDAP_SERVER_TYPE['UI']['ad']
        ldap_data['attr_login'] = LDAP_ATTR['login_ad']
    else:
        ldap_data['server_type'] = LDAP_SERVER_TYPE['UI']['posix']
        ldap_data['attr_login'] = LDAP_ATTR['login']
    yield ldap_data, auth_source
Exemplo n.º 18
0
    def test_positive_create_by_type(self):
        """Create entities of different types and check audit logs for these
        events using entity type as search criteria

        :id: 6c7ea7fc-6728-447f-9655-26fe0a2881bc

        :customerscenario: true

        :expectedresults: Audit logs contain corresponding entries per each
            create event

        :BZ: 1426742, 1492668, 1492696

        :CaseImportance: Critical
        """
        for entity_item in [
            {'entity': entities.Architecture()},
            {
                'entity': entities.AuthSourceLDAP(),
                'entity_type': 'auth_source',
                'value_template': 'LDAP-{entity.name}'
            },
            {
                'entity': entities.ComputeProfile(),
                'entity_type': 'compute_profile'
            },
            {
                'entity': entities.LibvirtComputeResource(),
                'entity_type': 'compute_resource',
                'value_template': '{entity.name} (Libvirt)'
            },
            {'entity': entities.ConfigGroup(), 'entity_type': 'config_group'},
            {'entity': entities.Domain()},
            {'entity': entities.Host()},
            {'entity': entities.HostGroup()},
            {'entity': entities.Image(
                compute_resource=entities.LibvirtComputeResource().create())},
            {'entity': entities.Location()},
            {'entity': entities.Media(), 'entity_type': 'medium'},
            {'entity': entities.Organization()},
            {
                'entity': entities.OperatingSystem(),
                'entity_type': 'os',
                'value_template': '{entity.name} {entity.major}'
            },
            {
                'entity': entities.PartitionTable(),
                'entity_type': 'ptable',
            },
            {'entity': entities.PuppetClass()},
            {'entity': entities.Role()},
            {
                'entity': entities.Subnet(),
                'value_template': '{entity.name} '
                                  '({entity.network}/{entity.cidr})'
            },
            {
                'entity': entities.ProvisioningTemplate(),
                'entity_type': 'template',
            },
            {'entity': entities.User(), 'value_template': '{entity.login}'},
            {'entity': entities.UserGroup()},
        ]:
            created_entity = entity_item['entity'].create()
            entity_type = entity_item.get(
                'entity_type', created_entity.__class__.__name__.lower())
            value_template = entity_item.get('value_template', '{entity.name}')
            entity_value = value_template.format(entity=created_entity)
            audits = entities.Audit().search(
                query={'search': 'type={0}'.format(entity_type)})
            entity_audits = [entry for entry in audits
                             if entry.auditable_name == entity_value]
            if not entity_audits:
                self.fail('audit not found by name "{}"'.format(entity_value))
            audit = entity_audits[0]
            self.assertEqual(audit.auditable_id, created_entity.id)
            self.assertEqual(audit.action, 'create')
            self.assertEqual(audit.version, 1)
Exemplo n.º 19
0
def test_positive_create_by_type():
    """Create entities of different types and check audit logs for these
    events using entity type as search criteria

    :id: 6c7ea7fc-6728-447f-9655-26fe0a2881bc

    :customerscenario: true

    :expectedresults: Audit logs contain corresponding entries per each
        create event

    :BZ: 1426742, 1492668, 1492696

    :CaseImportance: Medium
    """
    for entity_item in [
        {
            'entity': entities.Architecture()
        },
        {
            'entity': entities.AuthSourceLDAP(),
            'entity_type': 'auth_source',
            'value_template': 'LDAP-{entity.name}',
        },
        {
            'entity': entities.ComputeProfile(),
            'entity_type': 'compute_profile'
        },
        {
            'entity': entities.LibvirtComputeResource(),
            'entity_type': 'compute_resource',
            'value_template': '{entity.name} (Libvirt)',
        },
        {
            'entity': entities.ConfigGroup(),
            'entity_type': 'config_group'
        },
        {
            'entity': entities.Domain()
        },
        {
            'entity': entities.Host()
        },
        {
            'entity': entities.HostGroup()
        },
        {
            'entity':
            entities.Image(
                compute_resource=entities.LibvirtComputeResource().create())
        },
        {
            'entity': entities.Location()
        },
        {
            'entity': entities.Media(),
            'entity_type': 'medium'
        },
        {
            'entity': entities.Organization()
        },
        {
            'entity': entities.OperatingSystem(),
            'entity_type': 'os',
            'value_template': '{entity.name} {entity.major}',
        },
        {
            'entity': entities.PartitionTable(),
            'entity_type': 'ptable'
        },
        {
            'entity': entities.PuppetClass()
        },
        {
            'entity': entities.Role()
        },
        {
            'entity': entities.Subnet(),
            'value_template': '{entity.name} ({entity.network}/{entity.cidr})',
        },
        {
            'entity': entities.ProvisioningTemplate(),
            'entity_type': 'provisioning_template'
        },
        {
            'entity': entities.User(),
            'value_template': '{entity.login}'
        },
        {
            'entity': entities.UserGroup()
        },
        {
            'entity': entities.ContentView(),
            'entity_type': 'katello/content_view'
        },
        {
            'entity': entities.LifecycleEnvironment(),
            'entity_type': 'katello/kt_environment'
        },
        {
            'entity': entities.ActivationKey(),
            'entity_type': 'katello/activation_key'
        },
        {
            'entity': entities.HostCollection(),
            'entity_type': 'katello/host_collection'
        },
        {
            'entity': entities.Product(),
            'entity_type': 'katello/product'
        },
        {
            'entity': entities.GPGKey(),
            'entity_type': 'katello/gpg_key',
            'value_template': 'content credential (gpg_key - {entity.name})',
        },
        {
            'entity':
            entities.SyncPlan(organization=entities.Organization(id=1)),
            'entity_type': 'katello/sync_plan',
        },
    ]:
        created_entity = entity_item['entity'].create()
        entity_type = entity_item.get(
            'entity_type', created_entity.__class__.__name__.lower())
        value_template = entity_item.get('value_template', '{entity.name}')
        entity_value = value_template.format(entity=created_entity)
        audits = entities.Audit().search(
            query={'search': f'type={entity_type}'})
        entity_audits = [
            entry for entry in audits if entry.auditable_name == entity_value
        ]
        assert entity_audits, (
            f'audit not found by name "{entity_value}" for entity: '
            f'{created_entity.__class__.__name__.lower()}')
        audit = entity_audits[0]
        assert audit.auditable_id == created_entity.id
        assert audit.action == 'create'
        assert audit.version == 1
Exemplo n.º 20
0
    def test_positive_create_by_type(self):
        """Create entities of different types and check audit logs for these
        events using entity type and performed action as search criteria

        :id: 26197b39-4d56-4aab-8df8-f0fcedbffdb7

        :expectedresults: Audit logs contain corresponding entries per each
            create event

        :CaseImportance: Critical
        """
        with Session(self):
            for entity_item in [
                {
                    'entity': entities.Architecture(),
                    'entity_type': 'architecture'
                },
                {
                    'entity': entities.AuthSourceLDAP(),
                    'entity_type': 'auth_source',
                    'value_template': 'LDAP-{entity.name}'
                },
                {
                    'entity': entities.ComputeProfile(),
                    'entity_type': 'compute_profile'
                },
                {
                    'entity': entities.LibvirtComputeResource(),
                    'entity_type': 'compute_resource',
                    'value_template': '{entity.name} (Libvirt)'
                },
                {
                    'entity': entities.ConfigGroup(),
                    'entity_type': 'config_group'
                },
                {
                    'entity': entities.Domain(),
                    'entity_type': 'domain'
                },
                {
                    'entity': entities.Host(),
                    'entity_type': 'host'
                },
                {
                    'entity': entities.HostGroup(),
                    'entity_type': 'hostgroup'
                },
                {
                    'entity':
                    entities.Image(compute_resource=entities.
                                   LibvirtComputeResource().create()),
                    'entity_type':
                    'image'
                },
                {
                    'entity': entities.Location(),
                    'entity_type': 'location'
                },
                {
                    'entity': entities.Media(),
                    'entity_type': 'medium',
                    'custom_operation': 'added',
                },
                {
                    'entity': entities.Organization(),
                    'entity_type': 'organization'
                },
                {
                    'entity': entities.OperatingSystem(),
                    'entity_type': 'os',
                    'value_template': '{entity.name} {entity.major}'
                },
                {
                    'entity': entities.PartitionTable(),
                    'entity_type': 'ptable',
                },
                {
                    'entity': entities.PuppetClass(),
                    'entity_type': 'puppetclass'
                },
                {
                    'entity': entities.Role(),
                    'entity_type': 'role'
                },
                {
                    'entity':
                    entities.Subnet(),
                    'entity_type':
                    'subnet',
                    'value_template':
                    '{entity.name} '
                    '({entity.network}/{entity.cidr})'
                },
                {
                    'entity': entities.ProvisioningTemplate(),
                    'entity_type': 'template',
                },
                {
                    'entity': entities.User(),
                    'value_template': '{entity.login}',
                    'entity_type': 'user',
                },
                {
                    'entity': entities.UserGroup(),
                    'entity_type': 'usergroup'
                },
            ]:
                created_entity = entity_item['entity'].create()
                value_template = entity_item.get('value_template',
                                                 '{entity.name}')
                operation_type = entity_item.get('custom_operation', 'created')
                entity_value = value_template.format(entity=created_entity)
                self.audit.filter('type={} and action=create'.format(
                    entity_item['entity_type']))
                result = self.audit.get_last_entry()
                self.assertIn(operation_type, result['full_statement'])
                self.assertEqual(entity_value, result['entity_name'])