Skip to content

Commit

Permalink
(fix) correlation-id ensure plugin header not nil
Browse files Browse the repository at this point in the history
Fix clashing plugins issue reported in Kong#3924
  • Loading branch information
rsbrisci authored and jeremyjpj0916 committed Nov 9, 2018
1 parent cf54418 commit 8b1c41d
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 3 deletions.
2 changes: 1 addition & 1 deletion kong/plugins/correlation-id/handler.lua
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ end
function CorrelationIdHandler:header_filter(conf)
CorrelationIdHandler.super.header_filter(self)

if conf.echo_downstream then
if conf.echo_downstream and kong.ctx.plugin.correlationid_header_value then
kong.response.set_header(conf.header_name, kong.ctx.plugin.correlationid_header_value)
end
end
Expand Down
39 changes: 37 additions & 2 deletions spec/03-plugins/12-correlation-id/01-access_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ for _, strategy in helpers.each_strategy() do
local route4 = bp.routes:insert {
hosts = { "correlation-tracker.com" },
}

local route5 = bp.routes:insert {
hosts = { "correlation5.com" },
}

bp.plugins:insert {
name = "correlation-id",
Expand Down Expand Up @@ -59,6 +63,24 @@ for _, strategy in helpers.each_strategy() do
generator = "tracker",
},
}

bp.plugins:insert {
name = "correlation-id",
route = { id = route5.id },
config = {
generator = "uuid",
echo_downstream = true,
},
}

bp.plugins:insert {
name = "request-termination",
route = { id = route5.id },
config = {
status_code = 200,
message = "Success",
},
}

assert(helpers.start_kong({
database = strategy,
Expand Down Expand Up @@ -114,7 +136,7 @@ for _, strategy in helpers.each_strategy() do
end)
end)

describe("uuid genetator", function()
describe("uuid generator", function()
it("generates a unique UUID for every request", function()
local res = assert(proxy_client:send {
method = "GET",
Expand Down Expand Up @@ -228,5 +250,18 @@ for _, strategy in helpers.each_strategy() do
local id = json.headers["kong-request-id"]
assert.equal("foobar", id)
end)

it("successfully executes with echo_downstream and request-termination enabled", function()
local res = assert(proxy_client:send {
method = "GET",
path = "/request",
headers = {
["Host"] = "correlation5.com"
}
})
local body = assert.res_status(200, res)
local json = cjson.decode(body)
assert.same({ message = "Success" }, json)
end)
end)
end
end

0 comments on commit 8b1c41d

Please sign in to comment.