diff options
author | Frédéric Guillot <fred@miniflux.net> | 2018-07-06 21:18:14 -0700 |
---|---|---|
committer | Frédéric Guillot <fred@miniflux.net> | 2018-07-06 21:18:14 -0700 |
commit | 459bb4531f92f8663afb6f36aa9be5b789bd591f (patch) | |
tree | f14e6c06b8e5c63612d1ff36f8cab40ae8a99d20 /vendor/golang.org/x/net/http2/server_test.go | |
parent | 34a3fe426b33a63f2d8e02d4a70c88f137fa5410 (diff) |
Update vendor dependencies
Diffstat (limited to 'vendor/golang.org/x/net/http2/server_test.go')
-rw-r--r-- | vendor/golang.org/x/net/http2/server_test.go | 132 |
1 files changed, 125 insertions, 7 deletions
diff --git a/vendor/golang.org/x/net/http2/server_test.go b/vendor/golang.org/x/net/http2/server_test.go index bd1ba20..9c3e549 100644 --- a/vendor/golang.org/x/net/http2/server_test.go +++ b/vendor/golang.org/x/net/http2/server_test.go @@ -1760,6 +1760,42 @@ func TestServer_Response_Data_Sniff_DoesntOverride(t *testing.T) { }) } +func TestServer_Response_Nosniff_WithoutContentType(t *testing.T) { + const msg = "<html>this is HTML." + testServerResponse(t, func(w http.ResponseWriter, r *http.Request) error { + w.Header().Set("X-Content-Type-Options", "nosniff") + w.WriteHeader(200) + io.WriteString(w, msg) + return nil + }, func(st *serverTester) { + getSlash(st) + hf := st.wantHeaders() + if hf.StreamEnded() { + t.Fatal("don't want END_STREAM, expecting data") + } + if !hf.HeadersEnded() { + t.Fatal("want END_HEADERS flag") + } + goth := st.decodeHeader(hf.HeaderBlockFragment()) + wanth := [][2]string{ + {":status", "200"}, + {"x-content-type-options", "nosniff"}, + {"content-type", "application/octet-stream"}, + {"content-length", strconv.Itoa(len(msg))}, + } + if !reflect.DeepEqual(goth, wanth) { + t.Errorf("Got headers %v; want %v", goth, wanth) + } + df := st.wantData() + if !df.StreamEnded() { + t.Error("expected DATA to have END_STREAM flag") + } + if got := string(df.Data()); got != msg { + t.Errorf("got DATA %q; want %q", got, msg) + } + }) +} + func TestServer_Response_TransferEncoding_chunked(t *testing.T) { const msg = "hi" testServerResponse(t, func(w http.ResponseWriter, r *http.Request) error { @@ -2877,9 +2913,9 @@ func testServerWritesTrailers(t *testing.T, withFlush bool) { w.Header().Set("Trailer:post-header-trailer2", "hi2") w.Header().Set("Trailer:Range", "invalid") w.Header().Set("Trailer:Foo\x01Bogus", "invalid") - w.Header().Set("Transfer-Encoding", "should not be included; Forbidden by RFC 2616 14.40") - w.Header().Set("Content-Length", "should not be included; Forbidden by RFC 2616 14.40") - w.Header().Set("Trailer", "should not be included; Forbidden by RFC 2616 14.40") + w.Header().Set("Transfer-Encoding", "should not be included; Forbidden by RFC 7230 4.1.2") + w.Header().Set("Content-Length", "should not be included; Forbidden by RFC 7230 4.1.2") + w.Header().Set("Trailer", "should not be included; Forbidden by RFC 7230 4.1.2") return nil }, func(st *serverTester) { getSlash(st) @@ -2971,7 +3007,7 @@ func BenchmarkServerGets(b *testing.B) { defer st.Close() st.greet() - // Give the server quota to reply. (plus it has the the 64KB) + // Give the server quota to reply. (plus it has the 64KB) if err := st.fr.WriteWindowUpdate(0, uint32(b.N*len(msg))); err != nil { b.Fatal(err) } @@ -3009,7 +3045,7 @@ func BenchmarkServerPosts(b *testing.B) { defer st.Close() st.greet() - // Give the server quota to reply. (plus it has the the 64KB) + // Give the server quota to reply. (plus it has the 64KB) if err := st.fr.WriteWindowUpdate(0, uint32(b.N*len(msg))); err != nil { b.Fatal(err) } @@ -3316,7 +3352,7 @@ func BenchmarkServer_GetRequest(b *testing.B) { defer st.Close() st.greet() - // Give the server quota to reply. (plus it has the the 64KB) + // Give the server quota to reply. (plus it has the 64KB) if err := st.fr.WriteWindowUpdate(0, uint32(b.N*len(msg))); err != nil { b.Fatal(err) } @@ -3347,7 +3383,7 @@ func BenchmarkServer_PostRequest(b *testing.B) { }) defer st.Close() st.greet() - // Give the server quota to reply. (plus it has the the 64KB) + // Give the server quota to reply. (plus it has the 64KB) if err := st.fr.WriteWindowUpdate(0, uint32(b.N*len(msg))); err != nil { b.Fatal(err) } @@ -3723,3 +3759,85 @@ func TestIssue20704Race(t *testing.T) { resp.Body.Close() } } + +func TestServer_Rejects_TooSmall(t *testing.T) { + testServerResponse(t, func(w http.ResponseWriter, r *http.Request) error { + ioutil.ReadAll(r.Body) + return nil + }, func(st *serverTester) { + st.writeHeaders(HeadersFrameParam{ + StreamID: 1, // clients send odd numbers + BlockFragment: st.encodeHeader( + ":method", "POST", + "content-length", "4", + ), + EndStream: false, // to say DATA frames are coming + EndHeaders: true, + }) + st.writeData(1, true, []byte("12345")) + + st.wantRSTStream(1, ErrCodeProtocol) + }) +} + +// Tests that a handler setting "Connection: close" results in a GOAWAY being sent, +// and the connection still completing. +func TestServerHandlerConnectionClose(t *testing.T) { + unblockHandler := make(chan bool, 1) + defer close(unblockHandler) // backup; in case of errors + testServerResponse(t, func(w http.ResponseWriter, r *http.Request) error { + w.Header().Set("Connection", "close") + w.Header().Set("Foo", "bar") + w.(http.Flusher).Flush() + <-unblockHandler + return nil + }, func(st *serverTester) { + st.writeHeaders(HeadersFrameParam{ + StreamID: 1, + BlockFragment: st.encodeHeader(), + EndStream: true, + EndHeaders: true, + }) + var sawGoAway bool + var sawRes bool + for { + f, err := st.readFrame() + if err == io.EOF { + break + } + if err != nil { + t.Fatal(err) + } + switch f := f.(type) { + case *GoAwayFrame: + sawGoAway = true + unblockHandler <- true + if f.LastStreamID != 1 || f.ErrCode != ErrCodeNo { + t.Errorf("unexpected GOAWAY frame: %v", summarizeFrame(f)) + } + case *HeadersFrame: + goth := st.decodeHeader(f.HeaderBlockFragment()) + wanth := [][2]string{ + {":status", "200"}, + {"foo", "bar"}, + } + if !reflect.DeepEqual(goth, wanth) { + t.Errorf("got headers %v; want %v", goth, wanth) + } + sawRes = true + case *DataFrame: + if f.StreamID != 1 || !f.StreamEnded() || len(f.Data()) != 0 { + t.Errorf("unexpected DATA frame: %v", summarizeFrame(f)) + } + default: + t.Logf("unexpected frame: %v", summarizeFrame(f)) + } + } + if !sawGoAway { + t.Errorf("didn't see GOAWAY") + } + if !sawRes { + t.Errorf("didn't see response") + } + }) +} |