diff --git a/pkg/api/handlers/compat/images_history.go b/pkg/api/handlers/compat/images_history.go index 1b83d274a0..b0970b6efd 100644 --- a/pkg/api/handlers/compat/images_history.go +++ b/pkg/api/handlers/compat/images_history.go @@ -33,13 +33,17 @@ func HistoryImage(w http.ResponseWriter, r *http.Request) { allHistory := make([]handlers.HistoryResponse, 0, len(history)) for _, h := range history { l := handlers.HistoryResponse{ - ID: h.ID, Created: h.Created.Unix(), CreatedBy: h.CreatedBy, Tags: h.Tags, Size: h.Size, Comment: h.Comment, } + if utils.IsLibpodRequest(r) { + l.ID = h.ID + } else { + l.ID = "sha256:" + h.ID + } allHistory = append(allHistory, l) } utils.WriteResponse(w, http.StatusOK, allHistory) diff --git a/test/apiv2/10-images.at b/test/apiv2/10-images.at index 91355822fa..8f52a321f4 100644 --- a/test/apiv2/10-images.at +++ b/test/apiv2/10-images.at @@ -78,6 +78,15 @@ for i in $iid ${iid:0:12} $PODMAN_TEST_IMAGE_NAME; do .[0].Comment= done +for i in $iid ${iid:0:12} $PODMAN_TEST_IMAGE_NAME; do + t GET images/$i/history 200 \ + .[0].Id="sha256:"$iid \ + .[0].Created~[0-9]\\{10\\} \ + .[0].Tags=null \ + .[0].Size=0 \ + .[0].Comment= +done + # Export an image on the local t GET libpod/images/nonesuch/get 404 t GET libpod/images/$iid/get?format=foo 500 diff --git a/test/python/docker/compat/test_images.py b/test/python/docker/compat/test_images.py index cb2931b3ee..9a903cdac1 100644 --- a/test/python/docker/compat/test_images.py +++ b/test/python/docker/compat/test_images.py @@ -70,12 +70,11 @@ def test_image_history(self): """Image history""" img = self.docker.images.get(constant.ALPINE) history = img.history() - image_id = img.id[7:] if img.id.startswith("sha256:") else img.id found = False for change in history: - found |= image_id in change.values() - self.assertTrue(found, f"image id {image_id} not found in history") + found |= img.id in change.values() + self.assertTrue(found, f"image id {img.id} not found in history") def test_get_image_exists_not(self): """Negative test for get image"""