You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@apisix.apache.org by me...@apache.org on 2020/07/31 12:19:18 UTC
[incubator-apisix] branch master updated: bugfix: avoid to modify
the original plugin conf. (#1958)
This is an automated email from the ASF dual-hosted git repository.
membphis pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-apisix.git
The following commit(s) were added to refs/heads/master by this push:
new 8fc2af5 bugfix: avoid to modify the original plugin conf. (#1958)
8fc2af5 is described below
commit 8fc2af56aefe70c539f8ba181374ae80a657ab08
Author: YuanSheng Wang <me...@gmail.com>
AuthorDate: Fri Jul 31 20:19:12 2020 +0800
bugfix: avoid to modify the original plugin conf. (#1958)
relate issue: #1934 , #1956
---
apisix/plugins/openid-connect.lua | 3 ++-
apisix/plugins/redirect.lua | 19 ++++++++++++-------
apisix/plugins/uri-blocker.lua | 18 +++++++++++++-----
apisix/plugins/zipkin.lua | 4 ++--
t/plugin/uri-blocker.t | 22 ++++++++++++----------
5 files changed, 41 insertions(+), 25 deletions(-)
diff --git a/apisix/plugins/openid-connect.lua b/apisix/plugins/openid-connect.lua
index 2572c85..29aca4c 100644
--- a/apisix/plugins/openid-connect.lua
+++ b/apisix/plugins/openid-connect.lua
@@ -139,7 +139,8 @@ local function add_user_header(user)
end
-function _M.access(conf, ctx)
+function _M.access(plugin_conf, ctx)
+ local conf = core.table.clone(plugin_conf)
if not conf.redirect_uri then
conf.redirect_uri = ctx.var.request_uri
end
diff --git a/apisix/plugins/redirect.lua b/apisix/plugins/redirect.lua
index a9df21f..de9c769 100644
--- a/apisix/plugins/redirect.lua
+++ b/apisix/plugins/redirect.lua
@@ -126,21 +126,26 @@ end
function _M.rewrite(conf, ctx)
core.log.info("plugin rewrite phase, conf: ", core.json.delay_encode(conf))
+ local ret_code = conf.ret_code
+ local uri = conf.uri
+
if conf.http_to_https and ctx.var.scheme == "http" then
- conf.uri = "https://$host$request_uri"
- conf.ret_code = 301
+ -- TODOļ¼ add test case
+ -- PR: https://github.com/apache/incubator-apisix/pull/1958
+ uri = "https://$host$request_uri"
+ ret_code = 301
end
- if conf.uri and conf.ret_code then
- local new_uri, err = concat_new_uri(conf.uri, ctx)
+ if uri and ret_code then
+ local new_uri, err = concat_new_uri(uri, ctx)
if not new_uri then
- core.log.error("failed to generate new uri by: ", conf.uri, " error: ",
- err)
+ core.log.error("failed to generate new uri by: ", uri, " error: ",
+ err)
core.response.exit(500)
end
core.response.set_header("Location", new_uri)
- core.response.exit(conf.ret_code)
+ core.response.exit(ret_code)
end
end
diff --git a/apisix/plugins/uri-blocker.lua b/apisix/plugins/uri-blocker.lua
index ab5b682..b3dba18 100644
--- a/apisix/plugins/uri-blocker.lua
+++ b/apisix/plugins/uri-blocker.lua
@@ -57,18 +57,15 @@ function _M.check_schema(conf)
return false, err
end
- local block_rules = {}
for i, re_rule in ipairs(conf.block_rules) do
local ok, err = re_compile(re_rule, "j")
- -- core.log.warn("ok: ", tostring(ok), " err: ", tostring(err), " re_rule: ", re_rule)
+ -- core.log.warn("ok: ", tostring(ok), " err: ", tostring(err),
+ -- " re_rule: ", re_rule)
if not ok then
return false, err
end
- block_rules[i] = re_rule
end
- conf.block_rules_concat = core.table.concat(block_rules, "|")
- core.log.info("concat block_rules: ", conf.block_rules_concat)
return true
end
@@ -76,6 +73,17 @@ end
function _M.rewrite(conf, ctx)
core.log.info("uri: ", ctx.var.request_uri)
core.log.info("block uri rules: ", conf.block_rules_concat)
+
+ if not conf.block_rules_concat then
+ local block_rules = {}
+ for i, re_rule in ipairs(conf.block_rules) do
+ block_rules[i] = re_rule
+ end
+
+ conf.block_rules_concat = core.table.concat(block_rules, "|")
+ core.log.info("concat block_rules: ", conf.block_rules_concat)
+ end
+
local from = re_find(ctx.var.request_uri, conf.block_rules_concat, "jo")
if from then
core.response.exit(conf.rejected_code)
diff --git a/apisix/plugins/zipkin.lua b/apisix/plugins/zipkin.lua
index 934d883..eebf07e 100644
--- a/apisix/plugins/zipkin.lua
+++ b/apisix/plugins/zipkin.lua
@@ -81,8 +81,8 @@ local function report2endpoint(premature, reporter)
end
-function _M.rewrite(conf, ctx)
-
+function _M.rewrite(plugin_conf, ctx)
+ local conf = core.table.clone(plugin_conf)
-- once the server started, server_addr and server_port won't change, so we can cache it.
conf.server_port = tonumber(ctx.var['server_port'])
diff --git a/t/plugin/uri-blocker.t b/t/plugin/uri-blocker.t
index 3cf2e37..a470055 100644
--- a/t/plugin/uri-blocker.t
+++ b/t/plugin/uri-blocker.t
@@ -16,7 +16,7 @@
#
use t::APISIX 'no_plan';
-repeat_each(2);
+repeat_each(1);
no_long_string();
no_root_location();
no_shuffle();
@@ -86,8 +86,6 @@ GET /t
passed
--- no_error_log
[error]
---- error_log
-concat block_rules: ^a|^b,
@@ -124,7 +122,7 @@ GET /t
-=== TEST 4: sanity
+=== TEST 4: one block rule
--- config
location /t {
content_by_lua_block {
@@ -170,8 +168,6 @@ GET /t
passed
--- no_error_log
[error]
---- error_log
-concat block_rules: aa,
@@ -181,6 +177,8 @@ GET /hello?aa=1
--- error_code: 403
--- no_error_log
[error]
+--- error_log
+concat block_rules: aa
@@ -189,6 +187,8 @@ GET /hello?aa=1
GET /hello?bb=2
--- no_error_log
[error]
+--- error_log
+concat block_rules: aa
@@ -227,8 +227,6 @@ GET /t
passed
--- no_error_log
[error]
---- error_log
-concat block_rules: aa|bb|c\d+,
@@ -238,6 +236,8 @@ GET /hello?x=bb
--- error_code: 403
--- no_error_log
[error]
+--- error_log
+concat block_rules: aa|bb|c\d+,
@@ -247,6 +247,8 @@ GET /hello?bb=2
--- error_code: 403
--- no_error_log
[error]
+--- error_log
+concat block_rules: aa|bb|c\d+,
@@ -302,8 +304,6 @@ GET /t
passed
--- no_error_log
[error]
---- error_log
-concat block_rules: select.+(from|limit)|(?:(union(.*?)select)),
@@ -313,6 +313,8 @@ GET /hello?name=;select%20from%20sys
--- error_code: 403
--- no_error_log
[error]
+--- error_log
+concat block_rules: select.+(from|limit)|(?:(union(.*?)select)),