Skip to content

Commit

Permalink
fix(admin) prevent HTTP 500 on non-existing GET /certificates/{uuid}
Browse files Browse the repository at this point in the history
We now properly return HTTP 404 Not Found when the certificate's id
specified in the URL is non-existing.

From #3148

Signed-off-by: Thibault Charbonnier <[email protected]>
  • Loading branch information
vdesjardins authored and thibaultcha committed Jan 20, 2018
1 parent da53316 commit abc3f8a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
4 changes: 3 additions & 1 deletion kong/api/routes/certificates.lua
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,9 @@ return {
return helpers.yield_error(err)
end

assert(row, "no SSL certificate for given SNI")
if not row then
return helpers.responses.send_HTTP_NOT_FOUND()
end

-- add list of other SNIs for this certificate

Expand Down
16 changes: 16 additions & 0 deletions spec/02-integration/04-admin_api/06-certificates_routes_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -657,6 +657,22 @@ describe("Admin API: #" .. kong_config.database, function()
assert.same({ "foo.com", "bar.com" }, json1.snis)
assert.same(json1, json2)
end)

it("returns 404 for a random non-existing uuid", function()
local res = assert(client:send {
method = "GET",
path = "/certificates/" .. utils.uuid(),
})
assert.res_status(404, res)
end)

it("returns 404 for a random non-existing SNI", function()
local res = assert(client:send {
method = "GET",
path = "/certificates/doesntexist.com",
})
assert.res_status(404, res)
end)
end)

describe("PATCH", function()
Expand Down

0 comments on commit abc3f8a

Please sign in to comment.