Browse code

Merge pull request #12655 from jlhawn/fix_12281

Validate repo name before image pull

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