bugfix: global ruls admin api should list resource without id (#1199)

This commit is contained in:
Vinci Xu 2020-03-07 19:51:40 +08:00 committed by GitHub
parent b835bb79f1
commit c2250383f2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 51 additions and 6 deletions

View File

@ -77,7 +77,10 @@ end
function _M.get(id)
local key = "/global_rules/" .. id
local key = "/global_rules"
if id then
key = key .. "/" .. id
end
local res, err = core.etcd.get(key)
if not res then
core.log.error("failed to get global rule[", key, "]: ", err)

View File

@ -111,9 +111,51 @@ passed
--- no_error_log
[error]
=== TEST 3: list global rules
--- config
location /t {
content_by_lua_block {
local t = require("lib.test_admin").test
local code, body = t('/apisix/admin/global_rules',
ngx.HTTP_GET,
nil,
[[{
"node": {
"dir": true,
"nodes": [
{
"key": "/apisix/global_rules/1",
"value": {
"plugins": {
"limit-count": {
"time_window": 60,
"policy": "local",
"count": 2,
"key": "remote_addr",
"rejected_code": 503
}
}
}
}
],
"key": "/apisix/global_rules"
},
"action": "get"
}]]
)
ngx.status = code
ngx.say(body)
}
}
--- request
GET /t
--- response_body
passed
--- no_error_log
[error]
=== TEST 3: PATCH global rules
=== TEST 4: PATCH global rules
--- config
location /t {
content_by_lua_block {
@ -159,7 +201,7 @@ passed
=== TEST 4: delete global rules
=== TEST 5: delete global rules
--- config
location /t {
content_by_lua_block {
@ -183,7 +225,7 @@ GET /t
=== TEST 5: delete global rules(not_found)
=== TEST 6: delete global rules(not_found)
--- config
location /t {
content_by_lua_block {
@ -207,7 +249,7 @@ GET /t
=== TEST 6: set global rules(invalid host option)
=== TEST 7: set global rules(invalid host option)
--- config
location /t {
content_by_lua_block {
@ -241,7 +283,7 @@ GET /t
=== TEST 7: set global rules(missing plugins)
=== TEST 8: set global rules(missing plugins)
--- config
location /t {
content_by_lua_block {