Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

fix: auth plugin repeats the rewrite phase #7531

Merged
merged 6 commits into from
Jul 27, 2022
Merged
Show file tree
Hide file tree
Changes from 4 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: 10 additions & 5 deletions apisix/plugin.lua
Original file line number Diff line number Diff line change
Expand Up @@ -881,16 +881,21 @@ function _M.run_plugin(phase, plugins, api_ctx)
and phase ~= "delayed_body_filter"
then
for i = 1, #plugins, 2 do
if phase == "rewrite_in_consumer" and plugins[i + 1]._from_consumer
and plugins[i].type ~= "auth"then
phase = "rewrite"
local phase_func
if phase == "rewrite_in_consumer" then
if plugins[i].type == "auth" then
plugins[i + 1]._skip_rewrite_in_consumer = true
end
phase_func = plugins[i]["rewrite"]
else
phase_func = plugins[i][phase]
end
local phase_func = plugins[i][phase]

if phase == "rewrite" and plugins[i + 1]._skip_rewrite_in_consumer then
if phase == "rewrite_in_consumer" and plugins[i + 1]._skip_rewrite_in_consumer then
goto CONTINUE
end

ngx.log(ngx.WARN, "phase_func : ", require("inspect")(phase_func))
tzssangglass marked this conversation as resolved.
Show resolved Hide resolved
if phase_func then
plugin_run = true
local conf = plugins[i + 1]
Expand Down
60 changes: 60 additions & 0 deletions t/node/consumer-plugin2.t
Original file line number Diff line number Diff line change
Expand Up @@ -238,3 +238,63 @@ x-real-ip: 127.0.0.1
}
--- response_body
{"key-auth":true,"proxy-rewrite":true}



=== TEST 7: configure non-auth plugins in the consumer and run it's rewrite phase
--- config
location /t {
content_by_lua_block {
local t = require("lib.test_admin").test
local code, body = t('/apisix/admin/consumers/jack',
ngx.HTTP_PUT,
[[{
"username": "jack",
"plugins": {
"key-auth": {
"key": "auth-jack"
},
"ip-restriction": {
"blacklist": [
"127.0.0.0/24"
]
}
}
}]]
)

bzp2010 marked this conversation as resolved.
Show resolved Hide resolved
local code, body = t('/apisix/admin/routes/1',
ngx.HTTP_PUT,
[[{
"plugins": {
"key-auth": {}
},
"upstream": {
"nodes": {
"127.0.0.1:1980": 1
},
"type": "roundrobin"
},
"uri": "/hello"
}]]
)

if code >= 300 then
ngx.status = code
end
ngx.say(body)
}
}
--- response_body
passed



=== TEST 8: hit routes and ip-restriction work well
--- request
GET /hello
--- more_headers
apikey: auth-jack
--- error_code: 403
--- response_body
{"message":"Your IP address is not allowed"}