375f3cc136
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.
63 lines
947 B
Go
63 lines
947 B
Go
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)
|
|
}
|
|
}
|
|
}
|