mirror of
https://gitee.com/iresty/apisix.git
synced 2024-12-04 21:17:36 +08:00
chore(traffic-split): add additionalProperties field to restrict plugin configuration (#3285)
This commit is contained in:
parent
e00893e2b0
commit
ff60e57996
@ -130,10 +130,12 @@ local schema = {
|
||||
properties = {
|
||||
match = match_schema,
|
||||
weighted_upstreams = upstreams_schema
|
||||
}
|
||||
},
|
||||
additionalProperties = false
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
additionalProperties = false
|
||||
}
|
||||
|
||||
local plugin_name = "traffic-split"
|
||||
|
@ -1290,3 +1290,109 @@ qr/upstream_key: roundrobin#route_1_\d/
|
||||
upstream_key: roundrobin#route_1_1
|
||||
--- no_error_log
|
||||
[error]
|
||||
|
||||
|
||||
|
||||
=== TEST 38: schema validation, "additionalProperties = false" to limit the plugin configuration
|
||||
--- config
|
||||
location /t {
|
||||
content_by_lua_block {
|
||||
local plugin = require("apisix.plugins.traffic-split")
|
||||
local ok, err = plugin.check_schema({
|
||||
additional_properties = "hello",
|
||||
rules = {
|
||||
{
|
||||
match = {
|
||||
{
|
||||
vars = {
|
||||
{"arg_name", "==", "jack"},
|
||||
{"arg_age", "!", "<", "16"}
|
||||
}
|
||||
},
|
||||
{
|
||||
vars = {
|
||||
{"arg_name", "==", "rose"},
|
||||
{"arg_age", "!", ">", "32"}
|
||||
}
|
||||
}
|
||||
},
|
||||
weighted_upstreams = {
|
||||
{
|
||||
upstream = {
|
||||
name = "upstream_A",
|
||||
type = "roundrobin",
|
||||
nodes = {["127.0.0.1:1981"]=2},
|
||||
timeout = {connect = 15, send = 15, read = 15}
|
||||
},
|
||||
weight = 2
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
if not ok then
|
||||
ngx.say(err)
|
||||
end
|
||||
|
||||
ngx.say("done")
|
||||
}
|
||||
}
|
||||
--- request
|
||||
GET /t
|
||||
--- response_body eval
|
||||
qr/additional properties forbidden, found additional_properties/
|
||||
--- no_error_log
|
||||
[error]
|
||||
|
||||
|
||||
|
||||
=== TEST 39: schema validation, "additionalProperties = false" to limit the "rules" configuration
|
||||
--- config
|
||||
location /t {
|
||||
content_by_lua_block {
|
||||
local plugin = require("apisix.plugins.traffic-split")
|
||||
local ok, err = plugin.check_schema({
|
||||
rules = {
|
||||
{
|
||||
additional_properties = "hello",
|
||||
match = {
|
||||
{
|
||||
vars = {
|
||||
{"arg_name", "==", "jack"},
|
||||
{"arg_age", "!", "<", "16"}
|
||||
}
|
||||
},
|
||||
{
|
||||
vars = {
|
||||
{"arg_name", "==", "rose"},
|
||||
{"arg_age", "!", ">", "32"}
|
||||
}
|
||||
}
|
||||
},
|
||||
weighted_upstreams = {
|
||||
{
|
||||
upstream = {
|
||||
name = "upstream_A",
|
||||
type = "roundrobin",
|
||||
nodes = {["127.0.0.1:1981"]=2},
|
||||
timeout = {connect = 15, send = 15, read = 15}
|
||||
},
|
||||
weight = 2
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
if not ok then
|
||||
ngx.say(err)
|
||||
end
|
||||
|
||||
ngx.say("done")
|
||||
}
|
||||
}
|
||||
--- request
|
||||
GET /t
|
||||
--- response_body eval
|
||||
qr/property "rules" validation failed: failed to validate item 1: additional properties forbidden, found additional_properties/
|
||||
--- no_error_log
|
||||
[error]
|
||||
|
Loading…
Reference in New Issue
Block a user