9 TEST_PEM = '''-----BEGIN CERTIFICATE-----
10 MIICNDCCAaECEAKtZn5ORf5eV288mBle3cAwDQYJKoZIhvcNAQECBQAwXzELMAkG
11 A1UEBhMCVVMxIDAeBgNVBAoTF1JTQSBEYXRhIFNlY3VyaXR5LCBJbmMuMS4wLAYD
12 VQQLEyVTZWN1cmUgU2VydmVyIENlcnRpZmljYXRpb24gQXV0aG9yaXR5MB4XDTk0
13 MTEwOTAwMDAwMFoXDTEwMDEwNzIzNTk1OVowXzELMAkGA1UEBhMCVVMxIDAeBgNV
14 BAoTF1JTQSBEYXRhIFNlY3VyaXR5LCBJbmMuMS4wLAYDVQQLEyVTZWN1cmUgU2Vy
15 dmVyIENlcnRpZmljYXRpb24gQXV0aG9yaXR5MIGbMA0GCSqGSIb3DQEBAQUAA4GJ
16 ADCBhQJ+AJLOesGugz5aqomDV6wlAXYMra6OLDfO6zV4ZFQD5YRAUcm/jwjiioII
17 0haGN1XpsSECrXZogZoFokvJSyVmIlZsiAeP94FZbYQHZXATcXY+m3dM41CJVphI
18 uR2nKRoTLkoRWZweFdVJVCxzOmmCsZc5nG1wZ0jl3S3WyB57AgMBAAEwDQYJKoZI
19 hvcNAQECBQADfgBl3X7hsuyw4jrg7HFGmhkRuNPHoLQDQCYCPgmc4RKz0Vr2N6W3
20 YQO2WxZpO8ZECAyIUwxrl0nHPjXcbLm7qt9cuzovk2C2qUtN8iD3zV9/ZHuO3ABc
21 1/p3yjkWWW8O6tO1g39NTUJWdrTJXwT4OPjr0l91X817/OWOgHz8UA==
22 -----END CERTIFICATE-----
25 TEST_SHA1 = '44:63:C5:31:D7:CC:C1:00:67:94:61:2B:B6:56:D3:BF:82:57:84:6F'
26 TEST_MD5 = '74:7B:82:03:43:F0:00:9E:6B:B3:EC:47:BF:85:A5:93'
27 TEST_EXPIRY = 1262908799.0
32 def __init__(self, basedir):
33 self.basedir = basedir
36 class CertTest(unittest.TestCase):
39 self.tmpdir = tempfile.mkdtemp()
40 os.makedirs(os.path.join(self.tmpdir, 'public', 'certs'))
41 self.ca = CAStub(self.tmpdir)
42 self.crt_file = os.path.join(self.tmpdir, 'public', 'certs', 'test.pem')
43 fd = open(self.crt_file, 'w')
48 shutil.rmtree(self.tmpdir)
50 def test_get_fingerprint(self):
51 crt = cert.Cert(self.ca, 'test', {'cn': 'test.com'})
52 md5 = crt.get_fingerprint('md5')
53 self.assertEquals(TEST_MD5, md5)
54 sha1 = crt.get_fingerprint('sha1')
55 self.assertEquals(TEST_SHA1, sha1)
57 def test_get_fingerprint_nonexist(self):
58 crt = cert.Cert(self.ca, 'test-nonexist', {'cn': 'test.com'})
59 result = crt.get_fingerprint('md5')
60 self.assertEquals(None, result)
62 def test_cn_in_alt_names(self):
63 crt = cert.Cert(self.ca, 'test', {'cn': 'test.com',
64 'alt_names': 'test2.com'})
65 self.assert_('test.com' in crt.alt_names)
67 def test_get_expiration_date(self):
68 crt = cert.Cert(self.ca, 'test', {'cn': 'test.com'})
69 exp = crt.get_expiration_date()
70 self.assertEquals(TEST_EXPIRY, exp)
72 def test_get_expiration_date_nonexist(self):
73 crt = cert.Cert(self.ca, 'test-nonexist', {'cn': 'test.com'})
74 exp = crt.get_expiration_date()
75 self.assertEquals(None, exp)
77 def test_expired(self):
78 crt = cert.Cert(self.ca, 'test', {'cn': 'test.com'})
79 exp = crt.get_expiration_date()
81 is_expired = (exp > now)
82 self.assertEquals(is_expired, crt.expired())
85 if __name__ == '__main__':