1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
|
From 1b22985f2d67b6dd43259e3c6b853498f1cff712 Mon Sep 17 00:00:00 2001
From: Bob Halley <halley@dnspython.org>
Date: Sat, 27 Jan 2024 12:38:03 -0800
Subject: [PATCH] In tests, work around musl libc and docker issues.
Specifically: musl libc's getaddrinfo behavior always returns
a canonical name.
Docker's resolver proxy doesn't do dangling CNAMEs correctly
and also answers NXDOMAIN in some cases where it should say
no error, no data.
---
tests/test_async.py | 14 +++++++++++---
tests/test_resolver.py | 21 +++++++++++++++------
tests/test_resolver_override.py | 19 ++++++++++++-------
tests/util.py | 10 +++++++++-
4 files changed, 47 insertions(+), 17 deletions(-)
diff --git a/tests/test_resolver_override.py b/tests/test_resolver_override.py
index aed7a53d..be9e53f2 100644
--- a/tests/test_resolver_override.py
+++ b/tests/test_resolver_override.py
@@ -69,7 +69,7 @@ def test_override(self):
dns.resolver.restore_system_resolver()
self.assertTrue(socket.getaddrinfo is dns.resolver._original_getaddrinfo)
- def equivalent_info(self, a, b):
+ def equivalent_info(self, a, b, q):
if len(a) != len(b):
return False
for x in a:
@@ -78,16 +78,21 @@ def equivalent_info(self, a, b):
# looking for a zero protocol.
y = (x[0], x[1], 0, x[3], x[4])
if y not in b:
- print("NOT EQUIVALENT")
- print(a)
- print(b)
- return False
+ # musl libc insists on always providing a canonical name, so
+ # accept that too.
+ y = (x[0], x[1], x[2], q, x[4])
+ if y not in b:
+ print("NOT EQUIVALENT")
+ print(a)
+ print(b)
+ return False
return True
def equivalent(self, *args, **kwargs):
+ q = args[0]
a = socket.getaddrinfo(*args, **kwargs)
b = dns.resolver._original_getaddrinfo(*args, **kwargs)
- return self.equivalent_info(a, b)
+ return self.equivalent_info(a, b, q)
@unittest.skipIf(
sys.platform == "win32", "avoid windows original getaddrinfo issues"
@@ -139,7 +144,7 @@ def test_getaddrinfo_nxdomain(self):
def test_getaddrinfo_service(self):
a = socket.getaddrinfo("dns.google", "domain")
b = socket.getaddrinfo("dns.google", 53)
- self.assertTrue(self.equivalent_info(a, b))
+ self.assertTrue(self.equivalent_info(a, b, "dns.google"))
try:
socket.getaddrinfo("dns.google", "domain", flags=socket.AI_NUMERICSERV)
self.assertTrue(False) # should not happen!
|