Skip to content
This repository has been archived by the owner on Feb 22, 2020. It is now read-only.

Commit

Permalink
Merge pull request #4 from checkr/zz/fix-basic
Browse files Browse the repository at this point in the history
Fix basic
  • Loading branch information
zhouzhuojie authored Apr 20, 2018
2 parents ee7ef6f + 7c1eb7d commit 7a8b7a8
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion kong/plugins/basicauth2keyauth/handler.lua
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ local function retrieve_credentials(request, header_name, conf)
local authorization_header = request.get_headers()[header_name]

if authorization_header then
local iterator, iter_err = ngx.re.gmatch(authorization_header, "\\s*[Bb]asic\\s*(.+)")
local iterator, iter_err = ngx.re.gmatch(authorization_header, "\\s*Basic\\s*(.+)", "oji")
if not iterator then
ngx.log(ngx.ERR, iter_err)
return
Expand Down
13 changes: 13 additions & 0 deletions spec/basicauth2keyauth/01-access_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -100,5 +100,18 @@ describe("Plugin: key-auth (access)", function()
local header_value = assert.request(res).has.header("apikey_from_basicauth")
assert.equal("632d187cde1f395f3fb17e9783748d101b70174988a8e148bc7bc20f63453ea5", header_value)
end)
it("generates new api_key header with sha256 value if basic is in upper case", function()
local res = assert(client:send {
method = "GET",
path = "/request",
headers = {
["Host"] = "host2.com",
["Authorization"] = "BASIC YXBpMTIzNA==" -- "api1234"
}
})
assert.res_status(200, res)
local header_value = assert.request(res).has.header("apikey_from_basicauth")
assert.equal("632d187cde1f395f3fb17e9783748d101b70174988a8e148bc7bc20f63453ea5", header_value)
end)
end)
end)

0 comments on commit 7a8b7a8

Please sign in to comment.