summaryrefslogtreecommitdiffstats
path: root/test/unittest/test_certmaster.py
blob: acc451019dcaafc5a9b30b8b2c98508dc04eca04 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#!/usr/bin/python


# unit test for certmaster

import unittest

from certmaster import certs


class BaseTest:
    def __init__(self):
        pass


class TestCa(BaseTest):
    def __init__(self):
        self.test_dir = "/tmp/test_certs"
        
        self.ca_key_file = "%s/test.key" % self.test_dir
        self.ca_cert_file = "%s/test.crt" % self.test_dir
        self.CN = "Test-Cert-CN"
        
    def test_create_ca(self):
        certs.create_ca(self.CN, self.ca_key_file, self.ca_cert_file)


    def test_create_slave(self):
        certs.create_ca(self.CN, self.ca_key_file, self.ca_cert_file)
        pkey = certs.make_keypair("%s/test.pkey" % self.test_dir)
        csr = certs.make_csr(pkey, "%s/test.csr" % self.test_dir)
        certs.create_ca(self.CN, self.ca_key_file, self.ca_cert_file)
        ca_cert = certs.retrieve_cert_from_file(self.ca_cert_file)
        ca_key = certs.retrieve_key_from_file(self.ca_key_file)
        certs.create_slave_certificate(csr, ca_key, ca_cert, self.test_dir, "%s/test_signed.crt" % self.test_dir)