6db32fde |
package main
import ( |
4352da78 |
"fmt" |
c496f241 |
"strings" |
b80fae73 |
|
72269acf |
"github.com/docker/docker/pkg/integration/checker" |
4352da78 |
"github.com/docker/docker/pkg/stringid" |
b80fae73 |
"github.com/docker/docker/pkg/stringutils" |
dc944ea7 |
"github.com/go-check/check" |
6db32fde |
)
// tagging a named image in a new unprefixed repo should work |
dc944ea7 |
func (s *DockerSuite) TestTagUnprefixedRepoByName(c *check.C) { |
1723c647 |
// Don't attempt to pull on Windows as not in hub. It's installed
// as an image through .ensure-frozen-images-windows
if daemonPlatform != "windows" {
if err := pullImageIfNotExist("busybox:latest"); err != nil {
c.Fatal("couldn't find the busybox:latest image locally and failed to pull it")
} |
6db32fde |
}
|
eef6eda7 |
dockerCmd(c, "tag", "busybox:latest", "testfoobarbaz") |
6db32fde |
}
// tagging an image by ID in a new unprefixed repo should work |
dc944ea7 |
func (s *DockerSuite) TestTagUnprefixedRepoByID(c *check.C) { |
62a856e9 |
imageID := inspectField(c, "busybox", "Id") |
eef6eda7 |
dockerCmd(c, "tag", imageID, "testfoobarbaz") |
6db32fde |
}
|
46eb4140 |
// ensure we don't allow the use of invalid repository names; these tag operations should fail |
dc944ea7 |
func (s *DockerSuite) TestTagInvalidUnprefixedRepo(c *check.C) { |
e2afab9c |
invalidRepos := []string{"fo$z$", "Foo@3cc", "Foo$3", "Foo*3", "Fo^3", "Foo!3", "F)xcz(", "fo%asd", "FOO/bar"} |
6db32fde |
for _, repo := range invalidRepos { |
72269acf |
out, _, err := dockerCmdWithError("tag", "busybox", repo)
c.Assert(err, checker.NotNil, check.Commentf("tag busybox %v should have failed : %v", repo, out)) |
46eb4140 |
}
}
// ensure we don't allow the use of invalid tags; these tag operations should fail |
dc944ea7 |
func (s *DockerSuite) TestTagInvalidPrefixedRepo(c *check.C) { |
ae907e7a |
longTag := stringutils.GenerateRandomAlphaOnlyString(121) |
46eb4140 |
|
ae907e7a |
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:..", longTag} |
46eb4140 |
for _, repotag := range invalidTags { |
72269acf |
out, _, err := dockerCmdWithError("tag", "busybox", repotag)
c.Assert(err, checker.NotNil, check.Commentf("tag busybox %v should have failed : %v", repotag, out)) |
6db32fde |
}
}
// ensure we allow the use of valid tags |
dc944ea7 |
func (s *DockerSuite) TestTagValidPrefixedRepo(c *check.C) { |
1723c647 |
// Don't attempt to pull on Windows as not in hub. It's installed
// as an image through .ensure-frozen-images-windows
if daemonPlatform != "windows" {
if err := pullImageIfNotExist("busybox:latest"); err != nil {
c.Fatal("couldn't find the busybox:latest image locally and failed to pull it")
} |
6db32fde |
}
|
e2afab9c |
validRepos := []string{"fooo/bar", "fooaa/test", "foooo:t", "HOSTNAME.DOMAIN.COM:443/foo/bar"} |
6db32fde |
for _, repo := range validRepos { |
693ba98c |
_, _, err := dockerCmdWithError("tag", "busybox:latest", repo) |
6db32fde |
if err != nil { |
dc944ea7 |
c.Errorf("tag busybox %v should have worked: %s", repo, err) |
6db32fde |
continue
} |
e0927447 |
deleteImages(repo) |
6db32fde |
}
} |
c496f241 |
|
8d4fe141 |
// tag an image with an existed tag name without -f option should work |
dc944ea7 |
func (s *DockerSuite) TestTagExistedNameWithoutForce(c *check.C) { |
1723c647 |
// Don't attempt to pull on Windows as not in hub. It's installed
// as an image through .ensure-frozen-images-windows
if daemonPlatform != "windows" {
if err := pullImageIfNotExist("busybox:latest"); err != nil {
c.Fatal("couldn't find the busybox:latest image locally and failed to pull it")
} |
c496f241 |
}
|
eef6eda7 |
dockerCmd(c, "tag", "busybox:latest", "busybox:test") |
c496f241 |
}
|
b8301005 |
func (s *DockerSuite) TestTagWithPrefixHyphen(c *check.C) { |
1723c647 |
// Don't attempt to pull on Windows as not in hub. It's installed
// as an image through .ensure-frozen-images-windows
if daemonPlatform != "windows" {
if err := pullImageIfNotExist("busybox:latest"); err != nil {
c.Fatal("couldn't find the busybox:latest image locally and failed to pull it")
} |
e00cfbb6 |
}
// test repository name begin with '-' |
693ba98c |
out, _, err := dockerCmdWithError("tag", "busybox:latest", "-busybox:test") |
72269acf |
c.Assert(err, checker.NotNil, check.Commentf(out)) |
15d84a3a |
c.Assert(out, checker.Contains, "Error parsing reference", check.Commentf("tag a name begin with '-' should failed")) |
72269acf |
|
e00cfbb6 |
// test namespace name begin with '-' |
693ba98c |
out, _, err = dockerCmdWithError("tag", "busybox:latest", "-test/busybox:test") |
72269acf |
c.Assert(err, checker.NotNil, check.Commentf(out)) |
15d84a3a |
c.Assert(out, checker.Contains, "Error parsing reference", check.Commentf("tag a name begin with '-' should failed")) |
72269acf |
|
51462327 |
// test index name begin with '-' |
693ba98c |
out, _, err = dockerCmdWithError("tag", "busybox:latest", "-index:5000/busybox:test") |
72269acf |
c.Assert(err, checker.NotNil, check.Commentf(out)) |
15d84a3a |
c.Assert(out, checker.Contains, "Error parsing reference", check.Commentf("tag a name begin with '-' should failed")) |
e00cfbb6 |
}
|
568f86eb |
// ensure tagging using official names works
// ensure all tags result in the same name |
dc944ea7 |
func (s *DockerSuite) TestTagOfficialNames(c *check.C) { |
568f86eb |
names := []string{
"docker.io/busybox",
"index.docker.io/busybox",
"library/busybox",
"docker.io/library/busybox",
"index.docker.io/library/busybox",
}
for _, name := range names { |
8d4fe141 |
out, exitCode, err := dockerCmdWithError("tag", "busybox:latest", name+":latest") |
568f86eb |
if err != nil || exitCode != 0 { |
dc944ea7 |
c.Errorf("tag busybox %v should have worked: %s, %s", name, err, out) |
568f86eb |
continue
}
// ensure we don't have multiple tag names. |
693ba98c |
out, _, err = dockerCmdWithError("images") |
568f86eb |
if err != nil { |
dc944ea7 |
c.Errorf("listing images failed with errors: %v, %s", err, out) |
568f86eb |
} else if strings.Contains(out, name) { |
dc944ea7 |
c.Errorf("images should not have listed '%s'", name) |
568f86eb |
deleteImages(name + ":latest")
}
}
for _, name := range names { |
8d4fe141 |
_, exitCode, err := dockerCmdWithError("tag", name+":latest", "fooo/bar:latest") |
568f86eb |
if err != nil || exitCode != 0 { |
dc944ea7 |
c.Errorf("tag %v fooo/bar should have worked: %s", name, err) |
568f86eb |
continue
}
deleteImages("fooo/bar:latest")
}
} |
d08ca5c2 |
// ensure tags can not match digests
func (s *DockerSuite) TestTagMatchesDigest(c *check.C) { |
1723c647 |
// Don't attempt to pull on Windows as not in hub. It's installed
// as an image through .ensure-frozen-images-windows
if daemonPlatform != "windows" {
if err := pullImageIfNotExist("busybox:latest"); err != nil {
c.Fatal("couldn't find the busybox:latest image locally and failed to pull it")
} |
d08ca5c2 |
}
digest := "busybox@sha256:abcdef76720241213f5303bda7704ec4c2ef75613173910a56fb1b6e20251507"
// test setting tag fails |
8d4fe141 |
_, _, err := dockerCmdWithError("tag", "busybox:latest", digest) |
d08ca5c2 |
if err == nil {
c.Fatal("digest tag a name should have failed")
}
// check that no new image matches the digest
_, _, err = dockerCmdWithError("inspect", digest)
if err == nil {
c.Fatal("inspecting by digest should have failed")
}
} |
4352da78 |
func (s *DockerSuite) TestTagInvalidRepoName(c *check.C) { |
1723c647 |
// Don't attempt to pull on Windows as not in hub. It's installed
// as an image through .ensure-frozen-images-windows
if daemonPlatform != "windows" {
if err := pullImageIfNotExist("busybox:latest"); err != nil {
c.Fatal("couldn't find the busybox:latest image locally and failed to pull it")
} |
4352da78 |
}
// test setting tag fails |
8d4fe141 |
_, _, err := dockerCmdWithError("tag", "busybox:latest", "sha256:sometag") |
4352da78 |
if err == nil {
c.Fatal("tagging with image named \"sha256\" should have failed")
}
}
// ensure tags cannot create ambiguity with image ids
func (s *DockerSuite) TestTagTruncationAmbiguity(c *check.C) { |
1723c647 |
//testRequires(c, DaemonIsLinux)
// Don't attempt to pull on Windows as not in hub. It's installed
// as an image through .ensure-frozen-images-windows
if daemonPlatform != "windows" {
if err := pullImageIfNotExist("busybox:latest"); err != nil {
c.Fatal("couldn't find the busybox:latest image locally and failed to pull it")
} |
4352da78 |
}
imageID, err := buildImage("notbusybox:latest",
`FROM busybox
MAINTAINER dockerio`,
true)
if err != nil {
c.Fatal(err)
}
truncatedImageID := stringid.TruncateID(imageID)
truncatedTag := fmt.Sprintf("notbusybox:%s", truncatedImageID)
|
62a856e9 |
id := inspectField(c, truncatedTag, "Id") |
4352da78 |
// Ensure inspect by image id returns image for image id
c.Assert(id, checker.Equals, imageID)
c.Logf("Built image: %s", imageID)
// test setting tag fails |
8d4fe141 |
_, _, err = dockerCmdWithError("tag", "busybox:latest", truncatedTag) |
4352da78 |
if err != nil {
c.Fatalf("Error tagging with an image id: %s", err)
}
|
62a856e9 |
id = inspectField(c, truncatedTag, "Id") |
4352da78 |
// Ensure id is imageID and not busybox:latest
c.Assert(id, checker.Not(checker.Equals), imageID)
} |