This is an automated email from the ASF dual-hosted git repository. membphis 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 c90f0dc fix: SSL resource supports PATCH with sub path (#3405) c90f0dc is described below commit c90f0dcfb4218a9c6ade70b21b7974342aad5ed4 Author: 罗泽轩 <spacewander...@gmail.com> AuthorDate: Mon Jan 25 23:57:34 2021 +0800 fix: SSL resource supports PATCH with sub path (#3405) Fix #3351 --- apisix/admin/ssl.lua | 13 +++++++++++-- t/admin/ssl2.t | 40 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+), 2 deletions(-) diff --git a/apisix/admin/ssl.lua b/apisix/admin/ssl.lua index b97a194..3a6136e 100644 --- a/apisix/admin/ssl.lua +++ b/apisix/admin/ssl.lua @@ -172,7 +172,7 @@ function _M.delete(id) end -function _M.patch(id, conf) +function _M.patch(id, conf, sub_path) if not id then return 400, {error_msg = "missing route id"} end @@ -206,7 +206,16 @@ function _M.patch(id, conf) local node_value = res_old.body.node.value local modified_index = res_old.body.node.modifiedIndex - node_value = core.table.merge(node_value, conf); + if sub_path and sub_path ~= "" then + local code, err, node_val = core.table.patch(node_value, sub_path, conf) + node_value = node_val + if code then + return code, err + end + else + node_value = core.table.merge(node_value, conf); + end + utils.inject_timestamp(node_value, nil, conf) diff --git a/t/admin/ssl2.t b/t/admin/ssl2.t index 6614eef..0c68cd2 100644 --- a/t/admin/ssl2.t +++ b/t/admin/ssl2.t @@ -365,3 +365,43 @@ wzarryret/7GFW1/3cz+hTj9/d45i25zArr3Pocfpur5mfz3fJO8jg== --- error_code: 400 --- response_body {"error_msg":"invalid configuration: property \"snis\" validation failed: expect array to have at least 1 items"} + + + +=== TEST 11: update snis, PATCH with sub path +--- 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, snis = {"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 + + + local data = {"update1.com", "update2.com"} + local code, message, res = t.test('/apisix/admin/ssl/1/snis', + ngx.HTTP_PATCH, + json.encode(data) + ) + + if code >= 300 then + ngx.status = code + ngx.say(message) + return + end + ngx.say(res) + } + } +--- response_body_like eval +qr/"snis":\["update1.com","update2.com"\]/