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(admin): check username for updating consumer #4756

Merged
merged 5 commits into from
Aug 5, 2021
Merged
Show file tree
Hide file tree
Changes from 3 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
10 changes: 7 additions & 3 deletions apisix/admin/consumers.lua
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ local _M = {
}


local function check_conf(conf)
local function check_conf(username, conf)
-- core.log.error(core.json.encode(conf))
if not conf then
return nil, {error_msg = "missing configurations"}
Expand All @@ -38,6 +38,10 @@ local function check_conf(conf)
return nil, {error_msg = "invalid configuration: " .. err}
end

if username and username ~= conf.username then
return nil, {error_msg = "wrong username" }
end

if conf.plugins then
ok, err = plugins.check_schema(conf.plugins, core.schema.TYPE_CONSUMER)
if not ok then
Expand All @@ -61,8 +65,8 @@ local function check_conf(conf)
end


function _M.put(_, conf)
local consumer_name, err = check_conf(conf)
function _M.put(username, conf)
local consumer_name, err = check_conf(username, conf)
if not consumer_name then
return 400, err
end
Expand Down
29 changes: 29 additions & 0 deletions t/admin/consumers2.t
Original file line number Diff line number Diff line change
Expand Up @@ -151,3 +151,32 @@ __DATA__
}
--- response_body
{"action":"get","count":0,"node":{"dir":true,"key":"/apisix/consumers","nodes":{}}}



=== TEST 5: mismatched username, PUT
--- config
location /t {
content_by_lua_block {
local json = require("toolkit.json")
local t = require("lib.test_admin").test

local code, message, res = t('/apisix/admin/consumers/jack1',
ngx.HTTP_PUT,
[[{
"username":"jack"
}]]
)

ngx.status = code
if code >= 300 and code ~= 400 then
okaybase marked this conversation as resolved.
Show resolved Hide resolved
ngx.say(message)
return
end

ngx.say(message)
okaybase marked this conversation as resolved.
Show resolved Hide resolved
}
}
--- error_code: 400
--- response_body
{"error_msg":"wrong username"}