]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
rec: fix trace=fail regression and add regression test for it
authorOtto Moerbeek <otto.moerbeek@open-xchange.com>
Mon, 18 Mar 2024 08:00:57 +0000 (09:00 +0100)
committerOtto Moerbeek <otto.moerbeek@open-xchange.com>
Mon, 18 Mar 2024 08:06:12 +0000 (09:06 +0100)
pdns/recursordist/pdns_recursor.cc
regression-tests.recursor-dnssec/test_TraceFail.py [new file with mode: 0644]

index 56c9954643640ec42bd918a62fd0dfcd440e0cf9..c20d2876ee0df4e0a1ff94af4a862b004e977a11 100644 (file)
@@ -857,6 +857,15 @@ static void dumpTrace(const string& trace, const timeval& timev)
   if (trace.empty()) {
     return;
   }
+  if (t_tracefd < 0) {
+    std::istringstream buf(trace);
+    g_log << Logger::Warning << "=== START OF FAIL TRACE ====" << endl;
+    for (string line; std::getline(buf, line);) {
+      g_log << Logger::Warning << line << endl;
+    }
+    g_log << Logger::Warning << "=== END OF FAIL TRACE ====" << endl;
+    return;
+  }
   timeval now{};
   Utility::gettimeofday(&now);
   int traceFd = dup(t_tracefd);
diff --git a/regression-tests.recursor-dnssec/test_TraceFail.py b/regression-tests.recursor-dnssec/test_TraceFail.py
new file mode 100644 (file)
index 0000000..52e8c29
--- /dev/null
@@ -0,0 +1,48 @@
+import dns
+import os
+import time
+import subprocess
+from recursortests import RecursorTest
+
+class testTraceFail(RecursorTest):
+    _confdir = 'TraceFail'
+
+    _config_template = """
+trace=fail
+forward-zones-recurse=.=127.0.0.1:9999
+"""
+
+    @classmethod
+    def setUpClass(cls):
+
+        # we don't need all the auth stuff
+        cls.setUpSockets()
+        cls.startResponders()
+
+        confdir = os.path.join('configs', cls._confdir)
+        cls.createConfigDir(confdir)
+
+        cls.generateRecursorConfig(confdir)
+        cls.startRecursor(confdir, cls._recursorPort)
+
+    @classmethod
+    def tearDownClass(cls):
+        cls.tearDownRecursor()
+
+    def testA(self):
+        query = dns.message.make_query('example', 'A', want_dnssec=False)
+        res = self.sendUDPQuery(query)
+        self.assertRcodeEqual(res, dns.rcode.SERVFAIL)
+
+        grepCmd = ['grep', 'END OF FAIL TRACE', 'configs/' + self._confdir + '/recursor.log']
+        ret = b''
+        for i in range(10):
+            time.sleep(1)
+            try:
+                ret = subprocess.check_output(grepCmd, stderr=subprocess.STDOUT)
+            except subprocess.CalledProcessError as e:
+                continue
+            print(b'A' + ret)
+            break
+        print(ret)
+        self.assertNotEqual(ret, b'')