Skip to content

Commit

Permalink
fix(session) add back regenerate strategy for kong storage (#17)
Browse files Browse the repository at this point in the history
* test(*) adjust test to fail correctly

* fix(session) add back regenerate strategy
  • Loading branch information
darrenjennings authored May 7, 2020
1 parent f037d32 commit 013a8e3
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
16 changes: 9 additions & 7 deletions kong/plugins/session/session.lua
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,10 @@ local _M = {}


local function get_opts(conf)
local storage = conf.storage
if storage == "kong" then
storage = kong_storage
end

return {
local opts = {
name = conf.cookie_name,
secret = conf.secret,
storage = storage,
storage = conf.storage,
cookie = {
lifetime = conf.cookie_lifetime,
idletime = conf.cookie_idletime,
Expand All @@ -31,6 +26,13 @@ local function get_opts(conf)
discard = conf.cookie_discard,
}
}

if conf.storage == "kong" then
opts.strategy = 'regenerate'
opts.storage = kong_storage
end

return opts
end


Expand Down
7 changes: 6 additions & 1 deletion spec/02-kong_storage_adapter_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -197,15 +197,20 @@ for _, strategy in helpers.each_strategy() do
}

local function send_requests(request, number, step)
local did_renew = false
cookie = request.headers.cookie

for _ = 1, number do
request.headers.cookie = cookie
res = assert(client:send(request))
assert.response(res).has.status(200)
did_renew = did_renew or res.headers['Set-Cookie'] ~= nil

cookie = res.headers['Set-Cookie'] or cookie
ngx.sleep(step)
end

return did_renew
end

-- make sure the anonymous consumer can't get in (request termination)
Expand All @@ -228,7 +233,7 @@ for _, strategy in helpers.each_strategy() do

-- renewal period, make sure requests still come through and
-- if set-cookie header comes through, attach it to subsequent requests
send_requests(request, 5, 0.5)
assert.is_true(send_requests(request, 7, 0.5))
end)

it("destroys session on logout", function()
Expand Down

0 comments on commit 013a8e3

Please sign in to comment.