This is an automated email from the ASF dual-hosted git repository.
leslie 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 6050c9229 fix: opt wasm plugin config check (#10095)
6050c9229 is described below
commit 6050c9229540c4fa3cc1e2e62eded9a8548de972
Author: Sn0rt <[email protected]>
AuthorDate: Tue Aug 29 15:16:40 2023 +0800
fix: opt wasm plugin config check (#10095)
---
apisix/wasm.lua | 22 +++++++---------------
t/wasm/request-body.t | 2 +-
t/wasm/route.t | 4 ++--
3 files changed, 10 insertions(+), 18 deletions(-)
diff --git a/apisix/wasm.lua b/apisix/wasm.lua
index 940f4e2ec..c8b863aea 100644
--- a/apisix/wasm.lua
+++ b/apisix/wasm.lua
@@ -15,7 +15,6 @@
-- limitations under the License.
--
local core = require("apisix.core")
-local nkeys = require("table.nkeys")
local type = type
local support_wasm, wasm = pcall(require, "resty.proxy-wasm")
local ngx_var = ngx.var
@@ -24,7 +23,12 @@ local ngx_var = ngx.var
local schema = {
type = "object",
properties = {
- conf = {},
+ conf = {
+ oneOf = {
+ { type = "object", minProperties = 1},
+ { type = "string", minLength = 1},
+ }
+ },
},
required = {"conf"}
}
@@ -32,19 +36,7 @@ local _M = {}
local function check_schema(conf)
- if type(conf.conf) ~= "table" and type(conf.conf) ~= "string" then
- return false, "invalid conf type"
- end
-
- if type(conf.conf) == "string" and conf.conf == "" then
- return false, "empty conf"
- end
-
- if type(conf.conf) == "table" and nkeys(conf.conf) == 0 then
- return false, "empty conf"
- end
-
- return true, ""
+ return core.schema.check(schema, conf)
end
diff --git a/t/wasm/request-body.t b/t/wasm/request-body.t
index 83837684b..156df2527 100644
--- a/t/wasm/request-body.t
+++ b/t/wasm/request-body.t
@@ -237,7 +237,7 @@ request get body: ell
}
--- error_code: 400
--- response_body_like eval
-qr/invalid conf type/
+qr/property.*conf.*is required/
diff --git a/t/wasm/route.t b/t/wasm/route.t
index a905b9c87..717e54ebc 100644
--- a/t/wasm/route.t
+++ b/t/wasm/route.t
@@ -152,7 +152,7 @@ qr/invalid request body/
}
--- error_code: 400
--- response_body_like eval
-qr/empty conf/
+qr/value should match only one schema, but matches none/
@@ -187,7 +187,7 @@ qr/empty conf/
}
--- error_code: 400
--- response_body_like eval
-qr/empty conf/
+qr/value should match only one schema, but matches none/