]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
API: don't add priority to content field on save 1351/head
authorChristian Hofstaedtler <christian@hofstaedtler.name>
Wed, 2 Apr 2014 14:56:33 +0000 (16:56 +0200)
committerChristian Hofstaedtler <christian@hofstaedtler.name>
Wed, 2 Apr 2014 14:56:33 +0000 (16:56 +0200)
We need the prio in content for verification purposes, but for storage
it needs to stay in rr.priority. Adds a test for this.

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

index 551a1c6045037c70a2d0e65c884438a0068e960c..f71cfb09d512969d5ec6aa6812a8866ff5c09f15 100644 (file)
@@ -628,14 +628,15 @@ static void apiServerZoneRRset(HttpRequest* req, HttpResponse* resp) {
         rr.priority = intFromJson(record, "priority");
         rr.disabled = boolFromJson(record, "disabled");
 
-        if(rr.qtype.getCode() == QType::MX || rr.qtype.getCode() == QType::SRV)
-          rr.content = lexical_cast<string>(rr.priority)+" "+rr.content;
-
         if(rr.qname != qname || rr.qtype != qtype)
           throw ApiException("Record "+rr.qname+" IN "+rr.qtype.getName()+" "+rr.content+": Record bundled with wrong RRset");
 
+        string temp_content = rr.content;
+        if(rr.qtype.getCode() == QType::MX || rr.qtype.getCode() == QType::SRV)
+          temp_content = lexical_cast<string>(rr.priority)+" "+rr.content;
+
         try {
-          shared_ptr<DNSRecordContent> drc(DNSRecordContent::mastermake(rr.qtype.getCode(), 1, rr.content));
+          shared_ptr<DNSRecordContent> drc(DNSRecordContent::mastermake(rr.qtype.getCode(), 1, temp_content));
           string tmp = drc->serialize(rr.qname);
         }
         catch(std::exception& e)
index 104182aeb51e35b9cd93d916f4a8f1260076038f..075534c1eac002481b8788c78533145ea25a1860 100644 (file)
@@ -156,6 +156,37 @@ class AuthZones(ApiTestCase):
         recs = [rec for rec in data if rec['type'] == payload['type'] and rec['name'] == payload['name']]
         self.assertEquals(recs, payload['records'])
 
+    def test_ZoneRRUpdateMX(self):
+        # Important to test with MX records, as they have a priority field, which must not end up in the content field.
+        payload, zone = self.create_zone()
+        name = payload['name']
+        # do a replace (= update)
+        payload = {
+            'changetype': 'replace',
+            'name': name,
+            'type': 'MX',
+            'records': [
+                {
+                    "name": name,
+                    "type": "MX",
+                    "priority": 10,
+                    "ttl": 3600,
+                    "content": "mail.example.org",
+                    "disabled": False
+                }
+            ]
+        }
+        r = self.session.patch(
+            self.url("/servers/localhost/zones/" + name + "/rrset"),
+            data=json.dumps(payload),
+            headers={'content-type': 'application/json'})
+        self.assertSuccessJson(r)
+        # verify that (only) the new record is there
+        r = self.session.get(self.url("/servers/localhost/zones/" + name))
+        data = r.json()['records']
+        recs = [rec for rec in data if rec['type'] == payload['type'] and rec['name'] == payload['name']]
+        self.assertEquals(recs, payload['records'])
+
     def test_ZoneRRDelete(self):
         payload, zone = self.create_zone()
         name = payload['name']