mirror of
https://gitee.com/iresty/apisix.git
synced 2024-12-15 09:21:26 +08:00
238 lines
5.6 KiB
Perl
238 lines
5.6 KiB
Perl
|
BEGIN {
|
||
|
if ($ENV{TEST_NGINX_CHECK_LEAK}) {
|
||
|
$SkipReason = "unavailable for the hup tests";
|
||
|
|
||
|
} else {
|
||
|
$ENV{TEST_NGINX_USE_HUP} = 1;
|
||
|
undef $ENV{TEST_NGINX_USE_STAP};
|
||
|
}
|
||
|
}
|
||
|
|
||
|
use t::APISIX 'no_plan';
|
||
|
|
||
|
repeat_each(1);
|
||
|
no_long_string();
|
||
|
no_shuffle();
|
||
|
no_root_location();
|
||
|
run_tests;
|
||
|
|
||
|
__DATA__
|
||
|
|
||
|
=== TEST 1: sanity
|
||
|
--- config
|
||
|
location /t {
|
||
|
content_by_lua_block {
|
||
|
local plugin = require("apisix.plugins.proxy-rewrite")
|
||
|
local ok, err = plugin.check_schema({
|
||
|
uri = '/apisix/home',
|
||
|
host = 'apisix.iresty.com',
|
||
|
enable_websocket = true,
|
||
|
scheme = 'http'
|
||
|
})
|
||
|
if not ok then
|
||
|
ngx.say(err)
|
||
|
end
|
||
|
|
||
|
ngx.say("done")
|
||
|
}
|
||
|
}
|
||
|
--- request
|
||
|
GET /t
|
||
|
--- response_body
|
||
|
done
|
||
|
--- no_error_log
|
||
|
[error]
|
||
|
|
||
|
|
||
|
=== TEST 2: wrong value of key
|
||
|
--- config
|
||
|
location /t {
|
||
|
content_by_lua_block {
|
||
|
local plugin = require("apisix.plugins.proxy-rewrite")
|
||
|
local ok, err = plugin.check_schema({
|
||
|
uri = '/apisix/home',
|
||
|
host = 'apisix.iresty.com',
|
||
|
enable_websocket = true,
|
||
|
scheme = 'tcp'
|
||
|
})
|
||
|
if not ok then
|
||
|
ngx.say(err)
|
||
|
end
|
||
|
|
||
|
ngx.say("done")
|
||
|
}
|
||
|
}
|
||
|
--- request
|
||
|
GET /t
|
||
|
--- response_body
|
||
|
invalid "enum" in docuement at pointer "#/scheme"
|
||
|
done
|
||
|
--- no_error_log
|
||
|
[error]
|
||
|
|
||
|
|
||
|
=== TEST 3: add plugin
|
||
|
--- 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,
|
||
|
[[{
|
||
|
"plugins": {
|
||
|
"proxy-rewrite": {
|
||
|
"uri": "/test/add",
|
||
|
"scheme": "https",
|
||
|
"host": "apisix.iresty.com",
|
||
|
"enable_websocket": true
|
||
|
}
|
||
|
},
|
||
|
"upstream": {
|
||
|
"nodes": {
|
||
|
"127.0.0.1:1980": 1
|
||
|
},
|
||
|
"type": "roundrobin"
|
||
|
},
|
||
|
"uri": "/hello"
|
||
|
}]]
|
||
|
)
|
||
|
|
||
|
if code >= 300 then
|
||
|
ngx.status = code
|
||
|
end
|
||
|
ngx.say(body)
|
||
|
}
|
||
|
}
|
||
|
--- request
|
||
|
GET /t
|
||
|
--- response_body
|
||
|
passed
|
||
|
--- no_error_log
|
||
|
[error]
|
||
|
|
||
|
|
||
|
=== TEST 4: update plugin
|
||
|
--- 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,
|
||
|
[[{
|
||
|
"plugins": {
|
||
|
"proxy-rewrite": {
|
||
|
"uri": "/test/update",
|
||
|
"scheme": "http",
|
||
|
"host": "apisix.iresty.com",
|
||
|
"enable_websocket": false
|
||
|
}
|
||
|
},
|
||
|
"upstream": {
|
||
|
"nodes": {
|
||
|
"127.0.0.1:1980": 1
|
||
|
},
|
||
|
"type": "roundrobin"
|
||
|
},
|
||
|
"uri": "/hello"
|
||
|
}]]
|
||
|
)
|
||
|
|
||
|
if code >= 300 then
|
||
|
ngx.status = code
|
||
|
end
|
||
|
ngx.say(body)
|
||
|
}
|
||
|
}
|
||
|
--- request
|
||
|
GET /t
|
||
|
--- response_body
|
||
|
passed
|
||
|
--- no_error_log
|
||
|
[error]
|
||
|
|
||
|
|
||
|
=== TEST 5: disable plugin
|
||
|
--- 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,
|
||
|
[[{
|
||
|
"plugins": {
|
||
|
},
|
||
|
"upstream": {
|
||
|
"nodes": {
|
||
|
"127.0.0.1:1980": 1
|
||
|
},
|
||
|
"type": "roundrobin"
|
||
|
},
|
||
|
"uri": "/hello"
|
||
|
}]]
|
||
|
)
|
||
|
|
||
|
if code >= 300 then
|
||
|
ngx.status = code
|
||
|
end
|
||
|
ngx.say(body)
|
||
|
}
|
||
|
}
|
||
|
--- request
|
||
|
GET /t
|
||
|
--- response_body
|
||
|
passed
|
||
|
--- no_error_log
|
||
|
[error]
|
||
|
|
||
|
|
||
|
=== TEST 6: set route(id: 1)
|
||
|
--- 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,
|
||
|
[[{
|
||
|
"methods": ["GET"],
|
||
|
"plugins": {
|
||
|
"proxy-rewrite": {
|
||
|
"uri": "/plugin_proxy_rewrite",
|
||
|
"scheme": "http",
|
||
|
"host": "apisix.iresty.com",
|
||
|
"enable_websocket": true
|
||
|
}
|
||
|
},
|
||
|
"upstream": {
|
||
|
"nodes": {
|
||
|
"127.0.0.1:1980": 1
|
||
|
},
|
||
|
"type": "roundrobin"
|
||
|
},
|
||
|
"uri": "/hello"
|
||
|
}]]
|
||
|
)
|
||
|
|
||
|
if code >= 300 then
|
||
|
ngx.status = code
|
||
|
end
|
||
|
ngx.say(body)
|
||
|
}
|
||
|
}
|
||
|
--- request
|
||
|
GET /t
|
||
|
--- response_body
|
||
|
passed
|
||
|
--- no_error_log
|
||
|
[error]
|
||
|
|
||
|
|
||
|
=== TEST 7: rewrite
|
||
|
--- request
|
||
|
GET /hello HTTP/1.1
|
||
|
--- response_body
|
||
|
uri: /plugin_proxy_rewrite
|
||
|
host: apisix.iresty.com
|
||
|
scheme: http
|
||
|
--- no_error_log
|
||
|
[error]
|