Skip to content

Commit

Permalink
fix(limit-conn): conn and default_conn_delay should > 0 (#2478)
Browse files Browse the repository at this point in the history
Close #2472.
  • Loading branch information
spacewander authored Oct 20, 2020
1 parent 1f376ac commit ed1f08f
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 4 deletions.
4 changes: 2 additions & 2 deletions apisix/plugins/limit-conn.lua
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ local plugin_name = "limit-conn"
local schema = {
type = "object",
properties = {
conn = {type = "integer", minimum = 0},
conn = {type = "integer", exclusiveMinimum = 0},
burst = {type = "integer", minimum = 0},
default_conn_delay = {type = "number", minimum = 0},
default_conn_delay = {type = "number", exclusiveMinimum = 0},
key = {type = "string",
enum = {"remote_addr", "server_addr", "http_x_real_ip",
"http_x_forwarded_for"},
Expand Down
34 changes: 32 additions & 2 deletions t/plugin/limit-conn.t
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,7 @@ GET /t
GET /t
--- error_code: 400
--- response_body
{"error_msg":"failed to check the configuration of plugin limit-conn err: property \"conn\" validation failed: expected -1 to be greater than 0"}
{"error_msg":"failed to check the configuration of plugin limit-conn err: property \"conn\" validation failed: expected -1 to be sctrictly greater than 0"}
--- no_error_log
[error]
Expand Down Expand Up @@ -511,7 +511,7 @@ GET /t
GET /t
--- error_code: 400
--- response_body
{"error_msg":"failed to check the configuration of plugin limit-conn err: property \"conn\" validation failed: expected -1 to be greater than 0"}
{"error_msg":"failed to check the configuration of plugin limit-conn err: property \"conn\" validation failed: expected -1 to be sctrictly greater than 0"}
--- no_error_log
[error]
Expand Down Expand Up @@ -956,3 +956,33 @@ GET /test_concurrency
200
--- no_error_log
[error]
=== TEST 25: invalid schema
--- config
location /t {
content_by_lua_block {
local plugin = require("apisix.plugins.limit-conn")
local cases = {
{conn = 0, burst = 0, default_conn_delay = 0.1, rejected_code = 503, key = 'remote_addr'},
{conn = 1, burst = 0, default_conn_delay = 0, rejected_code = 503, key = 'remote_addr'},
}
for _, c in ipairs(cases) do
local ok, err = plugin.check_schema(c)
if not ok then
ngx.say(err)
end
end
ngx.say("done")
}
}
--- request
GET /t
--- response_body
property "conn" validation failed: expected 0 to be sctrictly greater than 0
property "default_conn_delay" validation failed: expected 0 to be sctrictly greater than 0
done
--- no_error_log
[error]

0 comments on commit ed1f08f

Please sign in to comment.