1
0
mirror of https://github.com/golang/go synced 2024-10-01 05:28:33 -06:00

net/http/cgi: skip tests if not functional perl

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>
This commit is contained in:
Kyohei Kadota 2019-09-26 13:39:52 +09:00 committed by Brad Fitzpatrick
parent e79b57d6c4
commit 148ec3e3bc

View 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) 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) { func TestDirWindows(t *testing.T) {
if runtime.GOOS != "windows" { if runtime.GOOS != "windows" {
t.Skip("Skipping windows specific test.") t.Skip("Skipping windows specific test.")
@ -462,13 +479,7 @@ func TestDirWindows(t *testing.T) {
cgifile, _ := filepath.Abs("testdata/test.cgi") cgifile, _ := filepath.Abs("testdata/test.cgi")
var perl string perl := findPerl(t)
var err error
perl, err = exec.LookPath("perl")
if err != nil {
t.Skip("Skipping test: perl not found.")
}
perl, _ = filepath.Abs(perl)
cwd, _ := os.Getwd() cwd, _ := os.Getwd()
h := &Handler{ h := &Handler{
@ -505,13 +516,7 @@ func TestEnvOverride(t *testing.T) {
check(t) check(t)
cgifile, _ := filepath.Abs("testdata/test.cgi") cgifile, _ := filepath.Abs("testdata/test.cgi")
var perl string perl := findPerl(t)
var err error
perl, err = exec.LookPath("perl")
if err != nil {
t.Skipf("Skipping test: perl not found.")
}
perl, _ = filepath.Abs(perl)
cwd, _ := os.Getwd() cwd, _ := os.Getwd()
h := &Handler{ h := &Handler{