Merge pull request #2142 from dmcgowan/reference-enforce-canonical-parsing

reference: ParseNamed updated to enforce canonical format
This commit is contained in:
Derek McGowan 2017-01-18 17:06:08 -08:00 committed by GitHub
commit 11cb04e994
23 changed files with 151 additions and 64 deletions

View file

@ -197,10 +197,14 @@ func TestConfigBuilder(t *testing.T) {
bs := &mockBlobService{descriptors: make(map[digest.Digest]distribution.Descriptor)} bs := &mockBlobService{descriptors: make(map[digest.Digest]distribution.Descriptor)}
ref, err := reference.ParseNamed("testrepo:testtag") ref, err := reference.WithName("testrepo")
if err != nil { if err != nil {
t.Fatalf("could not parse reference: %v", err) t.Fatalf("could not parse reference: %v", err)
} }
ref, err = reference.WithTag(ref, "testtag")
if err != nil {
t.Fatalf("could not add tag: %v", err)
}
builder := NewConfigManifestBuilder(bs, pk, ref, []byte(imgJSON)) builder := NewConfigManifestBuilder(bs, pk, ref, []byte(imgJSON))

View file

@ -55,7 +55,7 @@ func TestReferenceBuilder(t *testing.T) {
handCrafted := makeSignedManifest(t, pk, []Reference{r1, r2}) handCrafted := makeSignedManifest(t, pk, []Reference{r1, r2})
ref, err := reference.ParseNamed(handCrafted.Manifest.Name) ref, err := reference.WithName(handCrafted.Manifest.Name)
if err != nil { if err != nil {
t.Fatalf("could not parse reference: %v", err) t.Fatalf("could not parse reference: %v", err)
} }

View file

@ -43,7 +43,7 @@ func TestEventBridgeManifestPulled(t *testing.T) {
return nil return nil
})) }))
repoRef, _ := reference.ParseNamed(repo) repoRef, _ := reference.WithName(repo)
if err := l.ManifestPulled(repoRef, sm); err != nil { if err := l.ManifestPulled(repoRef, sm); err != nil {
t.Fatalf("unexpected error notifying manifest pull: %v", err) t.Fatalf("unexpected error notifying manifest pull: %v", err)
} }
@ -56,7 +56,7 @@ func TestEventBridgeManifestPushed(t *testing.T) {
return nil return nil
})) }))
repoRef, _ := reference.ParseNamed(repo) repoRef, _ := reference.WithName(repo)
if err := l.ManifestPushed(repoRef, sm); err != nil { if err := l.ManifestPushed(repoRef, sm); err != nil {
t.Fatalf("unexpected error notifying manifest pull: %v", err) t.Fatalf("unexpected error notifying manifest pull: %v", err)
} }
@ -72,7 +72,7 @@ func TestEventBridgeManifestPushedWithTag(t *testing.T) {
return nil return nil
})) }))
repoRef, _ := reference.ParseNamed(repo) repoRef, _ := reference.WithName(repo)
if err := l.ManifestPushed(repoRef, sm, distribution.WithTag(m.Tag)); err != nil { if err := l.ManifestPushed(repoRef, sm, distribution.WithTag(m.Tag)); err != nil {
t.Fatalf("unexpected error notifying manifest pull: %v", err) t.Fatalf("unexpected error notifying manifest pull: %v", err)
} }
@ -88,7 +88,7 @@ func TestEventBridgeManifestPulledWithTag(t *testing.T) {
return nil return nil
})) }))
repoRef, _ := reference.ParseNamed(repo) repoRef, _ := reference.WithName(repo)
if err := l.ManifestPulled(repoRef, sm, distribution.WithTag(m.Tag)); err != nil { if err := l.ManifestPulled(repoRef, sm, distribution.WithTag(m.Tag)); err != nil {
t.Fatalf("unexpected error notifying manifest pull: %v", err) t.Fatalf("unexpected error notifying manifest pull: %v", err)
} }
@ -100,7 +100,7 @@ func TestEventBridgeManifestDeleted(t *testing.T) {
return nil return nil
})) }))
repoRef, _ := reference.ParseNamed(repo) repoRef, _ := reference.WithName(repo)
if err := l.ManifestDeleted(repoRef, dgst); err != nil { if err := l.ManifestDeleted(repoRef, dgst); err != nil {
t.Fatalf("unexpected error notifying manifest pull: %v", err) t.Fatalf("unexpected error notifying manifest pull: %v", err)
} }
@ -160,7 +160,7 @@ func checkCommonManifest(t *testing.T, action string, events ...Event) {
t.Fatalf("unexpected event action: %q != %q", event.Action, action) t.Fatalf("unexpected event action: %q != %q", event.Action, action)
} }
repoRef, _ := reference.ParseNamed(repo) repoRef, _ := reference.WithName(repo)
ref, _ := reference.WithDigest(repoRef, dgst) ref, _ := reference.WithDigest(repoRef, dgst)
u, err := ub.BuildManifestURL(ref) u, err := ub.BuildManifestURL(ref)
if err != nil { if err != nil {

View file

@ -33,7 +33,7 @@ func TestListener(t *testing.T) {
ops: make(map[string]int), ops: make(map[string]int),
} }
repoRef, _ := reference.ParseNamed("foo/bar") repoRef, _ := reference.WithName("foo/bar")
repository, err := registry.Repository(ctx, repoRef) repository, err := registry.Repository(ctx, repoRef)
if err != nil { if err != nil {
t.Fatalf("unexpected error getting repo: %v", err) t.Fatalf("unexpected error getting repo: %v", err)

View file

@ -208,6 +208,13 @@ func TestParseRepositoryInfo(t *testing.T) {
AmbiguousName: "index.docker.io/library/ubuntu-12.04-base", AmbiguousName: "index.docker.io/library/ubuntu-12.04-base",
Domain: "docker.io", Domain: "docker.io",
}, },
{
RemoteName: "library/foo",
FamiliarName: "foo",
FullName: "docker.io/library/foo",
AmbiguousName: "docker.io/foo",
Domain: "docker.io",
},
{ {
RemoteName: "library/foo/bar", RemoteName: "library/foo/bar",
FamiliarName: "library/foo/bar", FamiliarName: "library/foo/bar",

View file

@ -55,6 +55,9 @@ var (
// ErrNameTooLong is returned when a repository name is longer than NameTotalLengthMax. // ErrNameTooLong is returned when a repository name is longer than NameTotalLengthMax.
ErrNameTooLong = fmt.Errorf("repository name must not be more than %v characters", NameTotalLengthMax) ErrNameTooLong = fmt.Errorf("repository name must not be more than %v characters", NameTotalLengthMax)
// ErrNameNotCanonical is returned when a name is not canonical.
ErrNameNotCanonical = errors.New("repository name must be canonical")
) )
// Reference is an opaque object reference identifier that may include // Reference is an opaque object reference identifier that may include
@ -231,18 +234,17 @@ func Parse(s string) (Reference, error) {
} }
// ParseNamed parses s and returns a syntactically valid reference implementing // ParseNamed parses s and returns a syntactically valid reference implementing
// the Named interface. The reference must have a name, otherwise an error is // the Named interface. The reference must have a name and be in the canonical
// returned. // form, otherwise an error is returned.
// If an error was encountered it is returned, along with a nil Reference. // If an error was encountered it is returned, along with a nil Reference.
// NOTE: ParseNamed will not handle short digests. // NOTE: ParseNamed will not handle short digests.
func ParseNamed(s string) (Named, error) { func ParseNamed(s string) (Named, error) {
ref, err := Parse(s) named, err := ParseNormalizedNamed(s)
if err != nil { if err != nil {
return nil, err return nil, err
} }
named, isNamed := ref.(Named) if named.String() != s {
if !isNamed { return nil, ErrNameNotCanonical
return nil, fmt.Errorf("reference %s has no name", ref.String())
} }
return named, nil return named, nil
} }

View file

@ -583,3 +583,77 @@ func TestWithDigest(t *testing.T) {
} }
} }
} }
func TestParseNamed(t *testing.T) {
testcases := []struct {
input string
domain string
name string
err error
}{
{
input: "test.com/foo",
domain: "test.com",
name: "foo",
},
{
input: "test:8080/foo",
domain: "test:8080",
name: "foo",
},
{
input: "test_com/foo",
err: ErrNameNotCanonical,
},
{
input: "test.com",
err: ErrNameNotCanonical,
},
{
input: "foo",
err: ErrNameNotCanonical,
},
{
input: "library/foo",
err: ErrNameNotCanonical,
},
{
input: "docker.io/library/foo",
domain: "docker.io",
name: "library/foo",
},
// Ambiguous case, parser will add "library/" to foo
{
input: "docker.io/foo",
err: ErrNameNotCanonical,
},
}
for _, testcase := range testcases {
failf := func(format string, v ...interface{}) {
t.Logf(strconv.Quote(testcase.input)+": "+format, v...)
t.Fail()
}
named, err := ParseNamed(testcase.input)
if err != nil && testcase.err == nil {
failf("error parsing name: %s", err)
continue
} else if err == nil && testcase.err != nil {
failf("parsing succeded: expected error %v", testcase.err)
continue
} else if err != testcase.err {
failf("unexpected error %v, expected %v", err, testcase.err)
continue
} else if err != nil {
continue
}
domain, name := SplitHostname(named)
if domain != testcase.domain {
failf("unexpected domain: got %q, expected %q", domain, testcase.domain)
}
if name != testcase.name {
failf("unexpected name: got %q, expected %q", name, testcase.name)
}
}
}

