mirror of
https://gitee.com/iresty/apisix.git
synced 2024-12-15 01:11:58 +08:00
fix: user's route was prior to the plugin's one (#2733)
This commit is contained in:
parent
91d99452c5
commit
23a47b9eac
@ -365,8 +365,8 @@ function _M.http_access_phase()
|
|||||||
api_ctx.global_rules = router.global_rules
|
api_ctx.global_rules = router.global_rules
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local uri = api_ctx.var.uri
|
||||||
if local_conf.apisix and local_conf.apisix.delete_uri_tail_slash then
|
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
|
if str_byte(uri, #uri) == str_byte("/") then
|
||||||
api_ctx.var.uri = str_sub(api_ctx.var.uri, 1, #uri - 1)
|
api_ctx.var.uri = str_sub(api_ctx.var.uri, 1, #uri - 1)
|
||||||
core.log.info("remove the end of uri '/', current uri: ",
|
core.log.info("remove the end of uri '/', current uri: ",
|
||||||
@ -374,11 +374,15 @@ function _M.http_access_phase()
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local user_defined_route_matched = router.router_http.match(api_ctx)
|
if core.string.has_prefix(uri, "/apisix/") then
|
||||||
if not user_defined_route_matched then
|
local matched = router.api.match(api_ctx)
|
||||||
router.api.match(api_ctx)
|
if matched then
|
||||||
|
return
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
router.router_http.match(api_ctx)
|
||||||
|
|
||||||
local route = api_ctx.matched_route
|
local route = api_ctx.matched_route
|
||||||
if not route then
|
if not route then
|
||||||
core.log.info("not find any matched route")
|
core.log.info("not find any matched route")
|
||||||
|
@ -20,7 +20,10 @@ add_block_preprocessor(sub {
|
|||||||
my ($block) = @_;
|
my ($block) = @_;
|
||||||
|
|
||||||
$block->set_value("no_error_log", "[error]");
|
$block->set_value("no_error_log", "[error]");
|
||||||
$block->set_value("request", "GET /t");
|
|
||||||
|
if (!defined $block->request) {
|
||||||
|
$block->set_value("request", "GET /t");
|
||||||
|
}
|
||||||
|
|
||||||
$block;
|
$block;
|
||||||
});
|
});
|
||||||
@ -52,3 +55,107 @@ __DATA__
|
|||||||
}
|
}
|
||||||
--- response_body
|
--- response_body
|
||||||
ok
|
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"}
|
||||||
|
Loading…
Reference in New Issue
Block a user