You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@apisix.apache.org by to...@apache.org on 2021/06/03 01:40:00 UTC
[apisix] branch master updated: fix(ext-plugin): missing schema
check (#4359)
This is an automated email from the ASF dual-hosted git repository.
tokers pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/apisix.git
The following commit(s) were added to refs/heads/master by this push:
new 62ceab5 fix(ext-plugin): missing schema check (#4359)
62ceab5 is described below
commit 62ceab5710859d39828c6a88e3602ab6df1a589f
Author: 罗泽轩 <sp...@gmail.com>
AuthorDate: Thu Jun 3 09:39:51 2021 +0800
fix(ext-plugin): missing schema check (#4359)
Signed-off-by: spacewander <sp...@gmail.com>
---
apisix/plugins/ext-plugin-post-req.lua | 6 ++++
apisix/plugins/ext-plugin-pre-req.lua | 6 ++++
apisix/plugins/ext-plugin/init.lua | 3 +-
t/plugin/ext-plugin/sanity.t | 63 ++++++++++++++++++++++++++++++++++
4 files changed, 77 insertions(+), 1 deletion(-)
diff --git a/apisix/plugins/ext-plugin-post-req.lua b/apisix/plugins/ext-plugin-post-req.lua
index 07ac6bd..3f7aaf5 100644
--- a/apisix/plugins/ext-plugin-post-req.lua
+++ b/apisix/plugins/ext-plugin-post-req.lua
@@ -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")
@@ -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
diff --git a/apisix/plugins/ext-plugin-pre-req.lua b/apisix/plugins/ext-plugin-pre-req.lua
index 3695ec5..8903e12 100644
--- a/apisix/plugins/ext-plugin-pre-req.lua
+++ b/apisix/plugins/ext-plugin-pre-req.lua
@@ -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")
@@ -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
diff --git a/apisix/plugins/ext-plugin/init.lua b/apisix/plugins/ext-plugin/init.lua
index 7be360f..53e1d1c 100644
--- a/apisix/plugins/ext-plugin/init.lua
+++ b/apisix/plugins/ext-plugin/init.lua
@@ -79,7 +79,8 @@ local schema = {
value = {
type = "string",
},
- }
+ },
+ required = {"name", "value"}
},
minItems = 1,
},
diff --git a/t/plugin/ext-plugin/sanity.t b/t/plugin/ext-plugin/sanity.t
index bde3fcc..aacb7b3 100644
--- a/t/plugin/ext-plugin/sanity.t
+++ b/t/plugin/ext-plugin/sanity.t
@@ -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"}