Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

bugfix: key-auth plugin cannot run accurately in the case of multiple consumers(branch: master) #826

Merged
merged 2 commits into from
Nov 10, 2019
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
15 changes: 8 additions & 7 deletions lua/apisix/consumer.lua
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ local consumers


local _M = {
version = 0.2,
version = 0.3,
}


Expand All @@ -37,12 +37,13 @@ local function plugin_consumer()
for _, consumer in ipairs(consumers.values) do
for name, config in pairs(consumer.value.plugins or {}) do
local plugin_obj = plugin.get(name)
if plugin_obj and plugin_obj.type == "auth"
and not plugins[name] then
plugins[name] = {
nodes = {},
conf_version = consumers.conf_version
}
if plugin_obj and plugin_obj.type == "auth" then
if not plugins[name] then
plugins[name] = {
nodes = {},
conf_version = consumers.conf_version
}
end

local new_consumer = core.table.clone(consumer.value)
new_consumer.consumer_id = new_consumer.id
Expand Down
31 changes: 27 additions & 4 deletions t/plugin/key-auth.t
Original file line number Diff line number Diff line change
Expand Up @@ -172,11 +172,34 @@ GET /hello


=== TEST 7: valid consumer
--- config
location /add_more_consumer {
content_by_lua_block {
local t = require("lib.test_admin").test
local username = ""
local key = ""
local code, body
for i = 1, 20 do
username = "user_" .. tostring(i)
key = "auth-" .. tostring(i)
code, body = t('/apisix/admin/consumers',
ngx.HTTP_PUT,
string.format('{"username":"%s","plugins":{"key-auth":{"key":"%s"}}}', username, key),
string.format('{"node":{"value":{"username":"%s","plugins":{"key-auth":{"key":"%s"}}}},"action":"set"}', username, key)
)
end

ngx.status = code
ngx.say(body)
}
}
--- request
GET /hello
GET /add_more_consumer
--- pipelined_requests eval
["GET /add_more_consumer", "GET /hello"]
--- more_headers
apikey: auth-one
--- response_body
hello world
apikey: auth-13
--- response_body eval
["passed\n", "hello world\n"]
--- no_error_log
[error]