Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion apisix/plugins/limit-count/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ local function gen_limit_key(conf, ctx, key)
-- A route which reuses a previous route's ID will inherits its counter.
local parent = conf._meta and conf._meta.parent
if not parent or not parent.resource_key then
error("failed to generate key invalid parent: ", core.json.encode(parent))
error("failed to generate key invalid parent: " .. core.json.encode(parent))
end

local new_key = parent.resource_key .. ':' .. apisix_plugin.conf_version(conf)
Expand Down
44 changes: 44 additions & 0 deletions t/plugin/limit-count5.t
Original file line number Diff line number Diff line change
Expand Up @@ -307,3 +307,47 @@ peek3: 3
commit2: 0
peek4: 0
commit3: rejected

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we need three empty lines in between tests.



=== TEST 9: error() call in gen_limit_key produces correct error message when parent is missing
--- config
location /t {
content_by_lua_block {
local init = require("apisix.plugins.limit-count.init")
local conf = {
policy = "local",
count = 5,
time_window = 60,
key = "remote_addr",
key_type = "var",
rejected_code = 503,
allow_degradation = false,
show_limit_quota_header = true,
_meta = {}
-- _meta.parent is intentionally missing
}
local ctx = {
var = {remote_addr = "127.0.0.1"},
conf_version = 1,
conf_type = "route"
}
local ok, err = pcall(init.rate_limit, conf, ctx, "limit-count", 1)
if not ok then
-- error message should contain the JSON of parent (null)
if err:find("failed to generate key invalid parent") then
ngx.say("correct error message")
else
ngx.say("wrong error: " .. tostring(err))
end
else
ngx.say("should have errored")
end
}
}
--- request
GET /t
--- response_body
correct error message
--- no_error_log
[alert]
Loading