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

return 404 resp for patch when entry does not exist #56

Merged
merged 1 commit into from
Nov 23, 2021
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 2 additions & 4 deletions path_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -402,10 +402,8 @@ func (b *versionedKVBackend) pathDataPatch() framework.OperationFunc {
return nil, err
}

// Returning a nil logical.Response and error will ultimately
// result in a 404 HTTP response status
if meta == nil {
return nil, nil
return logical.RespondWithStatusCode(nil, req, http.StatusNotFound)
}

config, err := b.config(ctx, req.Storage)
Expand All @@ -427,7 +425,7 @@ func (b *versionedKVBackend) pathDataPatch() framework.OperationFunc {
versionMetadata := meta.Versions[currentVersion]

if versionMetadata == nil {
return nil, nil
return logical.RespondWithStatusCode(nil, req, http.StatusNotFound)
}

// Like the read handler, initialize a resp with the version metadata
Expand Down
18 changes: 13 additions & 5 deletions path_data_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -615,8 +615,12 @@ func TestVersionedKV_Patch_NotFound(t *testing.T) {
}

resp, err := b.HandleRequest(context.Background(), req)
if err != nil || resp != nil {
t.Fatalf("expected nil response for PatchOperation - err:%s resp:%#v\n", err, resp)
if err != nil || resp == nil || resp.IsError() {
t.Fatalf("PatchOperation failed - err:%s resp:%#v", err, resp)
}

if resp.Data["http_status_code"] != 404 {
t.Fatalf("expected 404 response for PatchOperation: resp:%#v", resp)
}

metadata := map[string]interface{}{
Expand All @@ -634,7 +638,7 @@ func TestVersionedKV_Patch_NotFound(t *testing.T) {

resp, err = b.HandleRequest(context.Background(), req)
if err != nil || resp != nil {
t.Fatalf("metadata CreateOperation request failed - err:%s resp:%#v\n", err, resp)
t.Fatalf("metadata CreateOperation request failed - err:%s resp:%#v", err, resp)
}

req = &logical.Request{
Expand All @@ -645,8 +649,12 @@ func TestVersionedKV_Patch_NotFound(t *testing.T) {
}

resp, err = b.HandleRequest(context.Background(), req)
if err != nil || resp != nil {
t.Fatalf("expected nil response for PatchOperation - err:%s resp:%#v\n", err, resp)
if err != nil || resp == nil || resp.IsError() {
t.Fatalf("PatchOperation failed - err:%s resp:%#v", err, resp)
}

if resp.Data["http_status_code"] != 404 {
t.Fatalf("expected 404 response for PatchOperation: resp:%#v", resp)
}
}

Expand Down