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

In a list response, if there are no keys, 404 to be consistent with GET #1368

Merged
merged 2 commits into from
May 3, 2016
Merged
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
31 changes: 28 additions & 3 deletions http/logical.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,34 @@ func handleLogical(core *vault.Core, dataOnly bool, prepareRequestCallback Prepa
if !ok {
return
}
if (op == logical.ReadOperation || op == logical.ListOperation) && resp == nil {
respondError(w, http.StatusNotFound, nil)
return
switch {
case op == logical.ReadOperation:
if resp == nil {
respondError(w, http.StatusNotFound, nil)
return
}

// Basically: if we have empty "keys" or no keys at all, 404. This
// provides consistency with GET.
case op == logical.ListOperation:
if resp == nil || len(resp.Data) == 0 {
respondError(w, http.StatusNotFound, nil)
return
}
keysInt, ok := resp.Data["keys"]
if !ok || keysInt == nil {
respondError(w, http.StatusNotFound, nil)
return
}
keys, ok := keysInt.([]string)
Copy link
Contributor

Choose a reason for hiding this comment

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

Wouldn't it be safer to check if keys was nil here? It seems weird to return a 404 if the data type isn't an []string, since that seems more like a bug.

if !ok {
respondError(w, http.StatusInternalServerError, nil)
return
}
if len(keys) == 0 {
respondError(w, http.StatusNotFound, nil)
return
}
}

// Build the proper response
Expand Down