]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
API: search should not return ENTs 4543/head
authorChristian Hofstaedtler <christian.hofstaedtler@deduktiva.com>
Thu, 6 Oct 2016 14:18:09 +0000 (16:18 +0200)
committerChristian Hofstaedtler <christian@hofstaedtler.name>
Thu, 6 Oct 2016 14:20:23 +0000 (16:20 +0200)
This should also fix #4534, when backported.

pdns/ws-auth.cc
regression-tests.api/runtests.py
regression-tests.api/test_Zones.py
regression-tests.api/test_helper.py

index 5934a3b6b805e20f0517cb109399b7c26325230e..33f29687eef8853a80a59984eb6df4664d7fe76c 100644 (file)
@@ -1151,6 +1151,9 @@ static void apiServerSearchData(HttpRequest* req, HttpResponse* resp) {
   {
     for(const DNSResourceRecord& rr: result_rr)
     {
+      if (!rr.qtype.getCode())
+        continue; // skip empty non-terminals
+
       auto object = Json::object {
         { "object_type", "record" },
         { "name", rr.qname.toString() },
index 18189424c8508dbf990756598a5d639fddfa0034..4fac51b0849aff243896f5d39b1f931af918105b 100755 (executable)
@@ -13,6 +13,7 @@ import time
 SQLITE_DB = 'pdns.sqlite3'
 WEBPORT = '5556'
 APIKEY = '1234567890abcdefghijklmnopq-key'
+PDNSUTIL_CMD = ["../pdns/pdnsutil", "--config-dir=."]
 
 NAMED_CONF_TPL = """
 # Generated by runtests.py
@@ -99,7 +100,7 @@ if daemon == 'authoritative':
     with open('pdns.conf', 'w') as named_conf:
         named_conf.write(AUTH_CONF_TPL)
 
-    subprocess.check_call(["../pdns/pdnsutil", "--config-dir=.", "secure-zone", "powerdnssec.org"])
+    subprocess.check_call(PDNSUTIL_CMD + ["secure-zone", "powerdnssec.org"])
     pdnscmd = ("../pdns/pdns_server --daemon=no --local-address=127.0.0.1 --local-port=5300 --socket-dir=./ --no-shuffle --dnsupdate=yes --cache-ttl=0 --config-dir=. --api=yes --webserver=yes --webserver-port="+WEBPORT+" --webserver-address=127.0.0.1 --webserver-password=something --api-key="+APIKEY).split()
 
 else:
@@ -140,7 +141,13 @@ print "Running tests..."
 rc = 0
 test_env = {}
 test_env.update(os.environ)
-test_env.update({'WEBPORT': WEBPORT, 'APIKEY': APIKEY, 'DAEMON': daemon, 'SQLITE_DB': SQLITE_DB})
+test_env.update({
+    'WEBPORT': WEBPORT,
+    'APIKEY': APIKEY,
+    'DAEMON': daemon,
+    'SQLITE_DB': SQLITE_DB,
+    'PDNSUTIL_CMD': ' '.join(PDNSUTIL_CMD),
+})
 
 try:
     print ""
index 93e345b8c0e70cd61d4579f8c7c4cb169d902180..958e192e3cc6cc25dbe08f01cc060372a4b95d74 100644 (file)
@@ -3,7 +3,7 @@ import time
 import unittest
 from copy import deepcopy
 from pprint import pprint
-from test_helper import ApiTestCase, unique_zone_name, is_auth, is_recursor, get_db_records
+from test_helper import ApiTestCase, unique_zone_name, is_auth, is_recursor, get_db_records, pdnsutil_rectify
 
 
 def get_rrset(data, qname, qtype):
@@ -1106,6 +1106,25 @@ fred   IN  A      192.168.0.4
         # should return zone, SOA, ns1, ns2
         self.assertEquals(len(r.json()), 4)
 
+    def test_search_after_rectify_with_ent(self):
+        name = 'search-rectified.name.'
+        rrset = {
+            "name": 'sub.sub.' + name,
+            "type": "A",
+            "ttl": 3600,
+            "records": [{
+                "content": "4.3.2.1",
+                "disabled": False,
+            }],
+        }
+        self.create_zone(name=name, rrsets=[rrset])
+        pdnsutil_rectify(name)
+        r = self.session.get(self.url("/api/v1/servers/localhost/search-data?q=*search-rectified*"))
+        self.assert_success_json(r)
+        print r.json()
+        # should return zone, SOA, ns1, ns2, sub.sub A (but not the ENT)
+        self.assertEquals(len(r.json()), 5)
+
 
 @unittest.skipIf(not is_auth(), "Not applicable")
 class AuthRootZone(ApiTestCase, AuthZonesHelperMixin):
@@ -1205,7 +1224,6 @@ class RecursorZones(ApiTestCase):
             self.assertEquals(data[k], payload[k])
 
     def test_create_zone_no_name(self):
-        name = unique_zone_name()
         payload = {
             'name': '',
             'kind': 'Native',
index 04a851a9710c4d3829d4b259f52cc18ba5314e34..99b1ac99595d9462be97a9cc72cff6b016393c7c 100644 (file)
@@ -4,8 +4,10 @@ import requests
 import urlparse
 import unittest
 import sqlite3
+import subprocess
 
 DAEMON = os.environ.get('DAEMON', 'authoritative')
+PDNSUTIL_CMD = os.environ.get('PDNSUTIL_CMD', 'NOT_SET BUT_THIS MIGHT_BE_A_LIST').split(' ')
 SQLITE_DB = os.environ.get('SQLITE_DB', 'pdns.sqlite3')
 
 
@@ -66,3 +68,8 @@ def get_db_records(zonename, qtype):
         recs = [{'name': row[0], 'type': row[1], 'content': row[2], 'ttl': row[3]} for row in rows]
         print "DB Records:", recs
         return recs
+
+
+def pdnsutil_rectify(zonename):
+    """Run pdnsutil rectify-zone on the given zone."""
+    subprocess.check_call(PDNSUTIL_CMD + ['rectify-zone', zonename])