You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@apisix.apache.org by sp...@apache.org on 2020/12/09 00:53:46 UTC
[apisix] branch master updated: feat: delete useless data in the
response (#2993)
This is an automated email from the ASF dual-hosted git repository.
spacewander 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 1e882e3 feat: delete useless data in the response (#2993)
1e882e3 is described below
commit 1e882e378d4c0e62b904589fbdab0c4be173e60f
Author: 罗泽轩 <sp...@gmail.com>
AuthorDate: Wed Dec 9 08:53:38 2020 +0800
feat: delete useless data in the response (#2993)
Fix #2759
Signed-off-by: spacewander <sp...@gmail.com>
---
apisix/admin/init.lua | 26 ++++
t/admin/consumers2.t | 124 ++++++++++++++++
t/admin/global-rules.t | 136 ++++++++++++++++++
t/admin/plugin-metadata.t | 95 +++++++++++++
t/admin/routes.t | 141 -------------------
t/admin/routes2.t | 351 ++++++++++++++++++++++++++++++++++++++++++++++
t/admin/services2.t | 195 ++++++++++++++++++++++++++
t/admin/ssl2.t | 198 ++++++++++++++++++++++++++
t/admin/stream-routes.t | 153 ++++++++++++++++++++
t/admin/upstream2.t | 191 +++++++++++++++++++++++++
10 files changed, 1469 insertions(+), 141 deletions(-)
diff --git a/apisix/admin/init.lua b/apisix/admin/init.lua
index 7ac2b85..b5a20af 100644
--- a/apisix/admin/init.lua
+++ b/apisix/admin/init.lua
@@ -28,6 +28,9 @@ local str_lower = string.lower
local reload_event = "/apisix/admin/plugins/reload"
local ipairs = ipairs
local error = error
+local type = type
+
+
local events
local MAX_REQ_BODY = 1024 * 1024 * 1.5 -- 1.5 MiB
@@ -90,6 +93,27 @@ local function check_token(ctx)
end
+local function strip_etcd_resp(data)
+ if type(data) == "table"
+ and data.header ~= nil
+ and data.header.revision ~= nil
+ and data.header.raft_term ~= nil
+ then
+ -- strip etcd data
+ data.header = nil
+ data.responses = nil
+ data.succeeded = nil
+
+ if data.node then
+ data.node.createdIndex = nil
+ data.node.modifiedIndex = nil
+ end
+ end
+
+ return data
+end
+
+
local function run()
local api_ctx = {}
core.ctx.set_vars_meta(api_ctx)
@@ -150,6 +174,7 @@ local function run()
local code, data = resource[method](seg_id, req_body, seg_sub_path,
uri_args)
if code then
+ data = strip_etcd_resp(data)
core.response.exit(code, data)
end
end
@@ -219,6 +244,7 @@ local function run_stream()
local code, data = resource[method](seg_id, req_body, seg_sub_path,
uri_args)
if code then
+ data = strip_etcd_resp(data)
core.response.exit(code, data)
end
end
diff --git a/t/admin/consumers2.t b/t/admin/consumers2.t
new file mode 100644
index 0000000..455b3fc
--- /dev/null
+++ b/t/admin/consumers2.t
@@ -0,0 +1,124 @@
+#
+# 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.
+#
+use t::APISIX 'no_plan';
+
+repeat_each(1);
+no_long_string();
+no_root_location();
+no_shuffle();
+log_level("info");
+
+add_block_preprocessor(sub {
+ my ($block) = @_;
+
+ if (!$block->request) {
+ $block->set_value("request", "GET /t");
+ }
+
+ if (!$block->no_error_log) {
+ $block->set_value("no_error_log", "[error]\n[alert]");
+ }
+});
+
+run_tests;
+
+__DATA__
+
+=== TEST 1: not unwanted data, PUT
+--- config
+ location /t {
+ content_by_lua_block {
+ local json = require("toolkit.json")
+ local t = require("lib.test_admin").test
+
+ local code, message, res = t('/apisix/admin/consumers',
+ ngx.HTTP_PUT,
+ [[{
+ "username":"jack"
+ }]]
+ )
+
+ if code >= 300 then
+ ngx.status = code
+ ngx.say(message)
+ return
+ end
+
+ res = json.decode(res)
+ res.node.value.create_time = nil
+ res.node.value.update_time = nil
+ ngx.say(json.encode(res))
+ }
+ }
+--- response_body
+{"action":"set","node":{"key":"/apisix/consumers/jack","value":{"username":"jack"}}}
+
+
+
+
+=== TEST 2: not unwanted data, GET
+--- config
+ location /t {
+ content_by_lua_block {
+ local json = require("toolkit.json")
+ local t = require("lib.test_admin").test
+
+ local code, message, res = t('/apisix/admin/consumers/jack',
+ ngx.HTTP_GET
+ )
+
+ if code >= 300 then
+ ngx.status = code
+ ngx.say(message)
+ return
+ end
+
+ res = json.decode(res)
+ res.node.value.create_time = nil
+ res.node.value.update_time = nil
+ ngx.say(json.encode(res))
+ }
+ }
+--- response_body
+{"action":"get","count":"1","node":{"key":"/apisix/consumers/jack","value":{"username":"jack"}}}
+
+
+
+
+=== TEST 3: not unwanted data, DELETE
+--- config
+ location /t {
+ content_by_lua_block {
+ local json = require("toolkit.json")
+ local t = require("lib.test_admin").test
+
+ local code, message, res = t('/apisix/admin/consumers/jack',
+ ngx.HTTP_DELETE
+ )
+
+ if code >= 300 then
+ ngx.status = code
+ ngx.say(message)
+ return
+ end
+
+ res = json.decode(res)
+ ngx.say(json.encode(res))
+ }
+ }
+--- response_body
+{"action":"delete","deleted":"1","key":"/apisix/consumers/jack","node":{}}
diff --git a/t/admin/global-rules.t b/t/admin/global-rules.t
index 8b98cff..ee5c4a9 100644
--- a/t/admin/global-rules.t
+++ b/t/admin/global-rules.t
@@ -411,3 +411,139 @@ GET /t
passed
--- no_error_log
[error]
+
+
+
+=== TEST 12: not unwanted data, PUT
+--- config
+ location /t {
+ content_by_lua_block {
+ local json = require("toolkit.json")
+ local t = require("lib.test_admin").test
+ local code, message, res = t('/apisix/admin/global_rules/1',
+ ngx.HTTP_PUT,
+ [[{
+ "plugins": {
+ "proxy-rewrite": {
+ "uri": "/"
+ }
+ }
+ }]]
+ )
+
+ if code >= 300 then
+ ngx.status = code
+ ngx.say(message)
+ return
+ end
+
+ res = json.decode(res)
+ res.node.value.create_time = nil
+ res.node.value.update_time = nil
+ ngx.say(json.encode(res))
+ }
+ }
+--- response_body
+{"action":"set","node":{"key":"/apisix/global_rules/1","value":{"id":"1","plugins":{"proxy-rewrite":{"uri":"/"}}}}}
+--- request
+GET /t
+--- no_error_log
+[error]
+
+
+
+=== TEST 13: not unwanted data, PATCH
+--- config
+ location /t {
+ content_by_lua_block {
+ local json = require("toolkit.json")
+ local t = require("lib.test_admin").test
+ local code, message, res = t('/apisix/admin/global_rules/1',
+ ngx.HTTP_PATCH,
+ [[{
+ "plugins": {
+ "proxy-rewrite": {
+ "uri": "/"
+ }
+ }
+ }]]
+ )
+
+ if code >= 300 then
+ ngx.status = code
+ ngx.say(message)
+ return
+ end
+
+ res = json.decode(res)
+ res.node.value.create_time = nil
+ res.node.value.update_time = nil
+ ngx.say(json.encode(res))
+ }
+ }
+--- response_body
+{"action":"compareAndSwap","node":{"key":"/apisix/global_rules/1","value":{"id":"1","plugins":{"proxy-rewrite":{"uri":"/"}}}}}
+--- request
+GET /t
+--- no_error_log
+[error]
+
+
+
+=== TEST 14: not unwanted data, GET
+--- config
+ location /t {
+ content_by_lua_block {
+ local json = require("toolkit.json")
+ local t = require("lib.test_admin").test
+ local code, message, res = t('/apisix/admin/global_rules/1',
+ ngx.HTTP_GET
+ )
+
+ if code >= 300 then
+ ngx.status = code
+ ngx.say(message)
+ return
+ end
+
+ res = json.decode(res)
+ res.node.value.create_time = nil
+ res.node.value.update_time = nil
+ ngx.say(json.encode(res))
+ }
+ }
+--- response_body
+{"action":"get","count":"1","node":{"key":"/apisix/global_rules/1","value":{"id":"1","plugins":{"proxy-rewrite":{"uri":"/"}}}}}
+--- request
+GET /t
+--- no_error_log
+[error]
+
+
+
+=== TEST 15: not unwanted data, DELETE
+--- config
+ location /t {
+ content_by_lua_block {
+ local json = require("toolkit.json")
+ local t = require("lib.test_admin").test
+ local code, message, res = t('/apisix/admin/global_rules/1',
+ ngx.HTTP_DELETE
+ )
+
+ if code >= 300 then
+ ngx.status = code
+ ngx.say(message)
+ return
+ end
+
+ res = json.decode(res)
+ ngx.say(json.encode(res))
+ }
+ }
+--- response_body
+{"action":"delete","deleted":"1","key":"/apisix/global_rules/1","node":{}}
+--- request
+GET /t
+--- no_error_log
+[error]
diff --git a/t/admin/plugin-metadata.t b/t/admin/plugin-metadata.t
index 834daea..5d3278f 100644
--- a/t/admin/plugin-metadata.t
+++ b/t/admin/plugin-metadata.t
@@ -474,3 +474,98 @@ GET /t
qr/\{"error_msg":"invalid configuration: property \\"interceptors\\" validation failed: failed to validate item 1: failed to validate dependent schema for \\"name\\": value should match only one schema, but matches none"\}/
--- no_error_log
[error]
+
+
+
+=== TEST 16: not unwanted data, PUT
+--- config
+ location /t {
+ content_by_lua_block {
+ local json = require("toolkit.json")
+ local t = require("lib.test_admin").test
+ local code, message, res = t('/apisix/admin/plugin_metadata/example-plugin',
+ ngx.HTTP_PUT,
+ [[{
+ "skey": "val",
+ "ikey": 1
+ }]]
+ )
+
+ if code >= 300 then
+ ngx.status = code
+ ngx.say(message)
+ return
+ end
+
+ res = json.decode(res)
+ res.node.value.create_time = nil
+ res.node.value.update_time = nil
+ ngx.say(json.encode(res))
+ }
+ }
+--- response_body
+{"action":"set","node":{"key":"/apisix/plugin_metadata/example-plugin","value":{"ikey":1,"skey":"val"}}}
+--- request
+GET /t
+--- no_error_log
+[error]
+
+
+
+=== TEST 17: not unwanted data, GET
+--- config
+ location /t {
+ content_by_lua_block {
+ local json = require("toolkit.json")
+ local t = require("lib.test_admin").test
+ local code, message, res = t('/apisix/admin/plugin_metadata/example-plugin',
+ ngx.HTTP_GET
+ )
+
+ if code >= 300 then
+ ngx.status = code
+ ngx.say(message)
+ return
+ end
+
+ res = json.decode(res)
+ res.node.value.create_time = nil
+ res.node.value.update_time = nil
+ ngx.say(json.encode(res))
+ }
+ }
+--- response_body
+{"action":"get","count":"1","node":{"key":"/apisix/plugin_metadata/example-plugin","value":{"ikey":1,"skey":"val"}}}
+--- request
+GET /t
+--- no_error_log
+[error]
+
+
+
+=== TEST 18: not unwanted data, DELETE
+--- config
+ location /t {
+ content_by_lua_block {
+ local json = require("toolkit.json")
+ local t = require("lib.test_admin").test
+ local code, message, res = t('/apisix/admin/plugin_metadata/example-plugin',
+ ngx.HTTP_DELETE
+ )
+
+ if code >= 300 then
+ ngx.status = code
+ ngx.say(message)
+ return
+ end
+
+ res = json.decode(res)
+ ngx.say(json.encode(res))
+ }
+ }
+--- response_body
+{"action":"delete","deleted":"1","key":"/apisix/plugin_metadata/example-plugin","node":{}}
+--- request
+GET /t
+--- no_error_log
+[error]
diff --git a/t/admin/routes.t b/t/admin/routes.t
index f3b992d..202545f 100644
--- a/t/admin/routes.t
+++ b/t/admin/routes.t
@@ -2428,144 +2428,3 @@ GET /t
[delete] code: 200 message: passed
--- no_error_log
[error]
-
-
-
-=== TEST 65: invalid route: bad remote_addrs
---- 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"],
- "remote_addrs": [""],
- "upstream": {
- "nodes": {
- "127.0.0.1:8080": 1
- },
- "type": "roundrobin"
- },
- "desc": "new route",
- "uri": "/index.html"
- }]]
- )
-
- ngx.status = code
- ngx.print(body)
- }
- }
---- request
-GET /t
---- error_code: 400
---- response_body_like eval
-qr/property \\"remote_addrs\\" validation failed:/
---- no_error_log
-[error]
-
-
-
-=== TEST 66: invalid route: bad remote_addrs cidr
---- 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"],
- "remote_addrs": ["/16"],
- "upstream": {
- "nodes": {
- "127.0.0.1:8080": 1
- },
- "type": "roundrobin"
- },
- "desc": "new route",
- "uri": "/index.html"
- }]]
- )
-
- ngx.status = code
- ngx.print(body)
- }
- }
---- request
-GET /t
---- error_code: 400
---- response_body_like eval
-qr/property \\"remote_addrs\\" validation failed:/
---- no_error_log
-[error]
-
-
-
-=== TEST 67: valid route with remote_addrs
---- 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"],
- "remote_addrs": ["::1/16", "::1", "::", "1.1.1.1", "1.1.1.1/32"],
- "upstream": {
- "nodes": {
- "127.0.0.1:8080": 1
- },
- "type": "roundrobin"
- },
- "desc": "new route",
- "uri": "/index.html"
- }]]
- )
-
- if code >= 300 then
- ngx.status = code
- end
- ngx.say(body)
- }
- }
---- request
-GET /t
---- response_body
-passed
---- no_error_log
-[error]
-
-
-
-=== TEST 68: invalid route: bad vars operator
---- 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"],
- "vars": [["remote_addr", "=", "127.0.0.1"]],
- "upstream": {
- "nodes": {
- "127.0.0.1:8080": 1
- },
- "type": "roundrobin"
- },
- "desc": "new route",
- "uri": "/index.html"
- }]=]
- )
-
- ngx.status = code
- ngx.print(body)
- }
- }
---- request
-GET /t
---- error_code: 400
---- response_body
-{"error_msg":"failed to validate the 'vars' expression: invalid operator '='"}
---- no_error_log
-[error]
diff --git a/t/admin/routes2.t b/t/admin/routes2.t
new file mode 100644
index 0000000..20bc384
--- /dev/null
+++ b/t/admin/routes2.t
@@ -0,0 +1,351 @@
+#
+# 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.
+#
+use t::APISIX 'no_plan';
+
+repeat_each(1);
+no_long_string();
+no_root_location();
+no_shuffle();
+log_level("info");
+
+run_tests;
+
+__DATA__
+
+=== TEST 1: invalid route: bad remote_addrs
+--- 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"],
+ "remote_addrs": [""],
+ "upstream": {
+ "nodes": {
+ "127.0.0.1:8080": 1
+ },
+ "type": "roundrobin"
+ },
+ "desc": "new route",
+ "uri": "/index.html"
+ }]]
+ )
+
+ ngx.status = code
+ ngx.print(body)
+ }
+ }
+--- request
+GET /t
+--- error_code: 400
+--- response_body_like eval
+qr/property \\"remote_addrs\\" validation failed:/
+--- no_error_log
+[error]
+
+
+
+=== TEST 2: invalid route: bad remote_addrs cidr
+--- 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"],
+ "remote_addrs": ["/16"],
+ "upstream": {
+ "nodes": {
+ "127.0.0.1:8080": 1
+ },
+ "type": "roundrobin"
+ },
+ "desc": "new route",
+ "uri": "/index.html"
+ }]]
+ )
+
+ ngx.status = code
+ ngx.print(body)
+ }
+ }
+--- request
+GET /t
+--- error_code: 400
+--- response_body_like eval
+qr/property \\"remote_addrs\\" validation failed:/
+--- no_error_log
+[error]
+
+
+
+=== TEST 3: valid route with remote_addrs
+--- 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"],
+ "remote_addrs": ["::1/16", "::1", "::", "1.1.1.1", "1.1.1.1/32"],
+ "upstream": {
+ "nodes": {
+ "127.0.0.1:8080": 1
+ },
+ "type": "roundrobin"
+ },
+ "desc": "new route",
+ "uri": "/index.html"
+ }]]
+ )
+
+ if code >= 300 then
+ ngx.status = code
+ end
+ ngx.say(body)
+ }
+ }
+--- request
+GET /t
+--- response_body
+passed
+--- no_error_log
+[error]
+
+
+
+=== TEST 4: invalid route: bad vars operator
+--- 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"],
+ "vars": [["remote_addr", "=", "127.0.0.1"]],
+ "upstream": {
+ "nodes": {
+ "127.0.0.1:8080": 1
+ },
+ "type": "roundrobin"
+ },
+ "desc": "new route",
+ "uri": "/index.html"
+ }]=]
+ )
+
+ ngx.status = code
+ ngx.print(body)
+ }
+ }
+--- request
+GET /t
+--- error_code: 400
+--- response_body
+{"error_msg":"failed to validate the 'vars' expression: invalid operator '='"}
+--- no_error_log
+[error]
+
+
+
+=== TEST 5: not unwanted data, POST
+--- config
+ location /t {
+ content_by_lua_block {
+ local json = require("toolkit.json")
+ local t = require("lib.test_admin").test
+ local code, message, res = t('/apisix/admin/routes',
+ ngx.HTTP_POST,
+ [[{
+ "methods": ["GET"],
+ "upstream": {
+ "nodes": {
+ "127.0.0.1:8080": 1
+ },
+ "type": "roundrobin"
+ },
+ "uri": "/not_unwanted_data_post"
+ }]]
+ )
+
+ if code >= 300 then
+ ngx.status = code
+ ngx.say(message)
+ return
+ end
+
+ res = json.decode(res)
+ res.node.key = nil
+ res.node.value.create_time = nil
+ res.node.value.update_time = nil
+ ngx.say(json.encode(res))
+ }
+ }
+--- request
+GET /t
+--- response_body
+{"action":"create","node":{"value":{"methods":["GET"],"priority":0,"upstream":{"hash_on":"vars","nodes":{"127.0.0.1:8080":1},"pass_host":"pass","type":"roundrobin"},"uri":"/not_unwanted_data_post"}}}
+--- no_error_log
+[error]
+
+
+
+=== TEST 6: not unwanted data, PUT
+--- config
+ location /t {
+ content_by_lua_block {
+ local json = require("toolkit.json")
+ local t = require("lib.test_admin").test
+ local code, message, res = t('/apisix/admin/routes',
+ ngx.HTTP_PUT,
+ [[{
+ "id": 1,
+ "methods": ["GET"],
+ "upstream": {
+ "nodes": {
+ "127.0.0.1:8080": 1
+ },
+ "type": "roundrobin"
+ },
+ "uri": "/index.html"
+ }]]
+ )
+
+ if code >= 300 then
+ ngx.status = code
+ ngx.say(message)
+ return
+ end
+
+ res = json.decode(res)
+ res.node.value.create_time = nil
+ res.node.value.update_time = nil
+ ngx.say(json.encode(res))
+ }
+ }
+--- request
+GET /t
+--- response_body
+{"action":"set","node":{"key":"/apisix/routes/1","value":{"id":1,"methods":["GET"],"priority":0,"upstream":{"hash_on":"vars","nodes":{"127.0.0.1:8080":1},"pass_host":"pass","type":"roundrobin"},"uri":"/index.html"}}}
+--- no_error_log
+[error]
+
+
+
+=== TEST 7: not unwanted data, PATCH
+--- config
+ location /t {
+ content_by_lua_block {
+ local json = require("toolkit.json")
+ local t = require("lib.test_admin").test
+ local code, message, res = t('/apisix/admin/routes/1',
+ ngx.HTTP_PATCH,
+ [[{
+ "methods": ["GET"],
+ "upstream": {
+ "nodes": {
+ "127.0.0.1:8080": 1
+ },
+ "type": "roundrobin"
+ },
+ "uri": "/index"
+ }]]
+ )
+
+ if code >= 300 then
+ ngx.status = code
+ ngx.say(message)
+ return
+ end
+
+ res = json.decode(res)
+ res.node.value.create_time = nil
+ res.node.value.update_time = nil
+ ngx.say(json.encode(res))
+ }
+ }
+--- request
+GET /t
+--- response_body
+{"action":"compareAndSwap","node":{"key":"/apisix/routes/1","value":{"id":"1","methods":["GET"],"priority":0,"upstream":{"hash_on":"vars","nodes":{"127.0.0.1:8080":1},"pass_host":"pass","type":"roundrobin"},"uri":"/index"}}}
+--- no_error_log
+[error]
+
+
+
+=== TEST 8: not unwanted data, GET
+--- config
+ location /t {
+ content_by_lua_block {
+ local json = require("toolkit.json")
+ local t = require("lib.test_admin").test
+ local code, message, res = t('/apisix/admin/routes/1',
+ ngx.HTTP_GET
+ )
+
+ if code >= 300 then
+ ngx.status = code
+ ngx.say(message)
+ return
+ end
+
+ res = json.decode(res)
+ res.node.value.create_time = nil
+ res.node.value.update_time = nil
+ ngx.say(json.encode(res))
+ }
+ }
+--- request
+GET /t
+--- response_body
+{"action":"get","count":"1","node":{"key":"/apisix/routes/1","value":{"id":"1","methods":["GET"],"priority":0,"upstream":{"hash_on":"vars","nodes":{"127.0.0.1:8080":1},"pass_host":"pass","type":"roundrobin"},"uri":"/index"}}}
+--- no_error_log
+[error]
+
+
+
+=== TEST 9: not unwanted data, DELETE
+--- config
+ location /t {
+ content_by_lua_block {
+ local json = require("toolkit.json")
+ local t = require("lib.test_admin").test
+ local code, message, res = t('/apisix/admin/routes/1',
+ ngx.HTTP_DELETE
+ )
+
+ if code >= 300 then
+ ngx.status = code
+ ngx.say(message)
+ return
+ end
+
+ res = json.decode(res)
+ ngx.say(json.encode(res))
+ }
+ }
+--- request
+GET /t
+--- response_body
+{"action":"delete","deleted":"1","key":"/apisix/routes/1","node":{}}
+--- no_error_log
+[error]
diff --git a/t/admin/services2.t b/t/admin/services2.t
new file mode 100644
index 0000000..6af6a77
--- /dev/null
+++ b/t/admin/services2.t
@@ -0,0 +1,195 @@
+#
+# 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.
+#
+use t::APISIX 'no_plan';
+
+repeat_each(1);
+no_long_string();
+no_root_location();
+no_shuffle();
+log_level("info");
+
+add_block_preprocessor(sub {
+ my ($block) = @_;
+
+ if (!$block->request) {
+ $block->set_value("request", "GET /t");
+ }
+
+ if (!$block->no_error_log) {
+ $block->set_value("no_error_log", "[error]\n[alert]");
+ }
+});
+
+run_tests;
+
+__DATA__
+
+=== TEST 1: not unwanted data, POST
+--- config
+ location /t {
+ content_by_lua_block {
+ local json = require("toolkit.json")
+ local t = require("lib.test_admin").test
+ local code, message, res = t('/apisix/admin/services',
+ ngx.HTTP_POST,
+ [[{
+ "upstream": {
+ "nodes": {
+ "127.0.0.1:8080": 1
+ },
+ "type": "roundrobin"
+ }
+ }]]
+ )
+
+ if code >= 300 then
+ ngx.status = code
+ ngx.say(message)
+ return
+ end
+
+ res = json.decode(res)
+ res.node.key = nil
+ res.node.value.create_time = nil
+ res.node.value.update_time = nil
+ ngx.say(json.encode(res))
+ }
+ }
+--- response_body
+{"action":"create","node":{"value":{"upstream":{"hash_on":"vars","nodes":{"127.0.0.1:8080":1},"pass_host":"pass","type":"roundrobin"}}}}
+
+
+
+=== TEST 2: not unwanted data, PUT
+--- config
+ location /t {
+ content_by_lua_block {
+ local json = require("toolkit.json")
+ local t = require("lib.test_admin").test
+ local code, message, res = t('/apisix/admin/services/1',
+ ngx.HTTP_PUT,
+ [[{
+ "upstream": {
+ "nodes": {
+ "127.0.0.1:8080": 1
+ },
+ "type": "roundrobin"
+ }
+ }]]
+ )
+
+ if code >= 300 then
+ ngx.status = code
+ ngx.say(message)
+ return
+ end
+
+ res = json.decode(res)
+ res.node.value.create_time = nil
+ res.node.value.update_time = nil
+ ngx.say(json.encode(res))
+ }
+ }
+--- response_body
+{"action":"set","node":{"key":"/apisix/services/1","value":{"id":"1","upstream":{"hash_on":"vars","nodes":{"127.0.0.1:8080":1},"pass_host":"pass","type":"roundrobin"}}}}
+
+
+
+=== TEST 3: not unwanted data, PATCH
+--- config
+ location /t {
+ content_by_lua_block {
+ local json = require("toolkit.json")
+ local t = require("lib.test_admin").test
+ local code, message, res = t('/apisix/admin/services/1',
+ ngx.HTTP_PATCH,
+ [[{
+ "upstream": {
+ "nodes": {
+ "127.0.0.1:8080": 1
+ },
+ "type": "roundrobin"
+ }
+ }]]
+ )
+
+ if code >= 300 then
+ ngx.status = code
+ ngx.say(message)
+ return
+ end
+
+ res = json.decode(res)
+ res.node.value.create_time = nil
+ res.node.value.update_time = nil
+ ngx.say(json.encode(res))
+ }
+ }
+--- response_body
+{"action":"compareAndSwap","node":{"key":"/apisix/services/1","value":{"id":"1","upstream":{"hash_on":"vars","nodes":{"127.0.0.1:8080":1},"pass_host":"pass","type":"roundrobin"}}}}
+
+
+
+=== TEST 4: not unwanted data, GET
+--- config
+ location /t {
+ content_by_lua_block {
+ local json = require("toolkit.json")
+ local t = require("lib.test_admin").test
+ local code, message, res = t('/apisix/admin/services/1',
+ ngx.HTTP_GET
+ )
+
+ if code >= 300 then
+ ngx.status = code
+ ngx.say(message)
+ return
+ end
+
+ res = json.decode(res)
+ res.node.value.create_time = nil
+ res.node.value.update_time = nil
+ ngx.say(json.encode(res))
+ }
+ }
+--- response_body
+{"action":"get","count":"1","node":{"key":"/apisix/services/1","value":{"id":"1","upstream":{"hash_on":"vars","nodes":{"127.0.0.1:8080":1},"pass_host":"pass","type":"roundrobin"}}}}
+
+
+
+=== TEST 5: not unwanted data, DELETE
+--- config
+ location /t {
+ content_by_lua_block {
+ local json = require("toolkit.json")
+ local t = require("lib.test_admin").test
+ local code, message, res = t('/apisix/admin/services/1',
+ ngx.HTTP_DELETE
+ )
+
+ if code >= 300 then
+ ngx.status = code
+ ngx.say(message)
+ return
+ end
+
+ res = json.decode(res)
+ ngx.say(json.encode(res))
+ }
+ }
+--- response_body
+{"action":"delete","deleted":"1","key":"/apisix/services/1","node":{}}
diff --git a/t/admin/ssl2.t b/t/admin/ssl2.t
new file mode 100644
index 0000000..0235273
--- /dev/null
+++ b/t/admin/ssl2.t
@@ -0,0 +1,198 @@
+#
+# 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.
+#
+use t::APISIX 'no_plan';
+
+repeat_each(1);
+no_long_string();
+no_root_location();
+no_shuffle();
+log_level("info");
+
+add_block_preprocessor(sub {
+ my ($block) = @_;
+
+ if (!$block->request) {
+ $block->set_value("request", "GET /t");
+ }
+
+ if (!$block->no_error_log) {
+ $block->set_value("no_error_log", "[error]\n[alert]");
+ }
+});
+
+run_tests;
+
+__DATA__
+
+=== TEST 1: not unwanted data, POST
+--- config
+ location /t {
+ content_by_lua_block {
+ local json = require("toolkit.json")
+ local t = require("lib.test_admin")
+
+ local ssl_cert = t.read_file("t/certs/apisix.crt")
+ local ssl_key = t.read_file("t/certs/apisix.key")
+ local data = {cert = ssl_cert, key = ssl_key, sni = "not-unwanted-post.com"}
+ local code, message, res = t.test('/apisix/admin/ssl',
+ ngx.HTTP_POST,
+ json.encode(data)
+ )
+
+ if code >= 300 then
+ ngx.status = code
+ ngx.say(message)
+ return
+ end
+
+ res = json.decode(res)
+ res.node.key = nil
+ res.node.value.create_time = nil
+ res.node.value.update_time = nil
+ res.node.value.cert = ""
+ res.node.value.key = ""
+ ngx.say(json.encode(res))
+ }
+ }
+--- response_body
+{"action":"create","node":{"value":{"cert":"","key":"","sni":"not-unwanted-post.com","status":1}}}
+
+
+
+=== TEST 2: not unwanted data, PUT
+--- config
+ location /t {
+ content_by_lua_block {
+ local json = require("toolkit.json")
+ local t = require("lib.test_admin")
+ local ssl_cert = t.read_file("t/certs/apisix.crt")
+ local ssl_key = t.read_file("t/certs/apisix.key")
+ local data = {cert = ssl_cert, key = ssl_key, sni = "test.com"}
+ local code, message, res = t.test('/apisix/admin/ssl/1',
+ ngx.HTTP_PUT,
+ json.encode(data)
+ )
+
+ if code >= 300 then
+ ngx.status = code
+ ngx.say(message)
+ return
+ end
+
+ res = json.decode(res)
+ res.node.value.create_time = nil
+ res.node.value.update_time = nil
+ res.node.value.cert = ""
+ res.node.value.key = ""
+ ngx.say(json.encode(res))
+ }
+ }
+--- response_body
+{"action":"set","node":{"key":"/apisix/ssl/1","value":{"cert":"","id":"1","key":"","sni":"test.com","status":1}}}
+
+
+
+=== TEST 3: not unwanted data, PATCH
+--- config
+ location /t {
+ content_by_lua_block {
+ local json = require("toolkit.json")
+ local t = require("lib.test_admin")
+ local ssl_cert = t.read_file("t/certs/apisix.crt")
+ local ssl_key = t.read_file("t/certs/apisix.key")
+ local data = {cert = ssl_cert, key = ssl_key, sni = "t.com"}
+ local code, message, res = t.test('/apisix/admin/ssl/1',
+ ngx.HTTP_PATCH,
+ json.encode(data)
+ )
+
+ if code >= 300 then
+ ngx.status = code
+ ngx.say(message)
+ return
+ end
+
+ res = json.decode(res)
+ res.node.value.create_time = nil
+ res.node.value.update_time = nil
+ res.node.value.cert = ""
+ res.node.value.key = ""
+ ngx.say(json.encode(res))
+ }
+ }
+--- response_body
+{"action":"compareAndSwap","node":{"key":"/apisix/ssl/1","value":{"cert":"","id":"1","key":"","sni":"t.com","status":1}}}
+
+
+
+=== TEST 4: not unwanted data, GET
+--- config
+ location /t {
+ content_by_lua_block {
+ local json = require("toolkit.json")
+ local t = require("lib.test_admin")
+ local ssl_cert = t.read_file("t/certs/apisix.crt")
+ local ssl_key = t.read_file("t/certs/apisix.key")
+ local data = {cert = ssl_cert, key = ssl_key, sni = "test.com"}
+ local code, message, res = t.test('/apisix/admin/ssl/1',
+ ngx.HTTP_GET
+ )
+
+ if code >= 300 then
+ ngx.status = code
+ ngx.say(message)
+ return
+ end
+
+ res = json.decode(res)
+ res.node.value.create_time = nil
+ res.node.value.update_time = nil
+ res.node.value.cert = ""
+ res.node.value.key = ""
+ ngx.say(json.encode(res))
+ }
+ }
+--- response_body
+{"action":"get","count":"1","node":{"key":"/apisix/ssl/1","value":{"cert":"","id":"1","key":"","sni":"t.com","status":1}}}
+
+
+
+=== TEST 5: not unwanted data, DELETE
+--- config
+ location /t {
+ content_by_lua_block {
+ local json = require("toolkit.json")
+ local t = require("lib.test_admin")
+ local ssl_cert = t.read_file("t/certs/apisix.crt")
+ local ssl_key = t.read_file("t/certs/apisix.key")
+ local data = {cert = ssl_cert, key = ssl_key, sni = "test.com"}
+ local code, message, res = t.test('/apisix/admin/ssl/1',
+ ngx.HTTP_DELETE
+ )
+
+ if code >= 300 then
+ ngx.status = code
+ ngx.say(message)
+ return
+ end
+
+ res = json.decode(res)
+ ngx.say(json.encode(res))
+ }
+ }
+--- response_body
+{"action":"delete","deleted":"1","key":"/apisix/ssl/1","node":{}}
diff --git a/t/admin/stream-routes.t b/t/admin/stream-routes.t
index 5bd36ff..c4787d0 100644
--- a/t/admin/stream-routes.t
+++ b/t/admin/stream-routes.t
@@ -383,3 +383,156 @@ GET /t
--- error_code: 400
--- no_error_log
[error]
+
+
+
+=== TEST 11: not unwanted data, POST
+--- config
+ location /t {
+ content_by_lua_block {
+ local json = require("toolkit.json")
+ local t = require("lib.test_admin").test
+ local code, message, res = t('/apisix/admin/stream_routes',
+ ngx.HTTP_POST,
+ [[{
+ "remote_addr": "127.0.0.1",
+ "upstream": {
+ "nodes": {
+ "127.0.0.1:8080": 1
+ },
+ "type": "roundrobin"
+ }
+ }]]
+ )
+
+ if code >= 300 then
+ ngx.status = code
+ ngx.say(message)
+ return
+ end
+
+ res = json.decode(res)
+ -- clean data
+ local id = string.sub(res.node.key, #"/apisix/stream_routes/" + 1)
+ local code, message = t('/apisix/admin/stream_routes/' .. id,
+ ngx.HTTP_DELETE
+ )
+
+ if code >= 300 then
+ ngx.status = code
+ ngx.say(message)
+ return
+ end
+
+ res.node.key = nil
+ res.node.value.create_time = nil
+ res.node.value.update_time = nil
+ ngx.say(json.encode(res))
+ }
+ }
+--- response_body
+{"action":"create","node":{"value":{"remote_addr":"127.0.0.1","upstream":{"hash_on":"vars","nodes":{"127.0.0.1:8080":1},"pass_host":"pass","type":"roundrobin"}}}}
+--- request
+GET /t
+--- no_error_log
+[error]
+
+
+
+=== TEST 12: not unwanted data, PUT
+--- config
+ location /t {
+ content_by_lua_block {
+ local json = require("toolkit.json")
+ local t = require("lib.test_admin").test
+ local code, message, res = t('/apisix/admin/stream_routes/1',
+ ngx.HTTP_PUT,
+ [[{
+ "remote_addr": "127.0.0.1",
+ "upstream": {
+ "nodes": {
+ "127.0.0.1:8080": 1
+ },
+ "type": "roundrobin"
+ }
+ }]]
+ )
+
+ if code >= 300 then
+ ngx.status = code
+ ngx.say(message)
+ return
+ end
+
+ res = json.decode(res)
+ res.node.value.create_time = nil
+ res.node.value.update_time = nil
+ ngx.say(json.encode(res))
+ }
+ }
+--- response_body
+{"action":"set","node":{"key":"/apisix/stream_routes/1","value":{"id":"1","remote_addr":"127.0.0.1","upstream":{"hash_on":"vars","nodes":{"127.0.0.1:8080":1},"pass_host":"pass","type":"roundrobin"}}}}
+--- request
+GET /t
+--- no_error_log
+[error]
+
+
+
+=== TEST 13: not unwanted data, GET
+--- config
+ location /t {
+ content_by_lua_block {
+ local json = require("toolkit.json")
+ local t = require("lib.test_admin").test
+ local code, message, res = t('/apisix/admin/stream_routes/1',
+ ngx.HTTP_GET
+ )
+
+ if code >= 300 then
+ ngx.status = code
+ ngx.say(message)
+ return
+ end
+
+ res = json.decode(res)
+ res.node.value.create_time = nil
+ res.node.value.update_time = nil
+ ngx.say(json.encode(res))
+ }
+ }
+--- response_body
+{"action":"get","count":"1","node":{"key":"/apisix/stream_routes/1","value":{"id":"1","remote_addr":"127.0.0.1","upstream":{"hash_on":"vars","nodes":{"127.0.0.1:8080":1},"pass_host":"pass","type":"roundrobin"}}}}
+--- request
+GET /t
+--- no_error_log
+[error]
+
+
+
+=== TEST 14: not unwanted data, DELETE
+--- config
+ location /t {
+ content_by_lua_block {
+ local json = require("toolkit.json")
+ local t = require("lib.test_admin").test
+ local code, message, res = t('/apisix/admin/stream_routes/1',
+ ngx.HTTP_DELETE
+ )
+
+ if code >= 300 then
+ ngx.status = code
+ ngx.say(message)
+ return
+ end
+
+ res = json.decode(res)
+ ngx.say(json.encode(res))
+ }
+ }
+--- response_body
+{"action":"delete","deleted":"1","key":"/apisix/stream_routes/1","node":{}}
+--- request
+GET /t
+--- no_error_log
+[error]
diff --git a/t/admin/upstream2.t b/t/admin/upstream2.t
new file mode 100644
index 0000000..b05c1a7
--- /dev/null
+++ b/t/admin/upstream2.t
@@ -0,0 +1,191 @@
+#
+# 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.
+#
+use t::APISIX 'no_plan';
+
+repeat_each(1);
+no_long_string();
+no_root_location();
+no_shuffle();
+log_level("info");
+
+add_block_preprocessor(sub {
+ my ($block) = @_;
+
+ if (!$block->request) {
+ $block->set_value("request", "GET /t");
+ }
+
+ if (!$block->no_error_log) {
+ $block->set_value("no_error_log", "[error]\n[alert]");
+ }
+});
+
+run_tests;
+
+__DATA__
+
+=== TEST 1: not unwanted data, POST
+--- config
+ location /t {
+ content_by_lua_block {
+ local json = require("toolkit.json")
+ local t = require("lib.test_admin").test
+ local code, message, res = t('/apisix/admin/upstreams',
+ ngx.HTTP_POST,
+ [[{
+ "nodes": {
+ "127.0.0.1:8080": 1
+ },
+ "type": "roundrobin"
+ }]]
+ )
+
+ if code >= 300 then
+ ngx.status = code
+ ngx.say(message)
+ return
+ end
+
+ res = json.decode(res)
+ res.node.key = nil
+ res.node.value.create_time = nil
+ res.node.value.update_time = nil
+ ngx.say(json.encode(res))
+ }
+ }
+--- response_body
+{"action":"create","node":{"value":{"hash_on":"vars","nodes":{"127.0.0.1:8080":1},"pass_host":"pass","type":"roundrobin"}}}
+
+
+
+
+=== TEST 2: not unwanted data, PUT
+--- config
+ location /t {
+ content_by_lua_block {
+ local json = require("toolkit.json")
+ local t = require("lib.test_admin").test
+ local code, message, res = t('/apisix/admin/upstreams/1',
+ ngx.HTTP_PUT,
+ [[{
+ "nodes": {
+ "127.0.0.1:8080": 1
+ },
+ "type": "roundrobin"
+ }]]
+ )
+
+ if code >= 300 then
+ ngx.status = code
+ ngx.say(message)
+ return
+ end
+
+ res = json.decode(res)
+ res.node.value.create_time = nil
+ res.node.value.update_time = nil
+ ngx.say(json.encode(res))
+ }
+ }
+--- response_body
+{"action":"set","node":{"key":"/apisix/upstreams/1","value":{"hash_on":"vars","id":"1","nodes":{"127.0.0.1:8080":1},"pass_host":"pass","type":"roundrobin"}}}
+
+
+
+
+=== TEST 3: not unwanted data, PATCH
+--- config
+ location /t {
+ content_by_lua_block {
+ local json = require("toolkit.json")
+ local t = require("lib.test_admin").test
+ local code, message, res = t('/apisix/admin/upstreams/1',
+ ngx.HTTP_PATCH,
+ [[{
+ "nodes": {
+ "127.0.0.1:8080": 1
+ },
+ "type": "roundrobin"
+ }]]
+ )
+
+ if code >= 300 then
+ ngx.status = code
+ ngx.say(message)
+ return
+ end
+
+ res = json.decode(res)
+ res.node.value.create_time = nil
+ res.node.value.update_time = nil
+ ngx.say(json.encode(res))
+ }
+ }
+--- response_body
+{"action":"compareAndSwap","node":{"key":"/apisix/upstreams/1","value":{"hash_on":"vars","id":"1","nodes":{"127.0.0.1:8080":1},"pass_host":"pass","type":"roundrobin"}}}
+
+
+
+=== TEST 4: not unwanted data, GET
+--- config
+ location /t {
+ content_by_lua_block {
+ local json = require("toolkit.json")
+ local t = require("lib.test_admin").test
+ local code, message, res = t('/apisix/admin/upstreams/1',
+ ngx.HTTP_GET
+ )
+
+ if code >= 300 then
+ ngx.status = code
+ ngx.say(message)
+ return
+ end
+
+ res = json.decode(res)
+ res.node.value.create_time = nil
+ res.node.value.update_time = nil
+ ngx.say(json.encode(res))
+ }
+ }
+--- response_body
+{"action":"get","count":"1","node":{"key":"/apisix/upstreams/1","value":{"hash_on":"vars","id":"1","nodes":{"127.0.0.1:8080":1},"pass_host":"pass","type":"roundrobin"}}}
+
+
+
+=== TEST 5: not unwanted data, DELETE
+--- config
+ location /t {
+ content_by_lua_block {
+ local json = require("toolkit.json")
+ local t = require("lib.test_admin").test
+ local code, message, res = t('/apisix/admin/upstreams/1',
+ ngx.HTTP_DELETE
+ )
+
+ if code >= 300 then
+ ngx.status = code
+ ngx.say(message)
+ return
+ end
+
+ res = json.decode(res)
+ ngx.say(json.encode(res))
+ }
+ }
+--- response_body
+{"action":"delete","deleted":"1","key":"/apisix/upstreams/1","node":{}}