Skip to content

Commit

Permalink
Fixed unit tests to correct set and verify settings for not before and
Browse files Browse the repository at this point in the history
not after times
  • Loading branch information
philipkershaw committed Nov 24, 2015
1 parent 2a93d77 commit 6acf790
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
1 change: 1 addition & 0 deletions contrail/security/ca/test/ca.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ cert_filepath = %(here)s/ca_config/myca.crt
key_filepath = %(here)s/ca_config/myca.key
key_passwd = ndgtestca
min_key_nbits = 4096
not_after_time_nsecs = 86400
25 changes: 15 additions & 10 deletions contrail/security/ca/test/test_ca_impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,12 @@ def test01_issue_fqdn_cert_with_subj_alt_names(self):

not_before_nsecs = 0
not_after_nsecs = 60*60*24*365*5

ca.not_before_time_nsecs = not_before_nsecs
ca.not_after_time_nsecs = not_after_nsecs

cert = ca.issue_certificate(
cert_req,
not_before_time_nsecs=not_before_nsecs,
not_after_time_nsecs=not_after_nsecs,
subject_alt_name='DNS:localhost, DNS:localhost.domain')


Expand All @@ -69,14 +70,14 @@ def test02_check_ext(self):
ext_name = ext.get_short_name()
if ext_name == 'subjectAltName':
ext_dat = ext.get_data()
print ext_dat
print(ext_dat)
dec = decode(ext_dat, asn1Spec=GeneralNames())
print dec
print dec[0].prettyPrint()
print(dec)
print(dec[0].prettyPrint())
for i in range(len(dec[0])):
dns_name = str(
dec[0].getComponentByPosition(i).getComponent())
print dns_name
print(dns_name)

def test03_create_from_keywords(self):
ca = CertificateAuthority.from_keywords(
Expand Down Expand Up @@ -106,17 +107,21 @@ def test05_create_from_config(self):
self.assertIsInstance(ca.key, crypto.PKey,
'ca.key is not an PKey instance')

self.assertEqual(ca.not_after_time_nsecs, 86400,
'Expecting not after time of 86400 seconds')

def test06_issue_cert_with_custom_ext(self):
key_pair, cert_req, ca = self.__class__._create_ca_and_cert_req()

not_before_nsecs = 0
not_after_nsecs = 60*60*24*365*5

ca.not_before_time_nsecs = not_before_nsecs
ca.not_after_time_nsecs = not_after_nsecs

cert = ca.issue_certificate(
cert_req,
not_before_time_nsecs=not_before_nsecs,
not_after_time_nsecs=not_after_nsecs,
extensions=[('nsComment', 'my_cust_val', False)])
cert_req,
extensions=[('nsComment', 'my_cust_val', False)])

s_key = crypto.dump_privatekey(crypto.FILETYPE_PEM, key_pair)
open(path.join(THIS_DIR, 'my1.key'), 'w').write(s_key)
Expand Down

0 comments on commit 6acf790

Please sign in to comment.