From e64db8cbc2e9571200cd14e7d2313102022c2813 Mon Sep 17 00:00:00 2001 From: Petr Vobornik Date: Mon, 11 Mar 2013 12:37:29 +0100 Subject: Filter groups by type (POSIX, non-POSIX, external) Added flag for each groups type: --posix, --nonposix, --external to group-find command. Group types: * non-POSIX: not posix, not external * POSIX: with objectclass posixgroup * external: with objectclass ipaexternalgroup https://fedorahosted.org/freeipa/ticket/3483 --- tests/test_xmlrpc/objectclasses.py | 1 + tests/test_xmlrpc/test_group_plugin.py | 116 ++++++++++++++++++++++++++++++++- tests/test_xmlrpc/xmlrpc_test.py | 4 ++ 3 files changed, 119 insertions(+), 2 deletions(-) (limited to 'tests') diff --git a/tests/test_xmlrpc/objectclasses.py b/tests/test_xmlrpc/objectclasses.py index d98a7ee6..75ac3eb1 100644 --- a/tests/test_xmlrpc/objectclasses.py +++ b/tests/test_xmlrpc/objectclasses.py @@ -46,6 +46,7 @@ group = [ ] externalgroup = group + [u'ipaexternalgroup'] +posixgroup = group + [u'posixgroup'] host = [ u'ipasshhost', diff --git a/tests/test_xmlrpc/test_group_plugin.py b/tests/test_xmlrpc/test_group_plugin.py index 2d6d2014..7a9b8b6d 100644 --- a/tests/test_xmlrpc/test_group_plugin.py +++ b/tests/test_xmlrpc/test_group_plugin.py @@ -23,7 +23,8 @@ Test the `ipalib/plugins/group.py` module. from ipalib import api, errors from tests.test_xmlrpc import objectclasses -from xmlrpc_test import Declarative, fuzzy_digits, fuzzy_uuid +from tests.util import Fuzzy +from xmlrpc_test import Declarative, fuzzy_digits, fuzzy_uuid, fuzzy_set_ci from ipapython.dn import DN group1 = u'testgroup1' @@ -248,7 +249,7 @@ class test_group(Declarative): cn=[group2], description=[u'Test desc 2'], gidnumber=[fuzzy_digits], - objectclass=objectclasses.group + [u'posixgroup'], + objectclass=objectclasses.posixgroup, ipauniqueid=[fuzzy_uuid], dn=get_group_dn('testgroup2'), ), @@ -382,6 +383,98 @@ class test_group(Declarative): ), ), + dict( + desc='Search for non-POSIX groups', + command=('group_find', [], dict(nonposix=True, all=True)), + expected=dict( + summary=u'2 groups matched', + count=2, + truncated=False, + result=[ + { + 'dn': get_group_dn('ipausers'), + 'cn': [u'ipausers'], + 'description': [u'Default group for all users'], + 'objectclass': fuzzy_set_ci(objectclasses.group), + 'ipauniqueid': [fuzzy_uuid], + }, + { + 'dn': get_group_dn('trust admins'), + 'member_user': [u'admin'], + 'cn': [u'trust admins'], + 'description': [u'Trusts administrators group'], + 'objectclass': fuzzy_set_ci(objectclasses.group), + 'ipauniqueid': [fuzzy_uuid], + }, + ], + ), + ), + + dict( + desc='Search for non-POSIX groups with criteria filter', + command=('group_find', [u'users'], dict(nonposix=True, all=True)), + expected=dict( + summary=u'1 group matched', + count=1, + truncated=False, + result=[ + { + 'dn': get_group_dn('ipausers'), + 'cn': [u'ipausers'], + 'description': [u'Default group for all users'], + 'objectclass': fuzzy_set_ci(objectclasses.group), + 'ipauniqueid': [fuzzy_uuid], + }, + ], + ), + ), + + dict( + desc='Search for POSIX groups', + command=('group_find', [], dict(posix=True, all=True)), + expected=dict( + summary=u'4 groups matched', + count=4, + truncated=False, + result=[ + { + 'dn': get_group_dn('admins'), + 'member_user': [u'admin'], + 'gidnumber': [fuzzy_digits], + 'cn': [u'admins'], + 'description': [u'Account administrators group'], + 'objectclass': fuzzy_set_ci(objectclasses.posixgroup), + 'ipauniqueid': [fuzzy_uuid], + }, + { + 'dn': get_group_dn('editors'), + 'gidnumber': [fuzzy_digits], + 'cn': [u'editors'], + 'description': [u'Limited admins who can edit other users'], + 'objectclass': fuzzy_set_ci(objectclasses.posixgroup), + 'ipauniqueid': [fuzzy_uuid], + }, + dict( + dn=get_group_dn(group1), + cn=[group1], + description=[u'New desc 1'], + gidnumber=[fuzzy_digits], + objectclass=fuzzy_set_ci(objectclasses.posixgroup), + ipauniqueid=[fuzzy_uuid], + ), + dict( + dn=get_group_dn(group2), + cn=[group2], + description=[u'New desc 2'], + gidnumber=[fuzzy_digits], + objectclass=fuzzy_set_ci(objectclasses.posixgroup), + ipauniqueid=[fuzzy_uuid], + ), + ], + ), + ), + + ############### # test external SID members for group3: dict( @@ -402,6 +495,25 @@ class test_group(Declarative): ), ), + dict( + desc='Search for external groups', + command=('group_find', [], dict(external=True, all=True)), + expected=dict( + summary=u'1 group matched', + count=1, + truncated=False, + result=[ + dict( + cn=[group3], + description=[u'Test desc 3'], + objectclass=fuzzy_set_ci(objectclasses.externalgroup), + ipauniqueid=[fuzzy_uuid], + dn=get_group_dn(group3), + ), + ], + ), + ), + dict( desc='Convert posix group %r to support external membership' % (group2), diff --git a/tests/test_xmlrpc/xmlrpc_test.py b/tests/test_xmlrpc/xmlrpc_test.py index cfd7bd33..89f1adc3 100644 --- a/tests/test_xmlrpc/xmlrpc_test.py +++ b/tests/test_xmlrpc/xmlrpc_test.py @@ -83,6 +83,10 @@ fuzzy_dergeneralizedtime = Fuzzy('^[0-9]{14}Z$') # match any string fuzzy_string = Fuzzy(type=basestring) +# case insensitive match of sets +def fuzzy_set_ci(s): + return Fuzzy(test=lambda other: set(x.lower() for x in other) == set(y.lower() for y in s)) + try: if not api.Backend.xmlclient.isconnected(): api.Backend.xmlclient.connect(fallback=False) -- cgit