From 332d99c5af75a997d32960197d16c71c68075594 Mon Sep 17 00:00:00 2001 From: Thibault Charbonnier Date: Mon, 10 Apr 2017 16:44:28 -0700 Subject: [PATCH] feat(key-auth) allow underscore in key header name There is no incentive for Kong to not allow a header name containing an underscore. This reverts the change in behavior introduced in #2142 and 73437ef01d1514492fd645f1e9e04a74776878eb. The `underscores_in_headers` directive seems to already be enabled. --- CHANGELOG.md | 3 +++ kong/tools/utils.lua | 4 ++-- spec/01-unit/04-utils_spec.lua | 2 +- spec/03-plugins/10-key-auth/01-api_spec.lua | 4 ++-- 4 files changed, 8 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c880c84c0dfb..09c266539dca 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/kong/tools/utils.lua b/kong/tools/utils.lua index f889989cdce6..20d7c027050d 100644 --- a/kong/tools/utils.lua +++ b/kong/tools/utils.lua @@ -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 diff --git a/spec/01-unit/04-utils_spec.lua b/spec/01-unit/04-utils_spec.lua index 279caba4883f..0333c4ea23da 100644 --- a/spec/01-unit/04-utils_spec.lua +++ b/spec/01-unit/04-utils_spec.lua @@ -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) diff --git a/spec/03-plugins/10-key-auth/01-api_spec.lua b/spec/03-plugins/10-key-auth/01-api_spec.lua index 1d096c4023fb..4cc70405b356 100644 --- a/spec/03-plugins/10-key-auth/01-api_spec.lua +++ b/spec/03-plugins/10-key-auth/01-api_spec.lua @@ -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"