Commit c196a41c authored by Adrien Dorsaz's avatar Adrien Dorsaz
Browse files

test: add a test to check success when DNS Host is configured with IP address

logassert was added as requirements as the check have to look for log messages
parent 00918ab7
......@@ -4,7 +4,7 @@ import dns.resolver, dns.tsigkeyring, dns.update
from configparser import ConfigParser
from urllib.request import urlopen
LOGGER = logging.getLogger(__name__)
LOGGER = logging.getLogger('acme_dns_tiny_logger')
LOGGER.addHandler(logging.StreamHandler())
LOGGER.setLevel(logging.INFO)
......
......@@ -8,6 +8,7 @@ DOMAIN = os.getenv("GITLABCI_DOMAIN")
CAURL = os.getenv("GITLABCI_CAURL", "https://acme-staging.api.letsencrypt.org")
CHALLENGEDELAY = os.getenv("GITLABCI_CHALLENGEDELAY", "3")
DNSHOST = os.getenv("GITLABCI_DNSHOST")
DNSHOSTIP = os.getenv("GITLABCI_DNSHOSTIP")
DNSZONE = os.getenv("GITLABCI_DNSZONE")
DNSPORT = os.getenv("GITLABCI_DNSPORT", "53")
TSIGKEYNAME = os.getenv("GITLABCI_TSIGKEYNAME")
......@@ -63,6 +64,12 @@ def gen_configs():
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
......@@ -83,6 +90,7 @@ def gen_configs():
return {
"goodCName": goodCName,
"dnsHostIP": dnsHostIP,
"goodSAN": goodSAN,
"weakKey": weakKey,
"accountAsDomain": accountAsDomain,
......
......@@ -4,11 +4,15 @@ from io import StringIO
import acme_dns_tiny
from .monkey import gen_configs
from .acme_account_delete import delete_account
import logassert
CONFIGS = gen_configs()
class TestModule(unittest.TestCase):
"Tests for acme_dns_tiny.get_crt()"
def setUp(self):
logassert.setup(self, 'acme_dns_tiny_logger')
def test_success_cn(self):
""" Successfully issue a certificate via common name """
......@@ -22,6 +26,21 @@ 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
sys.stdout = StringIO()
result = acme_dns_tiny.main([CONFIGS['dnsHostIP'].name])
self.assertLoggedInfo("DNS IPv4 record not found for configured dns host.")
self.assertLoggedInfo("DNS IPv4 and IPv6 records not found for configured dns host.")
sys.stdout.seek(0)
crt = sys.stdout.read().encode("utf8")
sys.stdout = old_stdout
out, err = Popen(["openssl", "x509", "-text", "-noout"], stdin=PIPE,
stdout=PIPE, stderr=PIPE).communicate(crt)
self.assertIn("BEGIN", crt.decode("utf8"))
self.assertIn("Issuer", out.decode("utf8"))
def test_success_san(self):
""" Successfully issue a certificate via subject alt name """
......
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