throw HttpMethodNotAllowedException();
}
+// Throws 404 if the key with inquireKeyId does not exist
+static void apiZoneCryptoKeysCheckKeyExists(DNSName zonename, int inquireKeyId, 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();
+ }
+}
+
static void apiZoneCryptokeysGET(DNSName zonename, int inquireKeyId, HttpResponse *resp, DNSSECKeeper *dk) {
DNSSECKeeper::keyset_t keyset=dk->getKeys(zonename, false);
* 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 = 204;
int inquireKeyId = -1;
if (req->parameters.count("key_id")) {
inquireKeyId = std::stoi(req->parameters["key_id"]);
+ apiZoneCryptoKeysCheckKeyExists(zonename, inquireKeyId, &dk);
}
if (req->method == "GET") {
self.remove_zone_key(self.keyid)
#checks for key is gone. Its ok even if no key had to be deleted. Or something went wrong with the backend.
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.content, b"")
+ self.assertEquals(r.status_code, 404)
# Prepares the json object for Post and sends it to the server
def add_key(self, content='', type='ksk', active='true', algo='', bits=None):