fixing quotes, no escape characters in tests, fixed anchors

This commit is contained in:
alwaysjolley 2020-06-03 12:49:55 -04:00
parent 3ce7cd6c50
commit 1b8507636b
2 changed files with 18 additions and 18 deletions

View File

@ -35,7 +35,7 @@ def is_valid_domain(domain):
domain = domain[:-1] domain = domain[:-1]
if len(domain) > 253: if len(domain) > 253:
return False return False
fqdn_re = re.compile("(?=^.{1,63}$)(^(?:[a-z0-9](?:-*[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(".")) return all(fqdn_re.match(d) for d in domain.split("."))

View File

@ -4,20 +4,20 @@ from lemur.dns_providers import util as dnsutil
class TestDNSProvider(unittest.TestCase): class TestDNSProvider(unittest.TestCase):
def test_is_valid_domain(self): def test_is_valid_domain(self):
self.assertTrue(dnsutil.is_valid_domain("example.com")) self.assertTrue(dnsutil.is_valid_domain('example.com'))
self.assertTrue(dnsutil.is_valid_domain("foo.bar.org")) self.assertTrue(dnsutil.is_valid_domain('foo.bar.org'))
self.assertTrue(dnsutil.is_valid_domain("exam--ple.io")) self.assertTrue(dnsutil.is_valid_domain('exam--ple.io'))
self.assertTrue(dnsutil.is_valid_domain("a.example.com")) self.assertTrue(dnsutil.is_valid_domain('a.example.com'))
self.assertTrue(dnsutil.is_valid_domain("example.io")) self.assertTrue(dnsutil.is_valid_domain('example.io'))
self.assertTrue(dnsutil.is_valid_domain("example-of-under-63-character-domain-label-length-limit-1234567.com")) self.assertTrue(dnsutil.is_valid_domain('example-of-under-63-character-domain-label-length-limit-1234567.com'))
self.assertFalse(dnsutil.is_valid_domain("example-of-over-63-character-domain-label-length-limit-123456789.com")) self.assertFalse(dnsutil.is_valid_domain('example-of-over-63-character-domain-label-length-limit-123456789.com'))
self.assertFalse(dnsutil.is_valid_domain("_acme-chall.example.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('e/xample.com'))
self.assertFalse(dnsutil.is_valid_domain("exam\\ple.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.com'))
self.assertFalse(dnsutil.is_valid_domain("-example.io")) 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('example-.io'))
self.assertFalse(dnsutil.is_valid_domain("exa mple.io")) self.assertFalse(dnsutil.is_valid_domain('example..io'))
self.assertFalse(dnsutil.is_valid_domain("-")) self.assertFalse(dnsutil.is_valid_domain('exa mple.io'))
self.assertFalse(dnsutil.is_valid_domain("")) self.assertFalse(dnsutil.is_valid_domain('-'))