tzssangglass opened a new issue #3663:
URL: https://github.com/apache/apisix/issues/3663


   ### Issue description
   I used the script, but the script did not execute, see the following test 
case
   ```
   use t::APISIX 'no_plan';
   
   repeat_each(1);
   log_level('info');
   no_long_string();
   no_root_location();
   
   run_tests;
   
   __DATA__
   
   === TEST 1: add services
   --- config
       location /t {
           content_by_lua_block {
               local t = require("lib.test_admin").test
               local code, body = t('/apisix/admin/services/1',
                    ngx.HTTP_PUT,
                    [[{
                       "name": "script_test",
                       "upstream": {
                           "nodes": {
                               "127.0.0.1:1980": 1
                           },
                           "type": "roundrobin"
                       }
                   }]]
                   )
   
               if code >= 300 then
                   ngx.status = code
               end
               ngx.say(body)
           }
       }
   --- request
   GET /t
   --- response_body
   passed
   --- no_error_log
   [error]
   
   
   
   === TEST 2: route binding service and route has script
   --- config
       location /t {
           content_by_lua_block {
               local t = require("lib.test_admin").test
               local code, body = t('/apisix/admin/routes/1',
                    ngx.HTTP_PUT,
                    [[{
                       "service_id": 1,
                       "script": "local _M = {} \n function _M.access(api_ctx) 
\n ngx.log(ngx.INFO,\"hit access phase\") \n end \nreturn _M",
                       "uri": "/hello"
                   }]]
                   )
   
               if code >= 300 then
                   ngx.status = code
               end
               ngx.say(body)
           }
       }
   --- request
   GET /t
   --- response_body
   passed
   --- no_error_log
   [error]
   
   
   
   === TEST 3: hit route and trigger script
   --- request
   GET /hello
   --- response_body
   hello world
   --- error_log eval
   qr/loaded script_obj: \{"access":"function: 0x[\w]+"\}/
   
   ```
   
   based on the documentation for the script, I think the script should be 
executed because it is bound to the route and neither the route nor the service 
has plugins configured
   
   bugs may appear in 
https://github.com/apache/apisix/blob/16f017dfedebf8bf85ff8be9d48c05d088d21d0e/apisix/plugin.lua#L385
   
   maybe this function should be preceded by code like this before return
   
   ```
       if route_conf.value.script then
           new_conf.value.script = route_conf.value.script
       end
   ```
   
   ### Environment
   
   * apisix version (cmd: `apisix version`): greater than 2.2, less than 2.3
   * OS (cmd: `uname -a`): Centos 7
   * OpenResty / Nginx version (cmd: `nginx -V` or `openresty -V`): 
openresty/1.19.3.1
   * etcd version, if have (cmd: run `curl 
http://127.0.0.1:9090/v1/server_info` to get the info from server-info API): 
{"etcdserver":"3.4.13","etcdcluster":"3.4.0"}
   * apisix-dashboard version, if have:
   
   ### Minimal test code / Steps to reproduce the issue
   
   1.
   2.
   3.
   
   ### What's the actual result? (including assertion message & call stack if 
applicable)
   
   ### What's the expected result?
   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


Reply via email to