diff options
author | John Dennis <jdennis@redhat.com> | 2011-08-09 21:21:56 -0400 |
---|---|---|
committer | Rob Crittenden <rcritten@redhat.com> | 2011-08-16 23:52:26 -0400 |
commit | 2673782aec632e84e89e8963b59cca8f62dafd47 (patch) | |
tree | 85e549b842aa7c9cbef54f44abdae0f4130ec3d0 /tests/test_xmlrpc/test_host_plugin.py | |
parent | b6006f78f0e513b719ccf11831b8008516e0ef5e (diff) | |
download | freeipa-2673782aec632e84e89e8963b59cca8f62dafd47.tar.gz freeipa-2673782aec632e84e89e8963b59cca8f62dafd47.tar.xz freeipa-2673782aec632e84e89e8963b59cca8f62dafd47.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_host_plugin.py')
-rw-r--r-- | tests/test_xmlrpc/test_host_plugin.py | 48 |
1 files changed, 28 insertions, 20 deletions
diff --git a/tests/test_xmlrpc/test_host_plugin.py b/tests/test_xmlrpc/test_host_plugin.py index 426b0d7ca..87eb93768 100644 --- a/tests/test_xmlrpc/test_host_plugin.py +++ b/tests/test_xmlrpc/test_host_plugin.py @@ -23,6 +23,7 @@ Test the `ipalib.plugins.host` module. """ from ipalib import api, errors, x509 +from ipalib.dn import * from tests.test_xmlrpc.xmlrpc_test import Declarative, fuzzy_uuid, fuzzy_digits from tests.test_xmlrpc.xmlrpc_test import fuzzy_hash, fuzzy_date, fuzzy_issuer from tests.test_xmlrpc import objectclasses @@ -31,16 +32,21 @@ import base64 fqdn1 = u'testhost1.%s' % api.env.domain short1 = u'testhost1' -dn1 = u'fqdn=%s,cn=computers,cn=accounts,%s' % (fqdn1, api.env.basedn) +dn1 = DN(('fqdn',fqdn1),('cn','computers'),('cn','accounts'), + api.env.basedn) service1 = u'dns/%s@%s' % (fqdn1, api.env.realm) -service1dn = u'krbprincipalname=%s,cn=services,cn=accounts,%s' % (service1.lower(), api.env.basedn) +service1dn = DN(('krbprincipalname',service1.lower()),('cn','services'), + ('cn','accounts'),api.env.basedn) fqdn2 = u'shouldnotexist.%s' % api.env.domain -dn2 = u'fqdn=%s,cn=computers,cn=accounts,%s' % (fqdn2, api.env.basedn) +dn2 = DN(('fqdn',fqdn2),('cn','computers'),('cn','accounts'), + api.env.basedn) fqdn3 = u'testhost2.%s' % api.env.domain short3 = u'testhost2' -dn3 = u'fqdn=%s,cn=computers,cn=accounts,%s' % (fqdn3, api.env.basedn) +dn3 = DN(('fqdn',fqdn3),('cn','computers'),('cn','accounts'), + api.env.basedn) fqdn4 = u'testhost2.lab.%s' % api.env.domain -dn4 = u'fqdn=%s,cn=computers,cn=accounts,%s' % (fqdn4, api.env.basedn) +dn4 = DN(('fqdn',fqdn4),('cn','computers'),('cn','accounts'), + api.env.basedn) # We can use the same cert we generated for the service tests fd = open('tests/test_xmlrpc/service.crt', 'r') @@ -95,7 +101,7 @@ class test_host(Declarative): value=fqdn1, summary=u'Added host "%s"' % fqdn1, result=dict( - dn=dn1, + dn=lambda x: DN(x) == dn1, fqdn=[fqdn1], description=[u'Test host 1'], l=[u'Undisclosed location 1'], @@ -128,7 +134,7 @@ class test_host(Declarative): value=fqdn1, summary=None, result=dict( - dn=dn1, + dn=lambda x: DN(x) == dn1, fqdn=[fqdn1], description=[u'Test host 1'], l=[u'Undisclosed location 1'], @@ -147,7 +153,7 @@ class test_host(Declarative): value=fqdn1, summary=None, result=dict( - dn=dn1, + dn=lambda x: DN(x) == dn1, cn=[fqdn1], fqdn=[fqdn1], description=[u'Test host 1'], @@ -177,7 +183,7 @@ class test_host(Declarative): summary=u'1 host matched', result=[ dict( - dn=dn1, + dn=lambda x: DN(x) == dn1, fqdn=[fqdn1], description=[u'Test host 1'], l=[u'Undisclosed location 1'], @@ -198,7 +204,7 @@ class test_host(Declarative): summary=u'1 host matched', result=[ dict( - dn=dn1, + dn=lambda x: DN(x) == dn1, cn=[fqdn1], fqdn=[fqdn1], description=[u'Test host 1'], @@ -235,7 +241,8 @@ class test_host(Declarative): usercertificate=[base64.b64decode(servercert)], 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, @@ -252,7 +259,7 @@ class test_host(Declarative): value=fqdn1, summary=None, result=dict( - dn=dn1, + dn=lambda x: DN(x) == dn1, fqdn=[fqdn1], description=[u'Updated host 1'], l=[u'Undisclosed location 1'], @@ -262,7 +269,8 @@ class test_host(Declarative): usercertificate=[base64.b64decode(servercert)], 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, @@ -284,7 +292,7 @@ class test_host(Declarative): value=fqdn3, summary=u'Added host "%s"' % fqdn3, result=dict( - dn=dn3, + dn=lambda x: DN(x) == dn3, fqdn=[fqdn3], description=[u'Test host 2'], l=[u'Undisclosed location 2'], @@ -310,7 +318,7 @@ class test_host(Declarative): value=fqdn4, summary=u'Added host "%s"' % fqdn4, result=dict( - dn=dn4, + dn=lambda x: DN(x) == dn4, fqdn=[fqdn4], description=[u'Test host 4'], l=[u'Undisclosed location 4'], @@ -338,7 +346,7 @@ class test_host(Declarative): ), ), result=dict( - dn=dn3, + dn=lambda x: DN(x) == dn3, fqdn=[fqdn3], description=[u'Test host 2'], l=[u'Undisclosed location 2'], @@ -355,7 +363,7 @@ class test_host(Declarative): value=fqdn3, summary=None, result=dict( - dn=dn3, + dn=lambda x: DN(x) == dn3, fqdn=[fqdn3], description=[u'Test host 2'], l=[u'Undisclosed location 2'], @@ -381,7 +389,7 @@ class test_host(Declarative): ), ), result=dict( - dn=dn3, + dn=lambda x: DN(x) == dn3, fqdn=[fqdn3], description=[u'Test host 2'], l=[u'Undisclosed location 2'], @@ -452,7 +460,7 @@ class test_host(Declarative): value=fqdn1, summary=u'Added host "%s"' % fqdn1, result=dict( - dn=dn1, + dn=lambda x: DN(x) == dn1, fqdn=[fqdn1], description=[u'Test host 1'], l=[u'Undisclosed location 1'], @@ -523,7 +531,7 @@ class test_host(Declarative): value=fqdn2, summary=u'Added host "%s"' % fqdn2, result=dict( - dn=dn2, + dn=lambda x: DN(x) == dn2, fqdn=[fqdn2], description=[u'Test host 2'], l=[u'Undisclosed location 2'], |