Skip to content

Commit

Permalink
Adjust digest validation for image templating mechanism. (#6106)
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
markusthoemmes authored and knative-prow-robot committed Nov 26, 2019
1 parent 197028d commit d5ba001
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 9 deletions.
15 changes: 12 additions & 3 deletions test/conformance/api/v1/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
}
15 changes: 12 additions & 3 deletions test/conformance/api/v1alpha1/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
}
15 changes: 12 additions & 3 deletions test/conformance/api/v1beta1/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
}

0 comments on commit d5ba001

Please sign in to comment.