Commit 507688a7 authored by Adrien Dorsaz's avatar Adrien Dorsaz

tests: v2 update deactivation test

parent 51099579
......@@ -21,7 +21,7 @@ explains how to setup and test acme-tiny yourself.
## List of environment variables
* `GITLABCI_CAURL`: URL of a staging ACME server
* `GITLABCI_ACMEDIRECTORY_V2`: URL of a staging V2 ACME server
* `GITLABCI_CHALLENGEDELAY`: time to wait between dns update and self-check (set it to `0` to cover a bit more code)
* `GITLABCI_DNSHOST`: domain name to reach of your DNS server (e.g. `adorsaz.ch`)
* `GITLABCI_DNSHOSTIP`: IP address to reach of your DNS server
......
......@@ -4,7 +4,7 @@ from subprocess import Popen
# domain with server.py running on it for testing
DOMAIN = os.getenv("GITLABCI_DOMAIN")
ACMEDIRECTORY = os.getenv("GITLABCI_ACMEDIRECTORY", "https://acme-staging.api.letsencrypt.org/directory")
ACMEDIRECTORY = os.getenv("GITLABCI_ACMEDIRECTORY_V2", "https://acme-staging-v02.api.letsencrypt.org/directory")
CHALLENGEDELAY = os.getenv("GITLABCI_CHALLENGEDELAY", "3")
DNSHOST = os.getenv("GITLABCI_DNSHOST")
DNSHOSTIP = os.getenv("GITLABCI_DNSHOSTIP")
......@@ -50,8 +50,7 @@ def generate_acme_dns_tiny_config():
config.read("./example.ini".format(DOMAIN))
config["acmednstiny"]["ACMEDirectory"] = ACMEDIRECTORY
config["acmednstiny"]["CheckChallengeDelay"] = CHALLENGEDELAY
config["acmednstiny"]["MailContact"] = "mail@example.com"
del config["acmednstiny"]["PhoneContact"]
config["acmednstiny"]["Contacts"] = "mailto:mail@example.com"
config["TSIGKeyring"]["KeyName"] = TSIGKEYNAME
config["TSIGKeyring"]["KeyValue"] = TSIGKEYVALUE
config["TSIGKeyring"]["Algorithm"] = TSIGALGORITHM
......@@ -133,8 +132,30 @@ def generate_acme_account_rollover_config():
}
# generate an account key to delete it
def generate_acme_account_delete_config():
def generate_acme_account_deactivate_config():
# account key
account_key = NamedTemporaryFile()
Popen(["openssl", "genrsa", "-out", account_key.name, "2048"]).wait()
return account_key
# default test configuration
config = configparser.ConfigParser()
config.read("./example.ini".format(DOMAIN))
config["acmednstiny"]["AccountKeyFile"] = account_key.name
config["acmednstiny"]["CSRFile"] = account_key.name
config["acmednstiny"]["ACMEDirectory"] = ACMEDIRECTORY
config["acmednstiny"]["CheckChallengeDelay"] = CHALLENGEDELAY
config["TSIGKeyring"]["KeyName"] = TSIGKEYNAME
config["TSIGKeyring"]["KeyValue"] = TSIGKEYVALUE
config["TSIGKeyring"]["Algorithm"] = TSIGALGORITHM
config["DNS"]["Host"] = DNSHOST
config["DNS"]["Port"] = DNSPORT
config["DNS"]["Zone"] = DNSZONE
deactivateConfig = NamedTemporaryFile()
with open(deactivateConfig.name, 'w') as configfile:
config.write(configfile)
return {
"config": deactivateConfig.name,
"key": account_key
}
import unittest, os
import acme_dns_tiny
from tests.config_factory import generate_acme_account_delete_config
import tools.acme_account_delete
from tests.config_factory import generate_acme_account_deactivate_config
import tools.acme_account_deactivate
ACMEDirectory = os.getenv("GITLABCI_ACMEDIRECTORY", "https://acme-staging.api.letsencrypt.org/directory")
ACMEDirectory = os.getenv("GITLABCI_ACMEDIRECTORY_V2", "https://acme-staging-v02.api.letsencrypt.org/directory")
class TestACMEAccountDelete(unittest.TestCase):
"Tests for acme_account_delete"
class TestACMEAccountDeactivate(unittest.TestCase):
"Tests for acme_account_deactivate"
@classmethod
def setUpClass(self):
self.accountkey = generate_acme_account_delete_config()
super(TestACMEAccountDelete, self).setUpClass()
configs = generate_acme_account_deactivate_config()
self.account_key = configs["key"]
acme_dns_tiny.main([self.configs['config'].name])
super(TestACMEAccountDeactivate, self).setUpClass()
# To clean ACME staging server and close correctly temporary files
@classmethod
def tearDownClass(self):
# close temp files correctly
self.configs['config'].close
self.accountkey.close()
super(TestACMEAccountDelete, self).tearDownClass()
super(TestACMEAccountDeactivate, self).tearDownClass()
def test_success_account_delete(self):
""" Test success account key delete """
with self.assertLogs(level='INFO') as accountdeletelog:
tools.acme_account_delete.main(["--account-key", self.accountkey.name,
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.accountkey.name,
"--acme-directory", ACMEDirectory])
self.assertIn("INFO:acme_account_delete:Account key deleted !",
accountdeletelog.output)
self.assertIn("INFO:acme_account_deactivate:Account key deactivated !",
accountdeactivatelog.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