Commit df3733cd authored by Adrien Dorsaz's avatar Adrien Dorsaz

tests: refactor tests

* Use more specific test module (we'll create new test modules for future tools)
* Create gitlab-ci job for Debian Jessie and Debian Jessie + backports
parent db8247b2
before_script:
- apt-get update -qy
- apt-get install -qy python3-dev python3-pip
- pip3 install -r tests/requirements.txt
jessie:
image: adt-jessie_dnspython3_1.11
before_script:
- pip3 install -r tests/requirements.txt
script:
- coverage run --source ./ -m unittest -v tests/
- coverage report --include=acme_dns_tiny.py
coverage:
jessie_backport:
image: adt-jessie_dnspython3_1.15-bpo
before_script:
- pip3 install -r tests/requirements.txt
script:
- coverage run --source ./ -m unittest -v tests
- coverage run --source ./ -m unittest -v tests/
- coverage report --include=acme_dns_tiny.py
......@@ -15,12 +15,12 @@ TSIGKEYVALUE = os.getenv("GITLABCI_TSIGKEYVALUE")
TSIGALGORITHM = os.getenv("GITLABCI_TSIGALGORITHM")
# generate account and domain keys
def gen_config():
def generate_acme_dns_tiny_config():
# good account key
account_key = NamedTemporaryFile()
Popen(["openssl", "genrsa", "-out", account_key.name, "2048"]).wait()
# weak 1024 bit key
# weak 1024 bit account key
weak_key = NamedTemporaryFile()
Popen(["openssl", "genrsa", "-out", weak_key.name, "1024"]).wait()
......@@ -44,7 +44,7 @@ def gen_config():
account_csr = NamedTemporaryFile()
Popen(["openssl", "req", "-new", "-sha256", "-key", account_key.name,
"-subj", "/CN={0}".format(DOMAIN), "-out", account_csr.name]).wait()
# Default test configuration
config = configparser.ConfigParser()
config.read("./example.ini".format(DOMAIN))
......@@ -58,47 +58,47 @@ def gen_config():
config["DNS"]["Host"] = DNSHOST
config["DNS"]["Port"] = DNSPORT
config["DNS"]["Zone"] = DNSZONE
goodCName = NamedTemporaryFile()
config["acmednstiny"]["AccountKeyFile"] = account_key.name
config["acmednstiny"]["CSRFile"] = domain_csr.name
with open(goodCName.name, 'w') as configfile:
config.write(configfile)
dnsHostIP = NamedTemporaryFile()
config["DNS"]["Host"] = DNSHOSTIP
with open(dnsHostIP.name, 'w') as configfile:
config.write(configfile)
config["DNS"]["Host"] = DNSHOST
goodSAN = NamedTemporaryFile()
config["acmednstiny"]["AccountKeyFile"] = account_key.name
config["acmednstiny"]["CSRFile"] = san_csr.name
with open(goodSAN.name, 'w') as configfile:
config.write(configfile)
weakKey = NamedTemporaryFile()
config["acmednstiny"]["AccountKeyFile"] = weak_key.name
config["acmednstiny"]["CSRFile"] = domain_csr.name
with open(weakKey.name, 'w') as configfile:
config.write(configfile)
accountAsDomain = NamedTemporaryFile()
config["acmednstiny"]["AccountKeyFile"] = account_key.name
config["acmednstiny"]["CSRFile"] = account_csr.name
with open(accountAsDomain.name, 'w') as configfile:
config.write(configfile)
invalidTSIGName = NamedTemporaryFile()
config["TSIGKeyring"]["KeyName"] = "{0}.invalid".format(TSIGKEYNAME)
with open(invalidTSIGName.name, 'w') as configfile:
config.write(configfile)
missingDNS = NamedTemporaryFile()
config["DNS"] = {}
with open(missingDNS.name, 'w') as configfile:
config.write(configfile)
return {
# configs
"goodCName": goodCName,
......
......@@ -2,18 +2,18 @@ import unittest, sys
from subprocess import Popen, PIPE
from io import StringIO
import acme_dns_tiny
from tests.config_maker import gen_config
from tests.config_factory import generate_acme_dns_tiny_config
from tools.acme_account_delete import delete_account
import logassert
ACMEDirectory = os.getenv("GITLABCI_ACMEDIRECTORY", "https://acme-staging.api.letsencrypt.org/directory")
class TestModule(unittest.TestCase):
class TestACMEDNSTiny(unittest.TestCase):
"Tests for acme_dns_tiny.get_crt()"
@classmethod
def setUpClass(self):
self.configs = gen_config()
self.configs = generate_acme_dns_tiny_config()
super(TestModule, self).setUpClass()
# To clean ACME staging server and close correctly temporary files
......@@ -41,7 +41,7 @@ class TestModule(unittest.TestCase):
stdout=PIPE, stderr=PIPE).communicate(crt)
self.assertIn("BEGIN", crt.decode("utf8"))
self.assertIn("Issuer", out.decode("utf8"))
def test_success_dnshost_ip(self):
""" When DNS Host is an IP, DNS resolution have to fail without error """
old_stdout = sys.stdout
......
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