From a6f7c8571e3f006e6c27cf6cb062d6352f8451f6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B8=A9=E9=93=AD=20WenMing?= Date: Fri, 28 Feb 2020 16:26:39 +0800 Subject: [PATCH] bugfix: return 400 when not pass plugin name to admin API. (#1174) --- lua/apisix/admin/plugins.lua | 4 ++++ t/admin/plugins.t | 21 +++++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/lua/apisix/admin/plugins.lua b/lua/apisix/admin/plugins.lua index 1ae7dfe5..7d6262c5 100644 --- a/lua/apisix/admin/plugins.lua +++ b/lua/apisix/admin/plugins.lua @@ -87,6 +87,10 @@ end function _M.get(name) + if not name then + return 400, {error_msg = "not found plugin name"} + end + local plugin_name = "apisix.plugins." .. name local ok, plugin = pcall(require, plugin_name) diff --git a/t/admin/plugins.t b/t/admin/plugins.t index 031eaff9..106b0363 100644 --- a/t/admin/plugins.t +++ b/t/admin/plugins.t @@ -33,3 +33,24 @@ GET /apisix/admin/plugins/list qr/\["limit-req","limit-count","limit-conn","key-auth","basic-auth","prometheus","node-status","jwt-auth","zipkin","ip-restriction","grpc-transcode","serverless-pre-function","serverless-post-function","openid-connect","proxy-rewrite","redirect","response-rewrite","fault-injection","udp-logger","wolf-rbac"\]/ --- no_error_log [error] + + + +=== TEST 2: wrong path +--- request +GET /apisix/admin/plugins +--- error_code: 400 +--- response_body +{"error_msg":"not found plugin name"} +--- no_error_log +[error] + + + +=== TEST 3: get plugin schema +--- request +GET /apisix/admin/plugins/limit-req +--- response_body +{"properties":{"rate":{"minimum":0,"type":"number"},"burst":{"minimum":0,"type":"number"},"key":{"enum":["remote_addr","server_addr","http_x_real_ip","http_x_forwarded_for"],"type":"string"},"rejected_code":{"minimum":200,"type":"integer"}},"required":["rate","burst","key","rejected_code"],"type":"object"} +--- no_error_log +[error]