2010-12-01 10:23:52 -06:00
|
|
|
# Authors:
|
|
|
|
# Rob Crittenden <rcritten@redhat.com>
|
|
|
|
# Pavel Zuna <pzuna@redhat.com>
|
|
|
|
#
|
|
|
|
# Copyright (C) 2010 Red Hat
|
|
|
|
# see file 'COPYING' for use and warranty information
|
|
|
|
#
|
2010-12-09 06:59:11 -06:00
|
|
|
# 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, either version 3 of the License, or
|
|
|
|
# (at your option) any later version.
|
2010-12-01 10:23:52 -06:00
|
|
|
#
|
|
|
|
# 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
|
2010-12-09 06:59:11 -06:00
|
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2010-12-01 10:23:52 -06:00
|
|
|
|
|
|
|
"""
|
|
|
|
Test the `ipalib/plugins/permission.py` module.
|
|
|
|
"""
|
|
|
|
|
|
|
|
from ipalib import api, errors
|
|
|
|
from tests.test_xmlrpc import objectclasses
|
|
|
|
from xmlrpc_test import Declarative, fuzzy_digits, fuzzy_uuid
|
|
|
|
|
|
|
|
permission1 = u'testperm'
|
|
|
|
permission1_dn = u'cn=%s,%s,%s' % (permission1,
|
|
|
|
api.env.container_permission,api.env.basedn,
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
permission2 = u'testperm2'
|
|
|
|
permission2_dn = u'cn=%s,%s,%s' % (permission2,
|
|
|
|
api.env.container_permission,api.env.basedn,
|
|
|
|
)
|
|
|
|
|
|
|
|
privilege1 = u'testpriv1'
|
|
|
|
privilege1_dn = u'cn=%s,%s,%s' % (
|
|
|
|
privilege1, api.env.container_privilege, api.env.basedn
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
class test_permission(Declarative):
|
|
|
|
|
|
|
|
cleanup_commands = [
|
|
|
|
('permission_del', [permission1], {}),
|
|
|
|
('permission_del', [permission2], {}),
|
|
|
|
('privilege_del', [privilege1], {}),
|
|
|
|
]
|
|
|
|
|
|
|
|
tests = [
|
|
|
|
|
|
|
|
dict(
|
|
|
|
desc='Try to retrieve non-existent %r' % permission1,
|
|
|
|
command=('permission_show', [permission1], {}),
|
|
|
|
expected=errors.NotFound(reason='no such entry'),
|
|
|
|
),
|
|
|
|
|
|
|
|
|
|
|
|
dict(
|
|
|
|
desc='Try to update non-existent %r' % permission1,
|
|
|
|
command=('permission_mod', [permission1], dict(description=u'Foo')),
|
|
|
|
expected=errors.NotFound(reason='no such entry'),
|
|
|
|
),
|
|
|
|
|
|
|
|
|
|
|
|
dict(
|
|
|
|
desc='Try to delete non-existent %r' % permission1,
|
|
|
|
command=('permission_del', [permission1], {}),
|
|
|
|
expected=errors.NotFound(reason='no such entry'),
|
|
|
|
),
|
|
|
|
|
|
|
|
|
|
|
|
dict(
|
|
|
|
desc='Search for non-existent %r' % permission1,
|
|
|
|
command=('permission_find', [permission1], {}),
|
|
|
|
expected=dict(
|
|
|
|
count=0,
|
|
|
|
truncated=False,
|
|
|
|
summary=u'0 permissions matched',
|
|
|
|
result=[],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
|
|
|
|
|
|
|
|
dict(
|
|
|
|
desc='Create %r' % permission1,
|
|
|
|
command=(
|
|
|
|
'permission_add', [permission1], dict(
|
|
|
|
description=u'Test desc 1',
|
|
|
|
type=u'user',
|
|
|
|
permissions=u'write',
|
|
|
|
)
|
|
|
|
),
|
|
|
|
expected=dict(
|
|
|
|
value=permission1,
|
|
|
|
summary=u'Added permission "%s"' % permission1,
|
|
|
|
result=dict(
|
|
|
|
dn=permission1_dn,
|
|
|
|
cn=[permission1],
|
|
|
|
description=[u'Test desc 1'],
|
|
|
|
objectclass=objectclasses.permission,
|
|
|
|
type=u'user',
|
|
|
|
permissions=[u'write'],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
|
|
|
|
|
|
|
|
dict(
|
|
|
|
desc='Try to create duplicate %r' % permission1,
|
|
|
|
command=(
|
|
|
|
'permission_add', [permission1], dict(
|
|
|
|
description=u'Test desc 1',
|
|
|
|
type=u'user',
|
|
|
|
permissions=u'write',
|
|
|
|
),
|
|
|
|
),
|
|
|
|
expected=errors.DuplicateEntry(),
|
|
|
|
),
|
|
|
|
|
|
|
|
|
|
|
|
dict(
|
|
|
|
desc='Create %r' % privilege1,
|
|
|
|
command=('privilege_add', [privilege1],
|
|
|
|
dict(description=u'privilege desc. 1')
|
|
|
|
),
|
|
|
|
expected=dict(
|
|
|
|
value=privilege1,
|
|
|
|
summary=u'Added privilege "%s"' % privilege1,
|
|
|
|
result=dict(
|
|
|
|
dn=privilege1_dn,
|
|
|
|
cn=[privilege1],
|
|
|
|
description=[u'privilege desc. 1'],
|
|
|
|
objectclass=objectclasses.privilege,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
|
|
|
|
|
|
|
|
dict(
|
|
|
|
desc='Add permission %r to privilege %r' % (permission1, privilege1),
|
|
|
|
command=('privilege_add_permission', [privilege1],
|
|
|
|
dict(permission=permission1)
|
|
|
|
),
|
|
|
|
expected=dict(
|
|
|
|
completed=1,
|
|
|
|
failed=dict(
|
|
|
|
member=dict(
|
|
|
|
permission=[],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
result={
|
|
|
|
'dn': privilege1_dn,
|
|
|
|
'cn': [privilege1],
|
|
|
|
'description': [u'privilege desc. 1'],
|
|
|
|
'memberof_permission': [permission1],
|
|
|
|
}
|
|
|
|
),
|
|
|
|
),
|
|
|
|
|
|
|
|
|
|
|
|
dict(
|
|
|
|
desc='Retrieve %r' % permission1,
|
|
|
|
command=('permission_show', [permission1], {}),
|
|
|
|
expected=dict(
|
|
|
|
value=permission1,
|
|
|
|
summary=None,
|
|
|
|
result={
|
|
|
|
'dn': permission1_dn,
|
|
|
|
'cn': [permission1],
|
|
|
|
'description': [u'Test desc 1'],
|
|
|
|
'member_privilege': [privilege1],
|
|
|
|
'type': u'user',
|
|
|
|
'permissions': [u'write'],
|
|
|
|
},
|
|
|
|
),
|
|
|
|
),
|
|
|
|
|
|
|
|
|
|
|
|
dict(
|
|
|
|
desc='Search for %r' % permission1,
|
|
|
|
command=('permission_find', [permission1], {}),
|
|
|
|
expected=dict(
|
|
|
|
count=1,
|
|
|
|
truncated=False,
|
|
|
|
summary=u'1 permission matched',
|
|
|
|
result=[
|
|
|
|
{
|
|
|
|
'dn': permission1_dn,
|
|
|
|
'cn': [permission1],
|
|
|
|
'description': [u'Test desc 1'],
|
|
|
|
'member_privilege': [privilege1],
|
|
|
|
'type': u'user',
|
|
|
|
'permissions': [u'write'],
|
|
|
|
},
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
|
|
|
|
|
|
|
|
dict(
|
|
|
|
desc='Search for %r' % privilege1,
|
|
|
|
command=('permission_find', [privilege1], {}),
|
|
|
|
expected=dict(
|
|
|
|
count=1,
|
|
|
|
truncated=False,
|
|
|
|
summary=u'1 permission matched',
|
|
|
|
result=[
|
|
|
|
{
|
|
|
|
'dn': permission1_dn,
|
|
|
|
'cn': [permission1],
|
|
|
|
'description': [u'Test desc 1'],
|
|
|
|
'member_privilege': [privilege1],
|
|
|
|
'type': u'user',
|
|
|
|
'permissions': [u'write'],
|
|
|
|
},
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
|
|
|
|
|
|
|
|
dict(
|
|
|
|
desc='Create %r' % permission2,
|
|
|
|
command=(
|
|
|
|
'permission_add', [permission2], dict(
|
|
|
|
description=u'Test desc 2',
|
|
|
|
type=u'user',
|
|
|
|
permissions=u'write',
|
|
|
|
)
|
|
|
|
),
|
|
|
|
expected=dict(
|
|
|
|
value=permission2,
|
|
|
|
summary=u'Added permission "%s"' % permission2,
|
|
|
|
result=dict(
|
|
|
|
dn=permission2_dn,
|
|
|
|
cn=[permission2],
|
|
|
|
description=[u'Test desc 2'],
|
|
|
|
objectclass=objectclasses.permission,
|
|
|
|
type=u'user',
|
|
|
|
permissions=[u'write'],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
|
|
|
|
|
|
|
|
dict(
|
|
|
|
desc='Search for %r' % permission1,
|
|
|
|
command=('permission_find', [permission1], {}),
|
|
|
|
expected=dict(
|
|
|
|
count=2,
|
|
|
|
truncated=False,
|
|
|
|
summary=u'2 permissions matched',
|
|
|
|
result=[
|
|
|
|
{
|
|
|
|
'dn': permission1_dn,
|
|
|
|
'cn': [permission1],
|
|
|
|
'description': [u'Test desc 1'],
|
|
|
|
'member_privilege': [privilege1],
|
|
|
|
'type': u'user',
|
|
|
|
'permissions': [u'write'],
|
|
|
|
},
|
|
|
|
{
|
|
|
|
'dn': permission2_dn,
|
|
|
|
'cn': [permission2],
|
|
|
|
'description': [u'Test desc 2'],
|
|
|
|
'type': u'user',
|
|
|
|
'permissions': [u'write'],
|
|
|
|
},
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
|
|
|
|
|
|
|
|
dict(
|
|
|
|
desc='Search for %r' % privilege1,
|
|
|
|
command=('privilege_find', [privilege1], {}),
|
|
|
|
expected=dict(
|
|
|
|
count=1,
|
|
|
|
truncated=False,
|
|
|
|
summary=u'1 privilege matched',
|
|
|
|
result=[
|
|
|
|
{
|
|
|
|
'dn': privilege1_dn,
|
|
|
|
'cn': [privilege1],
|
|
|
|
'description': [u'privilege desc. 1'],
|
|
|
|
'memberof_permission': [permission1],
|
|
|
|
},
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
|
|
|
|
|
|
|
|
dict(
|
|
|
|
desc='Update %r' % permission1,
|
|
|
|
command=(
|
|
|
|
'permission_mod', [permission1], dict(description=u'New desc 1')
|
|
|
|
),
|
|
|
|
expected=dict(
|
|
|
|
value=permission1,
|
|
|
|
summary=u'Modified permission "%s"' % permission1,
|
|
|
|
result=dict(
|
|
|
|
dn=permission1_dn,
|
|
|
|
cn=[permission1],
|
|
|
|
description=[u'New desc 1'],
|
|
|
|
member_privilege=[privilege1],
|
|
|
|
type=u'user',
|
|
|
|
permissions=[u'write'],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
|
|
|
|
|
|
|
|
dict(
|
|
|
|
desc='Retrieve %r to verify update' % permission1,
|
|
|
|
command=('permission_show', [permission1], {}),
|
|
|
|
expected=dict(
|
|
|
|
value=permission1,
|
|
|
|
summary=None,
|
|
|
|
result={
|
|
|
|
'dn': permission1_dn,
|
|
|
|
'cn': [permission1],
|
|
|
|
'description': [u'New desc 1'],
|
|
|
|
'member_privilege': [privilege1],
|
|
|
|
'type': u'user',
|
|
|
|
'permissions': [u'write'],
|
|
|
|
},
|
|
|
|
),
|
|
|
|
),
|
|
|
|
|
|
|
|
|
|
|
|
dict(
|
|
|
|
desc='Delete %r' % permission1,
|
|
|
|
command=('permission_del', [permission1], {}),
|
|
|
|
expected=dict(
|
2011-01-07 10:17:55 -06:00
|
|
|
result=dict(failed=u''),
|
2010-12-01 10:23:52 -06:00
|
|
|
value=permission1,
|
|
|
|
summary=u'Deleted permission "%s"' % permission1,
|
|
|
|
)
|
|
|
|
),
|
|
|
|
|
|
|
|
|
|
|
|
dict(
|
|
|
|
desc='Try to delete non-existent %r' % permission1,
|
|
|
|
command=('permission_del', [permission1], {}),
|
|
|
|
expected=errors.NotFound(reason='no such entry'),
|
|
|
|
),
|
|
|
|
|
|
|
|
|
|
|
|
dict(
|
|
|
|
desc='Try to retrieve non-existent %r' % permission1,
|
|
|
|
command=('permission_show', [permission1], {}),
|
|
|
|
expected=errors.NotFound(reason='no such entry'),
|
|
|
|
),
|
|
|
|
|
|
|
|
|
|
|
|
dict(
|
|
|
|
desc='Try to update non-existent %r' % permission1,
|
|
|
|
command=('permission_mod', [permission1], dict(description=u'Foo')),
|
|
|
|
expected=errors.NotFound(reason='no such entry'),
|
|
|
|
),
|
|
|
|
|
|
|
|
|
|
|
|
dict(
|
|
|
|
desc='Delete %r' % permission2,
|
|
|
|
command=('permission_del', [permission2], {}),
|
|
|
|
expected=dict(
|
2011-01-07 10:17:55 -06:00
|
|
|
result=dict(failed=u''),
|
2010-12-01 10:23:52 -06:00
|
|
|
value=permission2,
|
|
|
|
summary=u'Deleted permission "%s"' % permission2,
|
|
|
|
)
|
|
|
|
),
|
|
|
|
|
|
|
|
|
|
|
|
dict(
|
|
|
|
desc='Search for %r' % permission1,
|
|
|
|
command=('permission_find', [permission1], {}),
|
|
|
|
expected=dict(
|
|
|
|
count=0,
|
|
|
|
truncated=False,
|
|
|
|
summary=u'0 permissions matched',
|
|
|
|
result=[],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
|
|
|
|
|
|
|
|
dict(
|
|
|
|
desc='Delete %r' % privilege1,
|
|
|
|
command=('privilege_del', [privilege1], {}),
|
|
|
|
expected=dict(
|
2011-01-07 10:17:55 -06:00
|
|
|
result=dict(failed=u''),
|
2010-12-01 10:23:52 -06:00
|
|
|
value=privilege1,
|
|
|
|
summary=u'Deleted privilege "%s"' % privilege1,
|
|
|
|
)
|
|
|
|
),
|
|
|
|
|
|
|
|
]
|