* It deletes a key from :zone_name specified by :cryptokey_id.
* Server Answers:
* Case 1: the backend returns true on removal. This means the key is gone.
- * The server returns 200 OK, no body.
+ * The server returns 204 No Content, no body.
* Case 2: the backend returns false on removal. An error occurred.
- * The sever returns 422 Unprocessable Entity with message "Could not DELETE :cryptokey_id".
+ * The server returns 422 Unprocessable Entity with message "Could not DELETE :cryptokey_id".
+ * Case 3: the key or zone does not exist.
+ * The server returns 404 Not Found
* */
static void apiZoneCryptokeysDELETE(DNSName zonename, int inquireKeyId, HttpRequest *req, HttpResponse *resp, DNSSECKeeper *dk) {
+ DNSSECKeeper::keyset_t keyset=dk->getKeys(zonename, false);
+ bool found = false;
+ for(const auto& value : keyset) {
+ if (value.second.id == (unsigned) inquireKeyId) {
+ found = true;
+ break;
+ }
+ }
+ if (!found) {
+ throw HttpNotFoundException();
+ }
+
if (dk->removeKey(zonename, inquireKeyId)) {
resp->body = "";
- resp->status = 200;
+ resp->status = 204;
} else {
resp->setErrorResult("Could not DELETE " + req->parameters["key_id"], 422);
}
#checks the status code. I don't know how to test explicit that the backend fail removing a key.
r = self.session.delete(self.url("/api/v1/servers/localhost/zones/"+self.zone+"/cryptokeys/"+self.keyid))
- self.assertEquals(r.status_code, 200)
+ self.assertEquals(r.status_code, 204)
self.assertEquals(r.content, b"")
# Check that the key is actually deleted
r = self.session.get(self.url("/api/v1/servers/localhost/zones/"+self.zone+"fail/cryptokeys/"+self.keyid))
self.assertEquals(r.status_code, 404)
+ def test_delete_wrong_id(self):
+ self.keyid = self.add_zone_key()
+ r = self.session.delete(self.url("/api/v1/servers/localhost/zones/"+self.zone+"/cryptokeys/1234567"))
+ self.assertEquals(r.status_code, 404)
+
def test_delete_wrong_zone(self):
self.keyid = self.add_zone_key()
#checks for not covered zonename