mirror of
https://salsa.debian.org/freeipa-team/freeipa.git
synced 2025-02-25 18:55:28 -06:00
Remove local get_dn() from hbacsvcgroup and add tests for hbacsvcgroup
This commit is contained in:
parent
72afb4c605
commit
71738f9177
@ -67,24 +67,6 @@ class hbacsvcgroup(LDAPObject):
|
||||
),
|
||||
)
|
||||
|
||||
def get_dn(self, *keys, **kwargs):
|
||||
try:
|
||||
(dn, entry_attrs) = self.backend.find_entry_by_attr(
|
||||
self.primary_key.name, keys[-1], self.object_class, [''],
|
||||
self.container_dn
|
||||
)
|
||||
except errors.NotFound:
|
||||
dn = super(hbacsvcgroup, self).get_dn(*keys, **kwargs)
|
||||
return dn
|
||||
|
||||
def get_primary_key_from_dn(self, dn):
|
||||
pkey = self.primary_key.name
|
||||
(dn, entry_attrs) = self.backend.get_entry(dn, [pkey])
|
||||
try:
|
||||
return entry_attrs[pkey][0]
|
||||
except (KeyError, IndexError):
|
||||
return ''
|
||||
|
||||
api.register(hbacsvcgroup)
|
||||
|
||||
|
||||
@ -92,6 +74,7 @@ class hbacsvcgroup_add(LDAPCreate):
|
||||
"""
|
||||
Create new hbacsvcgroup.
|
||||
"""
|
||||
msg_summary = _('Added HBAC Service group "%(value)s"')
|
||||
|
||||
api.register(hbacsvcgroup_add)
|
||||
|
||||
@ -100,6 +83,7 @@ class hbacsvcgroup_del(LDAPDelete):
|
||||
"""
|
||||
Delete hbacsvcgroup.
|
||||
"""
|
||||
msg_summary = _('Deleted HBAC Service group "%(value)s"')
|
||||
|
||||
api.register(hbacsvcgroup_del)
|
||||
|
||||
@ -108,6 +92,7 @@ class hbacsvcgroup_mod(LDAPUpdate):
|
||||
"""
|
||||
Modify hbacsvcgroup.
|
||||
"""
|
||||
msg_summary = _('Modified HBAC Service group "%(value)s"')
|
||||
|
||||
api.register(hbacsvcgroup_mod)
|
||||
|
||||
@ -116,6 +101,9 @@ class hbacsvcgroup_find(LDAPSearch):
|
||||
"""
|
||||
Search the groups.
|
||||
"""
|
||||
msg_summary = ngettext(
|
||||
'%(count)d group matched', '%(count)d groups matched', 0
|
||||
)
|
||||
|
||||
api.register(hbacsvcgroup_find)
|
||||
|
||||
|
@ -81,3 +81,14 @@ service = [
|
||||
u'pkiuser',
|
||||
u'top',
|
||||
]
|
||||
|
||||
hbacsvc = [
|
||||
u'ipahbacservice',
|
||||
]
|
||||
|
||||
hbacsvcgroup = [
|
||||
u'ipahbacservicegroup',
|
||||
u'nestedGroup',
|
||||
u'groupOfNames',
|
||||
u'top',
|
||||
]
|
||||
|
248
tests/test_xmlrpc/test_hbacsvcgroup_plugin.py
Normal file
248
tests/test_xmlrpc/test_hbacsvcgroup_plugin.py
Normal file
@ -0,0 +1,248 @@
|
||||
# Authors:
|
||||
# Rob Crittenden <rcritten@redhat.com>
|
||||
#
|
||||
# Copyright (C) 2010 Red Hat
|
||||
# see file 'COPYING' for use and warranty information
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License as
|
||||
# published by the Free Software Foundation; version 2 only
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
"""
|
||||
Test the `ipalib.plugins.hbacsvcgroup` module.
|
||||
"""
|
||||
|
||||
from ipalib import api, errors
|
||||
from tests.test_xmlrpc.xmlrpc_test import Declarative, fuzzy_uuid
|
||||
from tests.test_xmlrpc import objectclasses
|
||||
|
||||
hbacsvcgroup1 = u'testhbacsvcgroup1'
|
||||
dn1 = u'cn=%s,cn=hbacservicegroups,cn=accounts,%s' % (hbacsvcgroup1, api.env.basedn)
|
||||
|
||||
hbacsvc1 = u'sshd'
|
||||
hbacsvc_dn1 = u'cn=%s,cn=hbacservices,cn=accounts,%s' % (hbacsvc1, api.env.basedn)
|
||||
|
||||
|
||||
class test_hbacsvcgroup(Declarative):
|
||||
|
||||
cleanup_commands = [
|
||||
('hbacsvcgroup_del', [hbacsvcgroup1], {}),
|
||||
('hbacsvc_del', [hbacsvc1], {}),
|
||||
]
|
||||
|
||||
tests=[
|
||||
|
||||
dict(
|
||||
desc='Try to retrieve non-existent %r' % hbacsvcgroup1,
|
||||
command=('hbacsvcgroup_show', [hbacsvcgroup1], {}),
|
||||
expected=errors.NotFound(reason='no such entry'),
|
||||
),
|
||||
|
||||
|
||||
dict(
|
||||
desc='Try to update non-existent %r' % hbacsvcgroup1,
|
||||
command=('hbacsvcgroup_mod', [hbacsvcgroup1],
|
||||
dict(description=u'Updated hbacsvcgroup 1')
|
||||
),
|
||||
expected=errors.NotFound(reason='no such entry'),
|
||||
),
|
||||
|
||||
|
||||
dict(
|
||||
desc='Try to delete non-existent %r' % hbacsvcgroup1,
|
||||
command=('hbacsvcgroup_del', [hbacsvcgroup1], {}),
|
||||
expected=errors.NotFound(reason='no such entry'),
|
||||
),
|
||||
|
||||
|
||||
dict(
|
||||
desc='Create %r' % hbacsvcgroup1,
|
||||
command=('hbacsvcgroup_add', [hbacsvcgroup1],
|
||||
dict(description=u'Test hbacsvcgroup 1')
|
||||
),
|
||||
expected=dict(
|
||||
value=hbacsvcgroup1,
|
||||
summary=u'Added HBAC Service group "testhbacsvcgroup1"',
|
||||
result=dict(
|
||||
dn=dn1,
|
||||
cn=[hbacsvcgroup1],
|
||||
objectclass=objectclasses.hbacsvcgroup,
|
||||
description=[u'Test hbacsvcgroup 1'],
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
|
||||
dict(
|
||||
desc='Try to create duplicate %r' % hbacsvcgroup1,
|
||||
command=('hbacsvcgroup_add', [hbacsvcgroup1],
|
||||
dict(description=u'Test hbacsvcgroup 1')
|
||||
),
|
||||
expected=errors.DuplicateEntry(),
|
||||
),
|
||||
|
||||
|
||||
dict(
|
||||
desc='Create service %r' % hbacsvc1,
|
||||
command=('hbacsvc_add', [hbacsvc1],
|
||||
dict(
|
||||
description=u'Test service 1',
|
||||
),
|
||||
),
|
||||
expected=dict(
|
||||
value=hbacsvc1,
|
||||
summary=u'Added service "%s"' % hbacsvc1,
|
||||
result=dict(
|
||||
dn=hbacsvc_dn1,
|
||||
cn=[hbacsvc1],
|
||||
description=[u'Test service 1'],
|
||||
objectclass=objectclasses.hbacsvc,
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
|
||||
dict(
|
||||
desc=u'Add service %r to %r' % (hbacsvc1, hbacsvcgroup1),
|
||||
command=(
|
||||
'hbacsvcgroup_add_member', [hbacsvcgroup1], dict(hbacsvc=hbacsvc1)
|
||||
),
|
||||
expected=dict(
|
||||
completed=1,
|
||||
failed=dict(
|
||||
member=dict(
|
||||
hbacsvc=tuple(),
|
||||
hbacsvcgroup=tuple(),
|
||||
),
|
||||
),
|
||||
result={
|
||||
'dn': dn1,
|
||||
'cn': [hbacsvcgroup1],
|
||||
'description': [u'Test hbacsvcgroup 1'],
|
||||
'member_service': [hbacsvc1],
|
||||
},
|
||||
),
|
||||
),
|
||||
|
||||
|
||||
dict(
|
||||
desc='Retrieve %r' % hbacsvcgroup1,
|
||||
command=('hbacsvcgroup_show', [hbacsvcgroup1], {}),
|
||||
expected=dict(
|
||||
value=hbacsvcgroup1,
|
||||
summary=None,
|
||||
result={
|
||||
'dn': dn1,
|
||||
'member_service': [hbacsvc1],
|
||||
'cn': [hbacsvcgroup1],
|
||||
'description': [u'Test hbacsvcgroup 1'],
|
||||
},
|
||||
),
|
||||
),
|
||||
|
||||
|
||||
dict(
|
||||
desc='Search for %r' % hbacsvcgroup1,
|
||||
command=('hbacsvcgroup_find', [], dict(cn=hbacsvcgroup1)),
|
||||
expected=dict(
|
||||
count=1,
|
||||
truncated=False,
|
||||
summary=u'1 group matched',
|
||||
result=[
|
||||
{
|
||||
'dn': dn1,
|
||||
'member_service': [hbacsvc1],
|
||||
'cn': [hbacsvcgroup1],
|
||||
'description': [u'Test hbacsvcgroup 1'],
|
||||
},
|
||||
],
|
||||
),
|
||||
),
|
||||
|
||||
|
||||
dict(
|
||||
desc='Update %r' % hbacsvcgroup1,
|
||||
command=('hbacsvcgroup_mod', [hbacsvcgroup1],
|
||||
dict(description=u'Updated hbacsvcgroup 1')
|
||||
),
|
||||
expected=dict(
|
||||
value=hbacsvcgroup1,
|
||||
summary=u'Modified HBAC Service group "testhbacsvcgroup1"',
|
||||
result=dict(
|
||||
cn=[hbacsvcgroup1],
|
||||
description=[u'Updated hbacsvcgroup 1'],
|
||||
member_service=[hbacsvc1],
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
|
||||
dict(
|
||||
desc='Retrieve %r to verify update' % hbacsvcgroup1,
|
||||
command=('hbacsvcgroup_show', [hbacsvcgroup1], {}),
|
||||
expected=dict(
|
||||
value=hbacsvcgroup1,
|
||||
summary=None,
|
||||
result={
|
||||
'dn': dn1,
|
||||
'member_service': [hbacsvc1],
|
||||
'cn': [hbacsvcgroup1],
|
||||
'description': [u'Updated hbacsvcgroup 1'],
|
||||
},
|
||||
),
|
||||
),
|
||||
|
||||
|
||||
dict(
|
||||
desc='Remove service %r from %r' % (hbacsvc1, hbacsvcgroup1),
|
||||
command=('hbacsvcgroup_remove_member', [hbacsvcgroup1],
|
||||
dict(hbacsvc=hbacsvc1)
|
||||
),
|
||||
expected=dict(
|
||||
failed=dict(
|
||||
member=dict(
|
||||
hbacsvc=tuple(),
|
||||
hbacsvcgroup=tuple(),
|
||||
),
|
||||
),
|
||||
completed=1,
|
||||
result={
|
||||
'dn': dn1,
|
||||
'cn': [hbacsvcgroup1],
|
||||
'description': [u'Updated hbacsvcgroup 1'],
|
||||
},
|
||||
),
|
||||
),
|
||||
|
||||
|
||||
dict(
|
||||
desc='Delete %r' % hbacsvcgroup1,
|
||||
command=('hbacsvcgroup_del', [hbacsvcgroup1], {}),
|
||||
expected=dict(
|
||||
value=hbacsvcgroup1,
|
||||
summary=u'Deleted HBAC Service group "testhbacsvcgroup1"',
|
||||
result=True,
|
||||
),
|
||||
),
|
||||
|
||||
|
||||
dict(
|
||||
desc='Delete service %r' % hbacsvc1,
|
||||
command=('hbacsvc_del', [hbacsvc1], {}),
|
||||
expected=dict(
|
||||
value=hbacsvc1,
|
||||
summary=u'Deleted service "%s"' % hbacsvc1,
|
||||
result=True,
|
||||
),
|
||||
)
|
||||
|
||||
]
|
Loading…
Reference in New Issue
Block a user