Merge branch 'master' into dependabot/pip/flask-sqlalchemy-2.4.3
This commit is contained in:
commit
aadca10a12
|
@ -31,11 +31,11 @@ class DNSResolveError(DNSError):
|
||||||
|
|
||||||
def is_valid_domain(domain):
|
def is_valid_domain(domain):
|
||||||
"""Checks if a domain is syntactically valid and returns a bool"""
|
"""Checks if a domain is syntactically valid and returns a bool"""
|
||||||
if len(domain) > 253:
|
|
||||||
return False
|
|
||||||
if domain[-1] == ".":
|
if domain[-1] == ".":
|
||||||
domain = domain[:-1]
|
domain = domain[:-1]
|
||||||
fqdn_re = re.compile("(?=^.{1,254}$)(^(?:(?!\d+\.|-)[a-zA-Z0-9_\-]{1,63}(?<!-)\.?)+(?:[a-zA-Z]{2,})$)", re.IGNORECASE)
|
if len(domain) > 253:
|
||||||
|
return False
|
||||||
|
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("."))
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -4,9 +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("_acme-chall.example.com"))
|
self.assertTrue(dnsutil.is_valid_domain('exam--ple.io'))
|
||||||
self.assertFalse(dnsutil.is_valid_domain("e/xample.com"))
|
self.assertTrue(dnsutil.is_valid_domain('a.example.com'))
|
||||||
self.assertFalse(dnsutil.is_valid_domain("exam\ple.com"))
|
self.assertTrue(dnsutil.is_valid_domain('example.io'))
|
||||||
self.assertFalse(dnsutil.is_valid_domain("*.example.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.assertTrue(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.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('-'))
|
||||||
|
|
Loading…
Reference in New Issue