Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(admin): fix secrets do not support to update attributes by PATCH #9510

Merged
merged 3 commits into from
May 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions apisix/admin/resource.lua
Original file line number Diff line number Diff line change
Expand Up @@ -279,8 +279,8 @@ function _M:patch(id, conf, sub_path, args)
local typ = nil
if self.name == "secrets" then
local uri_segs = core.utils.split_uri(sub_path)
if #uri_segs < 2 then
return 400, {error_msg = "no secret id and/or sub path in uri"}
if #uri_segs < 1 then
return 400, {error_msg = "no secret id"}
end
typ = id
id = uri_segs[1]
Expand Down
68 changes: 65 additions & 3 deletions t/admin/secrets.t
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ passed



=== TEST 4: PATCH
=== TEST 4: PATCH on path
--- config
location /t {
content_by_lua_block {
Expand Down Expand Up @@ -169,7 +169,69 @@ passed



=== TEST 5: DELETE
=== TEST 5: PATCH
--- config
location /t {
content_by_lua_block {
local t = require("lib.test_admin").test
local etcd = require("apisix.core.etcd")
local res = assert(etcd.get('/secrets/vault/test1'))
local prev_create_time = res.body.node.value.create_time
assert(prev_create_time ~= nil, "create_time is nil")
local prev_update_time = res.body.node.value.update_time
assert(prev_update_time ~= nil, "update_time is nil")
ngx.sleep(1)

local code, body = t('/apisix/admin/secrets/vault/test1',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Which field was modified? Didn't see how you verified the execution result of PATCH?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TEST 4 changes the token to "unknown" by PATCH on path, then TEST 5 changes the token back to "apisix" by PATCH.

ngx.HTTP_PATCH,
[[{
"uri": "http://127.0.0.1:12800/get",
"prefix" : "apisix",
"token" : "apisix"
}]],
[[{
"value": {
"uri": "http://127.0.0.1:12800/get",
"prefix" : "apisix",
"token" : "apisix"
},
"key": "/apisix/secrets/vault/test1"
}]]
)

ngx.status = code
ngx.say(body)

local res = assert(etcd.get('/secrets/vault/test1'))
assert(res.body.node.value.token == "apisix")
}
}
--- response_body
passed



=== TEST 6: PATCH without id
--- config
location /t {
content_by_lua_block {
local t = require("lib.test_admin").test
local code, body = t('/apisix/admin/secrets/vault',
ngx.HTTP_PATCH,
[[{}]],
[[{}]]
)
ngx.status = code
ngx.print(body)
}
}
--- error_code: 400
--- response_body
{"error_msg":"no secret id"}



=== TEST 7: DELETE
--- config
location /t {
content_by_lua_block {
Expand All @@ -185,7 +247,7 @@ passed



=== TEST 6: PUT with invalid format
=== TEST 8: PUT with invalid format
--- config
location /t {
content_by_lua_block {
Expand Down