From: Chris Hofstaedtler Date: Tue, 6 Mar 2018 07:41:19 +0000 (+0100) Subject: Auth API: return status 409 if domain already exists #4482 X-Git-Tag: dnsdist-1.3.0~62^2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=331d3062dc8b15e8a4cb78e77525831a3af8a52b;p=thirdparty%2Fpdns.git Auth API: return status 409 if domain already exists #4482 --- diff --git a/pdns/webserver.hh b/pdns/webserver.hh index b3ede8925e..16d41e1197 100644 --- a/pdns/webserver.hh +++ b/pdns/webserver.hh @@ -102,6 +102,11 @@ public: HttpMethodNotAllowedException() : HttpException(405) { }; }; +class HttpConflictException : public HttpException { +public: + HttpConflictException() : HttpException(409) { }; +}; + class HttpInternalServerErrorException : public HttpException { public: HttpInternalServerErrorException() : HttpException(500) { }; diff --git a/pdns/ws-auth.cc b/pdns/ws-auth.cc index 9f8b9e7ac2..eada20704e 100644 --- a/pdns/ws-auth.cc +++ b/pdns/ws-auth.cc @@ -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")); diff --git a/regression-tests.api/test_Zones.py b/regression-tests.api/test_Zones.py index 6a456d9012..29f1645968 100644 --- a/regression-tests.api/test_Zones.py +++ b/regression-tests.api/test_Zones.py @@ -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)