From d5ba001d9e9a3f8ec9b6afdeabbb1ee81d651685 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markus=20Th=C3=B6mmes?= Date: Tue, 26 Nov 2019 22:16:21 +0100 Subject: [PATCH] Adjust digest validation for image templating mechanism. (#6106) * Adjust digest validation for image templating mechanism. We can no longer rely on the image format to be static since we introduced a templating mechanism. This adjusts the relevant validation functions to also take that into account. * Actually parse references and make sure their repositories are equal. --- test/conformance/api/v1/util.go | 15 ++++++++++++--- test/conformance/api/v1alpha1/util.go | 15 ++++++++++++--- test/conformance/api/v1beta1/util.go | 15 ++++++++++++--- 3 files changed, 36 insertions(+), 9 deletions(-) diff --git a/test/conformance/api/v1/util.go b/test/conformance/api/v1/util.go index 36f3677f49fb..6d1a6df8fcde 100644 --- a/test/conformance/api/v1/util.go +++ b/test/conformance/api/v1/util.go @@ -22,10 +22,10 @@ import ( "math" "net/http" "net/url" - "regexp" "strings" "testing" + "github.com/google/go-containerregistry/pkg/name" "golang.org/x/sync/errgroup" pkgTest "knative.dev/pkg/test" "knative.dev/pkg/test/spoof" @@ -327,6 +327,15 @@ func validateReleaseServiceShape(objs *v1test.ResourceObjects) error { } func validateImageDigest(imageName string, imageDigest string) (bool, error) { - imageDigestRegex := fmt.Sprintf("%s/%s@sha256:[0-9a-f]{64}", pkgTest.Flags.DockerRepo, imageName) - return regexp.MatchString(imageDigestRegex, imageDigest) + ref, err := name.ParseReference(pkgTest.ImagePath(imageName)) + if err != nil { + return false, err + } + + digest, err := name.NewDigest(imageDigest) + if err != nil { + return false, err + } + + return ref.Context().String() == digest.Context().String(), nil } diff --git a/test/conformance/api/v1alpha1/util.go b/test/conformance/api/v1alpha1/util.go index b150f2e81d16..a57fcfeaf882 100644 --- a/test/conformance/api/v1alpha1/util.go +++ b/test/conformance/api/v1alpha1/util.go @@ -22,10 +22,10 @@ import ( "math" "net/http" "net/url" - "regexp" "strings" "testing" + "github.com/google/go-containerregistry/pkg/name" "golang.org/x/sync/errgroup" pkgTest "knative.dev/pkg/test" "knative.dev/pkg/test/spoof" @@ -327,6 +327,15 @@ func validateReleaseServiceShape(objs *v1a1test.ResourceObjects) error { } func validateImageDigest(imageName string, imageDigest string) (bool, error) { - imageDigestRegex := fmt.Sprintf("%s/%s@sha256:[0-9a-f]{64}", pkgTest.Flags.DockerRepo, imageName) - return regexp.MatchString(imageDigestRegex, imageDigest) + ref, err := name.ParseReference(pkgTest.ImagePath(imageName)) + if err != nil { + return false, err + } + + digest, err := name.NewDigest(imageDigest) + if err != nil { + return false, err + } + + return ref.Context().String() == digest.Context().String(), nil } diff --git a/test/conformance/api/v1beta1/util.go b/test/conformance/api/v1beta1/util.go index 128a6058b859..63ba8eed3699 100644 --- a/test/conformance/api/v1beta1/util.go +++ b/test/conformance/api/v1beta1/util.go @@ -22,10 +22,10 @@ import ( "math" "net/http" "net/url" - "regexp" "strings" "testing" + "github.com/google/go-containerregistry/pkg/name" "golang.org/x/sync/errgroup" pkgTest "knative.dev/pkg/test" "knative.dev/pkg/test/spoof" @@ -327,6 +327,15 @@ func validateReleaseServiceShape(objs *v1b1test.ResourceObjects) error { } func validateImageDigest(imageName string, imageDigest string) (bool, error) { - imageDigestRegex := fmt.Sprintf("%s/%s@sha256:[0-9a-f]{64}", pkgTest.Flags.DockerRepo, imageName) - return regexp.MatchString(imageDigestRegex, imageDigest) + ref, err := name.ParseReference(pkgTest.ImagePath(imageName)) + if err != nil { + return false, err + } + + digest, err := name.NewDigest(imageDigest) + if err != nil { + return false, err + } + + return ref.Context().String() == digest.Context().String(), nil }