]> granicus.if.org Git - pdns/commitdiff
API: Reject unknown types (TYPE0)
authorChristian Hofstaedtler <christian@hofstaedtler.name>
Sat, 7 Feb 2015 12:38:33 +0000 (13:38 +0100)
committerChristian Hofstaedtler <christian@hofstaedtler.name>
Sat, 7 Feb 2015 12:47:12 +0000 (13:47 +0100)
Fixes #2130.

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

index baa35d020ca530c88ac238121858c7beb198acf0..d3f63a2b3bf9b41cacbb72332c50b5e27155812c 100644 (file)
@@ -396,6 +396,10 @@ static void gatherRecords(const Value& container, vector<DNSResourceRecord>& new
       rr.ttl = intFromJson(record, "ttl");
       rr.disabled = boolFromJson(record, "disabled");
 
+      if (rr.qtype.getCode() == 0) {
+        throw ApiException("Record "+rr.qname+"/"+stringFromJson(record, "type")+" is of unknown type");
+      }
+
       try {
         shared_ptr<DNSRecordContent> drc(DNSRecordContent::mastermake(rr.qtype.getCode(), 1, rr.content));
         string tmp = drc->serialize(rr.qname);
index 3e208729727310e4e2000d831a2bedd04773667f..f05117efcc33dc2429b63f19c79df1358a8ba752 100644 (file)
@@ -704,6 +704,29 @@ fred   IN  A      192.168.0.4
         self.assertEquals(r.status_code, 422)
         self.assertIn('out of zone', r.json()['error'])
 
+    def test_rrset_unknown_type(self):
+        payload, zone = self.create_zone()
+        name = payload['name']
+        rrset = {
+            'changetype': 'replace',
+            'name': name,
+            'type': 'FAFAFA',
+            'records': [
+                {
+                    "name": name,
+                    "type": "FAFAFA",
+                    "ttl": 3600,
+                    "content": "4.3.2.1",
+                    "disabled": False
+                }
+            ]
+        }
+        payload = {'rrsets': [rrset]}
+        r = self.session.patch(self.url("/servers/localhost/zones/" + name), data=json.dumps(payload),
+                               headers={'content-type': 'application/json'})
+        self.assertEquals(r.status_code, 422)
+        self.assertIn('unknown type', r.json()['error'])
+
     def test_zone_rr_delete_out_of_zone(self):
         payload, zone = self.create_zone()
         name = payload['name']