diff --git a/pkg/v1/remote/write.go b/pkg/v1/remote/write.go index 7b431c077..13f68733c 100644 --- a/pkg/v1/remote/write.go +++ b/pkg/v1/remote/write.go @@ -449,7 +449,7 @@ func scopesForUploadingImage(repo name.Repository, layers []v1.Layer) []string { if ml, ok := l.(*MountableLayer); ok { // we will add push scope for ref.Context() after the loop. // for now we ask pull scope for references of the same registry - if ml.Reference.Context() != repo && ml.Reference.Context().Registry == repo.Registry { + if ml.Reference.Context().String() != repo.String() && ml.Reference.Context().Registry.String() == repo.Registry.String() { scopeSet[ml.Reference.Scope(transport.PullScope)] = struct{}{} } } diff --git a/pkg/v1/remote/write_test.go b/pkg/v1/remote/write_test.go index bab1708b9..ce4aa7f43 100644 --- a/pkg/v1/remote/write_test.go +++ b/pkg/v1/remote/write_test.go @@ -915,6 +915,41 @@ func TestWriteWithErrors(t *testing.T) { } } +func TestDockerhubScopes(t *testing.T) { + src, err := name.ParseReference("busybox") + if err != nil { + t.Fatal(err) + } + rl, err := random.Layer(1024, types.DockerLayer) + if err != nil { + t.Fatal(err) + } + ml := &MountableLayer{ + Layer: rl, + Reference: src, + } + want := src.Scope(transport.PullScope) + + for _, s := range []string{ + "jonjohnson/busybox", + "docker.io/jonjohnson/busybox", + "index.docker.io/jonjohnson/busybox", + } { + dst, err := name.ParseReference(s) + if err != nil { + t.Fatal(err) + } + + scopes := scopesForUploadingImage(dst.Context(), []v1.Layer{ml}) + + if len(scopes) != 2 { + t.Errorf("Should have two scopes (src and dst), got %d", len(scopes)) + } else if diff := cmp.Diff(want, scopes[1]); diff != "" { + t.Errorf("TestDockerhubScopes %q: (-want +got) = %v", s, diff) + } + } +} + func TestScopesForUploadingImage(t *testing.T) { referenceToUpload, err := name.NewTag("example.com/sample/sample:latest", name.WeakValidation) if err != nil {