]> granicus.if.org Git - pdns/commitdiff
API: Allow deleting out-of-zone records
authorChristian Hofstaedtler <christian@hofstaedtler.name>
Mon, 30 Mar 2015 19:43:13 +0000 (21:43 +0200)
committerChristian Hofstaedtler <christian@hofstaedtler.name>
Mon, 30 Mar 2015 19:43:13 +0000 (21:43 +0200)
Useful for fixing legacy data (but note that it's impossible to re-create
such data using the API.)

Fixes #2393.

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

index 9fe2272bd4a76f697156ce98b3bd3d16a53009de..9e5525b76ed817e5e3391440dbbc422c9716aa74 100644 (file)
@@ -968,9 +968,6 @@ static void patchZone(HttpRequest* req, HttpResponse* resp) {
       qtype = stringFromJson(rrset, "type");
       changetype = toUpper(stringFromJson(rrset, "changetype"));
 
-      if (!iends_with(qname, dotsuffix) && !pdns_iequals(qname, zonename))
-        throw ApiException("RRset "+qname+" IN "+qtype.getName()+": Name is out of zone");
-
       if (changetype == "DELETE") {
         // delete all matching qname/qtype RRs (and, implictly comments).
         if (!di.backend->replaceRRSet(di.id, qname, qtype, vector<DNSResourceRecord>())) {
@@ -978,7 +975,11 @@ static void patchZone(HttpRequest* req, HttpResponse* resp) {
         }
       }
       else if (changetype == "REPLACE") {
-        new_records.clear();
+               // we only validate for REPLACE, as DELETE can be used to "fix" out of zone records.
+        if (!iends_with(qname, dotsuffix) && !pdns_iequals(qname, zonename))
+          throw ApiException("RRset "+qname+" IN "+qtype.getName()+": Name is out of zone");
+
+               new_records.clear();
         new_comments.clear();
         // new_ptrs is merged
         gatherRecords(rrset, new_records, new_ptrs);
index 3e0ece4bb8a368fdefde68698c5c7b552318f2f7..75f306a0ddbb436179cbb652d96e19ecc45f5be2 100644 (file)
@@ -766,7 +766,6 @@ fred   IN  A      192.168.0.4
     def test_zone_rr_delete_out_of_zone(self):
         payload, zone = self.create_zone()
         name = payload['name']
-        # replace with qname mismatch
         rrset = {
             'changetype': 'delete',
             'name': 'not-in-zone',
@@ -777,8 +776,8 @@ fred   IN  A      192.168.0.4
             self.url("/servers/localhost/zones/" + name),
             data=json.dumps(payload),
             headers={'content-type': 'application/json'})
-        self.assertEquals(r.status_code, 422)
-        self.assertIn('out of zone', r.json()['error'])
+        print r.content
+        self.assertEquals(r.status_code, 200)  # succeed so users can fix their wrong, old data
 
     def test_zone_delete(self):
         payload, zone = self.create_zone()