Skip to content

Commit

Permalink
Merge pull request #2370 from Mashape/feat/allow-underscore-in-headers
Browse files Browse the repository at this point in the history
feat(key-auth) allow underscore in key header name
  • Loading branch information
thibaultcha authored Apr 11, 2017
2 parents 59c93e4 + 332d99c commit 87cbd5d
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 5 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
weight Targets, instead of all nonzero weight targets. This is to provide
a better picture of the Targets currently in use by the Kong load balancer.
[#2310](https://github.com/Mashape/kong/pull/2310)
- Plugins:
- key-auth: Allow setting API key header names with an underscore.
[#2370](https://github.com/Mashape/kong/pull/2370)

### Added

Expand Down
4 changes: 2 additions & 2 deletions kong/tools/utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -598,12 +598,12 @@ _M.validate_header_name = function(name)
return nil, "no header name provided"
end

if re_match(name, "^[a-zA-Z0-9-]+$", "jo") then
if re_match(name, "^[a-zA-Z0-9-_]+$", "jo") then
return name
end

return nil, "bad header name '" .. name ..
"', allowed characters are A-Z, a-z, 0-9 and '-'"
"', allowed characters are A-Z, a-z, 0-9, '_', and '-'"
end

return _M
2 changes: 1 addition & 1 deletion spec/01-unit/04-utils_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,7 @@ describe("Utils", function()
end)

it("validate_header_name() validates header names", function()
local header_chars = [[-0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz]]
local header_chars = [[_-0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz]]

for i = 1, 255 do
local c = string.char(i)
Expand Down
4 changes: 2 additions & 2 deletions spec/03-plugins/10-key-auth/01-api_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -282,8 +282,8 @@ describe("Plugin: key-auth (API)", function()
assert.response(res).has.status(400)
local body = assert.response(res).has.jsonbody()
assert.equal("'hello\\world' is illegal: bad header name " ..
"'hello\\world', allowed characters are A-Z, a-z, 0-9 " ..
"and '-'", body["config.key_names"])
"'hello\\world', allowed characters are A-Z, a-z, 0-9," ..
" '_', and '-'", body["config.key_names"])
end)
it("succeeds with valid key_names", function()
local key_name = "hello-world"
Expand Down

0 comments on commit 87cbd5d

Please sign in to comment.