Skip to content

Commit

Permalink
Return 404 if entry isn't found in log (#915)
Browse files Browse the repository at this point in the history
Signed-off-by: Priya Wadhwa <priya@chainguard.dev>
  • Loading branch information
priyawadhwa committed Jul 11, 2022
1 parent c962a68 commit 6093a33
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
10 changes: 7 additions & 3 deletions pkg/api/entries.go
Original file line number Diff line number Diff line change
Expand Up @@ -299,8 +299,11 @@ func getEntryURL(locationURL url.URL, uuid string) strfmt.URI {
func GetLogEntryByUUIDHandler(params entries.GetLogEntryByUUIDParams) middleware.Responder {
logEntry, err := retrieveLogEntry(params.HTTPRequest.Context(), params.EntryUUID)
if err != nil {
if errors.Is(err, ErrNotFound) {
return handleRekorAPIError(params, http.StatusNotFound, err, "")
}
if _, ok := (err).(types.ValidationError); ok {
return handleRekorAPIError(params, http.StatusBadRequest, err, "incorrectly formatted uuid %s", params.EntryUUID)
return handleRekorAPIError(params, http.StatusBadRequest, err, fmt.Sprintf("incorrectly formatted uuid %s", params.EntryUUID), params.EntryUUID)
}
return handleRekorAPIError(params, http.StatusInternalServerError, err, "ID %s not found in any known trees", params.EntryUUID)
}
Expand Down Expand Up @@ -448,7 +451,7 @@ func retrieveLogEntryByIndex(ctx context.Context, logIndex int) (models.LogEntry
func retrieveLogEntry(ctx context.Context, entryUUID string) (models.LogEntry, error) {
uuid, err := sharding.GetUUIDFromIDString(entryUUID)
if err != nil {
return models.LogEntry{}, sharding.ErrPlainUUID
return nil, sharding.ErrPlainUUID
}

// Get the tree ID and check that shard for the entry
Expand All @@ -469,9 +472,10 @@ func retrieveLogEntry(ctx context.Context, entryUUID string) (models.LogEntry, e
}
return logEntry, nil
}
return nil, ErrNotFound
}

return models.LogEntry{}, err
return nil, err
}

func retrieveUUIDFromTree(ctx context.Context, uuid string, tid int64) (models.LogEntry, error) {
Expand Down
2 changes: 1 addition & 1 deletion tests/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -691,7 +691,7 @@ func TestGetNonExistantIndex(t *testing.T) {
func TestGetNonExistantUUID(t *testing.T) {
// this uuid is extremely likely to not exist
out := runCliErr(t, "get", "--uuid", "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")
outputContains(t, out, "400")
outputContains(t, out, "404")
}

func TestEntryUpload(t *testing.T) {
Expand Down

0 comments on commit 6093a33

Please sign in to comment.