Define common regexps used across registry application

This commit adds regular expression definitions for several string identifiers
used througout the registry. The repository name regex supports up to five path
path components and restricts repeated periods, dashes and underscores. The tag
regex simply validates the length of the tag and that printable characters are
required.

Though we define a new package common, these definition should land in docker
core.
This commit is contained in:
Stephen J Day 2014-11-12 16:39:35 -08:00
parent d245a502b2
commit 375f3cc136
4 changed files with 230 additions and 0 deletions

62
common/names_test.go Normal file
View file

@ -0,0 +1,62 @@
package common
import (
"testing"
)
func TestRepositoryNameRegexp(t *testing.T) {
for _, testcase := range []struct {
input string
valid bool
}{
{
input: "simple/name",
valid: true,
},
{
input: "library/ubuntu",
valid: true,
},
{
input: "docker/stevvooe/app",
valid: true,
},
{
input: "aa/aa/aa/aa/aa/aa/aa/aa/aa/bb/bb/bb/bb/bb/bb",
valid: true,
},
{
input: "a/a/a/a/a/a/b/b/b/b",
valid: false,
},
{
input: "a/a/a/a/",
valid: false,
},
{
input: "foo.com/bar/baz",
valid: true,
},
{
input: "blog.foo.com/bar/baz",
valid: true,
},
{
input: "asdf",
valid: false,
},
{
input: "asdf$$^/",
valid: false,
},
} {
if RepositoryNameRegexp.MatchString(testcase.input) != testcase.valid {
status := "invalid"
if testcase.valid {
status = "valid"
}
t.Fatalf("expected %q to be %s repository name", testcase.input, status)
}
}
}