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 2020/11/15 09:29:07 UTC
[apisix] branch master updated: fix: user's route was prior to the
plugin's one (#2733)
This is an automated email from the ASF dual-hosted git repository.
wenming pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/apisix.git
The following commit(s) were added to refs/heads/master by this push:
new 23a47b9 fix: user's route was prior to the plugin's one (#2733)
23a47b9 is described below
commit 23a47b9eaca3ef73e2a2953d57dd35449b5f46bd
Author: 罗泽轩 <sp...@gmail.com>
AuthorDate: Sun Nov 15 17:28:56 2020 +0800
fix: user's route was prior to the plugin's one (#2733)
---
apisix/init.lua | 12 ++++--
t/plugin/plugin.t | 109 +++++++++++++++++++++++++++++++++++++++++++++++++++++-
2 files changed, 116 insertions(+), 5 deletions(-)
diff --git a/apisix/init.lua b/apisix/init.lua
index 769de3c..4393488 100644
--- a/apisix/init.lua
+++ b/apisix/init.lua
@@ -365,8 +365,8 @@ function _M.http_access_phase()
api_ctx.global_rules = router.global_rules
end
+ local uri = api_ctx.var.uri
if local_conf.apisix and local_conf.apisix.delete_uri_tail_slash then
- local uri = api_ctx.var.uri
if str_byte(uri, #uri) == str_byte("/") then
api_ctx.var.uri = str_sub(api_ctx.var.uri, 1, #uri - 1)
core.log.info("remove the end of uri '/', current uri: ",
@@ -374,11 +374,15 @@ function _M.http_access_phase()
end
end
- local user_defined_route_matched = router.router_http.match(api_ctx)
- if not user_defined_route_matched then
- router.api.match(api_ctx)
+ if core.string.has_prefix(uri, "/apisix/") then
+ local matched = router.api.match(api_ctx)
+ if matched then
+ return
+ end
end
+ router.router_http.match(api_ctx)
+
local route = api_ctx.matched_route
if not route then
core.log.info("not find any matched route")
diff --git a/t/plugin/plugin.t b/t/plugin/plugin.t
index 9b502c2..367df8b 100644
--- a/t/plugin/plugin.t
+++ b/t/plugin/plugin.t
@@ -20,7 +20,10 @@ add_block_preprocessor(sub {
my ($block) = @_;
$block->set_value("no_error_log", "[error]");
- $block->set_value("request", "GET /t");
+
+ if (!defined $block->request) {
+ $block->set_value("request", "GET /t");
+ }
$block;
});
@@ -52,3 +55,107 @@ __DATA__
}
--- response_body
ok
+
+
+
+=== TEST 2: define route for /*
+--- 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": "jack",
+ "plugins": {
+ "jwt-auth": {
+ "key": "user-key",
+ "secret": "my-secret-key"
+ }
+ }
+ }]])
+
+ if code >= 300 then
+ ngx.status = code
+ ngx.say(body)
+ return
+ end
+
+ local code, body = t('/apisix/admin/routes/1',
+ ngx.HTTP_PUT,
+ [[{
+ "plugins": {
+ "jwt-auth": {}
+ },
+ "upstream": {
+ "nodes": {
+ "127.0.0.1:1980": 1
+ },
+ "type": "roundrobin"
+ },
+ "uri": "/*"
+ }]]
+ )
+
+ if code >= 300 then
+ ngx.status = code
+ end
+ ngx.say(body)
+ }
+ }
+--- response_body
+passed
+
+
+
+=== TEST 3: sign
+--- request
+GET /apisix/plugin/jwt/sign?key=user-key
+--- response_body_like eval
+qr/eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.\w+.\w+/
+
+
+
+=== TEST 4: delete /* and define route for /apisix/plugin/blah
+--- config
+ location /t {
+ content_by_lua_block {
+ local t = require("lib.test_admin").test
+ local code = t('/apisix/admin/routes/1', "DELETE")
+ if code >= 300 then
+ ngx.status = code
+ return
+ end
+ local code, body = t('/apisix/admin/routes/1',
+ ngx.HTTP_PUT,
+ [[{
+ "plugins": {
+ "jwt-auth": {}
+ },
+ "upstream": {
+ "nodes": {
+ "127.0.0.1:1980": 1
+ },
+ "type": "roundrobin"
+ },
+ "uri": "/apisix/plugin/blah"
+ }]]
+ )
+
+ if code >= 300 then
+ ngx.status = code
+ end
+ ngx.say(body)
+ }
+ }
+--- response_body
+passed
+
+
+
+=== TEST 5: hit
+--- request
+GET /apisix/plugin/blah
+--- error_code: 401
+--- response_body
+{"message":"Missing JWT token in request"}