Skip to content

Commit

Permalink
fix(key-auth) more accurate response when no key
Browse files Browse the repository at this point in the history
  • Loading branch information
p0pr0ck5 authored and thibaultcha committed May 5, 2017
1 parent d3e9071 commit 491cbb4
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 4 deletions.
3 changes: 1 addition & 2 deletions kong/plugins/key-auth/handler.lua
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,7 @@ local function do_authentication(conf)
-- this request is missing an API key, HTTP 401
if not key then
ngx.header["WWW-Authenticate"] = _realm
return false, {status = 401, message = "No API key found in headers"
.." or querystring"}
return false, { status = 401, message = "No API key found in request" }
end

-- retrieve our consumer linked to this API key
Expand Down
4 changes: 2 additions & 2 deletions spec/03-plugins/10-key-auth/02-access_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ describe("Plugin: key-auth (access)", function()
})
local body = assert.res_status(401, res)
local json = cjson.decode(body)
assert.same({ message = "No API key found in headers or querystring" }, json)
assert.same({ message = "No API key found in request" }, json)
end)
it("returns WWW-Authenticate header on missing credentials", function()
local res = assert(client:send {
Expand Down Expand Up @@ -222,7 +222,7 @@ describe("Plugin: key-auth (access)", function()
})
local body = assert.res_status(401, res)
local json = cjson.decode(body)
assert.same({ message = "No API key found in headers or querystring" }, json)
assert.same({ message = "No API key found in request" }, json)
end)
end)

Expand Down

0 comments on commit 491cbb4

Please sign in to comment.