import unittest from BaDCA import CRLs, Certificates from BaDCA.Testing import * class BaDCAbaseCATestCase(unittest.TestCase): def test01(self): """ Testing basic creation of CRL instance """ c = Certificates.Certificate(filename = 'tests/certs/ca1.pem') assert c.isValid(), "Certificate should be valid!" crl = CRLs.CRL(c, 'tests/crl') assert crl.isValid(), "CRL should be invalid!" assert crl.count == 0, "CRL count should be 0" def test02(self): """ Test validity period setting """ c = Certificates.Certificate(filename = 'tests/certs/ca1.pem', keyPaths = [ 'tests/keys/private']) assert c.isValid(), "Certificate should be valid!" assert c.key.hasPrivate(), "Certificate doesn't have a private key" crl = CRLs.CRL(c, 'tests/crl') assert crl.isValid(), "CRL should be invalid!" crl.setValidity(100) assert crl.validity == 100, "Incorrect validity period set" crl.setValidity(days = 1) assert crl.validity == (24 * 60 * 60), \ "Incorrect validity period set" def test03(self): """ Test adding a certificate to the CRL """ c = Certificates.Certificate(filename = 'tests/certs/ca1.pem', keyPaths = [ 'tests/keys/private']) assert c.isValid(), "Certificate should be valid!" assert c.key.hasPrivate(), "Certificate doesn't have a private key" crl = CRLs.CRL(c, 'tests/crl') assert crl.isValid(), "CRL should be invalid!" d = Certificates.Certificate(filename = 'tests/certs/test1.pem') assert d.isValid(), "Certificate should be valid" assert crl.addCertificate(d, 'unspecified') == 1, \ "Unable to add a certificate to the CRL" assert crl.count == 1, "Incorrect count after adding certificate" assert crl.writeXML() == 1, "Unable to write XML file" def test04(self): """ Testing creation of actual CRL file """ c = Certificates.Certificate(filename = 'tests/certs/ca1.pem', keyPaths = [ 'tests/keys/private']) assert c.isValid(), "Certificate should be valid!" assert c.key.hasPrivate(), "Certificate doesn't have a private key" crl = CRLs.CRL(c, 'tests/crl') assert crl.isValid(), "CRL should be invalid!" assert crl.count == 1, "CRL count should be 1" assert crl.generateCRL(c) == 1, "Unable to create a CRL" assert crl.write('tests/crl/test01.crl') == 1, \ "Unable to write the CRL to file" assert os.path.exists('tests/crl/test01.crl'), \ "CRL file was not written!!" if __name__ == "__main__": unittest.main()