summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBob Halley <halley@dnspython.org>2021-11-07 10:41:54 -0800
committerBob Halley <halley@dnspython.org>2021-11-07 10:41:54 -0800
commit246febc405089c8551cdba3e636d174e7446ca13 (patch)
treeb35b71d749ca8369e0271df6c5ab01d7c1734c4f
parent03b94513d17119dfcb708886197c81293cce7be0 (diff)
downloaddnspython-246febc405089c8551cdba3e636d174e7446ca13.tar.gz
Handle DHCP servers returning domains prefixed by dot [#687].
-rw-r--r--dns/resolver.py5
-rw-r--r--tests/test_resolver.py10
2 files changed, 15 insertions, 0 deletions
diff --git a/dns/resolver.py b/dns/resolver.py
index 108dd52..fbdf622 100644
--- a/dns/resolver.py
+++ b/dns/resolver.py
@@ -875,6 +875,11 @@ class BaseResolver:
self.nameservers.append(ns)
def _config_win32_domain(self, domain): # pragma: no cover
+ # Sometimes DHCP servers add a '.' prefix to the default domain, and
+ # Windows just stores such values in the registry (see #687).
+ # Check for this and fix it.
+ if domain.startswith('.'):
+ domain = domain[1:]
# we call str() on domain to convert it from unicode to ascii
self.domain = dns.name.from_text(str(domain))
diff --git a/tests/test_resolver.py b/tests/test_resolver.py
index ecd1bf2..eb83893 100644
--- a/tests/test_resolver.py
+++ b/tests/test_resolver.py
@@ -886,6 +886,16 @@ class ResolverMiscTestCase(unittest.TestCase):
# not raising is the test
res._compute_timeout(now + 0.5)
+ def test_configure_win32_domain(self):
+ # This is a win32-related test but it works on all platforms so we
+ # test it that way to make coverage analysis easier.
+ n = dns.name.from_text('home.')
+ res = dns.resolver.Resolver(configure=False)
+ res._config_win32_domain('home')
+ self.assertEqual(res.domain, n)
+ res._config_win32_domain('.home')
+ self.assertEqual(res.domain, n)
+
class ResolverNameserverValidTypeTestCase(unittest.TestCase):
def test_set_nameservers_to_list(self):