mirror of
https://gitee.com/iresty/apisix.git
synced 2024-12-04 21:17:36 +08:00
fix: correct the validation of route.vars (#3124)
Previously only the type is applied, and it is too strict. And now we should allow 4 items in the vars expression. Fix #3123 Signed-off-by: spacewander <spacewanderlzx@gmail.com>
This commit is contained in:
parent
e5c1c5984a
commit
53777519b8
@ -443,15 +443,9 @@ _M.route = {
|
||||
items = {
|
||||
description = "Nginx builtin variable name and value",
|
||||
type = "array",
|
||||
items = {
|
||||
maxItems = 3,
|
||||
minItems = 2,
|
||||
anyOf = {
|
||||
{type = "string",},
|
||||
{type = "number",},
|
||||
}
|
||||
}
|
||||
}
|
||||
maxItems = 4,
|
||||
minItems = 2,
|
||||
},
|
||||
},
|
||||
filter_func = {
|
||||
type = "string",
|
||||
|
@ -155,3 +155,168 @@ User-Agent: ios
|
||||
hello world
|
||||
--- no_error_log
|
||||
[error]
|
||||
|
||||
|
||||
|
||||
=== TEST 8: set route(id: 1) with vars(in table)
|
||||
--- config
|
||||
location /t {
|
||||
content_by_lua_block {
|
||||
local t = require("lib.test_admin").test
|
||||
local code, body = t('/apisix/admin/routes/1',
|
||||
ngx.HTTP_PUT,
|
||||
[=[{
|
||||
"methods": ["GET"],
|
||||
"upstream": {
|
||||
"nodes": {
|
||||
"127.0.0.1:1980": 1
|
||||
},
|
||||
"type": "roundrobin"
|
||||
},
|
||||
"uri": "/hello",
|
||||
"vars": [["http_user_agent", "IN", ["android", "ios"]]]
|
||||
}]=]
|
||||
)
|
||||
|
||||
if code >= 300 then
|
||||
ngx.status = code
|
||||
end
|
||||
ngx.say(body)
|
||||
}
|
||||
}
|
||||
--- request
|
||||
GET /t
|
||||
--- response_body
|
||||
passed
|
||||
--- no_error_log
|
||||
[error]
|
||||
|
||||
|
||||
|
||||
=== TEST 9: hit routes with user_agent=ios
|
||||
--- request
|
||||
GET /hello
|
||||
--- more_headers
|
||||
User-Agent: ios
|
||||
--- response_body
|
||||
hello world
|
||||
--- no_error_log
|
||||
[error]
|
||||
|
||||
|
||||
|
||||
=== TEST 10: hit routes with user_agent=android
|
||||
--- request
|
||||
GET /hello
|
||||
--- more_headers
|
||||
User-Agent: android
|
||||
--- response_body
|
||||
hello world
|
||||
--- no_error_log
|
||||
[error]
|
||||
|
||||
|
||||
|
||||
=== TEST 11: set route(id: 1) with vars(null)
|
||||
--- config
|
||||
location /t {
|
||||
content_by_lua_block {
|
||||
local t = require("lib.test_admin").test
|
||||
local code, body = t('/apisix/admin/routes/1',
|
||||
ngx.HTTP_PUT,
|
||||
[=[{
|
||||
"methods": ["GET"],
|
||||
"upstream": {
|
||||
"nodes": {
|
||||
"127.0.0.1:1980": 1
|
||||
},
|
||||
"type": "roundrobin"
|
||||
},
|
||||
"uri": "/hello",
|
||||
"vars": [["http_user_agent", "==", null]]
|
||||
}]=]
|
||||
)
|
||||
|
||||
if code >= 300 then
|
||||
ngx.status = code
|
||||
end
|
||||
ngx.say(body)
|
||||
}
|
||||
}
|
||||
--- request
|
||||
GET /t
|
||||
--- response_body
|
||||
passed
|
||||
--- no_error_log
|
||||
[error]
|
||||
|
||||
|
||||
|
||||
=== TEST 12: not found because user_agent=android
|
||||
--- request
|
||||
GET /hello
|
||||
--- more_headers
|
||||
User-Agent: android
|
||||
--- error_code: 404
|
||||
--- response_body
|
||||
{"error_msg":"404 Route Not Found"}
|
||||
--- no_error_log
|
||||
[error]
|
||||
|
||||
|
||||
|
||||
=== TEST 13: hit route
|
||||
--- request
|
||||
GET /hello
|
||||
--- response_body
|
||||
hello world
|
||||
--- no_error_log
|
||||
[error]
|
||||
|
||||
|
||||
|
||||
=== TEST 14: set route(id: 1) with vars(items are two)
|
||||
--- config
|
||||
location /t {
|
||||
content_by_lua_block {
|
||||
local t = require("lib.test_admin").test
|
||||
-- deprecated, will be removed soon
|
||||
local code, body = t('/apisix/admin/routes/1',
|
||||
ngx.HTTP_PUT,
|
||||
[=[{
|
||||
"methods": ["GET"],
|
||||
"upstream": {
|
||||
"nodes": {
|
||||
"127.0.0.1:1980": 1
|
||||
},
|
||||
"type": "roundrobin"
|
||||
},
|
||||
"uri": "/hello",
|
||||
"vars": [["http_user_agent", "ios"]]
|
||||
}]=]
|
||||
)
|
||||
|
||||
if code >= 300 then
|
||||
ngx.status = code
|
||||
end
|
||||
ngx.say(body)
|
||||
}
|
||||
}
|
||||
--- request
|
||||
GET /t
|
||||
--- response_body
|
||||
passed
|
||||
--- no_error_log
|
||||
[error]
|
||||
|
||||
|
||||
|
||||
=== TEST 15: hit routes with user_agent=ios
|
||||
--- request
|
||||
GET /hello
|
||||
--- more_headers
|
||||
User-Agent: ios
|
||||
--- response_body
|
||||
hello world
|
||||
--- no_error_log
|
||||
[error]
|
||||
|
Loading…
Reference in New Issue
Block a user