Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(admin): reject unknown stream plugin
Browse files Browse the repository at this point in the history
The behavior should be the same as http plugin.
Signed-off-by: spacewander <spacewanderlzx@gmail.com>
spacewander committed Apr 8, 2022
1 parent 78c1aff commit 8de2b56
Showing 5 changed files with 37 additions and 11 deletions.
6 changes: 0 additions & 6 deletions apisix/admin/plugins.lua
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion apisix/admin/stream_routes.lua
Original file line number Diff line number Diff line change
@@ -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
4 changes: 2 additions & 2 deletions apisix/plugin.lua
Original file line number Diff line number Diff line change
@@ -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
4 changes: 2 additions & 2 deletions apisix/stream/router/ip_port.lua
Original file line number Diff line number Diff line change
@@ -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
32 changes: 32 additions & 0 deletions t/admin/stream-routes.t
Original file line number Diff line number Diff line change
@@ -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]

0 comments on commit 8de2b56

Please sign in to comment.