]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
Auth API: return status 409 if domain already exists #4482
authorChris Hofstaedtler <chris.hofstaedtler@deduktiva.com>
Tue, 6 Mar 2018 07:41:19 +0000 (08:41 +0100)
committerChris Hofstaedtler <chris.hofstaedtler@deduktiva.com>
Tue, 6 Mar 2018 07:41:19 +0000 (08:41 +0100)
pdns/webserver.hh
pdns/ws-auth.cc
regression-tests.api/test_Zones.py

index b3ede8925ea67a863be5eaafa940bd0d81888dab..16d41e1197e0bc4add2b86fc548843ab877ad5fa 100644 (file)
@@ -102,6 +102,11 @@ public:
   HttpMethodNotAllowedException() : HttpException(405) { };
 };
 
+class HttpConflictException : public HttpException {
+public:
+  HttpConflictException() : HttpException(409) { };
+};
+
 class HttpInternalServerErrorException : public HttpException {
 public:
   HttpInternalServerErrorException() : HttpException(500) { };
index 9f8b9e7ac2f09779a279a5550d8dbe4cd221fcea..eada20704ef0468b0480fc76b9489cc8d0a0f7b3 100644 (file)
@@ -1195,7 +1195,7 @@ static void apiServerZones(HttpRequest* req, HttpResponse* resp) {
 
     bool exists = B.getDomainInfo(zonename, di);
     if(exists)
-      throw ApiException("Domain '"+zonename.toString()+"' already exists");
+      throw HttpConflictException();
 
     // validate 'kind' is set
     DomainInfo::DomainKind zonekind = DomainInfo::stringToKind(stringFromJson(document, "kind"));
index 6a456d9012d87347bcc32ac7a0b79b8db2e3f65d..29f1645968cc73f2022f72cd0e00bcfb2a064ee8 100644 (file)
@@ -141,6 +141,20 @@ class AuthZones(ApiTestCase, AuthZonesHelperMixin):
         print(data)
         self.assertEquals(data['soa_edit_api'], 'DEFAULT')
 
+    def test_create_zone_exists(self):
+        name, payload, data = self.create_zone()
+        print(data)
+        payload = {
+            'name': name,
+            'kind': 'Native'
+        }
+        print(payload)
+        r = self.session.post(
+            self.url("/api/v1/servers/localhost/zones"),
+            data=json.dumps(payload),
+            headers={'content-type': 'application/json'})
+        self.assertEquals(r.status_code, 409)  # Conflict - already exists
+
     def test_create_zone_with_soa_edit(self):
         name, payload, data = self.create_zone(soa_edit='INCEPTION-INCREMENT', soa_edit_api='SOA-EDIT-INCREASE')
         print(data)