From 990f9ed4de11a8f71dcf5bda08adb67002cbb88c Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa Date: Fri, 23 Jan 2015 23:37:11 +0900 Subject: [PATCH] integration: Split up single file to 3 based on frontend type --- integration-tests/Makefile.am | 9 +- integration-tests/nghttpx_http1_test.go | 173 ++++++++++++ ...{nghttpx_test.go => nghttpx_http2_test.go} | 267 ------------------ integration-tests/nghttpx_spdy_test.go | 111 ++++++++ 4 files changed, 291 insertions(+), 269 deletions(-) create mode 100644 integration-tests/nghttpx_http1_test.go rename integration-tests/{nghttpx_test.go => nghttpx_http2_test.go} (60%) create mode 100644 integration-tests/nghttpx_spdy_test.go diff --git a/integration-tests/Makefile.am b/integration-tests/Makefile.am index bc859626..98076f8f 100644 --- a/integration-tests/Makefile.am +++ b/integration-tests/Makefile.am @@ -22,8 +22,13 @@ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. EXTRA_DIST = \ - nghttpx_test.go \ - server_tester.go + nghttpx_http1_test.go \ + nghttpx_http2_test.go \ + nghttpx_spdy_test.go \ + server_tester.go \ + server.key \ + server.crt \ + setenv .PHONY: itprep it diff --git a/integration-tests/nghttpx_http1_test.go b/integration-tests/nghttpx_http1_test.go new file mode 100644 index 00000000..31fdf1aa --- /dev/null +++ b/integration-tests/nghttpx_http1_test.go @@ -0,0 +1,173 @@ +package nghttp2 + +import ( + "bufio" + "fmt" + "github.com/bradfitz/http2/hpack" + "io" + "net/http" + "syscall" + "testing" +) + +func TestH1H1PlainGET(t *testing.T) { + st := newServerTester(nil, t, noopHandler) + defer st.Close() + + res, err := st.http1(requestParam{ + name: "TestH1H1PlainGET", + }) + if err != nil { + t.Fatalf("Error st.http1() = %v", err) + } + + want := 200 + if got := res.status; got != want { + t.Errorf("status = %v; want %v", got, want) + } +} + +func TestH1H1PlainGETClose(t *testing.T) { + st := newServerTester(nil, t, noopHandler) + defer st.Close() + + res, err := st.http1(requestParam{ + name: "TestH1H1PlainGETClose", + header: []hpack.HeaderField{ + pair("Connection", "close"), + }, + }) + if err != nil { + t.Fatalf("Error st.http1() = %v", err) + } + + want := 200 + if got := res.status; got != want { + t.Errorf("status = %v; want %v", got, want) + } +} + +func TestH1H1MultipleRequestCL(t *testing.T) { + st := newServerTester(nil, t, func(w http.ResponseWriter, r *http.Request) { + t.Errorf("server should not forward bad request") + }) + defer st.Close() + + if _, err := io.WriteString(st.conn, fmt.Sprintf(`GET / HTTP/1.1 +Host: %v +Test-Case: TestH1H1MultipleRequestCL +Content-Length: 0 +Content-Length: 1 + +`, st.authority)); err != nil { + t.Fatalf("Error io.WriteString() = %v", err) + } + + resp, err := http.ReadResponse(bufio.NewReader(st.conn), nil) + if err != nil { + t.Fatalf("Error http.ReadResponse() = %v", err) + } + + want := 400 + if got := resp.StatusCode; got != want { + t.Errorf("status: %v; want %v", got, want) + } +} + +func TestH1H1ConnectFailure(t *testing.T) { + st := newServerTester(nil, t, noopHandler) + defer st.Close() + + // shutdown backend server to simulate backend connect failure + st.ts.Close() + + res, err := st.http1(requestParam{ + name: "TestH1H1ConnectFailure", + }) + if err != nil { + t.Fatalf("Error st.http1() = %v", err) + } + want := 503 + if got := res.status; got != want { + t.Errorf("status: %v; want %v", got, want) + } +} + +func TestH1H1GracefulShutdown(t *testing.T) { + st := newServerTester(nil, t, noopHandler) + defer st.Close() + + res, err := st.http1(requestParam{ + name: "TestH1H1GracefulShutdown-1", + }) + if err != nil { + t.Fatalf("Error st.http1() = %v", err) + } + + if got, want := res.status, 200; got != want { + t.Errorf("status: %v; want %v", got, want) + } + + st.cmd.Process.Signal(syscall.SIGQUIT) + + res, err = st.http1(requestParam{ + name: "TestH1H1GracefulShutdown-2", + }) + if err != nil { + t.Fatalf("Error st.http1() = %v", err) + } + + if got, want := res.status, 200; got != want { + t.Errorf("status: %v; want %v", got, want) + } + + if got, want := res.connClose, true; got != want { + t.Errorf("res.connClose: %v; want %v", got, want) + } + + want := io.EOF + if _, err := st.conn.Read(nil); err == nil || err != want { + t.Errorf("st.conn.Read(): %v; want %v", err, want) + } +} + +func TestH1H2ConnectFailure(t *testing.T) { + st := newServerTester([]string{"--http2-bridge"}, t, noopHandler) + defer st.Close() + + // simulate backend connect attempt failure + st.ts.Close() + + res, err := st.http1(requestParam{ + name: "TestH1H2ConnectFailure", + }) + if err != nil { + t.Fatalf("Error st.http1() = %v", err) + } + want := 503 + if got := res.status; got != want { + t.Errorf("status: %v; want %v", got, want) + } +} + +func TestH1H2NoHost(t *testing.T) { + st := newServerTester([]string{"--http2-bridge"}, t, func(w http.ResponseWriter, r *http.Request) { + t.Errorf("server should not forward bad request") + }) + defer st.Close() + + // without Host header field, we expect 400 response + if _, err := io.WriteString(st.conn, "GET / HTTP/1.1\r\nTest-Case: TestH1H2NoHost\r\n\r\n"); err != nil { + t.Fatalf("Error io.WriteString() = %v", err) + } + + resp, err := http.ReadResponse(bufio.NewReader(st.conn), nil) + if err != nil { + t.Fatalf("Error http.ReadResponse() = %v", err) + } + + want := 400 + if got := resp.StatusCode; got != want { + t.Errorf("status: %v; want %v", got, want) + } +} diff --git a/integration-tests/nghttpx_test.go b/integration-tests/nghttpx_http2_test.go similarity index 60% rename from integration-tests/nghttpx_test.go rename to integration-tests/nghttpx_http2_test.go index 861a067b..307e65b3 100644 --- a/integration-tests/nghttpx_test.go +++ b/integration-tests/nghttpx_http2_test.go @@ -1,11 +1,9 @@ package nghttp2 import ( - "bufio" "fmt" "github.com/bradfitz/http2" "github.com/bradfitz/http2/hpack" - "golang.org/x/net/spdy" "io" "io/ioutil" "net/http" @@ -13,168 +11,6 @@ import ( "testing" ) -func TestH1H1PlainGET(t *testing.T) { - st := newServerTester(nil, t, noopHandler) - defer st.Close() - - res, err := st.http1(requestParam{ - name: "TestH1H1PlainGET", - }) - if err != nil { - t.Fatalf("Error st.http1() = %v", err) - } - - want := 200 - if got := res.status; got != want { - t.Errorf("status = %v; want %v", got, want) - } -} - -func TestH1H1PlainGETClose(t *testing.T) { - st := newServerTester(nil, t, noopHandler) - defer st.Close() - - res, err := st.http1(requestParam{ - name: "TestH1H1PlainGETClose", - header: []hpack.HeaderField{ - pair("Connection", "close"), - }, - }) - if err != nil { - t.Fatalf("Error st.http1() = %v", err) - } - - want := 200 - if got := res.status; got != want { - t.Errorf("status = %v; want %v", got, want) - } -} - -func TestH1H1MultipleRequestCL(t *testing.T) { - st := newServerTester(nil, t, func(w http.ResponseWriter, r *http.Request) { - t.Errorf("server should not forward bad request") - }) - defer st.Close() - - if _, err := io.WriteString(st.conn, fmt.Sprintf(`GET / HTTP/1.1 -Host: %v -Test-Case: TestH1H1MultipleRequestCL -Content-Length: 0 -Content-Length: 1 - -`, st.authority)); err != nil { - t.Fatalf("Error io.WriteString() = %v", err) - } - - resp, err := http.ReadResponse(bufio.NewReader(st.conn), nil) - if err != nil { - t.Fatalf("Error http.ReadResponse() = %v", err) - } - - want := 400 - if got := resp.StatusCode; got != want { - t.Errorf("status: %v; want %v", got, want) - } -} - -func TestH1H1ConnectFailure(t *testing.T) { - st := newServerTester(nil, t, noopHandler) - defer st.Close() - - // shutdown backend server to simulate backend connect failure - st.ts.Close() - - res, err := st.http1(requestParam{ - name: "TestH1H1ConnectFailure", - }) - if err != nil { - t.Fatalf("Error st.http1() = %v", err) - } - want := 503 - if got := res.status; got != want { - t.Errorf("status: %v; want %v", got, want) - } -} - -func TestH1H1GracefulShutdown(t *testing.T) { - st := newServerTester(nil, t, noopHandler) - defer st.Close() - - res, err := st.http1(requestParam{ - name: "TestH1H1GracefulShutdown-1", - }) - if err != nil { - t.Fatalf("Error st.http1() = %v", err) - } - - if got, want := res.status, 200; got != want { - t.Errorf("status: %v; want %v", got, want) - } - - st.cmd.Process.Signal(syscall.SIGQUIT) - - res, err = st.http1(requestParam{ - name: "TestH1H1GracefulShutdown-2", - }) - if err != nil { - t.Fatalf("Error st.http1() = %v", err) - } - - if got, want := res.status, 200; got != want { - t.Errorf("status: %v; want %v", got, want) - } - - if got, want := res.connClose, true; got != want { - t.Errorf("res.connClose: %v; want %v", got, want) - } - - want := io.EOF - if _, err := st.conn.Read(nil); err == nil || err != want { - t.Errorf("st.conn.Read(): %v; want %v", err, want) - } -} - -func TestH1H2ConnectFailure(t *testing.T) { - st := newServerTester([]string{"--http2-bridge"}, t, noopHandler) - defer st.Close() - - // simulate backend connect attempt failure - st.ts.Close() - - res, err := st.http1(requestParam{ - name: "TestH1H2ConnectFailure", - }) - if err != nil { - t.Fatalf("Error st.http1() = %v", err) - } - want := 503 - if got := res.status; got != want { - t.Errorf("status: %v; want %v", got, want) - } -} - -func TestH1H2NoHost(t *testing.T) { - st := newServerTester([]string{"--http2-bridge"}, t, func(w http.ResponseWriter, r *http.Request) { - t.Errorf("server should not forward bad request") - }) - defer st.Close() - - // without Host header field, we expect 400 response - if _, err := io.WriteString(st.conn, "GET / HTTP/1.1\r\nTest-Case: TestH1H2NoHost\r\n\r\n"); err != nil { - t.Fatalf("Error io.WriteString() = %v", err) - } - - resp, err := http.ReadResponse(bufio.NewReader(st.conn), nil) - if err != nil { - t.Fatalf("Error http.ReadResponse() = %v", err) - } - - want := 400 - if got := resp.StatusCode; got != want { - t.Errorf("status: %v; want %v", got, want) - } -} - func TestH2H1PlainGET(t *testing.T) { st := newServerTester(nil, t, noopHandler) defer st.Close() @@ -561,106 +397,3 @@ func TestH2H2ConnectFailure(t *testing.T) { t.Errorf("status: %v; want %v", got, want) } } - -func TestS3H1PlainGET(t *testing.T) { - st := newServerTesterTLS([]string{"--npn-list=spdy/3.1"}, t, noopHandler) - defer st.Close() - - res, err := st.spdy(requestParam{ - name: "TestS3H1PlainGET", - }) - if err != nil { - t.Fatalf("Error st.spdy() = %v", err) - } - - want := 200 - if got := res.status; got != want { - t.Errorf("status = %v; want %v", got, want) - } -} - -func TestS3H1BadRequestCL(t *testing.T) { - st := newServerTesterTLS([]string{"--npn-list=spdy/3.1"}, t, noopHandler) - defer st.Close() - - // we set content-length: 1024, but the actual request body is - // 3 bytes. - res, err := st.spdy(requestParam{ - name: "TestS3H1BadRequestCL", - method: "POST", - header: []hpack.HeaderField{ - pair("content-length", "1024"), - }, - body: []byte("foo"), - }) - if err != nil { - t.Fatalf("Error st.spdy() = %v", err) - } - - want := spdy.ProtocolError - if got := res.spdyRstErrCode; got != want { - t.Errorf("res.spdyRstErrCode = %v; want %v", got, want) - } -} - -func TestS3H1MultipleRequestCL(t *testing.T) { - st := newServerTesterTLS([]string{"--npn-list=spdy/3.1"}, t, func(w http.ResponseWriter, r *http.Request) { - t.Errorf("server should not forward bad request") - }) - defer st.Close() - - res, err := st.spdy(requestParam{ - name: "TestS3H1MultipleRequestCL", - header: []hpack.HeaderField{ - pair("content-length", "1"), - pair("content-length", "2"), - }, - }) - if err != nil { - t.Fatalf("Error st.spdy() = %v", err) - } - want := 400 - if got := res.status; got != want { - t.Errorf("status: %v; want %v", got, want) - } -} - -func TestS3H1InvalidRequestCL(t *testing.T) { - st := newServerTesterTLS([]string{"--npn-list=spdy/3.1"}, t, func(w http.ResponseWriter, r *http.Request) { - t.Errorf("server should not forward bad request") - }) - defer st.Close() - - res, err := st.spdy(requestParam{ - name: "TestS3H1InvalidRequestCL", - header: []hpack.HeaderField{ - pair("content-length", ""), - }, - }) - if err != nil { - t.Fatalf("Error st.spdy() = %v", err) - } - want := 400 - if got := res.status; got != want { - t.Errorf("status: %v; want %v", got, want) - } -} - -func TestS3H2ConnectFailure(t *testing.T) { - st := newServerTesterTLS([]string{"--npn-list=spdy/3.1", "--http2-bridge"}, t, noopHandler) - defer st.Close() - - // simulate backend connect attempt failure - st.ts.Close() - - res, err := st.spdy(requestParam{ - name: "TestS3H2ConnectFailure", - }) - if err != nil { - t.Fatalf("Error st.spdy() = %v", err) - } - want := 503 - if got := res.status; got != want { - t.Errorf("status: %v; want %v", got, want) - } -} diff --git a/integration-tests/nghttpx_spdy_test.go b/integration-tests/nghttpx_spdy_test.go new file mode 100644 index 00000000..9c1cde48 --- /dev/null +++ b/integration-tests/nghttpx_spdy_test.go @@ -0,0 +1,111 @@ +package nghttp2 + +import ( + "github.com/bradfitz/http2/hpack" + "golang.org/x/net/spdy" + "net/http" + "testing" +) + +func TestS3H1PlainGET(t *testing.T) { + st := newServerTesterTLS([]string{"--npn-list=spdy/3.1"}, t, noopHandler) + defer st.Close() + + res, err := st.spdy(requestParam{ + name: "TestS3H1PlainGET", + }) + if err != nil { + t.Fatalf("Error st.spdy() = %v", err) + } + + want := 200 + if got := res.status; got != want { + t.Errorf("status = %v; want %v", got, want) + } +} + +func TestS3H1BadRequestCL(t *testing.T) { + st := newServerTesterTLS([]string{"--npn-list=spdy/3.1"}, t, noopHandler) + defer st.Close() + + // we set content-length: 1024, but the actual request body is + // 3 bytes. + res, err := st.spdy(requestParam{ + name: "TestS3H1BadRequestCL", + method: "POST", + header: []hpack.HeaderField{ + pair("content-length", "1024"), + }, + body: []byte("foo"), + }) + if err != nil { + t.Fatalf("Error st.spdy() = %v", err) + } + + want := spdy.ProtocolError + if got := res.spdyRstErrCode; got != want { + t.Errorf("res.spdyRstErrCode = %v; want %v", got, want) + } +} + +func TestS3H1MultipleRequestCL(t *testing.T) { + st := newServerTesterTLS([]string{"--npn-list=spdy/3.1"}, t, func(w http.ResponseWriter, r *http.Request) { + t.Errorf("server should not forward bad request") + }) + defer st.Close() + + res, err := st.spdy(requestParam{ + name: "TestS3H1MultipleRequestCL", + header: []hpack.HeaderField{ + pair("content-length", "1"), + pair("content-length", "2"), + }, + }) + if err != nil { + t.Fatalf("Error st.spdy() = %v", err) + } + want := 400 + if got := res.status; got != want { + t.Errorf("status: %v; want %v", got, want) + } +} + +func TestS3H1InvalidRequestCL(t *testing.T) { + st := newServerTesterTLS([]string{"--npn-list=spdy/3.1"}, t, func(w http.ResponseWriter, r *http.Request) { + t.Errorf("server should not forward bad request") + }) + defer st.Close() + + res, err := st.spdy(requestParam{ + name: "TestS3H1InvalidRequestCL", + header: []hpack.HeaderField{ + pair("content-length", ""), + }, + }) + if err != nil { + t.Fatalf("Error st.spdy() = %v", err) + } + want := 400 + if got := res.status; got != want { + t.Errorf("status: %v; want %v", got, want) + } +} + +func TestS3H2ConnectFailure(t *testing.T) { + st := newServerTesterTLS([]string{"--npn-list=spdy/3.1", "--http2-bridge"}, t, noopHandler) + defer st.Close() + + // simulate backend connect attempt failure + st.ts.Close() + + res, err := st.spdy(requestParam{ + name: "TestS3H2ConnectFailure", + }) + if err != nil { + t.Fatalf("Error st.spdy() = %v", err) + } + want := 503 + if got := res.status; got != want { + t.Errorf("status: %v; want %v", got, want) + } +}