diff --git a/apisix/admin/plugins.lua b/apisix/admin/plugins.lua index d2cc1fabc76e8..3807231634018 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 de1e14daefe43..eef11abf42329 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, false) if not ok then return nil, {error_msg = err} end diff --git a/apisix/plugin.lua b/apisix/plugin.lua index f6ea4274350ed..1516502f32cce 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_dp) if item.plugins then - return stream_check_schema(item.plugins, nil, true) + return stream_check_schema(item.plugins, nil, in_dp) end return true diff --git a/apisix/stream/router/ip_port.lua b/apisix/stream/router/ip_port.lua index 74563f9e4b839..b16b8bec95a7d 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_dp) if item.plugins then - local err, message = stream_plugin_checker(item) + local err, message = stream_plugin_checker(item, in_dp) if not err then return err, message end diff --git a/t/admin/stream-routes.t b/t/admin/stream-routes.t index 5e90c423592a6..85c7d9a5b1147 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]