diff --git a/README.rst b/README.rst index 14f565a1..f2d27adb 100644 --- a/README.rst +++ b/README.rst @@ -172,6 +172,29 @@ The generated documents will not be installed with ``make install``. The online documentation is available at https://nghttp2.org/documentation/ +Unit tests +---------- + +Unit tests are done by simply running `make check`. + +Integration tests +----------------- + +We have the integration tests for nghttpx proxy server. The tests are +written in `Go programming language `_ and uses +its testing framework. We depends on the following libraries: + +* https://github.com/bradfitz/http2 +* https://github.com/tatsuhiro-t/go-nghttp2 + +To run the tests, enter ``integration-tests`` directory and run:: + + $ sh setenv go test + +``setenv`` will set necessary environment variables to compile +go-nghttp2 library (which uses cgo to interface nghttp2). In side the +tests, we use port 3009 to run test subject server. + Client, Server and Proxy programs --------------------------------- diff --git a/configure.ac b/configure.ac index 9237b4ad..e932664b 100644 --- a/configure.ac +++ b/configure.ac @@ -652,6 +652,7 @@ AC_CONFIG_FILES([ python/Makefile python/setup.py integration-tests/config.go + integration-tests/setenv doc/Makefile doc/conf.py doc/index.rst diff --git a/integration-tests/nghttpx_test.go b/integration-tests/nghttpx_test.go index 33212668..ebed7e2a 100644 --- a/integration-tests/nghttpx_test.go +++ b/integration-tests/nghttpx_test.go @@ -240,3 +240,40 @@ func TestHTTP2InvalidRequestCL(t *testing.T) { t.Errorf("status: %v; want %v", got, want) } } + +func TestHTTP2DuplicateResponseCL(t *testing.T) { + st := newServerTester([]string{"--http2-bridge"}, t, func(w http.ResponseWriter, r *http.Request) { + w.Header().Add("content-length", "1") + w.Header().Add("content-length", "2") + }) + defer st.Close() + + res, err := st.http2(requestParam{ + name: "TestHTTP2DuplicateResponseCL", + }) + if err != nil { + t.Errorf("Error st.http2() = %v", err) + } + want := 502 + if got := res.status; got != want { + t.Errorf("status: %v; want %v", got, want) + } +} + +func TestHTTP2InvalidResponseCL(t *testing.T) { + st := newServerTester([]string{"--http2-bridge"}, t, func(w http.ResponseWriter, r *http.Request) { + w.Header().Add("content-length", "") + }) + defer st.Close() + + res, err := st.http2(requestParam{ + name: "TestHTTP2InvalidResponseCL", + }) + if err != nil { + t.Errorf("Error st.http2() = %v", err) + } + want := 502 + if got := res.status; got != want { + t.Errorf("status: %v; want %v", got, want) + } +} diff --git a/integration-tests/server_tester.go b/integration-tests/server_tester.go index d2b415b1..0ee251cf 100644 --- a/integration-tests/server_tester.go +++ b/integration-tests/server_tester.go @@ -2,10 +2,12 @@ package nghttp2 import ( "bytes" + "crypto/tls" "errors" "fmt" "github.com/bradfitz/http2" "github.com/bradfitz/http2/hpack" + "github.com/tatsuhiro-t/go-nghttp2" "net" "net/http" "net/http/httptest" @@ -48,8 +50,27 @@ type serverTester struct { } func newServerTester(args []string, t *testing.T, handler http.HandlerFunc) *serverTester { - ts := httptest.NewServer(handler) + ts := httptest.NewUnstartedServer(handler) + backendTLS := false + for _, k := range args { + if k == "--http2-bridge" { + backendTLS = true + break + } + } + if backendTLS { + nghttp2.ConfigureServer(ts.Config, &nghttp2.Server{}) + // According to httptest/server.go, we have to set + // NextProtos separately for ts.TLS. NextProtos set + // in nghttp2.ConfigureServer is effectively ignored. + ts.TLS = new(tls.Config) + ts.TLS.NextProtos = append(ts.TLS.NextProtos, "h2-14") + ts.StartTLS() + args = append(args, "-k") + } else { + ts.Start() + } u, err := url.Parse(ts.URL) if err != nil { t.Fatalf("Error parsing URL from httptest.Server: %v", err) diff --git a/integration-tests/setenv.in b/integration-tests/setenv.in new file mode 100644 index 00000000..2c2d3c95 --- /dev/null +++ b/integration-tests/setenv.in @@ -0,0 +1,6 @@ +#!/bin/sh -e + +export CGO_CFLAGS="-I@abs_top_srcdir@/lib/includes -I@abs_top_builddir@/lib/includes" +export CGO_LDFLAGS="-L@abs_top_builddir@/lib/.libs" +export LD_LIBRARY_PATH="@abs_top_builddir@/lib/.libs" +"$@"