You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@apisix.apache.org by we...@apache.org on 2019/11/10 14:01:45 UTC
[incubator-apisix] 02/02: bugfix: key-auth plugin cannot run
accurately in the case of multiple consumers (#826)
This is an automated email from the ASF dual-hosted git repository.
wenming pushed a commit to branch 0.9-rc1
in repository https://gitbox.apache.org/repos/asf/incubator-apisix.git
commit 8c56dc674769155e194b9d60b2219531a59e9c48
Author: 贝克 <12...@qq.com>
AuthorDate: Sun Nov 10 21:50:57 2019 +0800
bugfix: key-auth plugin cannot run accurately in the case of multiple consumers (#826)
---
lua/apisix/consumer.lua | 15 ++++++++-------
t/plugin/key-auth.t | 31 +++++++++++++++++++++++++++----
2 files changed, 35 insertions(+), 11 deletions(-)
diff --git a/lua/apisix/consumer.lua b/lua/apisix/consumer.lua
index ba09fde..fd0c91b 100644
--- a/lua/apisix/consumer.lua
+++ b/lua/apisix/consumer.lua
@@ -23,7 +23,7 @@ local consumers
local _M = {
- version = 0.2,
+ version = 0.3,
}
@@ -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
diff --git a/t/plugin/key-auth.t b/t/plugin/key-auth.t
index 792bd47..1608f96 100644
--- a/t/plugin/key-auth.t
+++ b/t/plugin/key-auth.t
@@ -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]