From 8de2b56433e5cb1ea0cfc0c32f4b863118167462 Mon Sep 17 00:00:00 2001 From: spacewander Date: Fri, 8 Apr 2022 23:07:23 +0800 Subject: [PATCH] fix(admin): reject unknown stream plugin The behavior should be the same as http plugin. Signed-off-by: spacewander --- apisix/admin/plugins.lua | 6 ------ apisix/admin/stream_routes.lua | 2 +- apisix/plugin.lua | 4 ++-- apisix/stream/router/ip_port.lua | 4 ++-- t/admin/stream-routes.t | 32 ++++++++++++++++++++++++++++++++ 5 files changed, 37 insertions(+), 11 deletions(-) diff --git a/apisix/admin/plugins.lua b/apisix/admin/plugins.lua index d2cc1fabc76e..380723163401 100644 --- a/apisix/admin/plugins.lua +++ b/apisix/admin/plugins.lua @@ -17,7 +17,6 @@ local require = require local core = require("apisix.core") local check_schema = require("apisix.plugin").check_schema -local stream_check_schema = require("apisix.plugin").stream_check_schema local ipairs = ipairs local pcall = pcall local table_sort = table.sort @@ -33,11 +32,6 @@ function _M.check_schema(plugins_conf, schema_type) end -function _M.stream_check_schema(plugins_conf, schema_type) - return stream_check_schema(plugins_conf, schema_type, false) -end - - function _M.get(name) local arg = get_uri_args() if arg and arg["all"] == "true" then diff --git a/apisix/admin/stream_routes.lua b/apisix/admin/stream_routes.lua index de1e14daefe4..6770830acf1f 100644 --- a/apisix/admin/stream_routes.lua +++ b/apisix/admin/stream_routes.lua @@ -69,7 +69,7 @@ local function check_conf(id, conf, need_id) end end - local ok, err = stream_route_checker(conf) + local ok, err = stream_route_checker(conf, true) if not ok then return nil, {error_msg = err} end diff --git a/apisix/plugin.lua b/apisix/plugin.lua index f6ea4274350e..da3b848f33a2 100644 --- a/apisix/plugin.lua +++ b/apisix/plugin.lua @@ -709,9 +709,9 @@ function _M.plugin_checker(item, schema_type) end -function _M.stream_plugin_checker(item) +function _M.stream_plugin_checker(item, in_cp) if item.plugins then - return stream_check_schema(item.plugins, nil, true) + return stream_check_schema(item.plugins, nil, not in_cp) end return true diff --git a/apisix/stream/router/ip_port.lua b/apisix/stream/router/ip_port.lua index 74563f9e4b83..a31e25904fd0 100644 --- a/apisix/stream/router/ip_port.lua +++ b/apisix/stream/router/ip_port.lua @@ -187,9 +187,9 @@ function _M.routes() return user_routes.values, user_routes.conf_version end -local function stream_route_checker(item) +local function stream_route_checker(item, in_cp) if item.plugins then - local err, message = stream_plugin_checker(item) + local err, message = stream_plugin_checker(item, in_cp) if not err then return err, message end diff --git a/t/admin/stream-routes.t b/t/admin/stream-routes.t index 5e90c423592a..85c7d9a5b114 100644 --- a/t/admin/stream-routes.t +++ b/t/admin/stream-routes.t @@ -562,3 +562,35 @@ GET /t GET /t --- no_error_log [error] + + + +=== TEST 15: set route with unknown plugin +--- config + location /t { + content_by_lua_block { + local t = require("lib.test_admin").test + local code, body = t('/apisix/admin/stream_routes/1', + ngx.HTTP_PUT, + [[{ + "remote_addr": "127.0.0.1", + "plugins": { + "mqttt-proxy": { + } + } + }]] + ) + + if code >= 300 then + ngx.status = code + end + ngx.print(body) + } + } +--- request +GET /t +--- error_code: 400 +--- response_body +{"error_msg":"unknown plugin [mqttt-proxy]"} +--- no_error_log +[error]