test_acme_account_rollover.py 1.55 KB
Newer Older
1
import unittest, os
2
import acme_dns_tiny
3
from tests.config_factory import generate_acme_account_rollover_config
4
from tools.acme_account_delete import account_delete
5
6
7
8
9
import tools.acme_account_rollover

ACMEDirectory = os.getenv("GITLABCI_ACMEDIRECTORY", "https://acme-staging.api.letsencrypt.org/directory")

class TestACMEAccountRollover(unittest.TestCase):
10
    "Tests for acme_account_rollover"
11
12
13

    @classmethod
    def setUpClass(self):
14
        self.configs = generate_acme_account_rollover_config()
15
16
17
18
19
20
        super(TestACMEAccountRollover, self).setUpClass()

    # To clean ACME staging server and close correctly temporary files
    @classmethod
    def tearDownClass(self):
        # delete account key registration at end of tests
21
        account_delete(self.configs["newaccountkey"].name, ACMEDirectory)
22
23
24
25
26
27
28
        # close temp files correctly
        for tmpfile in self.configs:
            self.configs[tmpfile].close()
        super(TestACMEAccountRollover, self).tearDownClass()

    def test_success_account_rollover(self):
        """ Test success account key rollover """
29
30
31
32
33
34
        with self.assertLogs(level='INFO') as accountrolloverlog:
            tools.acme_account_rollover.main(["--current", self.configs['oldaccountkey'].name,
                                          	    "--new", self.configs['newaccountkey'].name,
                                          	    "--acme-directory", ACMEDirectory])
        self.assertIn("INFO:acme_account_rollover:Account keys rolled over !",
            accountrolloverlog.output)
35
36
37

if __name__ == "__main__":
    unittest.main()