Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(key-auth) allow underscore in key header name #2370

Merged
merged 1 commit into from
Apr 11, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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