Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into next
Browse files Browse the repository at this point in the history
  • Loading branch information
thibaultcha committed Apr 15, 2017
2 parents 01c4c2e + f28f96f commit efb6612
Show file tree
Hide file tree
Showing 7 changed files with 117 additions and 6 deletions.
7 changes: 7 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 All @@ -30,6 +33,10 @@
upstream services. Thanks [Paul Austin](https://github.com/pauldaustin)
for the contribution.
[#2051](https://github.com/Mashape/kong/pull/2051)
- Logging plugins: The produced logs now include a `consumer` field,
which contains the properties of the authenticated Consumer
(`id`, `custom_id`, and `username`), if any.
[#2367](https://github.com/Mashape/kong/pull/2367)

### Fixed

Expand Down
1 change: 1 addition & 0 deletions kong/plugins/log-serializers/basic.lua
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ function _M.serialize(ngx)
},
authenticated_entity = authenticated_entity,
api = ngx.ctx.api,
consumer = ngx.ctx.authenticated_consumer,
client_ip = ngx.var.remote_addr,
started_at = ngx.req.start_time() * 1000
}
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
100 changes: 100 additions & 0 deletions spec/01-unit/13-log_serializer_spec.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
local basic = require "kong.plugins.log-serializers.basic"

describe("Log Serializer", function()
local ngx

before_each(function()
ngx = {
ctx = {},
var = {
request_uri = "/request_uri",
scheme = "http",
host = "test.com",
server_port = 80,
request_length = 200,
bytes_sent = 99,
request_time = 2,
remote_addr = "1.1.1.1"
},
req = {
get_uri_args = function() return {"arg1", "arg2"} end,
get_method = function() return "POST" end,
get_headers = function() return {"header1", "header2"} end,
start_time = function() return 3 end
},
resp = {
get_headers = function() return {"respheader1", "respheader2"} end
}
}
end)

describe("Basic", function()
it("serializes without API, Consumer or Authenticated entity", function()
local res = basic.serialize(ngx)
assert.is_table(res)

-- Simple properties
assert.equals("1.1.1.1", res.client_ip)
assert.equals(3000, res.started_at)

-- Latencies
assert.is_table(res.latencies)
assert.equal(0, res.latencies.kong)
assert.equal(-1, res.latencies.proxy)
assert.equal(2000, res.latencies.request)

-- Request
assert.is_table(res.request)
assert.same({"header1", "header2"}, res.request.headers)
assert.equal("POST", res.request.method)
assert.same({"arg1", "arg2"}, res.request.querystring)
assert.equal("http://test.com:80/request_uri", res.request.request_uri)
assert.equal(200, res.request.size)
assert.equal("/request_uri", res.request.uri)

-- Response
assert.is_table(res.response)
assert.same({"respheader1", "respheader2"}, res.response.headers)
assert.equal(99, res.response.size)

assert.is_nil(res.api)
assert.is_nil(res.consumer)
assert.is_nil(res.authenticated_entity)
end)

it("serializes the API object", function()
ngx.ctx.api = {id = "someapi"}

local res = basic.serialize(ngx)
assert.is_table(res)

assert.equal("someapi", res.api.id)
assert.is_nil(res.consumer)
assert.is_nil(res.authenticated_entity)
end)

it("serializes the Consumer object", function()
ngx.ctx.authenticated_consumer = {id = "someconsumer"}

local res = basic.serialize(ngx)
assert.is_table(res)

assert.equal("someconsumer", res.consumer.id)
assert.is_nil(res.api)
assert.is_nil(res.authenticated_entity)
end)

it("serializes the Authenticated Entity object", function()
ngx.ctx.authenticated_credential = {id = "somecred",
consumer_id = "user1"}

local res = basic.serialize(ngx)
assert.is_table(res)

assert.same({id = "somecred", consumer_id = "user1"},
res.authenticated_entity)
assert.is_nil(res.consumer)
assert.is_nil(res.api)
end)
end)
end)
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
5 changes: 4 additions & 1 deletion spec/03-plugins/23-aws-lambda/01-access_spec.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
local helpers = require "spec.helpers"

describe("Plugin: AWS Lambda (access)", function()
pending("Plugin: AWS Lambda (access)", function()
-- pending due to AWS account issues and
-- waiting for a mock solution as suggested by
-- https://github.com/Mashape/kong/pull/2287
local client, api_client

setup(function()
Expand Down

0 comments on commit efb6612

Please sign in to comment.