mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Validate repo name before image pull
Checks for reserved 'scratch' image name. fixes #12281 Docker-DCO-1.1-Signed-off-by: Josh Hawn <josh.hawn@docker.com> (github: jlhawn)
This commit is contained in:
parent
29265448ec
commit
18f4688385
2 changed files with 23 additions and 0 deletions
|
@ -39,6 +39,10 @@ func (s *TagStore) Pull(image string, tag string, imagePullConfig *ImagePullConf
|
|||
return err
|
||||
}
|
||||
|
||||
if err := validateRepoName(repoInfo.LocalName); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
c, err := s.poolAdd("pull", utils.ImageReference(repoInfo.LocalName, tag))
|
||||
if err != nil {
|
||||
if c != nil {
|
||||
|
|
|
@ -134,3 +134,22 @@ func (s *DockerSuite) TestPullImageOfficialNames(c *check.C) {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestPullScratchNotAllowed(c *check.C) {
|
||||
testRequires(c, Network)
|
||||
|
||||
pullCmd := exec.Command(dockerBinary, "pull", "scratch")
|
||||
out, exitCode, err := runCommandWithOutput(pullCmd)
|
||||
if err == nil {
|
||||
c.Fatal("expected pull of scratch to fail, but it didn't")
|
||||
}
|
||||
if exitCode != 1 {
|
||||
c.Fatalf("pulling scratch expected exit code 1, got %d", exitCode)
|
||||
}
|
||||
if strings.Contains(out, "Pulling repository scratch") {
|
||||
c.Fatalf("pulling scratch should not have begun: %s", out)
|
||||
}
|
||||
if !strings.Contains(out, "'scratch' is a reserved name") {
|
||||
c.Fatalf("unexpected output pulling scratch: %s", out)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue