Update test_role_plugin test to include a comma in a privilege

Introduce a comma into a privilege name to assure we can handle
commas.

Commas must be escaped for some parameters, add escape_comma() utility
and invoke it for the necessary parameters.

Utilize a DN object to properly construct a DN and most importantly to
allow equality testing beween the DN we expect and the one
returned. This is necessary because a DN can be encoded according to
different encoding syntaxes all of which are valid. DN objects always
decode from their input. DN objects can test for equality between DN's
without being affected by DN encoding.

Add a equality callback for the dn in the expected dict. When the test
framework tests for equality between the expected value and the
returned value it will call back into a function we provide which will
convert the returned dn into a DN object. An equality test is then
performed between two DN objects. This is the only way to properly
compare two dn's.
This commit is contained in:
John Dennis 2011-06-15 16:05:19 -04:00 committed by Rob Crittenden
parent 8c95eb68d2
commit d9d00f1522

View File

@ -1,6 +1,7 @@
# Authors:
# Rob Crittenden <rcritten@redhat.com>
# Pavel Zuna <pzuna@redhat.com>
# John Dennis <jdennis@redhat.com>
#
# Copyright (C) 2009 Red Hat
# see file 'COPYING' for use and warranty information
@ -24,6 +25,7 @@ Test the `ipalib/plugins/role.py` module.
from ipalib import api, errors
from tests.test_xmlrpc import objectclasses
from xmlrpc_test import Declarative, fuzzy_digits, fuzzy_uuid
from ipalib.dn import *
search = u'test-role'
@ -41,9 +43,11 @@ role2_dn = u'cn=%s,%s,%s' % (
group1 = u'testgroup1'
group1_dn = u'cn=%s,%s,%s' % (group1, api.env.container_group, api.env.basedn)
privilege1 = u'testpriv1'
privilege1_dn = u'cn=%s,%s,%s' % (privilege1, api.env.container_privilege, api.env.basedn)
privilege1 = u'r,w privilege 1'
privilege1_dn = DN('cn', privilege1, DN(api.env.container_privilege), DN(api.env.basedn))
def escape_comma(value):
return value.replace(',', '\\,')
class test_role(Declarative):
@ -158,7 +162,7 @@ class test_role(Declarative):
value=privilege1,
summary=u'Added privilege "%s"' % privilege1,
result=dict(
dn=privilege1_dn,
dn=lambda got: DN(got) == privilege1_dn,
cn=[privilege1],
description=[u'privilege desc. 1'],
objectclass=objectclasses.privilege,
@ -170,7 +174,7 @@ class test_role(Declarative):
dict(
desc='Add privilege %r to role %r' % (privilege1, role1),
command=('role_add_privilege', [role1],
dict(privilege=privilege1)
dict(privilege=escape_comma(privilege1))
),
expected=dict(
completed=1,
@ -451,7 +455,7 @@ class test_role(Declarative):
dict(
desc='Remove privilege %r from role %r' % (privilege1, role1),
command=('role_remove_privilege', [role1],
dict(privilege=privilege1)
dict(privilege=escape_comma(privilege1))
),
expected=dict(
completed=1,
@ -472,7 +476,7 @@ class test_role(Declarative):
dict(
desc='Remove privilege %r from role %r again' % (privilege1, role1),
command=('role_remove_privilege', [role1],
dict(privilege=privilege1)
dict(privilege=escape_comma(privilege1))
),
expected=dict(
completed=0,