2019-06-13 19:11:15 +08:00
|
|
|
use t::APISix 'no_plan';
|
|
|
|
|
2019-06-14 16:11:14 +08:00
|
|
|
repeat_each(1);
|
2019-06-13 19:11:15 +08:00
|
|
|
no_long_string();
|
2019-06-14 16:11:14 +08:00
|
|
|
no_shuffle();
|
2019-06-13 19:11:15 +08:00
|
|
|
no_root_location();
|
|
|
|
run_tests;
|
|
|
|
|
|
|
|
__DATA__
|
|
|
|
|
|
|
|
=== TEST 1: sanity
|
|
|
|
--- config
|
|
|
|
location /t {
|
|
|
|
content_by_lua_block {
|
|
|
|
local plugin = require("apisix.plugins.limit-count")
|
|
|
|
local ok, err = plugin.check_schema({count = 2, time_window = 60, rejected_code = 503, key = 'remote_addr'})
|
|
|
|
if not ok then
|
|
|
|
ngx.say(err)
|
|
|
|
end
|
|
|
|
|
|
|
|
ngx.say("done")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
--- request
|
|
|
|
GET /t
|
|
|
|
--- response_body
|
|
|
|
done
|
|
|
|
--- no_error_log
|
|
|
|
[error]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
=== TEST 2: wrong value of key
|
|
|
|
--- config
|
|
|
|
location /t {
|
|
|
|
content_by_lua_block {
|
|
|
|
local plugin = require("apisix.plugins.limit-count")
|
|
|
|
local ok, err = plugin.check_schema({count = 2, time_window = 60, rejected_code = 503, key = 'host'})
|
|
|
|
if not ok then
|
|
|
|
ngx.say(err)
|
|
|
|
end
|
|
|
|
|
|
|
|
ngx.say("done")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
--- request
|
|
|
|
GET /t
|
|
|
|
--- response_body
|
|
|
|
invalid "enum" in docuement at pointer "#/key"
|
|
|
|
done
|
|
|
|
--- no_error_log
|
|
|
|
[error]
|
2019-06-14 16:11:14 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
=== TEST 3: set route(id: 1)
|
|
|
|
--- config
|
|
|
|
location /t {
|
|
|
|
content_by_lua_block {
|
|
|
|
local t = require("lib.test_admin").test
|
|
|
|
local code, body = t('/apisix/admin/routes/1',
|
|
|
|
ngx.HTTP_PUT,
|
|
|
|
[[{
|
|
|
|
"methods": ["GET"],
|
|
|
|
"plugins": {
|
|
|
|
"limit-count": {
|
|
|
|
"count": 2,
|
|
|
|
"time_window": 60,
|
|
|
|
"rejected_code": 503,
|
|
|
|
"key": "remote_addr"
|
|
|
|
}
|
|
|
|
},
|
|
|
|
"id":1,
|
|
|
|
"upstream": {
|
|
|
|
"nodes": {
|
|
|
|
"127.0.0.1:1980": 1
|
|
|
|
},
|
|
|
|
"type": "roundrobin"
|
|
|
|
},
|
|
|
|
"uri": "/hello"
|
|
|
|
}]]
|
|
|
|
)
|
|
|
|
|
|
|
|
if code >= 300 then
|
|
|
|
ngx.status = code
|
|
|
|
end
|
|
|
|
ngx.say(body)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
--- request
|
|
|
|
GET /t
|
|
|
|
--- response_body
|
|
|
|
passed
|
|
|
|
--- no_error_log
|
|
|
|
[error]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
=== TEST 4: up the limit
|
|
|
|
--- pipelined_requests eval
|
|
|
|
["GET /hello", "GET /hello", "GET /hello", "GET /hello"]
|
|
|
|
--- error_code eval
|
|
|
|
[200, 200, 503, 503]
|
|
|
|
--- no_error_log
|
|
|
|
[error]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
=== TEST 5: up the limit
|
|
|
|
--- pipelined_requests eval
|
|
|
|
["GET /hello1", "GET /hello", "GET /hello2", "GET /hello", "GET /hello"]
|
|
|
|
--- error_code eval
|
|
|
|
[404, 200, 404, 200, 503]
|
|
|
|
--- no_error_log
|
|
|
|
[error]
|