summaryrefslogtreecommitdiffstats
path: root/tests/test_xmlrpc/test_service_plugin.py
diff options
context:
space:
mode:
authorJohn Dennis <jdennis@redhat.com>2011-08-09 21:21:56 -0400
committerRob Crittenden <rcritten@redhat.com>2011-08-16 23:52:41 -0400
commit9df6a4ed8cfa21e398ccb054e7ef4aaf323bdd70 (patch)
tree85e549b842aa7c9cbef54f44abdae0f4130ec3d0 /tests/test_xmlrpc/test_service_plugin.py
parent97f0671ce9dd1d260fea4e95f6e6e017a1ef1048 (diff)
downloadfreeipa-9df6a4ed8cfa21e398ccb054e7ef4aaf323bdd70.tar.gz
freeipa-9df6a4ed8cfa21e398ccb054e7ef4aaf323bdd70.tar.xz
freeipa-9df6a4ed8cfa21e398ccb054e7ef4aaf323bdd70.zip
ticket 1600 - convert unittests to use DN objects
We have a larger goal of replacing all DN creation via string formatting/concatenation with DN object operations because string operations are not a safe way to form a DN nor to compare a DN. This work needs to be broken into smaller chunks for easier review and testing. Addressing the unit tests first makes sense because we don't want to be modifying both the core code and the tests used to verify the core code simultaneously. If we modify the unittests first with existing core code and no regressions are found then we can move on to modifying parts of the core code with the belief the unittests can validate the changes in the core code. Also by doing the unittests first we also help to validate the DN objects are working correctly (although they do have an extensive unittest). The fundamental changes are: * replace string substitution & concatenation with DN object constructor * when comparing dn's the comparision is done after promotion to a DN object, then two DN objects are compared * when a list of string dn's are to be compared a new list is formed where each string dn is replaced by a DN object * because the unittest framework accepts a complex data structure of expected values where dn's are represeted as strings the unittest needs to express the expected value of a dn as a callable object (e.g. a lambda expression) which promotes the dn string to a DN object in order to do the comparision.
Diffstat (limited to 'tests/test_xmlrpc/test_service_plugin.py')
-rw-r--r--tests/test_xmlrpc/test_service_plugin.py46
1 files changed, 24 insertions, 22 deletions
diff --git a/tests/test_xmlrpc/test_service_plugin.py b/tests/test_xmlrpc/test_service_plugin.py
index 4f08f235e..d424eeedd 100644
--- a/tests/test_xmlrpc/test_service_plugin.py
+++ b/tests/test_xmlrpc/test_service_plugin.py
@@ -26,17 +26,17 @@ from tests.test_xmlrpc.xmlrpc_test import Declarative, fuzzy_uuid, fuzzy_hash
from tests.test_xmlrpc.xmlrpc_test import fuzzy_digits, fuzzy_date, fuzzy_issuer
from tests.test_xmlrpc import objectclasses
import base64
-
+from ipalib.dn import *
fqdn1 = u'testhost1.%s' % api.env.domain
fqdn2 = u'testhost2.%s' % api.env.domain
fqdn3 = u'TestHost3.%s' % api.env.domain
service1 = u'HTTP/%s@%s' % (fqdn1, api.env.realm)
hostprincipal1 = u'host/%s@%s' % (fqdn1, api.env.realm)
-service1dn = u'krbprincipalname=%s,cn=services,cn=accounts,%s' % (service1.lower(), api.env.basedn)
-host1dn = u'fqdn=%s,cn=computers,cn=accounts,%s' % (fqdn1, api.env.basedn)
-host2dn = u'fqdn=%s,cn=computers,cn=accounts,%s' % (fqdn2, api.env.basedn)
-host3dn = u'fqdn=%s,cn=computers,cn=accounts,%s' % (fqdn3.lower(), api.env.basedn)
+service1dn = DN(('krbprincipalname',service1),('cn','services'),('cn','accounts'),api.env.basedn)
+host1dn = DN(('fqdn',fqdn1),('cn','computers'),('cn','accounts'),api.env.basedn)
+host2dn = DN(('fqdn',fqdn2),('cn','computers'),('cn','accounts'),api.env.basedn)
+host3dn = DN(('fqdn',fqdn3),('cn','computers'),('cn','accounts'),api.env.basedn)
fd = open('tests/test_xmlrpc/service.crt', 'r')
servercert = fd.readlines()
@@ -91,7 +91,7 @@ class test_host(Declarative):
value=fqdn1,
summary=u'Added host "%s"' % fqdn1,
result=dict(
- dn=host1dn,
+ dn=lambda x: DN(x) == host1dn,
fqdn=[fqdn1],
description=[u'Test host 1'],
l=[u'Undisclosed location 1'],
@@ -117,7 +117,7 @@ class test_host(Declarative):
value=fqdn2,
summary=u'Added host "%s"' % fqdn2,
result=dict(
- dn=host2dn,
+ dn=lambda x: DN(x) == host2dn,
fqdn=[fqdn2],
description=[u'Test host 2'],
l=[u'Undisclosed location 2'],
@@ -143,7 +143,7 @@ class test_host(Declarative):
value=fqdn3.lower(),
summary=u'Added host "%s"' % fqdn3.lower(),
result=dict(
- dn=host3dn,
+ dn=lambda x: DN(x) == host3dn,
fqdn=[fqdn3.lower()],
description=[u'Test host 3'],
l=[u'Undisclosed location 3'],
@@ -167,7 +167,7 @@ class test_host(Declarative):
value=service1,
summary=u'Added service "%s"' % service1,
result=dict(
- dn=service1dn,
+ dn=lambda x: DN(x) == service1dn,
krbprincipalname=[service1],
objectclass=objectclasses.service,
ipauniqueid=[fuzzy_uuid],
@@ -195,7 +195,7 @@ class test_host(Declarative):
value=service1,
summary=None,
result=dict(
- dn=service1dn,
+ dn=lambda x: DN(x) == service1dn,
krbprincipalname=[service1],
has_keytab=False,
managedby_host=[fqdn1],
@@ -211,7 +211,7 @@ class test_host(Declarative):
value=service1,
summary=None,
result=dict(
- dn=service1dn,
+ dn=lambda x: DN(x) == service1dn,
krbprincipalname=[service1],
objectclass=objectclasses.service,
ipauniqueid=[fuzzy_uuid],
@@ -231,7 +231,7 @@ class test_host(Declarative):
summary=u'1 service matched',
result=[
dict(
- dn=service1dn,
+ dn=lambda x: DN(x) == service1dn,
krbprincipalname=[service1],
managedby_host=[fqdn1],
has_keytab=False,
@@ -250,7 +250,7 @@ class test_host(Declarative):
summary=u'1 service matched',
result=[
dict(
- dn=service1dn,
+ dn=lambda x: DN(x) == service1dn,
krbprincipalname=[service1],
objectclass=objectclasses.service,
ipauniqueid=[fuzzy_uuid],
@@ -269,7 +269,7 @@ class test_host(Declarative):
failed=dict(managedby=dict(host=[(u'notfound', u'no such entry')])),
completed=0,
result=dict(
- dn=service1dn,
+ dn=lambda x: DN(x) == service1dn,
krbprincipalname=[service1],
managedby_host=[fqdn1],
),
@@ -284,7 +284,7 @@ class test_host(Declarative):
failed=dict(managedby=dict(host=[(u'notfound', u'This entry is not a member')])),
completed=0,
result=dict(
- dn=service1dn,
+ dn=lambda x: DN(x) == service1dn,
krbprincipalname=[service1],
managedby_host=[fqdn1],
),
@@ -299,7 +299,7 @@ class test_host(Declarative):
failed=dict(managedby=dict(host=[])),
completed=1,
result=dict(
- dn=service1dn,
+ dn=lambda x: DN(x) == service1dn,
krbprincipalname=[service1],
managedby_host=[fqdn1, fqdn2],
),
@@ -314,7 +314,7 @@ class test_host(Declarative):
failed=dict(managedby=dict(host=[])),
completed=1,
result=dict(
- dn=service1dn,
+ dn=lambda x: DN(x) == service1dn,
krbprincipalname=[service1],
managedby_host=[fqdn1],
),
@@ -329,7 +329,7 @@ class test_host(Declarative):
failed=dict(managedby=dict(host=[])),
completed=1,
result=dict(
- dn=service1dn,
+ dn=lambda x: DN(x) == service1dn,
krbprincipalname=[service1],
managedby_host=[fqdn1, fqdn3.lower()],
),
@@ -344,7 +344,7 @@ class test_host(Declarative):
failed=dict(managedby=dict(host=[])),
completed=1,
result=dict(
- dn=service1dn,
+ dn=lambda x: DN(x) == service1dn,
krbprincipalname=[service1],
managedby_host=[fqdn1],
),
@@ -371,7 +371,8 @@ class test_host(Declarative):
managedby_host=[fqdn1],
valid_not_before=fuzzy_date,
valid_not_after=fuzzy_date,
- subject=u'CN=%s,O=%s' % (api.env.host, api.env.realm),
+ subject=lambda x: DN(x) == \
+ DN(('CN',api.env.host),('O',api.env.realm)),
serial_number=fuzzy_digits,
md5_fingerprint=fuzzy_hash,
sha1_fingerprint=fuzzy_hash,
@@ -388,7 +389,7 @@ class test_host(Declarative):
value=service1,
summary=None,
result=dict(
- dn=service1dn,
+ dn=lambda x: DN(x) == service1dn,
usercertificate=[base64.b64decode(servercert)],
krbprincipalname=[service1],
has_keytab=False,
@@ -397,7 +398,8 @@ class test_host(Declarative):
# test case.
valid_not_before=fuzzy_date,
valid_not_after=fuzzy_date,
- subject=u'CN=%s,O=%s' % (api.env.host, api.env.realm),
+ subject=lambda x: DN(x) == \
+ DN(('CN',api.env.host),('O',api.env.realm)),
serial_number=fuzzy_digits,
md5_fingerprint=fuzzy_hash,
sha1_fingerprint=fuzzy_hash,