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(wolf-rbac): other plugin in consumer not effective when consumer used wolf-rbac plugin (#9287) #9298

Merged
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
11 changes: 6 additions & 5 deletions apisix/plugins/wolf-rbac.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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))
Expand All @@ -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

Expand Down
50 changes: 50 additions & 0 deletions t/plugin/wolf-rbac.t
Original file line number Diff line number Diff line change
Expand Up @@ -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]