From e023936e8e0310ab2649e492c3d2fdf00f68a842 Mon Sep 17 00:00:00 2001 From: peusebiu Date: Fri, 14 Jun 2024 19:22:48 +0300 Subject: [PATCH] fix(ui): fix image details view (#2470) when a UI client tries to view image details for an image with multiple tags pointing to the same digest we make a query to dynamodb having duplicate keys (same digest) resulting in an error and the client is redirect back to image overview. closes: #2464 Signed-off-by: Petu Eusebiu --- pkg/extensions/search/resolver.go | 6 +++++- pkg/meta/dynamodb/dynamodb_test.go | 11 +++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/pkg/extensions/search/resolver.go b/pkg/extensions/search/resolver.go index 638cebb5..349932ae 100644 --- a/pkg/extensions/search/resolver.go +++ b/pkg/extensions/search/resolver.go @@ -1439,7 +1439,11 @@ func expandedRepoInfo(ctx context.Context, repo string, metaDB mTypes.MetaDB, cv continue } - tagsDigests = append(tagsDigests, repoMeta.Tags[i].Digest) + digest := repoMeta.Tags[i].Digest + + if !zcommon.Contains(tagsDigests, digest) { + tagsDigests = append(tagsDigests, digest) + } } imageMetaMap, err := metaDB.FilterImageMeta(ctx, tagsDigests) diff --git a/pkg/meta/dynamodb/dynamodb_test.go b/pkg/meta/dynamodb/dynamodb_test.go index 036cd652..39a60c65 100644 --- a/pkg/meta/dynamodb/dynamodb_test.go +++ b/pkg/meta/dynamodb/dynamodb_test.go @@ -236,6 +236,16 @@ func TestWrapperErrors(t *testing.T) { }) }) Convey("FilterImageMeta", func() { + Convey("FilterImageMeta with duplicate digests", func() { + image := CreateRandomImage() + + err := dynamoWrapper.SetRepoReference(ctx, "repo", "tag", image.AsImageMeta()) + So(err, ShouldBeNil) + + _, err = dynamoWrapper.FilterImageMeta(ctx, []string{image.DigestStr(), image.DigestStr()}) + So(err, ShouldNotBeNil) + }) + Convey("manifest meta unmarshal error", func() { err = setImageMeta(image.Digest(), badProtoBlob, dynamoWrapper) //nolint: contextcheck So(err, ShouldBeNil) @@ -243,6 +253,7 @@ func TestWrapperErrors(t *testing.T) { _, err = dynamoWrapper.FilterImageMeta(ctx, []string{image.DigestStr()}) So(err, ShouldNotBeNil) }) + Convey("MediaType ImageIndex, getProtoImageMeta fails", func() { err := dynamoWrapper.SetImageMeta(multiarchImageMeta.Digest, multiarchImageMeta) //nolint: contextcheck So(err, ShouldBeNil)