2019-10-31 09:27:28 +08:00
|
|
|
#
|
|
|
|
# Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
|
# contributor license agreements. See the NOTICE file distributed with
|
|
|
|
# this work for additional information regarding copyright ownership.
|
|
|
|
# The ASF licenses this file to You under the Apache License, Version 2.0
|
|
|
|
# (the "License"); you may not use this file except in compliance with
|
|
|
|
# the License. You may obtain a copy of the License at
|
|
|
|
#
|
|
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
#
|
|
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
|
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
# See the License for the specific language governing permissions and
|
|
|
|
# limitations under the License.
|
|
|
|
#
|
2019-09-10 09:42:55 +08:00
|
|
|
use t::APISIX 'no_plan';
|
2019-06-19 15:51:28 +08:00
|
|
|
|
2019-08-02 21:36:30 +08:00
|
|
|
worker_connections(256);
|
2019-06-19 15:51:28 +08:00
|
|
|
no_root_location();
|
|
|
|
|
|
|
|
run_tests();
|
|
|
|
|
|
|
|
__DATA__
|
|
|
|
|
|
|
|
=== TEST 1: set service(id: 1)
|
|
|
|
--- 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,
|
|
|
|
[[{
|
|
|
|
"plugins": {
|
|
|
|
"limit-count": {
|
|
|
|
"count": 2,
|
|
|
|
"time_window": 60,
|
|
|
|
"rejected_code": 503,
|
|
|
|
"key": "remote_addr"
|
|
|
|
}
|
|
|
|
},
|
|
|
|
"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: set route (different upstream)
|
|
|
|
--- config
|
|
|
|
location /t {
|
|
|
|
content_by_lua_block {
|
|
|
|
ngx.sleep(0.2)
|
|
|
|
local t = require("lib.test_admin").test
|
|
|
|
local code, body = t('/apisix/admin/routes/1',
|
|
|
|
ngx.HTTP_PUT,
|
|
|
|
[[{
|
|
|
|
"upstream": {
|
|
|
|
"nodes": {
|
|
|
|
"127.0.0.1:1981": 1
|
|
|
|
},
|
|
|
|
"type": "roundrobin"
|
|
|
|
},
|
|
|
|
"uri": "/server_port",
|
|
|
|
"service_id": 1
|
|
|
|
}]]
|
|
|
|
)
|
|
|
|
|
|
|
|
if code >= 300 then
|
|
|
|
ngx.status = code
|
|
|
|
end
|
|
|
|
ngx.say(body)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
--- request
|
|
|
|
GET /t
|
|
|
|
--- response_body
|
|
|
|
passed
|
|
|
|
--- no_error_log
|
|
|
|
[error]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
=== TEST 3: /not_found
|
|
|
|
--- request
|
|
|
|
GET /not_found
|
|
|
|
--- error_code: 404
|
2020-01-03 10:11:37 +08:00
|
|
|
--- response_body
|
2020-10-06 11:48:52 +08:00
|
|
|
{"error_msg":"404 Route Not Found"}
|
2019-06-19 15:51:28 +08:00
|
|
|
--- no_error_log
|
|
|
|
[error]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
=== TEST 4: hit routes
|
|
|
|
--- request
|
|
|
|
GET /server_port
|
|
|
|
--- response_headers
|
|
|
|
X-RateLimit-Limit: 2
|
|
|
|
X-RateLimit-Remaining: 1
|
|
|
|
--- response_body eval
|
|
|
|
qr/1981/
|
|
|
|
--- no_error_log
|
|
|
|
[error]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
=== TEST 5: set route with empty plugins, should do nothing
|
|
|
|
--- config
|
|
|
|
location /t {
|
|
|
|
content_by_lua_block {
|
|
|
|
ngx.sleep(0.2)
|
|
|
|
local t = require("lib.test_admin").test
|
|
|
|
local code, body = t('/apisix/admin/routes/1',
|
|
|
|
ngx.HTTP_PUT,
|
|
|
|
[[{
|
|
|
|
"plugins": {},
|
|
|
|
"uri": "/server_port",
|
|
|
|
"service_id": 1
|
|
|
|
}]]
|
|
|
|
)
|
|
|
|
|
|
|
|
if code >= 300 then
|
|
|
|
ngx.status = code
|
|
|
|
end
|
|
|
|
ngx.say(body)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
--- request
|
|
|
|
GET /t
|
|
|
|
--- response_body
|
|
|
|
passed
|
|
|
|
--- no_error_log
|
|
|
|
[error]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
=== TEST 6: hit routes
|
|
|
|
--- request
|
|
|
|
GET /server_port
|
|
|
|
--- response_headers
|
|
|
|
X-RateLimit-Limit: 2
|
|
|
|
X-RateLimit-Remaining: 1
|
|
|
|
--- response_body eval
|
|
|
|
qr/1980/
|
|
|
|
--- no_error_log
|
|
|
|
[error]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
=== TEST 7: disable plugin `limit-count`
|
|
|
|
--- config
|
|
|
|
location /t {
|
|
|
|
content_by_lua_block {
|
|
|
|
ngx.sleep(0.2)
|
|
|
|
local t = require("lib.test_admin").test
|
|
|
|
local code, body = t('/apisix/admin/routes/1',
|
|
|
|
ngx.HTTP_PUT,
|
|
|
|
[[{
|
|
|
|
"plugins": {
|
|
|
|
"limit-count": {
|
2020-09-17 22:31:02 +08:00
|
|
|
"count": 2,
|
|
|
|
"time_window": 60,
|
|
|
|
"rejected_code": 503,
|
|
|
|
"key": "remote_addr",
|
2019-06-19 15:51:28 +08:00
|
|
|
"disable": true
|
|
|
|
}
|
|
|
|
},
|
|
|
|
"uri": "/server_port",
|
|
|
|
"service_id": 1
|
|
|
|
}]]
|
|
|
|
)
|
|
|
|
|
|
|
|
if code >= 300 then
|
|
|
|
ngx.status = code
|
|
|
|
end
|
|
|
|
ngx.say(body)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
--- request
|
|
|
|
GET /t
|
|
|
|
--- response_body
|
|
|
|
passed
|
|
|
|
--- no_error_log
|
|
|
|
[error]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
=== TEST 8: hit routes
|
|
|
|
--- request
|
|
|
|
GET /server_port
|
|
|
|
--- raw_response_headers_unlike eval
|
|
|
|
qr/X-RateLimit-Limit/
|
|
|
|
--- response_body eval
|
|
|
|
qr/1980/
|
|
|
|
--- no_error_log
|
|
|
|
[error]
|
2019-08-19 15:26:38 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
=== TEST 9: hit routes two times, checker service configuration
|
|
|
|
--- config
|
|
|
|
location /t {
|
|
|
|
content_by_lua_block {
|
|
|
|
ngx.sleep(0.2)
|
|
|
|
local t = require("lib.test_admin").test
|
|
|
|
local code, body = t('/server_port',
|
|
|
|
ngx.HTTP_GET
|
|
|
|
)
|
|
|
|
ngx.say(body)
|
|
|
|
|
|
|
|
code, body = t('/server_port',
|
|
|
|
ngx.HTTP_GET
|
|
|
|
)
|
|
|
|
ngx.say(body)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
--- request
|
|
|
|
GET /t
|
|
|
|
--- error_log eval
|
2019-10-08 13:15:48 +08:00
|
|
|
[qr/merge_service_route.*"time_window":60,/,
|
|
|
|
qr/merge_service_route.*"time_window":60,/]
|
2020-04-12 09:31:58 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
=== TEST 10: set service(only upstream with host)
|
|
|
|
--- 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,
|
|
|
|
[[{
|
|
|
|
"upstream": {
|
|
|
|
"type": "roundrobin",
|
|
|
|
"nodes": {
|
|
|
|
"httpbin.org:443": 1
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}]]
|
|
|
|
)
|
|
|
|
|
|
|
|
if code >= 300 then
|
|
|
|
ngx.status = code
|
|
|
|
end
|
|
|
|
ngx.say(body)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
--- request
|
|
|
|
GET /t
|
|
|
|
--- response_body
|
|
|
|
passed
|
|
|
|
--- no_error_log
|
|
|
|
[error]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
=== TEST 11: set route(bind service 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,
|
|
|
|
[[{
|
|
|
|
"uri": "/get",
|
|
|
|
"host": "httpbin.org",
|
|
|
|
"plugins": {
|
|
|
|
"proxy-rewrite": {
|
2020-08-30 22:43:28 +08:00
|
|
|
"scheme": "https"
|
2020-04-12 09:31:58 +08:00
|
|
|
}
|
|
|
|
},
|
|
|
|
"service_id": "1"
|
|
|
|
}]]
|
|
|
|
)
|
|
|
|
|
|
|
|
if code >= 300 then
|
|
|
|
ngx.status = code
|
|
|
|
end
|
|
|
|
ngx.say(body)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
--- request
|
|
|
|
GET /t
|
|
|
|
--- response_body
|
|
|
|
passed
|
|
|
|
--- no_error_log
|
|
|
|
[error]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
=== TEST 12: hit route
|
|
|
|
--- request
|
|
|
|
GET /get
|
|
|
|
--- more_headers
|
|
|
|
host: httpbin.org
|
|
|
|
--- response_body eval
|
|
|
|
qr/"Host": "httpbin.org"/
|
|
|
|
--- no_error_log
|
|
|
|
[error]
|
|
|
|
--- timeout: 5
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
=== TEST 13: not hit route
|
|
|
|
--- request
|
|
|
|
GET /get
|
|
|
|
--- more_headers
|
|
|
|
host: httpbin.orgxxx
|
|
|
|
--- error_code: 404
|
|
|
|
--- no_error_log
|
|
|
|
[error]
|