You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@apisix.apache.org by we...@apache.org on 2020/12/27 04:02:43 UTC
[apisix] branch master updated: fix: correct the validation of
route.vars (#3124)
This is an automated email from the ASF dual-hosted git repository.
wenming pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/apisix.git
The following commit(s) were added to refs/heads/master by this push:
new 5377751 fix: correct the validation of route.vars (#3124)
5377751 is described below
commit 53777519b8261994f34dfd67fc07cc1b97ba2946
Author: 罗泽轩 <sp...@gmail.com>
AuthorDate: Sun Dec 27 12:02:31 2020 +0800
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 <sp...@gmail.com>
---
apisix/schema_def.lua | 12 +--
t/router/radixtree-uri-vars.t | 165 ++++++++++++++++++++++++++++++++++++++++++
2 files changed, 168 insertions(+), 9 deletions(-)
diff --git a/apisix/schema_def.lua b/apisix/schema_def.lua
index f4af8d0..2732edb 100644
--- a/apisix/schema_def.lua
+++ b/apisix/schema_def.lua
@@ -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",
diff --git a/t/router/radixtree-uri-vars.t b/t/router/radixtree-uri-vars.t
index bd06223..870fae2 100644
--- a/t/router/radixtree-uri-vars.t
+++ b/t/router/radixtree-uri-vars.t
@@ -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]