summaryrefslogtreecommitdiffstats
path: root/tests/test_ipalib
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_ipalib
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_ipalib')
-rw-r--r--tests/test_ipalib/test_x509.py14
1 files changed, 7 insertions, 7 deletions
diff --git a/tests/test_ipalib/test_x509.py b/tests/test_ipalib/test_x509.py
index 11c5495f0..a2e9b2265 100644
--- a/tests/test_ipalib/test_x509.py
+++ b/tests/test_ipalib/test_x509.py
@@ -32,7 +32,7 @@ from ipalib.constants import NAME_REGEX, NAME_ERROR
import base64
from ipalib import x509
from nss.error import NSPRError
-
+from ipalib.dn import *
# certutil -
@@ -92,18 +92,18 @@ class test_x509(object):
Test retrieving the subject
"""
subject = x509.get_subject(goodcert)
- assert str(subject) == 'CN=ipa.example.com,O=IPA'
+ assert DN(str(subject)) == DN(('CN','ipa.example.com'),('O','IPA'))
der = base64.b64decode(goodcert)
subject = x509.get_subject(der, x509.DER)
- assert str(subject) == 'CN=ipa.example.com,O=IPA'
+ assert DN(str(subject)) == DN(('CN','ipa.example.com'),('O','IPA'))
# We should be able to pass in a tuple/list of certs too
subject = x509.get_subject((goodcert))
- assert str(subject) == 'CN=ipa.example.com,O=IPA'
+ assert DN(str(subject)) == DN(('CN','ipa.example.com'),('O','IPA'))
subject = x509.get_subject([goodcert])
- assert str(subject) == 'CN=ipa.example.com,O=IPA'
+ assert DN(str(subject)) == DN(('CN','ipa.example.com'),('O','IPA'))
def test_2_get_serial_number(self):
"""
@@ -132,8 +132,8 @@ class test_x509(object):
cert = x509.load_certificate(goodcert)
- assert str(cert.subject) == 'CN=ipa.example.com,O=IPA'
- assert str(cert.issuer) == 'CN=IPA Test Certificate Authority'
+ assert DN(str(cert.subject)) == DN(('CN','ipa.example.com'),('O','IPA'))
+ assert DN(str(cert.issuer)) == DN(('CN','IPA Test Certificate Authority'))
assert cert.serial_number == 1093
assert cert.valid_not_before_str == 'Fri Jun 25 13:00:42 2010 UTC'
assert cert.valid_not_after_str == 'Thu Jun 25 13:00:42 2015 UTC'