Commit 9a961f60 authored by godog's avatar godog

add ca.verify tests

parent d439174a
...@@ -29,18 +29,27 @@ class CertStub(object): ...@@ -29,18 +29,27 @@ class CertStub(object):
return os.path.exists(self.public_key_file) return os.path.exists(self.public_key_file)
class CAStub(object):
def __init__(self, *args, **kwargs):
self.tmpdir = tempfile.mkdtemp()
self.ca = ca.CA(self.tmpdir, *args, **kwargs)
def destroy(self):
self.ca.close()
shutil.rmtree(self.tmpdir)
class CATest(unittest.TestCase): class CATest(unittest.TestCase):
def setUp(self): def setUp(self):
self.tmpdir = tempfile.mkdtemp() self.ca_stub = CAStub({'cn': 'test ca', 'org': 'test',
self.ca = ca.CA(self.tmpdir,
{'cn': 'test ca', 'org': 'test',
'bits': '1024', 'email': 'test@test.com'}, 'bits': '1024', 'email': 'test@test.com'},
password='testpw') password='testpw')
self.ca = self.ca_stub.ca
self.tmpdir = self.ca_stub.tmpdir
def tearDown(self): def tearDown(self):
self.ca.close() self.ca_stub.destroy()
shutil.rmtree(self.tmpdir)
def test_create(self): def test_create(self):
self.ca.create() self.ca.create()
...@@ -70,3 +79,22 @@ class CATest(unittest.TestCase): ...@@ -70,3 +79,22 @@ class CATest(unittest.TestCase):
self.ca.generate(cert) self.ca.generate(cert)
self.ca.revoke(cert) self.ca.revoke(cert)
self.assertTrue(os.path.exists(os.path.join(self.tmpdir, 'public/ca.crl'))) self.assertTrue(os.path.exists(os.path.join(self.tmpdir, 'public/ca.crl')))
def test_verify(self):
orig_cert = CertStub('test', 'www.test.com', self.tmpdir)
self.ca.create()
self.ca.generate(orig_cert)
alt_ca = CAStub({'cn': 'test ca', 'org': 'test',
'bits': '1024', 'email': 'test@test.com'},
password='testpw')
alt_ca.ca.create()
alt_cert = CertStub('test', 'www.test.com', alt_ca.tmpdir)
alt_ca.ca.generate(alt_cert)
self.assertTrue(self.ca.verify(orig_cert.public_key_file))
self.assertTrue(alt_ca.ca.verify(alt_cert.public_key_file))
self.assertFalse(self.ca.verify(alt_cert.public_key_file))
self.assertFalse(alt_ca.ca.verify(orig_cert.public_key_file))
alt_ca.destroy()
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment