Skip to content

bug: script does not work #3663

Description

@tzssangglass

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

local function merge_service_route(service_conf, route_conf)

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

What's the actual result? (including assertion message & call stack if applicable)

What's the expected result?

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions