This is an automated email from the ASF dual-hosted git repository.

spacewander pushed a commit to branch release/2.15
in repository https://gitbox.apache.org/repos/asf/apisix.git

commit e9a24d721b62977e35836fc2b300d699048ca239
Author: tzssangglass <[email protected]>
AuthorDate: Thu Dec 8 15:24:10 2022 +0800

    fix: the plugins bound on the service use the latest configuration (#8482)
    
    Fixes https://github.com/apache/apisix/issues/8481
    
    Signed-off-by: spacewander <[email protected]>
---
 apisix/plugin.lua        |   2 +-
 t/node/consumer-plugin.t | 114 +++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 115 insertions(+), 1 deletion(-)

diff --git a/apisix/plugin.lua b/apisix/plugin.lua
index 0f7845fe0..f35f55ec2 100644
--- a/apisix/plugin.lua
+++ b/apisix/plugin.lua
@@ -658,7 +658,7 @@ function _M.merge_consumer_route(route_conf, consumer_conf, 
api_ctx)
 
     local flag = route_conf.value.id .. "#" .. route_conf.modifiedIndex
                  .. "#" .. consumer_conf.id .. "#" .. 
consumer_conf.modifiedIndex
-    local new_conf = merged_route(flag, nil,
+    local new_conf = merged_route(flag, api_ctx.conf_version,
                         merge_consumer_route, route_conf, consumer_conf)
 
     api_ctx.conf_type = api_ctx.conf_type .. "&consumer"
diff --git a/t/node/consumer-plugin.t b/t/node/consumer-plugin.t
index 1007bed13..81f1b07cc 100644
--- a/t/node/consumer-plugin.t
+++ b/t/node/consumer-plugin.t
@@ -407,3 +407,117 @@ passed
 [error]
 --- 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

Reply via email to