Fix panic in libpod images exists endpoint

The libpod images exists endpoint panics when called with
a non existing image and therefore returns 500 as status
code instead of the expected 404.

A test is added to ensure it is working.

Signed-off-by: Paul Holzinger <paul.holzinger@web.de>
This commit is contained in:
Paul Holzinger
2020-12-10 14:22:36 +01:00
parent eaa19a1c10
commit 3fa61f0004
2 changed files with 3 additions and 1 deletions

View File

@ -51,7 +51,7 @@ func ImageExists(w http.ResponseWriter, r *http.Request) {
return return
} }
if !report.Value { if !report.Value {
utils.Error(w, "Something went wrong.", http.StatusNotFound, errors.Wrapf(nil, "failed to find image %s", name)) utils.Error(w, "Something went wrong.", http.StatusNotFound, errors.Errorf("failed to find image %s", name))
return return
} }
utils.WriteResponse(w, http.StatusNoContent, "") utils.WriteResponse(w, http.StatusNoContent, "")

View File

@ -12,6 +12,8 @@ iid=$(jq -r '.[0].Id' <<<"$output")
t GET libpod/images/$iid/exists 204 t GET libpod/images/$iid/exists 204
t GET libpod/images/$PODMAN_TEST_IMAGE_NAME/exists 204 t GET libpod/images/$PODMAN_TEST_IMAGE_NAME/exists 204
t GET libpod/images/${iid}abcdef/exists 404 \
.cause="failed to find image ${iid}abcdef"
# FIXME: compare to actual podman info # FIXME: compare to actual podman info
t GET libpod/images/json 200 \ t GET libpod/images/json 200 \