From 1f47a5b918c97867d71fd9371451de55c2c648b1 Mon Sep 17 00:00:00 2001 From: Darren Jennings Date: Fri, 29 Mar 2019 16:53:32 -0700 Subject: [PATCH 1/2] test(lint) fix linting issues --- spec/02-kong_storage_adapter_spec.lua | 30 +++++++++++++-------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/spec/02-kong_storage_adapter_spec.lua b/spec/02-kong_storage_adapter_spec.lua index 58000cdab20e..f0dcf99e2791 100644 --- a/spec/02-kong_storage_adapter_spec.lua +++ b/spec/02-kong_storage_adapter_spec.lua @@ -2,7 +2,7 @@ local helpers = require "spec.helpers" local utils = require "kong.tools.utils" -function get_sid_from_cookie(cookie) +local function get_sid_from_cookie(cookie) local cookie_parts = utils.split(cookie, "; ") return utils.split(utils.split(cookie_parts[1], "|")[1], "=")[2] end @@ -31,7 +31,7 @@ for _, strategy in helpers.each_strategy() do paths = {"/test2"}, hosts = {"httpbin.org"} } - + assert(bp.plugins:insert { name = "session", route = { @@ -42,7 +42,7 @@ for _, strategy in helpers.each_strategy() do secret = "ultra top secret session", } }) - + assert(bp.plugins:insert { name = "session", route = { @@ -113,10 +113,10 @@ for _, strategy in helpers.each_strategy() do after_each(function() if client then client:close() end - end) + end) describe("kong adapter - ", function() - it("kong adapter stores consumer", function() + it("kong adapter stores consumer", function() local res, cookie local request = { method = "GET", @@ -127,18 +127,18 @@ for _, strategy in helpers.each_strategy() do -- make sure the anonymous consumer can't get in (request termination) res = assert(client:send(request)) assert.response(res).has.status(403) - + -- make a request with a valid key, grab the cookie for later request.headers.apikey = "kong" res = assert(client:send(request)) assert.response(res).has.status(200) cookie = assert.response(res).has.header("Set-Cookie") - + ngx.sleep(2) -- use the cookie without the key to ensure cookie still lets them in request.headers.apikey = nil - request.headers.cookie = cookie + request.headers.cookie = cookie res = assert(client:send(request)) assert.response(res).has.status(200) @@ -151,7 +151,7 @@ for _, strategy in helpers.each_strategy() do assert.equal(sid, db.sessions:select_by_session_id(sid).session_id) end) - it("renews cookie", function() + it("renews cookie", function() local res, cookie local request = { method = "GET", @@ -160,9 +160,9 @@ for _, strategy in helpers.each_strategy() do } local function send_requests(request, number, step) - local cookie = request.headers.cookie + cookie = request.headers.cookie - for i = 1, number do + for _ = 1, number do request.headers.cookie = cookie res = assert(client:send(request)) assert.response(res).has.status(200) @@ -174,7 +174,7 @@ for _, strategy in helpers.each_strategy() do -- make sure the anonymous consumer can't get in (request termination) res = assert(client:send(request)) assert.response(res).has.status(403) - + -- make a request with a valid key, grab the cookie for later request.headers.apikey = "kong" res = assert(client:send(request)) @@ -188,13 +188,13 @@ for _, strategy in helpers.each_strategy() do request.headers.cookie = cookie res = assert(client:send(request)) assert.response(res).has.status(200) - + -- 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) end) - it("destroys session on logout", function() + it("destroys session on logout", function() local res, cookie local request = { method = "GET", @@ -205,7 +205,7 @@ for _, strategy in helpers.each_strategy() do -- make sure the anonymous consumer can't get in (request termination) res = assert(client:send(request)) assert.response(res).has.status(403) - + -- make a request with a valid key, grab the cookie for later request.headers.apikey = "kong" res = assert(client:send(request)) From 026eecf37b60473bca0f2d5a698a7d76be9eb292 Mon Sep 17 00:00:00 2001 From: Darren Jennings Date: Fri, 29 Mar 2019 16:54:36 -0700 Subject: [PATCH 2/2] fix(session) adjust params of :update for new dao * was throwing error during update --- kong/plugins/session/storage/kong.lua | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/kong/plugins/session/storage/kong.lua b/kong/plugins/session/storage/kong.lua index 41c9267f9455..ca6a70210b4a 100644 --- a/kong/plugins/session/storage/kong.lua +++ b/kong/plugins/session/storage/kong.lua @@ -75,7 +75,7 @@ function kong_storage:open(cookie, lifetime) expires = db_s.expires end end - + return id, expires, data, hmac end @@ -89,7 +89,7 @@ function kong_storage:insert_session(sid, data, expires) data = data, expires = expires, }, { ttl = self.lifetime }) - + if err then ngx.log(ngx.ERR, "Error inserting session: ", err) end @@ -97,7 +97,7 @@ end function kong_storage:update_session(id, params, ttl) - local _, err = self.db.sessions:update(params, { id = id }, { ttl = ttl }) + local _, err = self.db.sessions:update({ id = id }, params, { ttl = ttl }) if err then ngx.log(ngx.ERR, "Error updating session: ", err) end @@ -109,7 +109,6 @@ function kong_storage:save(id, expires, data, hmac) local value = concat({key, expires, self.encode(hmac)}, self.delimiter) if life > 0 then - if ngx.get_phase() == 'header_filter' then ngx.timer.at(0, function() self:insert_session(key, self.encode(data), expires) @@ -131,7 +130,7 @@ function kong_storage:destroy(id) if not db_s then return end - + local _, err = self.db.sessions:delete({ id = db_s.id })