]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
auth API: when querying with rrset_name, respect it for comments too 14045/head
authorPeter van Dijk <peter.van.dijk@powerdns.com>
Tue, 18 Jun 2024 18:25:23 +0000 (20:25 +0200)
committerPeter van Dijk <peter.van.dijk@powerdns.com>
Tue, 18 Jun 2024 21:02:43 +0000 (23:02 +0200)
pdns/ws-auth.cc
regression-tests.api/test_Zones.py

index 5002ffaeb684798993e7acab7df0496866a5dd2c..8dc0f3f7e3cad2e9c1ba15806327b882b3204dbd 100644 (file)
@@ -445,6 +445,9 @@ static void fillZone(UeberBackend& backend, const DNSName& zonename, HttpRespons
     vector<DNSResourceRecord> records;
     vector<Comment> comments;
 
+    QType qType = QType::ANY;
+    DNSName qName;
+
     // load all records + sort
     {
       DNSResourceRecord resourceRecord;
@@ -452,14 +455,11 @@ static void fillZone(UeberBackend& backend, const DNSName& zonename, HttpRespons
         domainInfo.backend->list(zonename, static_cast<int>(domainInfo.id), true); // incl. disabled
       }
       else {
-        QType qType;
-        if (req->getvars.count("rrset_type") == 0) {
-          qType = QType::ANY;
-        }
-        else {
+        qName = DNSName(req->getvars["rrset_name"]);
+        if (req->getvars.count("rrset_type") != 0) {
           qType = req->getvars["rrset_type"];
         }
-        domainInfo.backend->lookup(qType, DNSName(req->getvars["rrset_name"]), static_cast<int>(domainInfo.id));
+        domainInfo.backend->lookup(qType, qName, static_cast<int>(domainInfo.id));
       }
       while (domainInfo.backend->get(resourceRecord)) {
         if (resourceRecord.qtype.getCode() == 0) {
@@ -483,7 +483,9 @@ static void fillZone(UeberBackend& backend, const DNSName& zonename, HttpRespons
       Comment comment;
       domainInfo.backend->listComments(domainInfo.id);
       while (domainInfo.backend->getComment(comment)) {
-        comments.push_back(comment);
+        if ((qName.empty() || comment.qname == qName) && (qType == QType::ANY || comment.qtype == qType)) {
+          comments.push_back(comment);
+        }
       }
       sort(comments.begin(), comments.end(), [](const Comment& rrA, const Comment& rrB) {
         /* if you ever want to update this comparison function,
index 24012de62760534952c5abe78da07e3391af476e..2876b5e268d4b45f27866f7b00d7d8e7733d7bad 100644 (file)
@@ -1935,7 +1935,7 @@ $NAME$  1D  IN  SOA ns1.example.org. hostmaster.example.org. (
 
     def test_zone_comment_create(self):
         name, payload, zone = self.create_zone()
-        rrset = {
+        rrset1 = {
             'changetype': 'replace',
             'name': name,
             'type': 'NS',
@@ -1951,7 +1951,19 @@ $NAME$  1D  IN  SOA ns1.example.org. hostmaster.example.org. (
                 }
             ]
         }
-        payload = {'rrsets': [rrset]}
+        rrset2 = {
+            'changetype': 'replace',
+            'name': name,
+            'type': 'SOA',
+            'ttl': 3600,
+            'comments': [
+                {
+                    'account': 'test3',
+                    'content': 'this should not show up later'
+                }
+            ]
+        }
+        payload = {'rrsets': [rrset1, rrset2]}
         r = self.session.patch(
             self.url("/api/v1/servers/localhost/zones/" + name),
             data=json.dumps(payload),
@@ -1963,13 +1975,15 @@ $NAME$  1D  IN  SOA ns1.example.org. hostmaster.example.org. (
             self.assert_success(r)
         # make sure the comments have been set, and that the NS
         # records are still present
-        data = self.get_zone(name)
+        data = self.get_zone(name, rrset_name=name, rrset_type="NS")
         serverset = get_rrset(data, name, 'NS')
         print(serverset)
         self.assertNotEqual(serverset['records'], [])
         self.assertNotEqual(serverset['comments'], [])
         # verify that modified_at has been set by pdns
         self.assertNotEqual([c for c in serverset['comments']][0]['modified_at'], 0)
+        # verify that unrelated comments do not leak into the result
+        self.assertEqual(get_rrset(data, name, 'SOA'), None)
         # verify that TTL is correct (regression test)
         self.assertEqual(serverset['ttl'], 3600)
 
@@ -1997,7 +2011,7 @@ $NAME$  1D  IN  SOA ns1.example.org. hostmaster.example.org. (
 
     @unittest.skipIf(is_auth_lmdb(), "No comments in LMDB")
     def test_zone_comment_out_of_range_modified_at(self):
-        # Test if comments on an rrset stay intact if the rrset is replaced
+        # Test if a modified_at outside of the 32 bit range throws an error
         name, payload, zone = self.create_zone()
         rrset = {
             'changetype': 'replace',