From: Christian Hofstaedtler Date: Thu, 6 Oct 2016 14:18:09 +0000 (+0200) Subject: API: search should not return ENTs X-Git-Tag: auth-4.0.2~22^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3b5b0d5a89d2b163b146e74ad629dd18ae5193f8;p=thirdparty%2Fpdns.git API: search should not return ENTs This should also fix #4534, when backported. --- diff --git a/pdns/ws-auth.cc b/pdns/ws-auth.cc index 5934a3b6b8..33f29687ee 100644 --- a/pdns/ws-auth.cc +++ b/pdns/ws-auth.cc @@ -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() }, diff --git a/regression-tests.api/runtests.py b/regression-tests.api/runtests.py index 18189424c8..4fac51b084 100755 --- a/regression-tests.api/runtests.py +++ b/regression-tests.api/runtests.py @@ -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 "" diff --git a/regression-tests.api/test_Zones.py b/regression-tests.api/test_Zones.py index 93e345b8c0..958e192e3c 100644 --- a/regression-tests.api/test_Zones.py +++ b/regression-tests.api/test_Zones.py @@ -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', diff --git a/regression-tests.api/test_helper.py b/regression-tests.api/test_helper.py index 04a851a971..99b1ac9959 100644 --- a/regression-tests.api/test_helper.py +++ b/regression-tests.api/test_helper.py @@ -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])