]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
Merge pull request #16040 from miodvallat/dentist
authorMiod Vallat <miod.vallat@powerdns.com>
Thu, 11 Sep 2025 12:09:12 +0000 (14:09 +0200)
committerGitHub <noreply@github.com>
Thu, 11 Sep 2025 12:09:12 +0000 (14:09 +0200)
rest api: better report ill-formed zone data

1  2 
pdns/ws-auth.cc
regression-tests.api/test_Zones.py

diff --cc pdns/ws-auth.cc
Simple merge
index 0c8dd527414c434a3ad5f053b35e14a4faa74b28,1ec1770789e6d20c54b7b9ca1c2f72fe94f3a9ef..bf28bb14756831cd9fd49ce2a2f92c8901c3401d
@@@ -2649,8 -2640,45 +2649,45 @@@ $NAME$  1D  IN  SOA ns1.example.org. ho
          modified_at_new = data['rrsets'][0]['records'][0]['modified_at']
          self.assertGreater(modified_at_new, modified_at)
  
+     @unittest.skipIf(is_auth_lmdb(), "Needs to perform database update")
+     def test_access_zone_with_invalid_content(self):
+         name, payload, zone = self.create_zone()
+         rrset = {
+             'changetype': 'replace',
+             'name': name,
+             'type': 'TXT',
+             'ttl': 3600,
+             'records': [
+                 {
+                     "content": "\"innocuous data\"",
+                     "disabled": False
+                 }
+             ]
+         }
+         payload = {'rrsets': [rrset]}
+         r = self.session.patch(self.url("/api/v1/servers/localhost/zones/" + name), data=json.dumps(payload),
+                                headers={'content-type': 'application/json'})
+         self.assert_success(r)
+         # Now alter the data - see get_db_records() for inspiration
+         badcontent = 'invalid \"TXT data'
+         db, placeholder = get_auth_db()
+         cur = db.cursor()
+         cur.execute("""
+             UPDATE records
+             SET content="""+placeholder+"""
+             WHERE name="""+placeholder+""" AND type='TXT'"""
+             ,
+             (badcontent, name.rstrip('.')))
+         cur.execute('COMMIT') # Figuring out how many hours I wasted on this test because of this missing line is left as an exercize to the reader
+         cur.close()
+         db.close()
+         # Try and get the zone data
+         r = self.session.get(self.url("/api/v1/servers/localhost/zones/" + name))
+         self.assertEqual(r.status_code, 422)
+         self.assertIn('Data field in DNS should end on a quote', r.json()['error'])
  @unittest.skipIf(not is_auth(), "Not applicable")
 -class AuthRootZone(ApiTestCase, AuthZonesHelperMixin):
 +class AuthRootZone(ZonesApiTestCase, AuthZonesHelperMixin):
  
      def setUp(self):
          super(AuthRootZone, self).setUp()