View file

@ -15,7 +15,7 @@ type urlBuilderTestCase struct {
} }
func makeURLBuilderTestCases(urlBuilder *URLBuilder) []urlBuilderTestCase { func makeURLBuilderTestCases(urlBuilder *URLBuilder) []urlBuilderTestCase {
fooBarRef, _ := reference.ParseNamed("foo/bar") fooBarRef, _ := reference.WithName("foo/bar")
return []urlBuilderTestCase{ return []urlBuilderTestCase{
{ {
description: "test base url", description: "test base url",

View file

@ -100,7 +100,7 @@ func addTestCatalog(route string, content []byte, link string, m *testutil.Reque
func TestBlobDelete(t *testing.T) { func TestBlobDelete(t *testing.T) {
dgst, _ := newRandomBlob(1024) dgst, _ := newRandomBlob(1024)
var m testutil.RequestResponseMap var m testutil.RequestResponseMap
repo, _ := reference.ParseNamed("test.example.com/repo1") repo, _ := reference.WithName("test.example.com/repo1")
m = append(m, testutil.RequestResponseMapping{ m = append(m, testutil.RequestResponseMapping{
Request: testutil.Request{ Request: testutil.Request{
Method: "DELETE", Method: "DELETE",
@ -139,7 +139,7 @@ func TestBlobFetch(t *testing.T) {
defer c() defer c()
ctx := context.Background() ctx := context.Background()
repo, _ := reference.ParseNamed("test.example.com/repo1") repo, _ := reference.WithName("test.example.com/repo1")
r, err := NewRepository(ctx, repo, e, nil) r, err := NewRepository(ctx, repo, e, nil)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
@ -160,7 +160,7 @@ func TestBlobFetch(t *testing.T) {
func TestBlobExistsNoContentLength(t *testing.T) { func TestBlobExistsNoContentLength(t *testing.T) {
var m testutil.RequestResponseMap var m testutil.RequestResponseMap
repo, _ := reference.ParseNamed("biff") repo, _ := reference.WithName("biff")
dgst, content := newRandomBlob(1024) dgst, content := newRandomBlob(1024)
m = append(m, testutil.RequestResponseMapping{ m = append(m, testutil.RequestResponseMapping{
Request: testutil.Request{ Request: testutil.Request{
@ -219,7 +219,7 @@ func TestBlobExists(t *testing.T) {
defer c() defer c()
ctx := context.Background() ctx := context.Background()
repo, _ := reference.ParseNamed("test.example.com/repo1") repo, _ := reference.WithName("test.example.com/repo1")
r, err := NewRepository(ctx, repo, e, nil) r, err := NewRepository(ctx, repo, e, nil)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
@ -251,7 +251,7 @@ func TestBlobUploadChunked(t *testing.T) {
b1[512:513], b1[512:513],
b1[513:1024], b1[513:1024],
} }
repo, _ := reference.ParseNamed("test.example.com/uploadrepo") repo, _ := reference.WithName("test.example.com/uploadrepo")
uuids := []string{uuid.Generate().String()} uuids := []string{uuid.Generate().String()}
m = append(m, testutil.RequestResponseMapping{ m = append(m, testutil.RequestResponseMapping{
Request: testutil.Request{ Request: testutil.Request{
@ -366,7 +366,7 @@ func TestBlobUploadChunked(t *testing.T) {
func TestBlobUploadMonolithic(t *testing.T) { func TestBlobUploadMonolithic(t *testing.T) {
dgst, b1 := newRandomBlob(1024) dgst, b1 := newRandomBlob(1024)
var m testutil.RequestResponseMap var m testutil.RequestResponseMap
repo, _ := reference.ParseNamed("test.example.com/uploadrepo") repo, _ := reference.WithName("test.example.com/uploadrepo")
uploadID := uuid.Generate().String() uploadID := uuid.Generate().String()
m = append(m, testutil.RequestResponseMapping{ m = append(m, testutil.RequestResponseMapping{
Request: testutil.Request{ Request: testutil.Request{
@ -474,9 +474,9 @@ func TestBlobUploadMonolithic(t *testing.T) {
func TestBlobMount(t *testing.T) { func TestBlobMount(t *testing.T) {
dgst, content := newRandomBlob(1024) dgst, content := newRandomBlob(1024)
var m testutil.RequestResponseMap var m testutil.RequestResponseMap
repo, _ := reference.ParseNamed("test.example.com/uploadrepo") repo, _ := reference.WithName("test.example.com/uploadrepo")
sourceRepo, _ := reference.ParseNamed("test.example.com/sourcerepo") sourceRepo, _ := reference.WithName("test.example.com/sourcerepo")
canonicalRef, _ := reference.WithDigest(sourceRepo, dgst) canonicalRef, _ := reference.WithDigest(sourceRepo, dgst)
m = append(m, testutil.RequestResponseMapping{ m = append(m, testutil.RequestResponseMapping{
@ -678,7 +678,7 @@ func checkEqualManifest(m1, m2 *schema1.SignedManifest) error {
func TestV1ManifestFetch(t *testing.T) { func TestV1ManifestFetch(t *testing.T) {
ctx := context.Background() ctx := context.Background()
repo, _ := reference.ParseNamed("test.example.com/repo") repo, _ := reference.WithName("test.example.com/repo")
m1, dgst, _ := newRandomSchemaV1Manifest(repo, "latest", 6) m1, dgst, _ := newRandomSchemaV1Manifest(repo, "latest", 6)
var m testutil.RequestResponseMap var m testutil.RequestResponseMap
_, pl, err := m1.Payload() _, pl, err := m1.Payload()
@ -755,7 +755,7 @@ func TestV1ManifestFetch(t *testing.T) {
} }
func TestManifestFetchWithEtag(t *testing.T) { func TestManifestFetchWithEtag(t *testing.T) {
repo, _ := reference.ParseNamed("test.example.com/repo/by/tag") repo, _ := reference.WithName("test.example.com/repo/by/tag")
_, d1, p1 := newRandomSchemaV1Manifest(repo, "latest", 6) _, d1, p1 := newRandomSchemaV1Manifest(repo, "latest", 6)
var m testutil.RequestResponseMap var m testutil.RequestResponseMap
addTestManifestWithEtag(repo, "latest", p1, &m, d1.String()) addTestManifestWithEtag(repo, "latest", p1, &m, d1.String())
@ -785,7 +785,7 @@ func TestManifestFetchWithEtag(t *testing.T) {
} }
func TestManifestDelete(t *testing.T) { func TestManifestDelete(t *testing.T) {
repo, _ := reference.ParseNamed("test.example.com/repo/delete") repo, _ := reference.WithName("test.example.com/repo/delete")
_, dgst1, _ := newRandomSchemaV1Manifest(repo, "latest", 6) _, dgst1, _ := newRandomSchemaV1Manifest(repo, "latest", 6)
_, dgst2, _ := newRandomSchemaV1Manifest(repo, "latest", 6) _, dgst2, _ := newRandomSchemaV1Manifest(repo, "latest", 6)
var m testutil.RequestResponseMap var m testutil.RequestResponseMap
@ -825,7 +825,7 @@ func TestManifestDelete(t *testing.T) {
} }
func TestManifestPut(t *testing.T) { func TestManifestPut(t *testing.T) {
repo, _ := reference.ParseNamed("test.example.com/repo/delete") repo, _ := reference.WithName("test.example.com/repo/delete")
m1, dgst, _ := newRandomSchemaV1Manifest(repo, "other", 6) m1, dgst, _ := newRandomSchemaV1Manifest(repo, "other", 6)
_, payload, err := m1.Payload() _, payload, err := m1.Payload()
@ -890,7 +890,7 @@ func TestManifestPut(t *testing.T) {
} }
func TestManifestTags(t *testing.T) { func TestManifestTags(t *testing.T) {
repo, _ := reference.ParseNamed("test.example.com/repo/tags/list") repo, _ := reference.WithName("test.example.com/repo/tags/list")
tagsList := []byte(strings.TrimSpace(` tagsList := []byte(strings.TrimSpace(`
{ {
"name": "test.example.com/repo/tags/list", "name": "test.example.com/repo/tags/list",
@ -952,7 +952,7 @@ func TestManifestTags(t *testing.T) {
} }
func TestObtainsErrorForMissingTag(t *testing.T) { func TestObtainsErrorForMissingTag(t *testing.T) {
repo, _ := reference.ParseNamed("test.example.com/repo") repo, _ := reference.WithName("test.example.com/repo")
var m testutil.RequestResponseMap var m testutil.RequestResponseMap
var errors errcode.Errors var errors errcode.Errors
@ -998,7 +998,7 @@ func TestManifestTagsPaginated(t *testing.T) {
s := httptest.NewServer(http.NotFoundHandler()) s := httptest.NewServer(http.NotFoundHandler())
defer s.Close() defer s.Close()
repo, _ := reference.ParseNamed("test.example.com/repo/tags/list") repo, _ := reference.WithName("test.example.com/repo/tags/list")
tagsList := []string{"tag1", "tag2", "funtag"} tagsList := []string{"tag1", "tag2", "funtag"}
var m testutil.RequestResponseMap var m testutil.RequestResponseMap
for i := 0; i < 3; i++ { for i := 0; i < 3; i++ {
@ -1067,7 +1067,7 @@ func TestManifestTagsPaginated(t *testing.T) {
} }
func TestManifestUnauthorized(t *testing.T) { func TestManifestUnauthorized(t *testing.T) {
repo, _ := reference.ParseNamed("test.example.com/repo") repo, _ := reference.WithName("test.example.com/repo")
_, dgst, _ := newRandomSchemaV1Manifest(repo, "latest", 6) _, dgst, _ := newRandomSchemaV1Manifest(repo, "latest", 6)
var m testutil.RequestResponseMap var m testutil.RequestResponseMap

View file

@ -280,7 +280,7 @@ func makeBlobArgs(t *testing.T) blobArgs {
layerFile: layerFile, layerFile: layerFile,
layerDigest: layerDigest, layerDigest: layerDigest,
} }
args.imageName, _ = reference.ParseNamed("foo/bar") args.imageName, _ = reference.WithName("foo/bar")
return args return args
} }
@ -705,7 +705,7 @@ func TestDeleteDisabled(t *testing.T) {
env := newTestEnv(t, false) env := newTestEnv(t, false)
defer env.Shutdown() defer env.Shutdown()
imageName, _ := reference.ParseNamed("foo/bar") imageName, _ := reference.WithName("foo/bar")
// "build" our layer file // "build" our layer file
layerFile, layerDigest, err := testutil.CreateRandomTarFile() layerFile, layerDigest, err := testutil.CreateRandomTarFile()
if err != nil { if err != nil {
@ -732,7 +732,7 @@ func TestDeleteReadOnly(t *testing.T) {
env := newTestEnv(t, true) env := newTestEnv(t, true)
defer env.Shutdown() defer env.Shutdown()
imageName, _ := reference.ParseNamed("foo/bar") imageName, _ := reference.WithName("foo/bar")
// "build" our layer file // "build" our layer file
layerFile, layerDigest, err := testutil.CreateRandomTarFile() layerFile, layerDigest, err := testutil.CreateRandomTarFile()
if err != nil { if err != nil {
@ -762,7 +762,7 @@ func TestStartPushReadOnly(t *testing.T) {
defer env.Shutdown() defer env.Shutdown()
env.app.readOnly = true env.app.readOnly = true
imageName, _ := reference.ParseNamed("foo/bar") imageName, _ := reference.WithName("foo/bar")
layerUploadURL, err := env.builder.BuildBlobUploadURL(imageName) layerUploadURL, err := env.builder.BuildBlobUploadURL(imageName)
if err != nil { if err != nil {
@ -800,8 +800,8 @@ type manifestArgs struct {
} }
func TestManifestAPI(t *testing.T) { func TestManifestAPI(t *testing.T) {
schema1Repo, _ := reference.ParseNamed("foo/schema1") schema1Repo, _ := reference.WithName("foo/schema1")
schema2Repo, _ := reference.ParseNamed("foo/schema2") schema2Repo, _ := reference.WithName("foo/schema2")
deleteEnabled := false deleteEnabled := false
env1 := newTestEnv(t, deleteEnabled) env1 := newTestEnv(t, deleteEnabled)
@ -906,8 +906,8 @@ func TestGetManifestWithStorageError(t *testing.T) {
} }
func TestManifestDelete(t *testing.T) { func TestManifestDelete(t *testing.T) {
schema1Repo, _ := reference.ParseNamed("foo/schema1") schema1Repo, _ := reference.WithName("foo/schema1")
schema2Repo, _ := reference.ParseNamed("foo/schema2") schema2Repo, _ := reference.WithName("foo/schema2")
deleteEnabled := true deleteEnabled := true
env := newTestEnv(t, deleteEnabled) env := newTestEnv(t, deleteEnabled)
@ -919,7 +919,7 @@ func TestManifestDelete(t *testing.T) {
} }
func TestManifestDeleteDisabled(t *testing.T) { func TestManifestDeleteDisabled(t *testing.T) {
schema1Repo, _ := reference.ParseNamed("foo/schema1") schema1Repo, _ := reference.WithName("foo/schema1")
deleteEnabled := false deleteEnabled := false
env := newTestEnv(t, deleteEnabled) env := newTestEnv(t, deleteEnabled)
defer env.Shutdown() defer env.Shutdown()
@ -2403,7 +2403,7 @@ func checkErr(t *testing.T, err error, msg string) {
} }
func createRepository(env *testEnv, t *testing.T, imageName string, tag string) digest.Digest { func createRepository(env *testEnv, t *testing.T, imageName string, tag string) digest.Digest {
imageNameRef, err := reference.ParseNamed(imageName) imageNameRef, err := reference.WithName(imageName)
if err != nil { if err != nil {
t.Fatalf("unable to parse reference: %v", err) t.Fatalf("unable to parse reference: %v", err)
} }
@ -2474,7 +2474,7 @@ func TestRegistryAsCacheMutationAPIs(t *testing.T) {
env := newTestEnvMirror(t, deleteEnabled) env := newTestEnvMirror(t, deleteEnabled)
defer env.Shutdown() defer env.Shutdown()
imageName, _ := reference.ParseNamed("foo/bar") imageName, _ := reference.WithName("foo/bar")
tag := "latest" tag := "latest"
tagRef, _ := reference.WithTag(imageName, tag) tagRef, _ := reference.WithTag(imageName, tag)
manifestURL, err := env.builder.BuildManifestURL(tagRef) manifestURL, err := env.builder.BuildManifestURL(tagRef)
@ -2567,7 +2567,7 @@ func TestProxyManifestGetByTag(t *testing.T) {
} }
truthConfig.HTTP.Headers = headerConfig truthConfig.HTTP.Headers = headerConfig
imageName, _ := reference.ParseNamed("foo/bar") imageName, _ := reference.WithName("foo/bar")
tag := "latest" tag := "latest"
truthEnv := newTestEnvWithConfig(t, &truthConfig) truthEnv := newTestEnvWithConfig(t, &truthConfig)

View file

@ -650,7 +650,7 @@ func (app *App) dispatcher(dispatch dispatchFunc) http.Handler {
context.Context = ctxu.WithLogger(context.Context, ctxu.GetLogger(context.Context, auth.UserNameKey)) context.Context = ctxu.WithLogger(context.Context, ctxu.GetLogger(context.Context, auth.UserNameKey))
if app.nameRequired(r) { if app.nameRequired(r) {
nameRef, err := reference.ParseNamed(getName(context)) nameRef, err := reference.WithName(getName(context))
if err != nil { if err != nil {
ctxu.GetLogger(context).Errorf("error parsing reference from context: %v", err) ctxu.GetLogger(context).Errorf("error parsing reference from context: %v", err)
context.Errors = append(context.Errors, distribution.ErrRepositoryNameInvalid{ context.Errors = append(context.Errors, distribution.ErrRepositoryNameInvalid{

View file

@ -334,7 +334,7 @@ func (buh *blobUploadHandler) createBlobMountOption(fromRepo, mountDigest string
return nil, err return nil, err
} }
ref, err := reference.ParseNamed(fromRepo) ref, err := reference.WithName(fromRepo)
if err != nil { if err != nil {
return nil, err return nil, err
} }

View file

@ -115,7 +115,7 @@ func (te *testEnv) RemoteStats() *map[string]int {
// Populate remote store and record the digests // Populate remote store and record the digests
func makeTestEnv(t *testing.T, name string) *testEnv { func makeTestEnv(t *testing.T, name string) *testEnv {
nameRef, err := reference.ParseNamed(name) nameRef, err := reference.WithName(name)
if err != nil { if err != nil {
t.Fatalf("unable to parse reference: %s", err) t.Fatalf("unable to parse reference: %s", err)
} }

View file

@ -83,7 +83,7 @@ func (m *mockChallenger) challengeManager() challenge.Manager {
} }
func newManifestStoreTestEnv(t *testing.T, name, tag string) *manifestStoreTestEnv { func newManifestStoreTestEnv(t *testing.T, name, tag string) *manifestStoreTestEnv {
nameRef, err := reference.ParseNamed(name) nameRef, err := reference.WithName(name)
if err != nil { if err != nil {
t.Fatalf("unable to parse reference: %s", err) t.Fatalf("unable to parse reference: %s", err)
} }

View file

@ -24,7 +24,7 @@ import (
// obtained using Seek // obtained using Seek
func TestWriteSeek(t *testing.T) { func TestWriteSeek(t *testing.T) {
ctx := context.Background() ctx := context.Background()
imageName, _ := reference.ParseNamed("foo/bar") imageName, _ := reference.WithName("foo/bar")
driver := testdriver.New() driver := testdriver.New()
registry, err := NewRegistry(ctx, driver, BlobDescriptorCacheProvider(memory.NewInMemoryBlobDescriptorCacheProvider()), EnableDelete, EnableRedirect) registry, err := NewRegistry(ctx, driver, BlobDescriptorCacheProvider(memory.NewInMemoryBlobDescriptorCacheProvider()), EnableDelete, EnableRedirect)
if err != nil { if err != nil {
@ -60,7 +60,7 @@ func TestSimpleBlobUpload(t *testing.T) {
} }
ctx := context.Background() ctx := context.Background()
imageName, _ := reference.ParseNamed("foo/bar") imageName, _ := reference.WithName("foo/bar")
driver := testdriver.New() driver := testdriver.New()
registry, err := NewRegistry(ctx, driver, BlobDescriptorCacheProvider(memory.NewInMemoryBlobDescriptorCacheProvider()), EnableDelete, EnableRedirect) registry, err := NewRegistry(ctx, driver, BlobDescriptorCacheProvider(memory.NewInMemoryBlobDescriptorCacheProvider()), EnableDelete, EnableRedirect)
if err != nil { if err != nil {
@ -255,7 +255,7 @@ func TestSimpleBlobUpload(t *testing.T) {
// other tests. // other tests.
func TestSimpleBlobRead(t *testing.T) { func TestSimpleBlobRead(t *testing.T) {
ctx := context.Background() ctx := context.Background()
imageName, _ := reference.ParseNamed("foo/bar") imageName, _ := reference.WithName("foo/bar")
driver := testdriver.New() driver := testdriver.New()
registry, err := NewRegistry(ctx, driver, BlobDescriptorCacheProvider(memory.NewInMemoryBlobDescriptorCacheProvider()), EnableDelete, EnableRedirect) registry, err := NewRegistry(ctx, driver, BlobDescriptorCacheProvider(memory.NewInMemoryBlobDescriptorCacheProvider()), EnableDelete, EnableRedirect)
if err != nil { if err != nil {
@ -366,8 +366,8 @@ func TestBlobMount(t *testing.T) {
} }
ctx := context.Background() ctx := context.Background()
imageName, _ := reference.ParseNamed("foo/bar") imageName, _ := reference.WithName("foo/bar")
sourceImageName, _ := reference.ParseNamed("foo/source") sourceImageName, _ := reference.WithName("foo/source")
driver := testdriver.New() driver := testdriver.New()
registry, err := NewRegistry(ctx, driver, BlobDescriptorCacheProvider(memory.NewInMemoryBlobDescriptorCacheProvider()), EnableDelete, EnableRedirect) registry, err := NewRegistry(ctx, driver, BlobDescriptorCacheProvider(memory.NewInMemoryBlobDescriptorCacheProvider()), EnableDelete, EnableRedirect)
if err != nil { if err != nil {
@ -518,7 +518,7 @@ func TestBlobMount(t *testing.T) {
// TestLayerUploadZeroLength uploads zero-length // TestLayerUploadZeroLength uploads zero-length
func TestLayerUploadZeroLength(t *testing.T) { func TestLayerUploadZeroLength(t *testing.T) {
ctx := context.Background() ctx := context.Background()
imageName, _ := reference.ParseNamed("foo/bar") imageName, _ := reference.WithName("foo/bar")
driver := testdriver.New() driver := testdriver.New()
registry, err := NewRegistry(ctx, driver, BlobDescriptorCacheProvider(memory.NewInMemoryBlobDescriptorCacheProvider()), EnableDelete, EnableRedirect) registry, err := NewRegistry(ctx, driver, BlobDescriptorCacheProvider(memory.NewInMemoryBlobDescriptorCacheProvider()), EnableDelete, EnableRedirect)
if err != nil { if err != nil {

View file

@ -26,7 +26,7 @@ func NewInMemoryBlobDescriptorCacheProvider() cache.BlobDescriptorCacheProvider
} }
func (imbdcp *inMemoryBlobDescriptorCacheProvider) RepositoryScoped(repo string) (distribution.BlobDescriptorService, error) { func (imbdcp *inMemoryBlobDescriptorCacheProvider) RepositoryScoped(repo string) (distribution.BlobDescriptorService, error) {
if _, err := reference.ParseNamed(repo); err != nil { if _, err := reference.ParseNormalizedNamed(repo); err != nil {
return nil, err return nil, err
} }

View file

@ -41,7 +41,7 @@ func NewRedisBlobDescriptorCacheProvider(pool *redis.Pool) cache.BlobDescriptorC
// RepositoryScoped returns the scoped cache. // RepositoryScoped returns the scoped cache.
func (rbds *redisBlobDescriptorService) RepositoryScoped(repo string) (distribution.BlobDescriptorService, error) { func (rbds *redisBlobDescriptorService) RepositoryScoped(repo string) (distribution.BlobDescriptorService, error) {
if _, err := reference.ParseNamed(repo); err != nil { if _, err := reference.ParseNormalizedNamed(repo); err != nil {
return nil, err return nil, err
} }

View file

@ -68,7 +68,7 @@ func setupFS(t *testing.T) *setupEnv {
} }
func makeRepo(ctx context.Context, t *testing.T, name string, reg distribution.Namespace) { func makeRepo(ctx context.Context, t *testing.T, name string, reg distribution.Namespace) {
named, err := reference.ParseNamed(name) named, err := reference.WithName(name)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }

View file

@ -27,7 +27,7 @@ func MarkAndSweep(ctx context.Context, storageDriver driver.StorageDriver, regis
emit(repoName) emit(repoName)
var err error var err error
named, err := reference.ParseNamed(repoName) named, err := reference.WithName(repoName)
if err != nil { if err != nil {
return fmt.Errorf("failed to parse repo name %s: %v", repoName, err) return fmt.Errorf("failed to parse repo name %s: %v", repoName, err)
} }

View file

@ -39,7 +39,7 @@ func makeRepository(t *testing.T, registry distribution.Namespace, name string)
ctx := context.Background() ctx := context.Background()
// Initialize a dummy repository // Initialize a dummy repository
named, err := reference.ParseNamed(name) named, err := reference.WithName(name)
if err != nil { if err != nil {
t.Fatalf("Failed to parse name %s: %v", name, err) t.Fatalf("Failed to parse name %s: %v", name, err)
} }

View file

@ -16,7 +16,7 @@ import (
) )
func TestLinkedBlobStoreCreateWithMountFrom(t *testing.T) { func TestLinkedBlobStoreCreateWithMountFrom(t *testing.T) {
fooRepoName, _ := reference.ParseNamed("nm/foo") fooRepoName, _ := reference.WithName("nm/foo")
fooEnv := newManifestStoreTestEnv(t, fooRepoName, "thetag") fooEnv := newManifestStoreTestEnv(t, fooRepoName, "thetag")
ctx := context.Background() ctx := context.Background()
stats, err := mockRegistry(t, fooEnv.registry) stats, err := mockRegistry(t, fooEnv.registry)
@ -54,7 +54,7 @@ func TestLinkedBlobStoreCreateWithMountFrom(t *testing.T) {
} }
// create another repository nm/bar // create another repository nm/bar
barRepoName, _ := reference.ParseNamed("nm/bar") barRepoName, _ := reference.WithName("nm/bar")
barRepo, err := fooEnv.registry.Repository(ctx, barRepoName) barRepo, err := fooEnv.registry.Repository(ctx, barRepoName)
if err != nil { if err != nil {
t.Fatalf("unexpected error getting repo: %v", err) t.Fatalf("unexpected error getting repo: %v", err)
@ -94,7 +94,7 @@ func TestLinkedBlobStoreCreateWithMountFrom(t *testing.T) {
clearStats(stats) clearStats(stats)
// create yet another repository nm/baz // create yet another repository nm/baz
bazRepoName, _ := reference.ParseNamed("nm/baz") bazRepoName, _ := reference.WithName("nm/baz")
bazRepo, err := fooEnv.registry.Repository(ctx, bazRepoName) bazRepo, err := fooEnv.registry.Repository(ctx, bazRepoName)
if err != nil { if err != nil {
t.Fatalf("unexpected error getting repo: %v", err) t.Fatalf("unexpected error getting repo: %v", err)

View file

@ -60,7 +60,7 @@ func TestManifestStorage(t *testing.T) {
} }
func testManifestStorage(t *testing.T, options ...RegistryOption) { func testManifestStorage(t *testing.T, options ...RegistryOption) {
repoName, _ := reference.ParseNamed("foo/bar") repoName, _ := reference.WithName("foo/bar")
env := newManifestStoreTestEnv(t, repoName, "thetag", options...) env := newManifestStoreTestEnv(t, repoName, "thetag", options...)
ctx := context.Background() ctx := context.Background()
ms, err := env.repository.Manifests(ctx) ms, err := env.repository.Manifests(ctx)

View file

@ -22,7 +22,7 @@ func testTagStore(t *testing.T) *tagsTestEnv {
t.Fatal(err) t.Fatal(err)
} }
repoRef, _ := reference.ParseNamed("a/b") repoRef, _ := reference.WithName("a/b")
repo, err := reg.Repository(ctx, repoRef) repo, err := reg.Repository(ctx, repoRef)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)