diff --git a/registry/api/v2/names_test.go b/registry/api/v2/names_test.go index 51e0ba8b..3a017037 100644 --- a/registry/api/v2/names_test.go +++ b/registry/api/v2/names_test.go @@ -6,7 +6,7 @@ import ( "testing" ) -func TestRepositoryNameRegexp(t *testing.T) { +func TestRepositoryComponentNameRegexp(t *testing.T) { for _, testcase := range []struct { input string err error @@ -149,3 +149,143 @@ func TestRepositoryNameRegexp(t *testing.T) { } } } + +func TestRepositoryNameRegexp(t *testing.T) { + for _, testcase := range []struct { + input string + invalid bool + }{ + { + input: "short", + }, + { + input: "simple/name", + }, + { + input: "library/ubuntu", + }, + { + input: "docker/stevvooe/app", + }, + { + input: "aa/aa/aa/aa/aa/aa/aa/aa/aa/bb/bb/bb/bb/bb/bb", + }, + { + input: "aa/aa/bb/bb/bb", + }, + { + input: "a/a/a/b/b", + }, + { + input: "a/a/a/a/", + invalid: true, + }, + { + input: "a//a/a", + invalid: true, + }, + { + input: "a", + }, + { + input: "a/aa", + }, + { + input: "aa/a", + }, + { + input: "a/aa/a", + }, + { + input: "foo.com/", + invalid: true, + }, + { + // currently not allowed by the regex + input: "foo.com:8080/bar", + invalid: true, + }, + { + input: "foo.com/bar", + }, + { + input: "foo.com/bar/baz", + }, + { + input: "foo.com/bar/baz/quux", + }, + { + input: "blog.foo.com/bar/baz", + }, + { + input: "asdf", + }, + { + input: "asdf$$^/aa", + invalid: true, + }, + { + input: "aa-a/aa", + }, + { + input: "aa/aa", + }, + { + input: "a-a/a-a", + }, + { + input: "a-/a/a/a", + invalid: true, + }, + { + input: "-foo/bar", + invalid: true, + }, + { + input: "foo/bar-", + invalid: true, + }, + { + input: "foo-/bar", + invalid: true, + }, + { + input: "foo/-bar", + invalid: true, + }, + { + input: "_foo/bar", + invalid: true, + }, + { + input: "foo/bar_", + invalid: true, + }, + { + input: "____/____", + invalid: true, + }, + { + input: "_docker/_docker", + invalid: true, + }, + { + input: "docker_/docker_", + invalid: true, + }, + } { + failf := func(format string, v ...interface{}) { + t.Logf(strconv.Quote(testcase.input)+": "+format, v...) + t.Fail() + } + + matches := RepositoryNameRegexp.FindString(testcase.input) == testcase.input + if matches == testcase.invalid { + if testcase.invalid { + failf("expected invalid repository name %s", testcase.input) + } else { + failf("expected valid repository name %s", testcase.input) + } + } + } +} diff --git a/registry/api/v2/routes_test.go b/registry/api/v2/routes_test.go index 9fd29a4f..b8d724df 100644 --- a/registry/api/v2/routes_test.go +++ b/registry/api/v2/routes_test.go @@ -66,6 +66,27 @@ func TestRouter(t *testing.T) { "name": "foo/bar", }, }, + { + RouteName: RouteNameTags, + RequestURI: "/v2/docker.com/foo/tags/list", + Vars: map[string]string{ + "name": "docker.com/foo", + }, + }, + { + RouteName: RouteNameTags, + RequestURI: "/v2/docker.com/foo/bar/tags/list", + Vars: map[string]string{ + "name": "docker.com/foo/bar", + }, + }, + { + RouteName: RouteNameTags, + RequestURI: "/v2/docker.com/foo/bar/baz/tags/list", + Vars: map[string]string{ + "name": "docker.com/foo/bar/baz", + }, + }, { RouteName: RouteNameBlob, RequestURI: "/v2/foo/bar/blobs/tarsum.dev+foo:abcdef0919234",