Re: [Freeipa-devel] [PATCH 28/28] Update test_role_plugin test to include a comma in a, privilege

2011-06-22 Thread Rob Crittenden

John Dennis wrote:

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 between 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.



ack, pushed to master and ipa-2-0

___
Freeipa-devel mailing list
Freeipa-devel@redhat.com
https://www.redhat.com/mailman/listinfo/freeipa-devel


[Freeipa-devel] [PATCH 28/28] Update test_role_plugin test to include a comma in a, privilege

2011-06-15 Thread John Dennis

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 between 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.

--
John Dennis 

Looking to carve out IT costs?
www.redhat.com/carveoutcosts/
>From 3c2a92fd1a01a7750e90a119d497d5751932c796 Mon Sep 17 00:00:00 2001
From: John Dennis 
Date: Wed, 15 Jun 2011 16:05:19 -0400
Subject: [PATCH 28/28] Update test_role_plugin test to include a comma in a
 privilege
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 8bit

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.
---
 tests/test_xmlrpc/test_role_plugin.py |   16 ++--
 1 files changed, 10 insertions(+), 6 deletions(-)

diff --git a/tests/test_xmlrpc/test_role_plugin.py b/tests/test_xmlrpc/test_role_plugin.py
index 28d1c6b..82342c3 100644
--- a/tests/test_xmlrpc/test_role_plugin.py
+++ b/tests/test_xmlrpc/test_role_plugin.py
@@ -1,6 +1,7 @@
 # Authors:
 #   Rob Crittenden 
 #   Pavel Zuna 
+#   John Dennis 
 #
 # 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_c