...
 
Commits (3)
......@@ -21,12 +21,12 @@ stages:
- merge_requests
- master
syntax:
compile:
extends: .check
before_script:
- apt-get update && apt-get install -y --no-install-recommends python3
script:
- python3 -m py_compile acme_dns_tiny.py tools/acme_account_deactivate.py tools/acme_account_rollover.py
- python3 -m py_compile acme_dns_tiny.py tools/*.py tests/*.py
lint:
extends: .check
......@@ -36,6 +36,9 @@ lint:
- pylint3 acme_dns_tiny.py
- pylint3 tools/acme_account_deactivate.py
- pylint3 tools/acme_account_rollover.py
- pylint3 tests/config_factory.py
- pylint3 tests/test_acme_dns_tiny.py
- pylint3 tests/test_acme_account_deactivate.py
jessie:
extends: .test
......
This diff is collapsed.
import unittest, os, time, configparser
#!/usr/bin/env python3
"""Test the 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")
ACMEDIRECTORY = 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", ACMEDIRECTORY])
self.assertIn("INFO:acme_account_deactivate:Account key deactivated !",
accountdeactivatelog.output)
accountdeactivatelog.output)
if __name__ == "__main__":
unittest.main()
import unittest, os, time, configparser
#!/usr/bin/env python3
"""Test the 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")
ACMEDIRECTORY = 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"], ACMEDIRECTORY)
# 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])
tools.acme_account_rollover.main(["--current", self.configs['old_account_key'],
"--new", self.configs['new_account_key'],
"--acme-directory", ACMEDIRECTORY])
self.assertIn("INFO:acme_account_rollover:Account keys rolled over !",
accountrolloverlog.output)
accountrolloverlog.output)
if __name__ == "__main__":
unittest.main()
This diff is collapsed.