]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
JSON API: strip trailing dots when creating zones 1316/head
authorChristian Hofstaedtler <christian@hofstaedtler.name>
Tue, 4 Mar 2014 15:07:36 +0000 (16:07 +0100)
committerChristian Hofstaedtler <christian@hofstaedtler.name>
Tue, 4 Mar 2014 15:07:36 +0000 (16:07 +0100)
Otherwise we end up with example.org. in the DB, when it should have been
example.org .

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

index c1261b21fe2c1e7748adfbf773e771442f5d99a8..ed8ac960b13f4f6f876457c5b64afab37ce0ec5b 100644 (file)
@@ -379,6 +379,11 @@ static void apiServerZones(HttpRequest* req, HttpResponse* resp) {
     if(zonename.empty())
       throw ApiException("Zone name empty");
 
+    // strip any trailing dots
+    while (zonename.substr(zonename.size()-1) == ".") {
+      zonename.resize(zonename.size()-1);
+    }
+
     string kind = stringFromJson(document, "kind");
 
     bool exists = B.getDomainInfo(zonename, di);
index 3055d75c15ddd3baf79819f8977a1ab3fe58aca5..3ccee84ac50f93e7780adf5c71f069b3a33a28a9 100644 (file)
@@ -50,6 +50,12 @@ class AuthZones(ApiTestCase):
                 self.assertEquals(data[k], payload[k])
         self.assertEquals(data['comments'], [])
 
+    def test_CreateZoneTrailingDot(self):
+        # Trailing dots should not end up in the zone name.
+        basename = unique_zone_name()
+        payload, data = self.create_zone(name=basename+'.')
+        self.assertEquals(data['name'], basename)
+
     def test_CreateZoneWithSymbols(self):
         payload, data = self.create_zone(name='foo/bar.'+unique_zone_name())
         name = payload['name']