Skip to content

Commit

Permalink
feat: strictly validate the input of core resources (#10233)
Browse files Browse the repository at this point in the history
  • Loading branch information
Sn0rt authored Sep 20, 2023
1 parent 57a7dcd commit a98f1ca
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 16 deletions.
19 changes: 16 additions & 3 deletions apisix/schema_def.lua
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,7 @@ local health_checker = {
{required = {"active"}},
{required = {"active", "passive"}},
},
additionalProperties = false,
}


Expand Down Expand Up @@ -501,7 +502,8 @@ local upstream_schema = {
oneOf = {
{required = {"nodes"}},
{required = {"service_name", "discovery_type"}},
}
},
additionalProperties = false
}

-- TODO: add more nginx variable support
Expand Down Expand Up @@ -662,6 +664,7 @@ _M.route = {
{required = {"script", "plugin_config_id"}},
}
},
additionalProperties = false,
}


Expand Down Expand Up @@ -689,6 +692,7 @@ _M.service = {
uniqueItems = true,
},
},
additionalProperties = false,
}


Expand All @@ -707,6 +711,7 @@ _M.consumer = {
desc = desc_def,
},
required = {"username"},
additionalProperties = false,
}


Expand Down Expand Up @@ -817,7 +822,8 @@ _M.ssl = {
{required = {"snis", "key", "cert"}}
}
},
["else"] = {required = {"key", "cert"}}
["else"] = {required = {"key", "cert"}},
additionalProperties = false,
}


Expand All @@ -834,6 +840,7 @@ _M.proto = {
}
},
required = {"content"},
additionalProperties = false,
}


Expand All @@ -846,6 +853,7 @@ _M.global_rule = {
update_time = timestamp_def
},
required = {"id", "plugins"},
additionalProperties = false,
}


Expand Down Expand Up @@ -879,6 +887,7 @@ local xrpc_protocol_schema = {
dependencies = {
name = {"conf"},
},
additionalProperties = false,
},
},

Expand Down Expand Up @@ -913,7 +922,8 @@ _M.stream_route = {
upstream_id = id_schema,
plugins = plugins_schema,
protocol = xrpc_protocol_schema,
}
},
additionalProperties = false,
}


Expand All @@ -929,6 +939,7 @@ _M.plugins = {
stream = {
type = "boolean"
},
additionalProperties = false,
},
required = {"name"}
}
Expand All @@ -946,6 +957,7 @@ _M.plugin_config = {
update_time = timestamp_def
},
required = {"id", "plugins"},
additionalProperties = false,
}


Expand All @@ -960,6 +972,7 @@ _M.consumer_group = {
update_time = timestamp_def
},
required = {"id", "plugins"},
additionalProperties = false,
}


Expand Down
7 changes: 4 additions & 3 deletions t/admin/upstream-array-nodes.t
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ no valid upstream node



=== TEST 9: additional properties is valid
=== TEST 9: additional properties is invalid
--- config
location /t {
content_by_lua_block {
Expand All @@ -277,8 +277,9 @@ no valid upstream node
}
--- request
GET /t
--- response_body
passed
--- error_code: 400
--- response_body eval
qr/\{"error_msg":"invalid configuration: additional properties forbidden, found .*"\}/



Expand Down
7 changes: 4 additions & 3 deletions t/admin/upstream.t
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ GET /t



=== TEST 11: additional properties is valid
=== TEST 11: additional properties is invalid
--- config
location /t {
content_by_lua_block {
Expand All @@ -354,8 +354,9 @@ GET /t
}
--- request
GET /t
--- response_body
passed
--- error_code: 400
--- response_body eval
qr/\{"error_msg":"invalid configuration: additional properties forbidden, found .*"\}/



Expand Down
7 changes: 0 additions & 7 deletions t/wasm/global-rule.t
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,6 @@ __DATA__
local code, body = t('/apisix/admin/global_rules/1',
ngx.HTTP_PUT,
[[{
"uri": "/hello",
"upstream": {
"type": "roundrobin",
"nodes": {
"127.0.0.1:1980": 1
}
},
"plugins": {
"wasm_log": {
"conf": "blahblah"
Expand Down

0 comments on commit a98f1ca

Please sign in to comment.