8 from cam import openssl_wrap
11 logging.basicConfig(level=logging.DEBUG)
14 class CertStub(object):
16 def __init__(self, name, cn, tmpdir):
22 self.public_key_file = os.path.join(tmpdir, '%s.pub' % name)
23 self.private_key_file = os.path.join(tmpdir, '%s.priv' % name)
25 def get_expiration_date(self):
29 return os.path.exists(self.public_key_file)
32 class CATest(unittest.TestCase):
35 self.tmpdir = tempfile.mkdtemp()
36 self.ca = ca.CA(self.tmpdir,
37 {'cn': 'test ca', 'org': 'test',
38 'bits': '1024', 'email': 'test@test.com'},
43 shutil.rmtree(self.tmpdir)
45 def test_create(self):
47 self.assertTrue(os.path.exists(os.path.join(self.tmpdir, 'conf/ca.conf')))
49 def test_create_cert(self):
51 cert = CertStub('test', 'www.test.com', self.tmpdir)
52 self.ca.generate(cert)
53 self.assertTrue(os.path.exists(cert.public_key_file))
54 self.assertTrue(os.path.exists(cert.private_key_file))
56 def test_create_cert_with_digest_override(self):
57 self.ca.config['signature_algorithm'] = 'md5'
59 cert = CertStub('test', 'www.test.com', self.tmpdir)
60 self.ca.generate(cert)
61 self.assertTrue(os.path.exists(cert.public_key_file))
62 self.assertTrue(os.path.exists(cert.private_key_file))
64 'Signature Algorithm: md5WithRSAEncryption' in subprocess.check_output(
65 ['openssl', 'x509', '-text', '-noout', '-in', cert.public_key_file]))
67 def test_revoke(self):
69 cert = CertStub('test', 'www.test.com', self.tmpdir)
70 self.ca.generate(cert)
72 self.assertTrue(os.path.exists(os.path.join(self.tmpdir, 'public/ca.crl')))