]> Cypherpunks.ru repositories - gostls13.git/blobdiff - src/net/http/cgi/host_test.go
net/http/cgi: the PATH_INFO should be empty or start with a slash
[gostls13.git] / src / net / http / cgi / host_test.go
index f8abc88c8973775397063bb28468b9c1c57763c8..f310a83d498b1c167f36b9a6981e1f039a07236a 100644 (file)
@@ -8,8 +8,8 @@ package cgi
 
 import (
        "bufio"
-       "bytes"
        "fmt"
+       "internal/testenv"
        "io"
        "net"
        "net/http"
@@ -94,7 +94,7 @@ var cgiTested, cgiWorks bool
 func check(t *testing.T) {
        if !cgiTested {
                cgiTested = true
-               cgiWorks = exec.Command("./testdata/test.cgi").Run() == nil
+               cgiWorks = testenv.Command(t, "./testdata/test.cgi").Run() == nil
        }
        if !cgiWorks {
                // No Perl on Windows, needed by test.cgi
@@ -114,7 +114,7 @@ func TestCGIBasicGet(t *testing.T) {
                "param-a":               "b",
                "param-foo":             "bar",
                "env-GATEWAY_INTERFACE": "CGI/1.1",
-               "env-HTTP_HOST":         "example.com",
+               "env-HTTP_HOST":         "example.com:80",
                "env-PATH_INFO":         "",
                "env-QUERY_STRING":      "foo=bar&a=b",
                "env-REMOTE_ADDR":       "1.2.3.4",
@@ -128,7 +128,7 @@ func TestCGIBasicGet(t *testing.T) {
                "env-SERVER_PORT":       "80",
                "env-SERVER_SOFTWARE":   "go",
        }
-       replay := runCgiTest(t, h, "GET /test.cgi?foo=bar&a=b HTTP/1.0\nHost: example.com\n\n", expectedMap)
+       replay := runCgiTest(t, h, "GET /test.cgi?foo=bar&a=b HTTP/1.0\nHost: example.com:80\n\n", expectedMap)
 
        if expected, got := "text/html", replay.Header().Get("Content-Type"); got != expected {
                t.Errorf("got a Content-Type of %q; expected %q", got, expected)
@@ -210,14 +210,14 @@ func TestPathInfoDirRoot(t *testing.T) {
        check(t)
        h := &Handler{
                Path: "testdata/test.cgi",
-               Root: "/myscript/",
+               Root: "/myscript//",
        }
        expectedMap := map[string]string{
-               "env-PATH_INFO":       "bar",
+               "env-PATH_INFO":       "/bar",
                "env-QUERY_STRING":    "a=b",
                "env-REQUEST_URI":     "/myscript/bar?a=b",
                "env-SCRIPT_FILENAME": "testdata/test.cgi",
-               "env-SCRIPT_NAME":     "/myscript/",
+               "env-SCRIPT_NAME":     "/myscript",
        }
        runCgiTest(t, h, "GET /myscript/bar?a=b HTTP/1.0\nHost: example.com\n\n", expectedMap)
 }
@@ -278,7 +278,7 @@ func TestPathInfoNoRoot(t *testing.T) {
                "env-QUERY_STRING":    "a=b",
                "env-REQUEST_URI":     "/bar?a=b",
                "env-SCRIPT_FILENAME": "testdata/test.cgi",
-               "env-SCRIPT_NAME":     "/",
+               "env-SCRIPT_NAME":     "",
        }
        runCgiTest(t, h, "GET /bar?a=b HTTP/1.0\nHost: example.com\n\n", expectedMap)
 }
@@ -463,7 +463,7 @@ func findPerl(t *testing.T) string {
        }
        perl, _ = filepath.Abs(perl)
 
-       cmd := exec.Command(perl, "-e", "print 123")
+       cmd := testenv.Command(t, perl, "-e", "print 123")
        cmd.Env = []string{"PATH=/garbage"}
        out, err := cmd.Output()
        if err != nil || string(out) != "123" {
@@ -540,7 +540,7 @@ func TestEnvOverride(t *testing.T) {
 
 func TestHandlerStderr(t *testing.T) {
        check(t)
-       var stderr bytes.Buffer
+       var stderr strings.Builder
        h := &Handler{
                Path:   "testdata/test.cgi",
                Root:   "/test.cgi",