2010-12-08 12:33:40 -06:00
|
|
|
# Authors:
|
|
|
|
# Rob Crittenden <rcritten@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-08 12:33:40 -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-08 12:33:40 -06:00
|
|
|
|
|
|
|
"""
|
|
|
|
Test the `ipalib/plugins/selfservice.py` module.
|
|
|
|
"""
|
|
|
|
|
|
|
|
from ipalib import api, errors
|
2013-05-21 06:40:27 -05:00
|
|
|
from ipatests.test_xmlrpc import objectclasses
|
2015-07-31 03:15:01 -05:00
|
|
|
from ipatests.test_xmlrpc.xmlrpc_test import (Declarative, fuzzy_digits,
|
|
|
|
fuzzy_uuid)
|
2010-12-08 12:33:40 -06:00
|
|
|
|
|
|
|
selfservice1 = u'testself'
|
2012-04-06 03:56:46 -05:00
|
|
|
invalid_selfservice1 = u'bad+name'
|
2010-12-08 12:33:40 -06:00
|
|
|
|
|
|
|
class test_selfservice(Declarative):
|
|
|
|
|
|
|
|
cleanup_commands = [
|
|
|
|
('selfservice_del', [selfservice1], {}),
|
|
|
|
]
|
|
|
|
|
|
|
|
tests = [
|
|
|
|
|
|
|
|
dict(
|
|
|
|
desc='Try to retrieve non-existent %r' % selfservice1,
|
|
|
|
command=('selfservice_show', [selfservice1], {}),
|
2012-03-27 08:27:11 -05:00
|
|
|
expected=errors.NotFound(
|
|
|
|
reason=u'ACI with name "%s" not found' % selfservice1),
|
2010-12-08 12:33:40 -06:00
|
|
|
),
|
|
|
|
|
|
|
|
|
|
|
|
dict(
|
|
|
|
desc='Try to update non-existent %r' % selfservice1,
|
2012-04-17 11:48:33 -05:00
|
|
|
command=('selfservice_mod', [selfservice1],
|
|
|
|
dict(permissions=u'write')),
|
2012-03-27 08:27:11 -05:00
|
|
|
expected=errors.NotFound(
|
|
|
|
reason=u'ACI with name "%s" not found' % selfservice1),
|
2010-12-08 12:33:40 -06:00
|
|
|
),
|
|
|
|
|
|
|
|
|
|
|
|
dict(
|
|
|
|
desc='Try to delete non-existent %r' % selfservice1,
|
|
|
|
command=('selfservice_del', [selfservice1], {}),
|
2012-03-27 08:27:11 -05:00
|
|
|
expected=errors.NotFound(
|
|
|
|
reason=u'ACI with name "%s" not found' % selfservice1),
|
2010-12-08 12:33:40 -06:00
|
|
|
),
|
|
|
|
|
|
|
|
|
|
|
|
dict(
|
|
|
|
desc='Search for non-existent %r' % selfservice1,
|
|
|
|
command=('selfservice_find', [selfservice1], {}),
|
|
|
|
expected=dict(
|
|
|
|
count=0,
|
|
|
|
truncated=False,
|
|
|
|
summary=u'0 selfservices matched',
|
|
|
|
result=[],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
|
|
|
|
|
2010-12-17 15:57:28 -06:00
|
|
|
# Note that we add postalCode but expect postalcode. This tests
|
|
|
|
# the attrs normalizer.
|
2010-12-08 12:33:40 -06:00
|
|
|
dict(
|
|
|
|
desc='Create %r' % selfservice1,
|
|
|
|
command=(
|
|
|
|
'selfservice_add', [selfservice1], dict(
|
Only split CSV in the client, quote instead of escaping
Splitting on commas is not an idempotent operation:
'a,b\,c' -> ('a', 'b,c') -> ('a', 'b', 'c')
That means we can't do it when the call is forwarded, so this is only
done on the CLI. The UI already sends values as a tuple.
Replace escaping in the csv parser with quoting. Quoted strings can have
embedded commas instead of having to escape them. This prevents the csv
parser from eating all escape characters.
Also, document Param's csv arguments, and update tests.
https://fedorahosted.org/freeipa/ticket/2417
https://fedorahosted.org/freeipa/ticket/2227
2012-02-23 06:29:47 -06:00
|
|
|
attrs=[u'street', u'c', u'l', u'st', u'postalcode'],
|
|
|
|
permissions=u'write',
|
2010-12-08 12:33:40 -06:00
|
|
|
)
|
|
|
|
),
|
|
|
|
expected=dict(
|
|
|
|
value=selfservice1,
|
|
|
|
summary=u'Added selfservice "%s"' % selfservice1,
|
|
|
|
result=dict(
|
2010-12-17 15:57:28 -06:00
|
|
|
attrs=[u'street', u'c', u'l', u'st', u'postalcode'],
|
2010-12-08 12:33:40 -06:00
|
|
|
permissions=[u'write'],
|
|
|
|
selfaci=True,
|
|
|
|
aciname=selfservice1,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
|
|
|
|
|
|
|
|
dict(
|
|
|
|
desc='Try to create duplicate %r' % selfservice1,
|
|
|
|
command=(
|
|
|
|
'selfservice_add', [selfservice1], dict(
|
Only split CSV in the client, quote instead of escaping
Splitting on commas is not an idempotent operation:
'a,b\,c' -> ('a', 'b,c') -> ('a', 'b', 'c')
That means we can't do it when the call is forwarded, so this is only
done on the CLI. The UI already sends values as a tuple.
Replace escaping in the csv parser with quoting. Quoted strings can have
embedded commas instead of having to escape them. This prevents the csv
parser from eating all escape characters.
Also, document Param's csv arguments, and update tests.
https://fedorahosted.org/freeipa/ticket/2417
https://fedorahosted.org/freeipa/ticket/2227
2012-02-23 06:29:47 -06:00
|
|
|
attrs=[u'street', u'c', u'l', u'st', u'postalcode'],
|
|
|
|
permissions=u'write',
|
2010-12-08 12:33:40 -06:00
|
|
|
),
|
|
|
|
),
|
|
|
|
expected=errors.DuplicateEntry(),
|
|
|
|
),
|
|
|
|
|
|
|
|
|
|
|
|
dict(
|
|
|
|
desc='Retrieve %r' % selfservice1,
|
|
|
|
command=('selfservice_show', [selfservice1], {}),
|
|
|
|
expected=dict(
|
|
|
|
value=selfservice1,
|
|
|
|
summary=None,
|
|
|
|
result={
|
2010-12-17 15:57:28 -06:00
|
|
|
'attrs': [u'street', u'c', u'l', u'st', u'postalcode'],
|
2010-12-08 12:33:40 -06:00
|
|
|
'permissions': [u'write'],
|
|
|
|
'selfaci': True,
|
|
|
|
'aciname': selfservice1,
|
|
|
|
},
|
|
|
|
),
|
|
|
|
),
|
|
|
|
|
|
|
|
|
2012-02-02 14:28:15 -06:00
|
|
|
dict(
|
|
|
|
desc='Retrieve %r with --raw' % selfservice1,
|
|
|
|
command=('selfservice_show', [selfservice1], {'raw':True}),
|
|
|
|
expected=dict(
|
|
|
|
value=selfservice1,
|
|
|
|
summary=None,
|
|
|
|
result={
|
|
|
|
'aci': u'(targetattr = "street || c || l || st || postalcode")(version 3.0;acl "selfservice:testself";allow (write) userdn = "ldap:///self";)',
|
|
|
|
},
|
|
|
|
),
|
|
|
|
),
|
|
|
|
|
|
|
|
|
2010-12-08 12:33:40 -06:00
|
|
|
dict(
|
|
|
|
desc='Search for %r' % selfservice1,
|
|
|
|
command=('selfservice_find', [selfservice1], {}),
|
|
|
|
expected=dict(
|
|
|
|
count=1,
|
|
|
|
truncated=False,
|
|
|
|
summary=u'1 selfservice matched',
|
|
|
|
result=[
|
|
|
|
{
|
2010-12-17 15:57:28 -06:00
|
|
|
'attrs': [u'street', u'c', u'l', u'st', u'postalcode'],
|
2010-12-08 12:33:40 -06:00
|
|
|
'permissions': [u'write'],
|
|
|
|
'selfaci': True,
|
|
|
|
'aciname': selfservice1,
|
|
|
|
},
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
|
2012-01-16 04:14:59 -06:00
|
|
|
dict(
|
|
|
|
desc='Search for %r with --pkey-only' % selfservice1,
|
|
|
|
command=('selfservice_find', [selfservice1], {'pkey_only' : True}),
|
|
|
|
expected=dict(
|
|
|
|
count=1,
|
|
|
|
truncated=False,
|
|
|
|
summary=u'1 selfservice matched',
|
|
|
|
result=[
|
|
|
|
{
|
|
|
|
'aciname': selfservice1,
|
|
|
|
},
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
|
2010-12-08 12:33:40 -06:00
|
|
|
|
2012-01-06 05:44:59 -06:00
|
|
|
dict(
|
|
|
|
desc='Search for %r with empty attrs and permissions' % selfservice1,
|
|
|
|
command=('selfservice_find', [selfservice1], {'attrs' : None, 'permissions' : None}),
|
|
|
|
expected=dict(
|
|
|
|
count=1,
|
|
|
|
truncated=False,
|
|
|
|
summary=u'1 selfservice matched',
|
|
|
|
result=[
|
|
|
|
{
|
|
|
|
'attrs': [u'street', u'c', u'l', u'st', u'postalcode'],
|
|
|
|
'permissions': [u'write'],
|
|
|
|
'selfaci': True,
|
|
|
|
'aciname': selfservice1,
|
|
|
|
},
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
|
|
|
|
|
2012-02-02 14:28:15 -06:00
|
|
|
dict(
|
|
|
|
desc='Search for %r with --raw' % selfservice1,
|
|
|
|
command=('selfservice_find', [selfservice1], {'raw':True}),
|
|
|
|
expected=dict(
|
|
|
|
count=1,
|
|
|
|
truncated=False,
|
|
|
|
summary=u'1 selfservice matched',
|
|
|
|
result=[
|
|
|
|
{
|
|
|
|
'aci': u'(targetattr = "street || c || l || st || postalcode")(version 3.0;acl "selfservice:testself";allow (write) userdn = "ldap:///self";)'
|
|
|
|
},
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
|
|
|
|
|
2010-12-08 12:33:40 -06:00
|
|
|
dict(
|
|
|
|
desc='Update %r' % selfservice1,
|
|
|
|
command=(
|
|
|
|
'selfservice_mod', [selfservice1], dict(permissions=u'read')
|
|
|
|
),
|
|
|
|
expected=dict(
|
|
|
|
value=selfservice1,
|
|
|
|
summary=u'Modified selfservice "%s"' % selfservice1,
|
|
|
|
result=dict(
|
2010-12-17 15:57:28 -06:00
|
|
|
attrs=[u'street', u'c', u'l', u'st', u'postalcode'],
|
2010-12-08 12:33:40 -06:00
|
|
|
permissions=[u'read'],
|
|
|
|
selfaci=True,
|
|
|
|
aciname=selfservice1,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
|
|
|
|
|
|
|
|
dict(
|
|
|
|
desc='Retrieve %r to verify update' % selfservice1,
|
|
|
|
command=('selfservice_show', [selfservice1], {}),
|
|
|
|
expected=dict(
|
|
|
|
value=selfservice1,
|
|
|
|
summary=None,
|
|
|
|
result={
|
2010-12-17 15:57:28 -06:00
|
|
|
'attrs': [u'street', u'c', u'l', u'st', u'postalcode'],
|
2010-12-08 12:33:40 -06:00
|
|
|
'permissions': [u'read'],
|
|
|
|
'selfaci': True,
|
|
|
|
'aciname': selfservice1,
|
|
|
|
},
|
|
|
|
),
|
|
|
|
),
|
|
|
|
|
|
|
|
|
2012-01-06 06:58:01 -06:00
|
|
|
dict(
|
|
|
|
desc='Try to update %r with empty permissions' % selfservice1,
|
|
|
|
command=(
|
|
|
|
'selfservice_mod', [selfservice1], dict(permissions=None)
|
|
|
|
),
|
|
|
|
expected=errors.RequirementError(name='permissions'),
|
|
|
|
),
|
|
|
|
|
|
|
|
|
|
|
|
dict(
|
|
|
|
desc='Retrieve %r to verify invalid update' % selfservice1,
|
|
|
|
command=('selfservice_show', [selfservice1], {}),
|
|
|
|
expected=dict(
|
|
|
|
value=selfservice1,
|
|
|
|
summary=None,
|
|
|
|
result={
|
|
|
|
'attrs': [u'street', u'c', u'l', u'st', u'postalcode'],
|
|
|
|
'permissions': [u'read'],
|
|
|
|
'selfaci': True,
|
|
|
|
'aciname': selfservice1,
|
|
|
|
},
|
|
|
|
),
|
|
|
|
),
|
|
|
|
|
|
|
|
|
2010-12-08 12:33:40 -06:00
|
|
|
dict(
|
|
|
|
desc='Delete %r' % selfservice1,
|
|
|
|
command=('selfservice_del', [selfservice1], {}),
|
|
|
|
expected=dict(
|
|
|
|
result=True,
|
|
|
|
value=selfservice1,
|
|
|
|
summary=u'Deleted selfservice "%s"' % selfservice1,
|
|
|
|
)
|
|
|
|
),
|
|
|
|
|
2012-04-06 03:56:46 -05:00
|
|
|
dict(
|
|
|
|
desc='Create invalid %r' % invalid_selfservice1,
|
|
|
|
command=(
|
|
|
|
'selfservice_add', [invalid_selfservice1], dict(
|
|
|
|
attrs=[u'street', u'c', u'l', u'st', u'postalcode'],
|
|
|
|
permissions=u'write',
|
|
|
|
)
|
|
|
|
),
|
|
|
|
expected=errors.ValidationError(name='name',
|
|
|
|
error='May only contain letters, numbers, -, _, and space'),
|
|
|
|
),
|
|
|
|
|
2010-12-08 12:33:40 -06:00
|
|
|
]
|