Skip to content

Commit

Permalink
fix(ext-plugin): missing schema check (#4359)
Browse files Browse the repository at this point in the history
Signed-off-by: spacewander <spacewanderlzx@gmail.com>
  • Loading branch information
spacewander authored Jun 3, 2021
1 parent 0637d79 commit 62ceab5
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 1 deletion.
6 changes: 6 additions & 0 deletions apisix/plugins/ext-plugin-post-req.lua
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
-- See the License for the specific language governing permissions and
-- limitations under the License.
--
local core = require("apisix.core")
local ext = require("apisix.plugins.ext-plugin.init")


Expand All @@ -25,6 +26,11 @@ local _M = {
}


function _M.check_schema(conf)
return core.schema.check(_M.schema, conf)
end


function _M.access(conf, ctx)
return ext.communicate(conf, ctx)
end
Expand Down
6 changes: 6 additions & 0 deletions apisix/plugins/ext-plugin-pre-req.lua
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
-- See the License for the specific language governing permissions and
-- limitations under the License.
--
local core = require("apisix.core")
local ext = require("apisix.plugins.ext-plugin.init")


Expand All @@ -25,6 +26,11 @@ local _M = {
}


function _M.check_schema(conf)
return core.schema.check(_M.schema, conf)
end


function _M.rewrite(conf, ctx)
return ext.communicate(conf, ctx)
end
Expand Down
3 changes: 2 additions & 1 deletion apisix/plugins/ext-plugin/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@ local schema = {
value = {
type = "string",
},
}
},
required = {"name", "value"}
},
minItems = 1,
},
Expand Down
63 changes: 63 additions & 0 deletions t/plugin/ext-plugin/sanity.t
Original file line number Diff line number Diff line change
Expand Up @@ -382,3 +382,66 @@ env MY_ENV_VAR=foo;
}
--- error_log
MY_ENV_VAR foo
=== TEST 14: bad conf
--- config
location /t {
content_by_lua_block {
local json = require("toolkit.json")
local t = require("lib.test_admin")
local code, message, res = t.test('/apisix/admin/routes/1',
ngx.HTTP_PUT,
[[{
"uri": "/hello",
"plugins": {
"ext-plugin-pre-req": {
"conf": [
{"value":"bar"}
]
}
},
"upstream": {
"nodes": {
"127.0.0.1:1980": 1
},
"type": "roundrobin"
}
}]]
)
if code >= 300 then
ngx.say(message)
end
local code, message, res = t.test('/apisix/admin/routes/1',
ngx.HTTP_PUT,
[[{
"uri": "/hello",
"plugins": {
"ext-plugin-post-req": {
"conf": [
{"name":"bar"}
]
}
},
"upstream": {
"nodes": {
"127.0.0.1:1980": 1
},
"type": "roundrobin"
}
}]]
)
if code >= 300 then
ngx.print(message)
end
}
}
--- response_body
{"error_msg":"failed to check the configuration of plugin ext-plugin-pre-req err: property \"conf\" validation failed: failed to validate item 1: property \"name\" is required"}
{"error_msg":"failed to check the configuration of plugin ext-plugin-post-req err: property \"conf\" validation failed: failed to validate item 1: property \"value\" is required"}

0 comments on commit 62ceab5

Please sign in to comment.