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: the plugins bound on the service use the latest configuration #8482

Merged
merged 1 commit into from
Dec 8, 2022
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion apisix/plugin.lua
Original file line number Diff line number Diff line change
Expand Up @@ -688,7 +688,7 @@ function _M.merge_consumer_route(route_conf, consumer_conf, consumer_group_conf,
.. "#" .. consumer_group_conf.modifiedIndex
end

local new_conf = merged_route(flag, nil,
local new_conf = merged_route(flag, api_ctx.conf_version,
merge_consumer_route, route_conf, consumer_conf, consumer_group_conf)

api_ctx.conf_type = api_ctx.conf_type .. "&consumer"
Expand Down
114 changes: 114 additions & 0 deletions t/node/consumer-plugin.t
Original file line number Diff line number Diff line change
Expand Up @@ -385,3 +385,117 @@ GET /t
passed
--- error_log
find consumer John_Doe



=== TEST 12: the plugins bound on the service should use the latest configuration
--- 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": {
"key-auth": {
"key": "auth-jack"
}
}
}]]
)
if code >= 300 then
ngx.status = code
ngx.say(body)
return
end

local code, body = t('/apisix/admin/services/1',
ngx.HTTP_PUT,
[[{
"plugins": {
"key-auth": {
"header": "Authorization"
},
"proxy-rewrite": {
"uri": "/hello1"
}
}
}]]
)
if code >= 300 then
ngx.status = code
ngx.say(body)
return
end

local code, body = t('/apisix/admin/routes/1',
ngx.HTTP_PUT,
[[{
"methods": [
"GET"
],
"uri": "/hello",
"service_id": "1",
"upstream": {
"nodes": {
"127.0.0.1:1980": 1
},
"type": "roundrobin"
}
}]]
)
if code >= 300 then
ngx.status = code
ngx.say(body)
return
end

local http = require "resty.http"
local uri = "http://127.0.0.1:" .. ngx.var.server_port .. "/hello"
local httpc = http.new()
local headers = {
["Authorization"] = "auth-jack"
}
local res, err = httpc:request_uri(uri, {headers = headers})
assert(res.status == 200)
if not res then
ngx.log(ngx.ERR, err)
return
end
ngx.print(res.body)

local code, body = t('/apisix/admin/services/1',
ngx.HTTP_PUT,
[[{
"plugins": {
"key-auth": {
"header": "Authorization"
},
"proxy-rewrite": {
"uri": "/server_port"
}
}
}]]
)
if code >= 300 then
ngx.status = code
ngx.say(body)
return
end
ngx.sleep(0.1)

local res, err = httpc:request_uri(uri, {headers = headers})
assert(res.status == 200)
if not res then
ngx.log(ngx.ERR, err)
return
end
ngx.say(res.body)
}
}
--- request
GET /t
--- response_body
hello1 world
1980