From 607f2b4849cafeb0bd87ec07b64ff86367b7c361 Mon Sep 17 00:00:00 2001 From: soulbird Date: Tue, 5 Jul 2022 11:58:45 +0800 Subject: [PATCH 1/3] fix(limit-count): conf with group and disable can't be configured --- apisix/plugins/limit-count.lua | 2 +- t/plugin/limit-count2.t | 37 ++++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/apisix/plugins/limit-count.lua b/apisix/plugins/limit-count.lua index 746e474b93d0..ea4fc1b09d29 100644 --- a/apisix/plugins/limit-count.lua +++ b/apisix/plugins/limit-count.lua @@ -139,7 +139,7 @@ local _M = { local function group_conf(conf) - return conf + return core.table.deepcopy(conf) end diff --git a/t/plugin/limit-count2.t b/t/plugin/limit-count2.t index 621edad8a912..b7730ac2c25f 100644 --- a/t/plugin/limit-count2.t +++ b/t/plugin/limit-count2.t @@ -764,3 +764,40 @@ limit key: afafafhao2:remote_addr limit key: afafafhao2:remote_addr --- response_body [200,200,503,503] + + + +=== TEST 21: group with disable +--- config + location /t { + content_by_lua_block { + local t = require("lib.test_admin").test + local code, body = t('/apisix/admin/services/1', + ngx.HTTP_PUT, + [[{ + "plugins": { + "limit-count": { + "count": 2, + "time_window": 60, + "rejected_code": 503, + "group": "abcd", + "disable": false + } + }, + "upstream": { + "nodes": { + "127.0.0.1:1980": 1 + }, + "type": "roundrobin" + } + }]] + ) + + if code >= 300 then + ngx.status = code + end + ngx.say(body) + } + } +--- response_body +passed From ccba06700b76cea6f4b26076f6b65a6dcceda4cc Mon Sep 17 00:00:00 2001 From: soulbird Date: Tue, 5 Jul 2022 12:08:43 +0800 Subject: [PATCH 2/3] fix lint --- t/plugin/limit-count2.t | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/t/plugin/limit-count2.t b/t/plugin/limit-count2.t index b7730ac2c25f..e3025be5d564 100644 --- a/t/plugin/limit-count2.t +++ b/t/plugin/limit-count2.t @@ -767,7 +767,7 @@ limit key: afafafhao2:remote_addr -=== TEST 21: group with disable +=== TEST 22: group with disable --- config location /t { content_by_lua_block { From 4919032fc84ee65824e00cba222e84df7824b944 Mon Sep 17 00:00:00 2001 From: soulbird Date: Thu, 7 Jul 2022 09:40:47 +0800 Subject: [PATCH 3/3] deepcopy schema --- apisix/plugins/limit-count.lua | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/apisix/plugins/limit-count.lua b/apisix/plugins/limit-count.lua index ea4fc1b09d29..e191b62232bf 100644 --- a/apisix/plugins/limit-count.lua +++ b/apisix/plugins/limit-count.lua @@ -129,6 +129,7 @@ local schema = { } } +local schema_copy = core.table.deepcopy(schema) local _M = { version = 0.4, @@ -139,7 +140,7 @@ local _M = { local function group_conf(conf) - return core.table.deepcopy(conf) + return conf end @@ -151,7 +152,10 @@ function _M.check_schema(conf) if conf.group then local fields = {} - for k in pairs(schema.properties) do + -- When the goup field is configured, + -- we will use schema_copy to get the whitelist of properties, + -- so that we can avoid getting injected properties. + for k in pairs(schema_copy.properties) do tab_insert(fields, k) end local extra = policy_to_additional_properties[conf.policy]