From 08db6fde86b79cdd19955b168019b9d7c2ac964e Mon Sep 17 00:00:00 2001 From: Jens Keiner Date: Mon, 30 Nov 2020 22:36:59 +0100 Subject: [PATCH 1/3] Change phase from access to rewrite. --- apisix/plugins/basic-auth.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apisix/plugins/basic-auth.lua b/apisix/plugins/basic-auth.lua index 1171537d58d6..7c3efb63c456 100644 --- a/apisix/plugins/basic-auth.lua +++ b/apisix/plugins/basic-auth.lua @@ -125,7 +125,7 @@ do end end -function _M.access(conf, ctx) +function _M.rewrite(conf, ctx) core.log.info("plugin access phase, conf: ", core.json.delay_encode(conf)) -- 1. extract authorization from header From e55e3f3eb260b75d73441d45b0269e5ec788f27d Mon Sep 17 00:00:00 2001 From: Jens Keiner Date: Mon, 30 Nov 2020 22:39:45 +0100 Subject: [PATCH 2/3] Add stub to verify that consumers are handled correctly. --- apisix/init.lua | 2 ++ t/plugin/basic-auth.t | 4 ++++ 2 files changed, 6 insertions(+) diff --git a/apisix/init.lua b/apisix/init.lua index 629e7507226d..cb3afa97c439 100644 --- a/apisix/init.lua +++ b/apisix/init.lua @@ -513,6 +513,8 @@ function _M.http_access_phase() api_ctx.consumer, api_ctx ) + core.log.debug("find consumer ", api_ctx.consumer.username, + ", config changed: ", changed) if changed then core.table.clear(api_ctx.plugins) api_ctx.plugins = plugin.filter(route, api_ctx.plugins) diff --git a/t/plugin/basic-auth.t b/t/plugin/basic-auth.t index ebdf78112048..97b3ca71567b 100644 --- a/t/plugin/basic-auth.t +++ b/t/plugin/basic-auth.t @@ -16,6 +16,7 @@ # use t::APISIX 'no_plan'; +log_level('debug'); repeat_each(2); no_long_string(); no_root_location(); @@ -189,6 +190,7 @@ Authorization: Basic Zm9vOmZvbwo= === TEST 8: verify +--- yaml_config eval: $::yaml_config --- request GET /hello --- more_headers @@ -197,6 +199,8 @@ Authorization: Basic Zm9vOmJhcg== hello world --- no_error_log [error] +--- error_log +find consumer foo From aad39d26c3bd2357db643a8c4c04f3642db6c4e8 Mon Sep 17 00:00:00 2001 From: Jens Keiner Date: Tue, 1 Dec 2020 09:27:33 +0100 Subject: [PATCH 3/3] Remove setting debug log level. --- t/plugin/basic-auth.t | 2 -- 1 file changed, 2 deletions(-) diff --git a/t/plugin/basic-auth.t b/t/plugin/basic-auth.t index 82fa4f327475..8382de0cc2e0 100644 --- a/t/plugin/basic-auth.t +++ b/t/plugin/basic-auth.t @@ -16,7 +16,6 @@ # use t::APISIX 'no_plan'; -log_level('debug'); repeat_each(2); no_long_string(); no_root_location(); @@ -191,7 +190,6 @@ Authorization: Basic Zm9vOmZvbwo= === TEST 8: verify ---- yaml_config eval: $::yaml_config --- request GET /hello --- more_headers