Browse code

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)

Josh Hawn authored on 2015/04/23 06:41:24
Showing 2 changed files
... ...
@@ -39,6 +39,10 @@ func (s *TagStore) Pull(image string, tag string, imagePullConfig *ImagePullConf
39 39
 		return err
40 40
 	}
41 41
 
42
+	if err := validateRepoName(repoInfo.LocalName); err != nil {
43
+		return err
44
+	}
45
+
42 46
 	c, err := s.poolAdd("pull", utils.ImageReference(repoInfo.LocalName, tag))
43 47
 	if err != nil {
44 48
 		if c != nil {
... ...
@@ -134,3 +134,22 @@ func (s *DockerSuite) TestPullImageOfficialNames(c *check.C) {
134 134
 		}
135 135
 	}
136 136
 }
137
+
138
+func (s *DockerSuite) TestPullScratchNotAllowed(c *check.C) {
139
+	testRequires(c, Network)
140
+
141
+	pullCmd := exec.Command(dockerBinary, "pull", "scratch")
142
+	out, exitCode, err := runCommandWithOutput(pullCmd)
143
+	if err == nil {
144
+		c.Fatal("expected pull of scratch to fail, but it didn't")
145
+	}
146
+	if exitCode != 1 {
147
+		c.Fatalf("pulling scratch expected exit code 1, got %d", exitCode)
148
+	}
149
+	if strings.Contains(out, "Pulling repository scratch") {
150
+		c.Fatalf("pulling scratch should not have begun: %s", out)
151
+	}
152
+	if !strings.Contains(out, "'scratch' is a reserved name") {
153
+		c.Fatalf("unexpected output pulling scratch: %s", out)
154
+	}
155
+}