Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into johnfitzpatrick-pat…
Browse files Browse the repository at this point in the history
…ch-1
  • Loading branch information
hanshuebner committed Jan 5, 2024
2 parents d1c1878 + 428ff45 commit b2a904a
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 19 deletions.

This file was deleted.

2 changes: 1 addition & 1 deletion kong/plugins/request-transformer/access.lua
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ local function transform_headers(conf, template_env)
old_name = old_name:lower()
local value = headers[old_name]
if value then
headers[new_name] = value
headers[new_name:lower()] = value
headers[old_name] = nil
headers_to_remove[old_name] = true
end
Expand Down
26 changes: 16 additions & 10 deletions spec/03-plugins/23-rate-limiting/02-policies_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ local timestamp = require "kong.tools.timestamp"
local SYNC_RATE_REALTIME = -1

--[[
basically a copy of `get_local_key()`
basically a copy of `get_local_key()`
in `kong/plugins/rate-limiting/policies/init.lua`
--]]
local EMPTY_UUID = "00000000-0000-0000-0000-000000000000"
Expand Down Expand Up @@ -41,7 +41,7 @@ describe("Plugin: rate-limiting (policies)", function()
lazy_setup(function()
package.loaded["kong.plugins.rate-limiting.policies"] = nil
policies = require "kong.plugins.rate-limiting.policies"

if not _G.kong then
_G.kong.db = {}
end
Expand Down Expand Up @@ -80,18 +80,24 @@ describe("Plugin: rate-limiting (policies)", function()
end)

it("expires after due time", function ()
local timestamp = 569000048000
local key = get_local_key(conf, identifier, 'second', timestamp)
local current_timestamp = 1553263548
local periods = timestamp.get_timestamps(current_timestamp)

assert(policies['local'].increment(conf, {second=100}, identifier, timestamp+20, 1))
local v = assert(shm:ttl(key))
local limits = {
second = 100,
}
local cache_key = get_local_key(conf, identifier, 'second', periods.second)

assert(policies['local'].increment(conf, limits, identifier, current_timestamp, 1))
local v = assert(shm:ttl(cache_key))
assert(v > 0, "wrong value")
ngx.sleep(1.020)

v = shm:ttl(key)
assert(v < 0, "expected ttl to be negative")
local val = shm:get(key)
assert.is_nil(val)
shm:flush_expired()
local err
v, err = shm:ttl(cache_key)
assert(v == nil, "still there")
assert.matches("not found", err)
end)
end)

Expand Down
10 changes: 5 additions & 5 deletions spec/03-plugins/36-request-transformer/02-access_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ describe("Plugin: request-transformer(access) [#" .. strategy .. "]", function()
name = "request-transformer",
config = {
rename = {
headers = {"x-to-rename:X-Is-Renamed"},
headers = {"x-to-rename:x-is-renamed"},
querystring = {"originalparam:renamedparam"},
body = {"originalparam:renamedparam"}
}
Expand Down Expand Up @@ -712,7 +712,7 @@ describe("Plugin: request-transformer(access) [#" .. strategy .. "]", function()
assert.response(r).has.status(200)
assert.response(r).has.jsonbody()
assert.request(r).has.no.header("x-to-rename")
assert.request(r).has.header("X-Is-Renamed")
assert.request(r).has.header("x-is-renamed")
assert.request(r).has.header("x-another-header")
end)
it("does not add as new header if header does not exist", function()
Expand All @@ -738,13 +738,13 @@ describe("Plugin: request-transformer(access) [#" .. strategy .. "]", function()
headers = {
host = "test9.test",
["x-to-rename"] = "new-result",
["X-Is-Renamed"] = "old-result",
["x-is-renamed"] = "old-result",
}
})
assert.response(r).has.status(200)
assert.response(r).has.jsonbody()
assert.request(r).has.no.header("x-to-rename")
local h_is_renamed = assert.request(r).has.header("X-Is-Renamed")
local h_is_renamed = assert.request(r).has.header("x-is-renamed")
assert.equals("new-result", h_is_renamed)
end)
for _, seq in ipairs({ 1, 2, 3, 4, 5, 6}) do
Expand All @@ -761,7 +761,7 @@ describe("Plugin: request-transformer(access) [#" .. strategy .. "]", function()
assert.response(r).has.status(200)
assert.response(r).has.jsonbody()
assert.request(r).has.no.header("x-to-rename")
local h_is_renamed = assert.request(r).has.header("X-Is-Renamed")
local h_is_renamed = assert.request(r).has.header("x-is-renamed")
assert.equals("new-result", h_is_renamed)
end)
end
Expand Down

0 comments on commit b2a904a

Please sign in to comment.