You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@apisix.apache.org by mo...@apache.org on 2023/05/07 08:00:30 UTC
[apisix] branch master updated: fix(wolf-rbac): other plugin in consumer not effective when consumer used wolf-rbac plugin (#9287) (#9298)
This is an automated email from the ASF dual-hosted git repository.
monkeydluffy 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 f100cff36 fix(wolf-rbac): other plugin in consumer not effective when consumer used wolf-rbac plugin (#9287) (#9298)
f100cff36 is described below
commit f100cff361770e5ea3cf98ff294c2090543d5090
Author: lingliy <li...@126.com>
AuthorDate: Sun May 7 16:00:24 2023 +0800
fix(wolf-rbac): other plugin in consumer not effective when consumer used wolf-rbac plugin (#9287) (#9298)
---
apisix/plugins/wolf-rbac.lua | 11 +++++-----
t/plugin/wolf-rbac.t | 50 ++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 56 insertions(+), 5 deletions(-)
diff --git a/apisix/plugins/wolf-rbac.lua b/apisix/plugins/wolf-rbac.lua
index 62cb7b04f..154fde41a 100644
--- a/apisix/plugins/wolf-rbac.lua
+++ b/apisix/plugins/wolf-rbac.lua
@@ -266,13 +266,13 @@ function _M.rewrite(conf, ctx)
local consumers = consumer.consumers_kv(plugin_name, consumer_conf, "appid")
core.log.info("------ consumers: ", core.json.delay_encode(consumers))
- local consumer = consumers[appid]
- if not consumer then
+ local cur_consumer = consumers[appid]
+ if not cur_consumer then
core.log.error("consumer [", appid, "] not found")
return 401, fail_response("Invalid appid in rbac token")
end
- core.log.info("consumer: ", core.json.delay_encode(consumer))
- local server = consumer.auth_conf.server
+ core.log.info("consumer: ", core.json.delay_encode(cur_consumer))
+ local server = cur_consumer.auth_conf.server
local res = check_url_permission(server, appid, action, url,
client_ip, wolf_token)
@@ -287,7 +287,7 @@ function _M.rewrite(conf, ctx)
local userId = userInfo.id
username = userInfo.username
nickname = userInfo.nickname or userInfo.username
- local prefix = consumer.auth_conf.header_prefix or ''
+ local prefix = cur_consumer.auth_conf.header_prefix or ''
core.response.set_header(prefix .. "UserId", userId)
core.response.set_header(prefix .. "Username", username)
core.response.set_header(prefix .. "Nickname", ngx.escape_uri(nickname))
@@ -303,6 +303,7 @@ function _M.rewrite(conf, ctx)
") failed, res: ",core.json.delay_encode(res))
return res.status, fail_response(res.err, { username = username, nickname = nickname })
end
+ consumer.attach_consumer(ctx, cur_consumer, consumer_conf)
core.log.info("wolf-rbac check permission passed")
end
diff --git a/t/plugin/wolf-rbac.t b/t/plugin/wolf-rbac.t
index 34c7068ca..8136e3df6 100644
--- a/t/plugin/wolf-rbac.t
+++ b/t/plugin/wolf-rbac.t
@@ -685,3 +685,53 @@ passed
ngx.status = code
}
}
+
+
+
+=== TEST 36: add consumer with echo plugin
+--- config
+ location /t {
+ content_by_lua_block {
+ local t = require("lib.test_admin").test
+ local code, body = t('/apisix/admin/consumers',
+ ngx.HTTP_PUT,
+ [[{
+ "username": "wolf_rbac_with_other_plugins",
+ "plugins": {
+ "wolf-rbac": {
+ "appid": "wolf-rbac-app",
+ "server": "http://127.0.0.1:1982"
+ },
+ "echo": {
+ "body": "consumer merge echo plugins\n"
+ }
+ }
+ }]]
+ )
+
+ if code >= 300 then
+ ngx.status = code
+ end
+ ngx.say(body)
+ }
+ }
+--- response_body
+passed
+--- no_error_log
+[error]
+
+
+
+=== TEST 37: verify echo plugin in consumer
+--- request
+GET /hello
+--- more_headers
+Authorization: V1#wolf-rbac-app#wolf-rbac-token
+--- response_headers
+X-UserId: 100
+X-Username: admin
+X-Nickname: administrator
+--- response_body
+consumer merge echo plugins
+--- no_error_log
+[error]