mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Fix Tag Test for longer tags
Docker-DCO-1.1-Signed-off-by: Jessica Frazelle <jess@docker.com> (github: jfrazelle)
This commit is contained in:
parent
60908acff6
commit
de32f48e66
3 changed files with 15 additions and 4 deletions
|
@ -2394,13 +2394,12 @@ func TestBuildOnBuildOutput(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestBuildInvalidTag(t *testing.T) {
|
func TestBuildInvalidTag(t *testing.T) {
|
||||||
name := "abcd:A0123456789B0123456789C0123456789"
|
name := "abcd:" + makeRandomString(200)
|
||||||
defer deleteImages(name)
|
defer deleteImages(name)
|
||||||
_, out, err := buildImageWithOut(name, "FROM scratch\nMAINTAINER quux\n", true)
|
_, out, err := buildImageWithOut(name, "FROM scratch\nMAINTAINER quux\n", true)
|
||||||
// if the error doesnt check for illegal tag name, or the image is built
|
// if the error doesnt check for illegal tag name, or the image is built
|
||||||
// then this should fail
|
// then this should fail
|
||||||
if !strings.Contains(err.Error(), "Illegal tag name") ||
|
if !strings.Contains(out, "Illegal tag name") || strings.Contains(out, "Sending build context to Docker daemon") {
|
||||||
strings.Contains(out, "Sending build context to Docker daemon") {
|
|
||||||
t.Fatalf("failed to stop before building. Error: %s, Output: %s", err, out)
|
t.Fatalf("failed to stop before building. Error: %s, Output: %s", err, out)
|
||||||
}
|
}
|
||||||
logDone("build - invalid tag")
|
logDone("build - invalid tag")
|
||||||
|
|
|
@ -54,8 +54,9 @@ func TestTagInvalidUnprefixedRepo(t *testing.T) {
|
||||||
|
|
||||||
// ensure we don't allow the use of invalid tags; these tag operations should fail
|
// ensure we don't allow the use of invalid tags; these tag operations should fail
|
||||||
func TestTagInvalidPrefixedRepo(t *testing.T) {
|
func TestTagInvalidPrefixedRepo(t *testing.T) {
|
||||||
|
long_tag := makeRandomString(121)
|
||||||
|
|
||||||
invalidTags := []string{"repo:fo$z$", "repo:Foo@3cc", "repo:Foo$3", "repo:Foo*3", "repo:Fo^3", "repo:Foo!3", "repo:%goodbye", "repo:#hashtagit", "repo:F)xcz(", "repo:fwaytoolongandwaymorethan30characterslong", "repo:-foo", "repo:.."}
|
invalidTags := []string{"repo:fo$z$", "repo:Foo@3cc", "repo:Foo$3", "repo:Foo*3", "repo:Fo^3", "repo:Foo!3", "repo:%goodbye", "repo:#hashtagit", "repo:F)xcz(", "repo:-foo", "repo:..", long_tag}
|
||||||
|
|
||||||
for _, repotag := range invalidTags {
|
for _, repotag := range invalidTags {
|
||||||
tagCmd := exec.Command(dockerBinary, "tag", "busybox", repotag)
|
tagCmd := exec.Command(dockerBinary, "tag", "busybox", repotag)
|
||||||
|
|
|
@ -5,6 +5,7 @@ import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
|
"math/rand"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/http/httptest"
|
"net/http/httptest"
|
||||||
"os"
|
"os"
|
||||||
|
@ -255,3 +256,13 @@ func copyWithCP(source, target string) error {
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func makeRandomString(n int) string {
|
||||||
|
// make a really long string
|
||||||
|
letters := []byte("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ")
|
||||||
|
b := make([]byte, n)
|
||||||
|
for i := range b {
|
||||||
|
b[i] = letters[rand.Intn(len(letters))]
|
||||||
|
}
|
||||||
|
return string(b)
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue