From 8658ac531e456c47031316ef20fffaf3d43837b5 Mon Sep 17 00:00:00 2001 From: alwaysjolley Date: Wed, 3 Jun 2020 08:08:49 -0400 Subject: [PATCH] fixing unittests and allowing for single character domains --- lemur/dns_providers/util.py | 2 +- lemur/tests/test_dns_providers.py | 13 ++++++++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/lemur/dns_providers/util.py b/lemur/dns_providers/util.py index 9aa10458..fc930eb3 100644 --- a/lemur/dns_providers/util.py +++ b/lemur/dns_providers/util.py @@ -35,7 +35,7 @@ def is_valid_domain(domain): domain = domain[:-1] if len(domain) > 253: return False - fqdn_re = re.compile("(?=^.{1,63}$)(^(?:[a-z0-9](?:-*[a-z0-9])+)$)", re.IGNORECASE) + fqdn_re = re.compile("(?=^.{1,63}$)(^(?:[a-z0-9](?:-*[a-z0-9])+)|[a-z0-9]$)", re.IGNORECASE) return all(fqdn_re.match(d) for d in domain.split(".")) diff --git a/lemur/tests/test_dns_providers.py b/lemur/tests/test_dns_providers.py index b8714a2d..640277c6 100644 --- a/lemur/tests/test_dns_providers.py +++ b/lemur/tests/test_dns_providers.py @@ -6,7 +6,18 @@ class TestDNSProvider(unittest.TestCase): def test_is_valid_domain(self): self.assertTrue(dnsutil.is_valid_domain("example.com")) self.assertTrue(dnsutil.is_valid_domain("foo.bar.org")) - self.assertTrue(dnsutil.is_valid_domain("_acme-chall.example.com")) + self.assertTrue(dnsutil.is_valid_domain("exam--ple.io")) + self.assertTrue(dnsutil.is_valid_domain("a.example.com")) + self.assertTrue(dnsutil.is_valid_domain("example.io")) + self.assertTrue(dnsutil.is_valid_domain("example-of-63-character-domain-label-length-limit-1234567890123.com")) + self.assertFalse(dnsutil.is_valid_domain("example-of-63-character-domain-label-length-limit-12345678901234.com")) + self.assertFalse(dnsutil.is_valid_domain("_acme-chall.example.com")) self.assertFalse(dnsutil.is_valid_domain("e/xample.com")) self.assertFalse(dnsutil.is_valid_domain("exam\ple.com")) self.assertFalse(dnsutil.is_valid_domain("*.example.com")) + self.assertFalse(dnsutil.is_valid_domain("-example.io")) + self.assertFalse(dnsutil.is_valid_domain("example-.io")) + self.assertFalse(dnsutil.is_valid_domain("example..io")) + self.assertFalse(dnsutil.is_valid_domain("exa mple.io")) + self.assertFalse(dnsutil.is_valid_domain("-")) + self.assertFalse(dnsutil.is_valid_domain(""))