Browse code

Add failing testcase for single quotes in CMD

Closes #5701

This is due to @SvenDowideit comment at: https://github.com/docker/docker/issues/5701#issuecomment-58133541
where he asked for a testcase showing the error case.

Signed-off-by: Doug Davis <dug@us.ibm.com>

Doug Davis authored on 2014/10/09 12:34:20
Showing 1 changed files
... ...
@@ -2740,3 +2740,25 @@ func TestBuildExoticShellInterpolation(t *testing.T) {
2740 2740
 
2741 2741
 	logDone("build - exotic shell interpolation")
2742 2742
 }
2743
+
2744
+func TestBuildVerifySingleQuoteFails(t *testing.T) {
2745
+	// This testcase is supposed to generate an error because the
2746
+	// JSON array we're passing in on the CMD uses single quotes instead
2747
+	// of double quotes (per the JSON spec). This means we interpret it
2748
+	// as a "string" insead of "JSON array" and pass it on to "sh -c" and
2749
+	// it should barf on it.
2750
+	name := "testbuildsinglequotefails"
2751
+	defer deleteImages(name)
2752
+
2753
+	_, err := buildImage(name,
2754
+		`FROM busybox
2755
+		CMD [ '/bin/sh', '-c', 'echo hi' ]`,
2756
+		true)
2757
+	_, _, err = runCommandWithOutput(exec.Command(dockerBinary, "run", name))
2758
+
2759
+	if err == nil {
2760
+		t.Fatal("The image was not supposed to be able to run")
2761
+	}
2762
+
2763
+	logDone("build - verify single quotes fail")
2764
+}