chore(traffic-split): add additionalProperties field to restrict plugin configuration (#3285)

This commit is contained in:
Yuelin Zheng 2021-01-14 16:37:36 +08:00 committed by GitHub
parent e00893e2b0
commit ff60e57996
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 110 additions and 2 deletions

View File

@ -130,10 +130,12 @@ local schema = {
properties = {
match = match_schema,
weighted_upstreams = upstreams_schema
}
},
additionalProperties = false
}
}
}
},
additionalProperties = false
}
local plugin_name = "traffic-split"

View File

@ -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]