Browse code

Windows: No security warning on quiet

Signed-off-by: John Howard <jhoward@microsoft.com>

John Howard authored on 2016/07/07 06:34:14
Showing 2 changed files
... ...
@@ -289,7 +289,7 @@ func runBuild(dockerCli *client.DockerCli, options buildOptions) error {
289 289
 
290 290
 	// Windows: show error message about modified file permissions if the
291 291
 	// daemon isn't running Windows.
292
-	if response.OSType != "windows" && runtime.GOOS == "windows" {
292
+	if response.OSType != "windows" && runtime.GOOS == "windows" && !options.quiet {
293 293
 		fmt.Fprintln(dockerCli.Err(), `SECURITY WARNING: You are building a Docker image from Windows against a non-Windows Docker host. All files and directories added to build context will have '-rwxr-xr-x' permissions. It is recommended to double check and reset permissions for sensitive files and directories.`)
294 294
 	}
295 295
 
... ...
@@ -4599,26 +4599,9 @@ func (s *DockerSuite) TestBuildNotVerboseSuccess(c *check.C) {
4599 4599
 		if outRegexp.Find([]byte(stdout)) == nil {
4600 4600
 			c.Fatalf("Test %s expected stdout to match the [%v] regexp, but it is [%v]", te.Name, outRegexp, stdout)
4601 4601
 		}
4602
-		if runtime.GOOS == "windows" {
4603
-			// stderr contains a security warning on Windows if the daemon isn't Windows
4604
-			lines := strings.Split(stderr, "\n")
4605
-			warningCount := 0
4606
-			for _, v := range lines {
4607
-				warningText := "SECURITY WARNING: You are building a Docker image from Windows against a non-Windows Docker host."
4608
-				if strings.Contains(v, warningText) {
4609
-					warningCount++
4610
-				}
4611
-				if v != "" && !strings.Contains(v, warningText) {
4612
-					c.Fatalf("Stderr contains unexpected output line: %q", v)
4613
-				}
4614
-			}
4615
-			if warningCount != 1 && daemonPlatform != "windows" {
4616
-				c.Fatalf("Test %s didn't get security warning running from Windows to non-Windows", te.Name)
4617
-			}
4618
-		} else {
4619
-			if stderr != "" {
4620
-				c.Fatalf("Test %s expected stderr to be empty, but it is [%#v]", te.Name, stderr)
4621
-			}
4602
+
4603
+		if stderr != "" {
4604
+			c.Fatalf("Test %s expected stderr to be empty, but it is [%#v]", te.Name, stderr)
4622 4605
 		}
4623 4606
 	}
4624 4607
 
... ...
@@ -4691,17 +4674,16 @@ func (s *DockerSuite) TestBuildStderr(c *check.C) {
4691 4691
 		c.Fatal(err)
4692 4692
 	}
4693 4693
 
4694
-	if runtime.GOOS == "windows" {
4695
-		// stderr might contain a security warning on windows
4696
-		lines := strings.Split(stderr, "\n")
4697
-		for _, v := range lines {
4698
-			if v != "" && !strings.Contains(v, "SECURITY WARNING:") {
4699
-				c.Fatalf("Stderr contains unexpected output line: %q", v)
4700
-			}
4694
+	if runtime.GOOS == "windows" &&
4695
+		daemonPlatform != "windows" {
4696
+		// Windows to non-Windows should have a security warning
4697
+		if !strings.Contains(stderr, "SECURITY WARNING:") {
4698
+			c.Fatalf("Stderr contains unexpected output: %q", stderr)
4701 4699
 		}
4702 4700
 	} else {
4701
+		// Other platform combinations should have no stderr written too
4703 4702
 		if stderr != "" {
4704
-			c.Fatalf("Stderr should have been empty, instead its: %q", stderr)
4703
+			c.Fatalf("Stderr should have been empty, instead it's: %q", stderr)
4705 4704
 		}
4706 4705
 	}
4707 4706
 }