Skip to content

Commit

Permalink
In a list response, if there are no keys, 404 to be consistent with GET
Browse files Browse the repository at this point in the history
and with different backend conditions

Fixes #1365
  • Loading branch information
jefferai committed May 2, 2016
1 parent aa2ca43 commit 289fd54
Showing 1 changed file with 28 additions and 3 deletions.
31 changes: 28 additions & 3 deletions http/logical.go
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 {
respondError(w, http.StatusNotFound, nil)
return
}
keys, ok := keysInt.([]string)
if !ok {
respondError(w, http.StatusNotFound, nil)
return
}
if len(keys) == 0 {
respondError(w, http.StatusNotFound, nil)
return
}
}

// Build the proper response
Expand Down

0 comments on commit 289fd54

Please sign in to comment.