This is an automated email from the ASF dual-hosted git repository.
tokers 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 a1dd370 fix(traffic-split): the header set in vars cannot have a
horizontal line (#3310)
a1dd370 is described below
commit a1dd370962a39be652e03978a37231660a2641b6
Author: Yuelin Zheng <[email protected]>
AuthorDate: Sun Jan 17 12:40:31 2021 +0800
fix(traffic-split): the header set in vars cannot have a horizontal line
(#3310)
fix #3306
---
apisix/plugins/traffic-split.lua | 2 +-
t/plugin/traffic-split.t | 160 ++++++++++++++++++++++++++++++++++++++-
2 files changed, 158 insertions(+), 4 deletions(-)
diff --git a/apisix/plugins/traffic-split.lua b/apisix/plugins/traffic-split.lua
index a94f6dd..bf348cc 100644
--- a/apisix/plugins/traffic-split.lua
+++ b/apisix/plugins/traffic-split.lua
@@ -291,7 +291,7 @@ function _M.access(conf, ctx)
return 500, err
end
- match_flag = expr:eval()
+ match_flag = expr:eval(ctx.var)
if match_flag then
break
end
diff --git a/t/plugin/traffic-split.t b/t/plugin/traffic-split.t
index cb05004..f9460d3 100644
--- a/t/plugin/traffic-split.t
+++ b/t/plugin/traffic-split.t
@@ -908,8 +908,10 @@ location /t {
content_by_lua_block {
local t = require("lib.test_admin").test
local bodys = {}
+ local headers = {}
+ headers["appkey"] = "api-key"
for i = 1, 5 do
- local _, _, body = t('/server_port?name=jack&age=36', ngx.HTTP_GET)
+ local _, _, body = t('/server_port?name=jack&age=36',
ngx.HTTP_GET, "", nil, headers)
bodys[i] = body
end
table.sort(bodys)
@@ -1057,8 +1059,10 @@ location /t {
content_by_lua_block {
local t = require("lib.test_admin").test
local bodys = {}
+ local headers = {}
+ headers["appkey"] = "api-key"
for i = 1, 5 do
- local _, _, body = t('/server_port?name=jack&age=36', ngx.HTTP_GET)
+ local _, _, body = t('/server_port?name=jack&age=36',
ngx.HTTP_GET, "", nil, headers)
bodys[i] = body
end
table.sort(bodys)
@@ -1130,8 +1134,10 @@ location /t {
content_by_lua_block {
local t = require("lib.test_admin").test
local bodys = {}
+ local headers = {}
+ headers["appkey"] = "api-key"
for i = 1, 5 do
- local _, _, body = t('/server_port?name=jack&age=36', ngx.HTTP_GET)
+ local _, _, body = t('/server_port?name=jack&age=36',
ngx.HTTP_GET, "", nil, headers)
bodys[i] = body
end
table.sort(bodys)
@@ -1396,3 +1402,151 @@ GET /t
qr/property "rules" validation failed: failed to validate item 1: additional
properties forbidden, found additional_properties/
--- no_error_log
[error]
+
+
+
+=== TEST 40: the request header contains horizontal lines("-")
+--- 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,
+ [=[{
+ "uri": "/server_port",
+ "plugins": {
+ "traffic-split": {
+ "rules": [
+ {
+ "match": [
+ {
+ "vars": [["http_x-api-appkey",
"==", "api-key"]]
+ }
+ ],
+ "weighted_upstreams": [
+ {"upstream": {"name": "upstream_A",
"type": "roundrobin", "nodes": [{"host":"127.0.0.1", "port":1981, "weight": 2},
{"host":"127.0.0.1", "port":1982, "weight": 2}]}, "weight": 4},
+ {"weight": 1}
+ ]
+ }
+ ]
+ }
+ },
+ "upstream": {
+ "type": "roundrobin",
+ "nodes": {
+ "127.0.0.1:1980": 1
+ }
+ }
+ }]=]
+ )
+ if code >= 300 then
+ ngx.status = code
+ end
+ ngx.say(body)
+ }
+ }
+--- request
+GET /t
+--- response_body
+passed
+--- no_error_log
+[error]
+
+
+
+=== TEST 41: `match` rule passed
+--- config
+location /t {
+ content_by_lua_block {
+ local t = require("lib.test_admin").test
+ local bodys = {}
+ local headers = {}
+ headers["x-api-appkey"] = "api-key"
+ for i = 1, 5 do
+ local _, _, body = t('/server_port', ngx.HTTP_GET, "", nil,
headers)
+ bodys[i] = body
+ end
+ table.sort(bodys)
+ ngx.say(table.concat(bodys, ", "))
+ }
+}
+--- request
+GET /t
+--- response_body
+1980, 1981, 1981, 1982, 1982
+--- no_error_log
+[error]
+
+
+
+=== TEST 42: request args and request headers contain horizontal lines("-")
+--- 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,
+ [=[{
+ "uri": "/server_port",
+ "plugins": {
+ "traffic-split": {
+ "rules": [
+ {
+ "match": [
+ {
+ "vars": [["arg_x-api-name", "==",
"jack"], ["arg_x-api-age", ">", "23"],["http_x-api-appkey", "~~", "[a-z]{1,5}"]]
+ }
+ ],
+ "weighted_upstreams": [
+ {"upstream": {"name": "upstream_A",
"type": "roundrobin", "nodes": [{"host":"127.0.0.1", "port":1981, "weight": 2},
{"host":"127.0.0.1", "port":1982, "weight": 2}]}, "weight": 4},
+ {"weight": 1}
+ ]
+ }
+ ]
+ }
+ },
+ "upstream": {
+ "type": "roundrobin",
+ "nodes": {
+ "127.0.0.1:1980": 1
+ }
+ }
+ }]=]
+ )
+ if code >= 300 then
+ ngx.status = code
+ end
+ ngx.say(body)
+ }
+ }
+--- request
+GET /t
+--- response_body
+passed
+--- no_error_log
+[error]
+
+
+
+=== TEST 43: `match` rule passed
+--- config
+location /t {
+ content_by_lua_block {
+ local t = require("lib.test_admin").test
+ local bodys = {}
+ local headers = {}
+ headers["x-api-appkey"] = "hello"
+ for i = 1, 5 do
+ local _, _, body = t('/server_port?x-api-name=jack&x-api-age=36',
ngx.HTTP_GET, "", nil, headers)
+ bodys[i] = body
+ end
+ table.sort(bodys)
+ ngx.say(table.concat(bodys, ", "))
+ }
+}
+--- request
+GET /t
+--- response_body
+1980, 1981, 1981, 1982, 1982
+--- no_error_log
+[error]