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

shreemaanabhishek 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 a0b1a4554 fix(body-transformer): add nil check to conf (#11768)
a0b1a4554 is described below

commit a0b1a4554dc9ce23e877cc1fc58507c795203878
Author: Shreemaan Abhishek <[email protected]>
AuthorDate: Mon Nov 25 20:24:42 2024 +0545

    fix(body-transformer): add nil check to conf (#11768)
---
 apisix/plugins/body-transformer.lua |  3 +++
 t/plugin/body-transformer2.t        | 45 +++++++++++++++++++++++++++++++++++++
 2 files changed, 48 insertions(+)

diff --git a/apisix/plugins/body-transformer.lua 
b/apisix/plugins/body-transformer.lua
index f63381e01..f9d5400e4 100644
--- a/apisix/plugins/body-transformer.lua
+++ b/apisix/plugins/body-transformer.lua
@@ -219,6 +219,9 @@ end
 
 function _M.body_filter(_, ctx)
     local conf = ctx.body_transformer_conf
+    if not conf then
+        return
+    end
     if conf.response then
         local body = core.response.hold_body_chunk(ctx)
         if ngx.arg[2] == false and not body then
diff --git a/t/plugin/body-transformer2.t b/t/plugin/body-transformer2.t
index 748b1fd1f..1db206cce 100644
--- a/t/plugin/body-transformer2.t
+++ b/t/plugin/body-transformer2.t
@@ -87,3 +87,48 @@ POST /echo
 {"name": "foo", "address":"LA", "age": 18}
 -- response_body
 {"name": "bar", "age": 19}
+
+
+
+=== TEST 3: body transformer plugin with key-auth that fails
+--- config
+    location /t {
+        content_by_lua_block {
+            local t = require("lib.test_admin")
+            local core = require("apisix.core")
+            local code, body = t.test('/apisix/admin/routes/1',
+                ngx.HTTP_PUT,
+                [[{
+                    "uri": "/foobar",
+                    "plugins": {
+                        "body-transformer": {
+                            "request": {
+                                "template": "some-template"
+                            }
+                        },
+                        "key-auth": {}
+                    },
+                    "upstream": {
+                        "type": "roundrobin",
+                        "nodes": {
+                            "127.0.0.1:1980": 1
+                        }
+                    }
+                }]]
+            )
+            if code >= 300 then
+                ngx.status = code
+                return
+            end
+            ngx.sleep(0.5)
+            local http = require("resty.http")
+            local uri = "http://127.0.0.1:"; .. ngx.var.server_port .. "/foobar"
+            local opt = {method = "POST", body = "body", headers = 
{["Content-Type"] = "application/json"}}
+            local httpc = http.new()
+            local res = httpc:request_uri(uri, opt)
+            assert(res.status == 401)
+            ngx.say(res.reason)
+        }
+    }
+--- response_body
+Unauthorized

Reply via email to