From 74cb2b855860387375f0255b5dc1ea408a866680 Mon Sep 17 00:00:00 2001 From: soulbird Date: Thu, 7 Jul 2022 11:37:31 +0800 Subject: [PATCH] fix(limit-count): conf with group and disable can't be configured (#7384) --- apisix/plugins/limit-count.lua | 6 +++++- t/plugin/limit-count2.t | 37 ++++++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+), 1 deletion(-) diff --git a/apisix/plugins/limit-count.lua b/apisix/plugins/limit-count.lua index 746e474b93d0..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, @@ -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] diff --git a/t/plugin/limit-count2.t b/t/plugin/limit-count2.t index 621edad8a912..e3025be5d564 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 22: 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