Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: correct the validation of route.vars #3124

Merged
merged 1 commit into from
Dec 27, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 3 additions & 9 deletions apisix/schema_def.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
165 changes: 165 additions & 0 deletions t/router/radixtree-uri-vars.t
Original file line number Diff line number Diff line change
Expand Up @@ -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]