Commit 8646a506 authored by Adrien Dorsaz's avatar Adrien Dorsaz

tests: adapt tests "deactivate" and "rollover" to linter

parent da319857
import unittest, os, time, configparser
"""Test acme_account_deactivate script with real ACME server"""
import unittest
import os
import configparser
import acme_dns_tiny
from tests.config_factory import generate_acme_account_deactivate_config
import tools.acme_account_deactivate
ACMEDirectory = os.getenv("GITLABCI_ACMEDIRECTORY_V2", "https://acme-staging-v02.api.letsencrypt.org/directory")
ACME_DIRECTORY = os.getenv("GITLABCI_ACMEDIRECTORY_V2",
"https://acme-staging-v02.api.letsencrypt.org/directory")
class TestACMEAccountDeactivate(unittest.TestCase):
"Tests for acme_account_deactivate"
@classmethod
def setUpClass(self):
self.configs = generate_acme_account_deactivate_config()
def setUpClass(cls):
cls.configs = generate_acme_account_deactivate_config()
try:
acme_dns_tiny.main([self.configs['config']])
acme_dns_tiny.main([cls.configs['config']])
except ValueError as err:
if str(err).startswith("Error register"):
raise ValueError("Fail test as account has not been registered correctly: {0}".format(err))
raise ValueError("Fail test as account has not been registered correctly: {0}"
.format(err))
super(TestACMEAccountDeactivate, self).setUpClass()
super(TestACMEAccountDeactivate, cls).setUpClass()
# To clean ACME staging server and close correctly temporary files
@classmethod
def tearDownClass(self):
def tearDownClass(cls):
# Remove temporary files
parser = configparser.ConfigParser()
parser.read(self.configs['config'])
parser.read(cls.configs['config'])
try:
os.remove(parser["acmednstiny"]["AccountKeyFile"])
os.remove(parser["acmednstiny"]["CSRFile"])
os.remove(self.configs['config'])
except:
os.remove(cls.configs['config'])
except: #pylint: disable=bare-except
pass
super(TestACMEAccountDeactivate, self).tearDownClass()
super(TestACMEAccountDeactivate, cls).tearDownClass()
def test_success_account_deactivate(self):
""" Test success account key deactivate """
with self.assertLogs(level='INFO') as accountdeactivatelog:
tools.acme_account_deactivate.main(["--account-key", self.configs['key'],
"--acme-directory", ACMEDirectory])
"--acme-directory", ACME_DIRECTORY])
self.assertIn("INFO:acme_account_deactivate:Account key deactivated !",
accountdeactivatelog.output)
accountdeactivatelog.output)
if __name__ == "__main__":
unittest.main()
import unittest, os, time, configparser
"""Test acme_account_rollover script with real ACME server"""
import unittest
import os
import configparser
import acme_dns_tiny
from tests.config_factory import generate_acme_account_rollover_config
from tools.acme_account_deactivate import account_deactivate
import tools.acme_account_rollover
ACMEDirectory = os.getenv("GITLABCI_ACMEDIRECTORY_V2", "https://acme-staging-v02.api.letsencrypt.org/directory")
ACME_DIRECTORY = os.getenv("GITLABCI_ACMEDIRECTORY_V2",
"https://acme-staging-v02.api.letsencrypt.org/directory")
class TestACMEAccountRollover(unittest.TestCase):
"Tests for acme_account_rollover"
@classmethod
def setUpClass(self):
self.configs = generate_acme_account_rollover_config()
acme_dns_tiny.main([self.configs['config']])
super(TestACMEAccountRollover, self).setUpClass()
def setUpClass(cls):
cls.configs = generate_acme_account_rollover_config()
acme_dns_tiny.main([cls.configs['config']])
super(TestACMEAccountRollover, cls).setUpClass()
# To clean ACME staging server and close correctly temporary files
@classmethod
def tearDownClass(self):
def tearDownClass(cls):
# deactivate account key registration at end of tests
# (we assume the key has been roll oved)
account_deactivate(self.configs["newaccountkey"], ACMEDirectory)
account_deactivate(cls.configs["newaccountkey"], ACME_DIRECTORY)
# Remove temporary files
parser = configparser.ConfigParser()
parser.read(self.configs['config'])
parser.read(cls.configs['config'])
try:
os.remove(parser["acmednstiny"]["AccountKeyFile"])
os.remove(parser["acmednstiny"]["CSRFile"])
os.remove(self.configs["newaccountkey"])
os.remove(self.configs['config'])
except:
os.remove(cls.configs["newaccountkey"])
os.remove(cls.configs['config'])
except: #pylint: disable=bare-except
pass
super(TestACMEAccountRollover, self).tearDownClass()
super(TestACMEAccountRollover, cls).tearDownClass()
def test_success_account_rollover(self):
""" Test success account key rollover """
with self.assertLogs(level='INFO') as accountrolloverlog:
tools.acme_account_rollover.main(["--current", self.configs['oldaccountkey'],
"--new", self.configs['newaccountkey'],
"--acme-directory", ACMEDirectory])
"--new", self.configs['newaccountkey'],
"--acme-directory", ACME_DIRECTORY])
self.assertIn("INFO:acme_account_rollover:Account keys rolled over !",
accountrolloverlog.output)
accountrolloverlog.output)
if __name__ == "__main__":
unittest.main()
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment