]> Cypherpunks repositories - gostls13.git/commitdiff
net/http/cgi: skip tests if not functional perl
authorKyohei Kadota <lufia@lufia.org>
Thu, 26 Sep 2019 04:39:52 +0000 (13:39 +0900)
committerBrad Fitzpatrick <bradfitz@golang.org>
Wed, 2 Oct 2019 05:52:16 +0000 (05:52 +0000)
TestEnvOverride sets PATH to /wibble before executing a CGI.
So customized Perl that is starting with '#!/usr/bin/env bash' will fail
because /usr/bin/env can't lookup bash.

Fixes #27790

Change-Id: I25e433061a7ff9da8c86429e934418fc15f12f90
Reviewed-on: https://go-review.googlesource.com/c/go/+/196845
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>

src/net/http/cgi/host_test.go

index 1790d5de982fb75ea014c4e571ba9ccae5e9c95f..fb869a67282d60df9abd4626accfe737a9f995a3 100644 (file)
@@ -455,6 +455,23 @@ func TestDirUnix(t *testing.T) {
        runCgiTest(t, h, "GET /test.cgi HTTP/1.0\nHost: example.com\n\n", expectedMap)
 }
 
+func findPerl(t *testing.T) string {
+       t.Helper()
+       perl, err := exec.LookPath("perl")
+       if err != nil {
+               t.Skip("Skipping test: perl not found.")
+       }
+       perl, _ = filepath.Abs(perl)
+
+       cmd := exec.Command(perl, "-e", "print 123")
+       cmd.Env = []string{"PATH=/garbage"}
+       out, err := cmd.Output()
+       if err != nil || string(out) != "123" {
+               t.Skipf("Skipping test: %s is not functional", perl)
+       }
+       return perl
+}
+
 func TestDirWindows(t *testing.T) {
        if runtime.GOOS != "windows" {
                t.Skip("Skipping windows specific test.")
@@ -462,13 +479,7 @@ func TestDirWindows(t *testing.T) {
 
        cgifile, _ := filepath.Abs("testdata/test.cgi")
 
-       var perl string
-       var err error
-       perl, err = exec.LookPath("perl")
-       if err != nil {
-               t.Skip("Skipping test: perl not found.")
-       }
-       perl, _ = filepath.Abs(perl)
+       perl := findPerl(t)
 
        cwd, _ := os.Getwd()
        h := &Handler{
@@ -505,13 +516,7 @@ func TestEnvOverride(t *testing.T) {
        check(t)
        cgifile, _ := filepath.Abs("testdata/test.cgi")
 
-       var perl string
-       var err error
-       perl, err = exec.LookPath("perl")
-       if err != nil {
-               t.Skipf("Skipping test: perl not found.")
-       }
-       perl, _ = filepath.Abs(perl)
+       perl := findPerl(t)
 
        cwd, _ := os.Getwd()
        h := &Handler{