Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions pkg/name/digest.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,11 @@ func NewDigest(name string, strict Strictness) (Digest, error) {
}
}

tag, err := NewTag(base, strict)
if err == nil {
base = tag.Repository.Name()
}

repo, err := NewRepository(base, strict)
if err != nil {
return Digest{}, err
Expand Down
19 changes: 18 additions & 1 deletion pkg/name/digest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,23 @@ var goodStrictValidationDigestNames = []string{
"example.text/foo/bar@" + validDigest,
}

var goodStrictValidationTagDigestNames = []string{
"example.text/foo/bar:latest@" + validDigest,
"example.text:8443/foo/bar:latest@" + validDigest,
"example.text/foo/bar:v1.0.0-alpine@" + validDigest,
}

var goodWeakValidationDigestNames = []string{
"namespace/pathcomponent/image@" + validDigest,
"library/ubuntu@" + validDigest,
"gcr.io/project-id/missing-digest@",
}

var goodWeakValidationTagDigestNames = []string{
"nginx:latest@" + validDigest,
"library/nginx:latest@" + validDigest,
}

var badDigestNames = []string{
"gcr.io/project-id/unknown-alg@unknown:abc123",
"gcr.io/project-id/wrong-length@sha256:d34db33fd34db33f",
Expand All @@ -50,6 +61,12 @@ func TestNewDigestStrictValidation(t *testing.T) {
}
}

for _, name := range goodStrictValidationTagDigestNames {
if _, err := NewDigest(name, StrictValidation); err != nil {
t.Errorf("`%s` should be a valid Digest name, got error: %v", name, err)
}
}

for _, name := range append(goodWeakValidationDigestNames, badDigestNames...) {
if repo, err := NewDigest(name, StrictValidation); err == nil {
t.Errorf("`%s` should be an invalid Digest name, got Digest: %#v", name, repo)
Expand All @@ -60,7 +77,7 @@ func TestNewDigestStrictValidation(t *testing.T) {
func TestNewDigest(t *testing.T) {
t.Parallel()

for _, name := range append(goodStrictValidationDigestNames, goodWeakValidationDigestNames...) {
for _, name := range append(goodStrictValidationDigestNames, append(goodWeakValidationDigestNames, goodWeakValidationTagDigestNames...)...) {
if _, err := NewDigest(name, WeakValidation); err != nil {
t.Errorf("`%s` should be a valid Digest name, got error: %v", name, err)
}
Expand Down