staging_test_acme_account_deactivate.py 2.07 KB
Newer Older
1 2 3 4
"""Test acme_account_deactivate script with real ACME server"""
import unittest
import os
import configparser
5
import acme_dns_tiny
6 7
from tests.config_factory import generate_acme_account_deactivate_config
import tools.acme_account_deactivate
8

9 10
ACME_DIRECTORY = os.getenv("GITLABCI_ACMEDIRECTORY_V2",
                           "https://acme-staging-v02.api.letsencrypt.org/directory")
11

12 13
class TestACMEAccountDeactivate(unittest.TestCase):
    "Tests for acme_account_deactivate"
14 15

    @classmethod
16 17
    def setUpClass(cls):
        cls.configs = generate_acme_account_deactivate_config()
18
        try:
19
            acme_dns_tiny.main([cls.configs['config']])
20 21
        except ValueError as err:
            if str(err).startswith("Error register"):
22 23
                raise ValueError("Fail test as account has not been registered correctly: {0}"
                                 .format(err))
24

25
        super(TestACMEAccountDeactivate, cls).setUpClass()
26 27

    # To clean ACME staging server and close correctly temporary files
28
    #pylint: disable=bare-except
29
    @classmethod
30
    def tearDownClass(cls):
31
        # Remove temporary files
32
        parser = configparser.ConfigParser()
33
        parser.read(cls.configs['config'])
34 35
        try:
            os.remove(parser["acmednstiny"]["AccountKeyFile"])
36 37 38
        except:
            pass
        try:
39
            os.remove(parser["acmednstiny"]["CSRFile"])
40 41 42
        except:
            pass
        try:
43
            os.remove(cls.configs['config'])
44
        except:
45
            pass
46
        super(TestACMEAccountDeactivate, cls).tearDownClass()
47

48 49 50
    def test_success_account_deactivate(self):
        """ Test success account key deactivate """
        with self.assertLogs(level='INFO') as accountdeactivatelog:
51
            tools.acme_account_deactivate.main(["--account-key", self.configs['key'],
52
                                                "--acme-directory", ACME_DIRECTORY])
53
        self.assertIn("INFO:acme_account_deactivate:The account has been deactivated.",
54
                      accountdeactivatelog.output)
55

56
if __name__ == "__main__":  # pragma: no cover
57
    unittest.main()