From 42eb36f8454404969290264451ba3117adede6d2 Mon Sep 17 00:00:00 2001 From: chhsiao90 Date: Mon, 27 Feb 2017 13:28:08 +0800 Subject: [PATCH] Removed redundant ClienetSpecConfig, reused and extend exists config.Config --- client/1_starting_http2.go | 2 +- client/4_1_frame_format.go | 6 +- client/4_2_frame_size.go | 6 +- ..._3_header_compression_and_decompression.go | 2 +- client/5_1_1_stream_identifiers.go | 2 +- client/5_1_stream_states.go | 20 +++---- client/5_4_1_connection_error_handling.go | 4 +- client/5_5_extending_http2.go | 2 +- client/6_10_continuation.go | 12 ++-- client/6_1_data.go | 6 +- client/6_2_headers.go | 6 +- client/6_3_priority.go | 4 +- client/6_4_rst_stream.go | 6 +- client/6_5_2_defined_settings_parameters.go | 8 +-- client/6_5_3_settings_synchronization.go | 2 +- client/6_5_settings.go | 6 +- client/6_7_ping.go | 8 +-- client/6_8_goaway.go | 2 +- client/6_9_1_the_flow_control_window.go | 4 +- client/6_9_window_update.go | 6 +- cmd/h2spec/h2specd.go | 2 +- config/client_config.go | 56 ------------------- config/config.go | 25 ++++++++- h2spec.go | 2 +- spec/connection.go | 11 +++- spec/server.go | 4 +- spec/specd.go | 8 +-- spec/util.go | 4 +- 28 files changed, 97 insertions(+), 129 deletions(-) delete mode 100644 config/client_config.go diff --git a/client/1_starting_http2.go b/client/1_starting_http2.go index 9e5468d..4cec6e0 100644 --- a/client/1_starting_http2.go +++ b/client/1_starting_http2.go @@ -11,7 +11,7 @@ func StartingHTTP2() *spec.ClientTestGroup { tg.AddTestCase(&spec.ClientTestCase{ Desc: "Sends a client connection preface", Requirement: "The endpoint MUST accept client connection preface.", - Run: func(c *config.ClientSpecConfig, conn *spec.Conn, req *spec.Request) error { + Run: func(c *config.Config, conn *spec.Conn, req *spec.Request) error { conn.WriteSuccessResponse(req.StreamID, c) return nil diff --git a/client/4_1_frame_format.go b/client/4_1_frame_format.go index facea86..8f150dc 100644 --- a/client/4_1_frame_format.go +++ b/client/4_1_frame_format.go @@ -14,7 +14,7 @@ func FrameFormat() *spec.ClientTestGroup { tg.AddTestCase(&spec.ClientTestCase{ Desc: "Sends a frame with unknown type", Requirement: "The endpoint MUST ignore and discard any frame that has a type that is unknown.", - Run: func(c *config.ClientSpecConfig, conn *spec.Conn, req *spec.Request) error { + Run: func(c *config.Config, conn *spec.Conn, req *spec.Request) error { // UNKONWN Frame: // Length: 8, Type: 255, Flags: 0, R: 0, StreamID: 0 conn.Send([]byte("\x00\x00\x08\x16\x00\x00\x00\x00\x00")) @@ -36,7 +36,7 @@ func FrameFormat() *spec.ClientTestGroup { tg.AddTestCase(&spec.ClientTestCase{ Desc: "Sends a frame with undefined flag", Requirement: "The endpoint MUST ignore any flags that is undefined.", - Run: func(c *config.ClientSpecConfig, conn *spec.Conn, req *spec.Request) error { + Run: func(c *config.Config, conn *spec.Conn, req *spec.Request) error { // PING Frame: // Length: 8, Type: 6, Flags: 255, R: 0, StreamID: 0 conn.Send([]byte("\x00\x00\x08\x06\x16\x00\x00\x00\x00")) @@ -54,7 +54,7 @@ func FrameFormat() *spec.ClientTestGroup { tg.AddTestCase(&spec.ClientTestCase{ Desc: "Sends a frame with reserved field bit", Requirement: "The endpoint MUST ignore the value of reserved field.", - Run: func(c *config.ClientSpecConfig, conn *spec.Conn, req *spec.Request) error { + Run: func(c *config.Config, conn *spec.Conn, req *spec.Request) error { // PING Frame: // Length: 8, Type: 6, Flags: 255, R: 1, StreamID: 0 conn.Send([]byte("\x00\x00\x08\x06\x16\x80\x00\x00\x00")) diff --git a/client/4_2_frame_size.go b/client/4_2_frame_size.go index 59814ff..e9ee03e 100644 --- a/client/4_2_frame_size.go +++ b/client/4_2_frame_size.go @@ -15,7 +15,7 @@ func FrameSize() *spec.ClientTestGroup { tg.AddTestCase(&spec.ClientTestCase{ Desc: "Sends a DATA frame with 2^14 octets in length", Requirement: "The endpoint MUST be capable of receiving and minimally processing frames up to 2^14 octets in length.", - Run: func(c *config.ClientSpecConfig, conn *spec.Conn, req *spec.Request) error { + Run: func(c *config.Config, conn *spec.Conn, req *spec.Request) error { headers := spec.CommonRespHeaders(c) hp := http2.HeadersFrameParam{ @@ -44,7 +44,7 @@ func FrameSize() *spec.ClientTestGroup { tg.AddTestCase(&spec.ClientTestCase{ Desc: "Sends a large size DATA frame that exceeds the SETTINGS_MAX_FRAME_SIZE", Requirement: "The endpoint MUST send an error code of FRAME_SIZE_ERROR.", - Run: func(c *config.ClientSpecConfig, conn *spec.Conn, req *spec.Request) error { + Run: func(c *config.Config, conn *spec.Conn, req *spec.Request) error { headers := spec.CommonRespHeaders(c) hp := http2.HeadersFrameParam{ @@ -71,7 +71,7 @@ func FrameSize() *spec.ClientTestGroup { tg.AddTestCase(&spec.ClientTestCase{ Desc: "Sends a large size HEADERS frame that exceeds the SETTINGS_MAX_FRAME_SIZE", Requirement: "The endpoint MUST respond with a connection error of type FRAME_SIZE_ERROR.", - Run: func(c *config.ClientSpecConfig, conn *spec.Conn, req *spec.Request) error { + Run: func(c *config.Config, conn *spec.Conn, req *spec.Request) error { headers := spec.CommonRespHeaders(c) headers = append(headers, spec.DummyRespHeaders(c, 5)...) diff --git a/client/4_3_header_compression_and_decompression.go b/client/4_3_header_compression_and_decompression.go index ce44e0c..566d037 100644 --- a/client/4_3_header_compression_and_decompression.go +++ b/client/4_3_header_compression_and_decompression.go @@ -17,7 +17,7 @@ func HeaderCompressionAndDecompression() *spec.ClientTestGroup { tg.AddTestCase(&spec.ClientTestCase{ Desc: "Sends invalid header block fragment", Requirement: "The endpoint MUST terminate the connection with a connection error of type COMPRESSION_ERROR.", - Run: func(c *config.ClientSpecConfig, conn *spec.Conn, req *spec.Request) error { + Run: func(c *config.Config, conn *spec.Conn, req *spec.Request) error { // Literal Header Field with Incremental Indexing without // Length and String segment. data := new(bytes.Buffer) diff --git a/client/5_1_1_stream_identifiers.go b/client/5_1_1_stream_identifiers.go index c2c2492..d34e570 100644 --- a/client/5_1_1_stream_identifiers.go +++ b/client/5_1_1_stream_identifiers.go @@ -15,7 +15,7 @@ func StreamIdentifiers() *spec.ClientTestGroup { tg.AddTestCase(&spec.ClientTestCase{ Desc: "Sends odd-numbered stream identifier", Requirement: "The endpoint MUST respond with a connection error of type PROTOCOL_ERROR.", - Run: func(c *config.ClientSpecConfig, conn *spec.Conn, req *spec.Request) error { + Run: func(c *config.Config, conn *spec.Conn, req *spec.Request) error { headers := spec.CommonRespHeaders(c) hp := http2.HeadersFrameParam{ StreamID: req.StreamID + 2, diff --git a/client/5_1_stream_states.go b/client/5_1_stream_states.go index ed1c9d0..94cd208 100644 --- a/client/5_1_stream_states.go +++ b/client/5_1_stream_states.go @@ -16,7 +16,7 @@ func StreamStates() *spec.ClientTestGroup { tg.AddTestCase(&spec.ClientTestCase{ Desc: "idle: Sends a DATA frame", Requirement: "The endpoint MUST treat this as a connection error of type PROTOCOL_ERROR.", - Run: func(c *config.ClientSpecConfig, conn *spec.Conn, req *spec.Request) error { + Run: func(c *config.Config, conn *spec.Conn, req *spec.Request) error { conn.WriteData(2, true, []byte("test")) return spec.VerifyConnectionError(conn, http2.ErrCodeProtocol) @@ -30,7 +30,7 @@ func StreamStates() *spec.ClientTestGroup { tg.AddTestCase(&spec.ClientTestCase{ Desc: "idle: Sends a RST_STREAM frame", Requirement: "The endpoint MUST treat this as a connection error of type PROTOCOL_ERROR.", - Run: func(c *config.ClientSpecConfig, conn *spec.Conn, req *spec.Request) error { + Run: func(c *config.Config, conn *spec.Conn, req *spec.Request) error { conn.WriteRSTStream(2, http2.ErrCodeCancel) return spec.VerifyConnectionError(conn, http2.ErrCodeProtocol) @@ -44,7 +44,7 @@ func StreamStates() *spec.ClientTestGroup { tg.AddTestCase(&spec.ClientTestCase{ Desc: "idle: Sends a WINDOW_UPDATE frame", Requirement: "The endpoint MUST treat this as a connection error of type PROTOCOL_ERROR.", - Run: func(c *config.ClientSpecConfig, conn *spec.Conn, req *spec.Request) error { + Run: func(c *config.Config, conn *spec.Conn, req *spec.Request) error { conn.WriteWindowUpdate(2, 100) return spec.VerifyConnectionError(conn, http2.ErrCodeProtocol) @@ -58,7 +58,7 @@ func StreamStates() *spec.ClientTestGroup { tg.AddTestCase(&spec.ClientTestCase{ Desc: "idle: Sends a CONTINUATION frame", Requirement: "The endpoint MUST treat this as a connection error of type PROTOCOL_ERROR.", - Run: func(c *config.ClientSpecConfig, conn *spec.Conn, req *spec.Request) error { + Run: func(c *config.Config, conn *spec.Conn, req *spec.Request) error { headers := spec.CommonRespHeaders(c) blockFragment := conn.EncodeHeaders(headers) conn.WriteContinuation(2, true, blockFragment) @@ -74,7 +74,7 @@ func StreamStates() *spec.ClientTestGroup { tg.AddTestCase(&spec.ClientTestCase{ Desc: "closed: Sends a DATA frame after sending RST_STREAM frame", Requirement: "The endpoint MUST treat this as a stream error of type STREAM_CLOSED.", - Run: func(c *config.ClientSpecConfig, conn *spec.Conn, req *spec.Request) error { + Run: func(c *config.Config, conn *spec.Conn, req *spec.Request) error { headers := spec.CommonRespHeaders(c) hp := http2.HeadersFrameParam{ StreamID: req.StreamID, @@ -99,7 +99,7 @@ func StreamStates() *spec.ClientTestGroup { tg.AddTestCase(&spec.ClientTestCase{ Desc: "closed: Sends a HEADERS frame after sending RST_STREAM frame", Requirement: "The endpoint MUST treat this as a stream error of type STREAM_CLOSED.", - Run: func(c *config.ClientSpecConfig, conn *spec.Conn, req *spec.Request) error { + Run: func(c *config.Config, conn *spec.Conn, req *spec.Request) error { headers := spec.CommonRespHeaders(c) hp1 := http2.HeadersFrameParam{ StreamID: req.StreamID, @@ -130,7 +130,7 @@ func StreamStates() *spec.ClientTestGroup { tg.AddTestCase(&spec.ClientTestCase{ Desc: "closed: Sends a CONTINUATION frame after sending RST_STREAM frame", Requirement: "The endpoint MUST treat this as a stream error of type STREAM_CLOSED.", - Run: func(c *config.ClientSpecConfig, conn *spec.Conn, req *spec.Request) error { + Run: func(c *config.Config, conn *spec.Conn, req *spec.Request) error { headers := spec.CommonRespHeaders(c) hp := http2.HeadersFrameParam{ StreamID: req.StreamID, @@ -160,7 +160,7 @@ func StreamStates() *spec.ClientTestGroup { tg.AddTestCase(&spec.ClientTestCase{ Desc: "closed: Sends a DATA frame", Requirement: "The endpoint MUST treat this as a connection error of type STREAM_CLOSED.", - Run: func(c *config.ClientSpecConfig, conn *spec.Conn, req *spec.Request) error { + Run: func(c *config.Config, conn *spec.Conn, req *spec.Request) error { headers := spec.CommonRespHeaders(c) hp := http2.HeadersFrameParam{ StreamID: req.StreamID, @@ -183,7 +183,7 @@ func StreamStates() *spec.ClientTestGroup { tg.AddTestCase(&spec.ClientTestCase{ Desc: "closed: Sends a HEADERS frame", Requirement: "The endpoint MUST treat this as a connection error of type STREAM_CLOSED.", - Run: func(c *config.ClientSpecConfig, conn *spec.Conn, req *spec.Request) error { + Run: func(c *config.Config, conn *spec.Conn, req *spec.Request) error { headers := spec.CommonRespHeaders(c) hp := http2.HeadersFrameParam{ StreamID: req.StreamID, @@ -206,7 +206,7 @@ func StreamStates() *spec.ClientTestGroup { tg.AddTestCase(&spec.ClientTestCase{ Desc: "closed: Sends a CONTINUATION frame", Requirement: "The endpoint MUST treat this as a connection error of type STREAM_CLOSED.", - Run: func(c *config.ClientSpecConfig, conn *spec.Conn, req *spec.Request) error { + Run: func(c *config.Config, conn *spec.Conn, req *spec.Request) error { headers := spec.CommonRespHeaders(c) hp := http2.HeadersFrameParam{ StreamID: req.StreamID, diff --git a/client/5_4_1_connection_error_handling.go b/client/5_4_1_connection_error_handling.go index 5ebe34a..293d114 100644 --- a/client/5_4_1_connection_error_handling.go +++ b/client/5_4_1_connection_error_handling.go @@ -17,7 +17,7 @@ func ConnectionErrorHandling() *spec.ClientTestGroup { tg.AddTestCase(&spec.ClientTestCase{ Desc: "Sends an invalid PING frame for connection close", Requirement: "The endpoint MUST close the TCP connection", - Run: func(c *config.ClientSpecConfig, conn *spec.Conn, req *spec.Request) error { + Run: func(c *config.Config, conn *spec.Conn, req *spec.Request) error { // PING frame with invalid stream ID conn.Send([]byte("\x00\x00\x08\x06\x00\x00\x00\x00\x03")) conn.Send([]byte("\x00\x00\x00\x00\x00\x00\x00\x00")) @@ -32,7 +32,7 @@ func ConnectionErrorHandling() *spec.ClientTestGroup { tg.AddTestCase(&spec.ClientTestCase{ Desc: "Sends an invalid PING frame to receive GOAWAY frame", Requirement: "An endpoint that encounters a connection error SHOULD first send a GOAWAY frame", - Run: func(c *config.ClientSpecConfig, conn *spec.Conn, req *spec.Request) error { + Run: func(c *config.Config, conn *spec.Conn, req *spec.Request) error { // PING frame with invalid stream ID conn.Send([]byte("\x00\x00\x08\x06\x00\x00\x00\x00\x03")) conn.Send([]byte("\x00\x00\x00\x00\x00\x00\x00\x00")) diff --git a/client/5_5_extending_http2.go b/client/5_5_extending_http2.go index e578ec7..73cb17d 100644 --- a/client/5_5_extending_http2.go +++ b/client/5_5_extending_http2.go @@ -11,7 +11,7 @@ func ExtendingHTTP2() *spec.ClientTestGroup { tg.AddTestCase(&spec.ClientTestCase{ Desc: "Sends an unknown extension frame", Requirement: "The endpoint MUST ignore unknown or unsupported values in all extensible protocol elements.", - Run: func(c *config.ClientSpecConfig, conn *spec.Conn, req *spec.Request) error { + Run: func(c *config.Config, conn *spec.Conn, req *spec.Request) error { // UNKONWN Frame: // Length: 8, Type: 255, Flags: 0, R: 0, StreamID: 0 diff --git a/client/6_10_continuation.go b/client/6_10_continuation.go index 80528b0..35bc252 100644 --- a/client/6_10_continuation.go +++ b/client/6_10_continuation.go @@ -18,7 +18,7 @@ func Continuation() *spec.ClientTestGroup { tg.AddTestCase(&spec.ClientTestCase{ Desc: "Sends multiple CONTINUATION frames preceded by a HEADERS frame", Requirement: "The endpoint must accept the frame.", - Run: func(c *config.ClientSpecConfig, conn *spec.Conn, req *spec.Request) error { + Run: func(c *config.Config, conn *spec.Conn, req *spec.Request) error { headers := spec.CommonRespHeaders(c) hp := http2.HeadersFrameParam{ StreamID: req.StreamID, @@ -47,7 +47,7 @@ func Continuation() *spec.ClientTestGroup { tg.AddTestCase(&spec.ClientTestCase{ Desc: "Sends a CONTINUATION frame followed by any frame other than CONTINUATION", Requirement: "The endpoint MUST treat this as a connection error of type PROTOCOL_ERROR.", - Run: func(c *config.ClientSpecConfig, conn *spec.Conn, req *spec.Request) error { + Run: func(c *config.Config, conn *spec.Conn, req *spec.Request) error { headers := spec.CommonRespHeaders(c) hp := http2.HeadersFrameParam{ @@ -73,7 +73,7 @@ func Continuation() *spec.ClientTestGroup { tg.AddTestCase(&spec.ClientTestCase{ Desc: "Sends a CONTINUATION frame with 0x0 stream identifier", Requirement: "The endpoint MUST respond with a connection error of type PROTOCOL_ERROR.", - Run: func(c *config.ClientSpecConfig, conn *spec.Conn, req *spec.Request) error { + Run: func(c *config.Config, conn *spec.Conn, req *spec.Request) error { headers := spec.CommonRespHeaders(c) hp := http2.HeadersFrameParam{ StreamID: req.StreamID, @@ -97,7 +97,7 @@ func Continuation() *spec.ClientTestGroup { tg.AddTestCase(&spec.ClientTestCase{ Desc: "Sends a CONTINUATION frame preceded by a HEADERS frame with END_HEADERS flag", Requirement: "The endpoint MUST respond with a connection error of type PROTOCOL_ERROR.", - Run: func(c *config.ClientSpecConfig, conn *spec.Conn, req *spec.Request) error { + Run: func(c *config.Config, conn *spec.Conn, req *spec.Request) error { headers := spec.CommonRespHeaders(c) hp := http2.HeadersFrameParam{ StreamID: req.StreamID, @@ -121,7 +121,7 @@ func Continuation() *spec.ClientTestGroup { tg.AddTestCase(&spec.ClientTestCase{ Desc: "Sends a CONTINUATION frame preceded by a CONTINUATION frame with END_HEADERS flag", Requirement: "The endpoint MUST respond with a connection error of type PROTOCOL_ERROR.", - Run: func(c *config.ClientSpecConfig, conn *spec.Conn, req *spec.Request) error { + Run: func(c *config.Config, conn *spec.Conn, req *spec.Request) error { headers := spec.CommonRespHeaders(c) hp := http2.HeadersFrameParam{ StreamID: req.StreamID, @@ -146,7 +146,7 @@ func Continuation() *spec.ClientTestGroup { tg.AddTestCase(&spec.ClientTestCase{ Desc: "Sends a CONTINUATION frame preceded by a DATA frame", Requirement: "The endpoint MUST respond with a connection error of type PROTOCOL_ERROR.", - Run: func(c *config.ClientSpecConfig, conn *spec.Conn, req *spec.Request) error { + Run: func(c *config.Config, conn *spec.Conn, req *spec.Request) error { headers := spec.CommonRespHeaders(c) hp := http2.HeadersFrameParam{ diff --git a/client/6_1_data.go b/client/6_1_data.go index 9655eae..1df4da7 100644 --- a/client/6_1_data.go +++ b/client/6_1_data.go @@ -17,7 +17,7 @@ func Data() *spec.ClientTestGroup { tg.AddTestCase(&spec.ClientTestCase{ Desc: "Sends a DATA frame with 0x0 stream identifier", Requirement: "The endpoint MUST respond with a connection error of type PROTOCOL_ERROR.", - Run: func(c *config.ClientSpecConfig, conn *spec.Conn, req *spec.Request) error { + Run: func(c *config.Config, conn *spec.Conn, req *spec.Request) error { conn.WriteData(0, true, []byte("test")) return spec.VerifyConnectionError(conn, http2.ErrCodeProtocol) @@ -32,7 +32,7 @@ func Data() *spec.ClientTestGroup { tg.AddTestCase(&spec.ClientTestCase{ Desc: "Sends a DATA frame on the stream that is not in \"open\" or \"half-closed (local)\" state", Requirement: "The endpoint MUST respond with a stream error of type STREAM_CLOSED.", - Run: func(c *config.ClientSpecConfig, conn *spec.Conn, req *spec.Request) error { + Run: func(c *config.Config, conn *spec.Conn, req *spec.Request) error { headers := spec.CommonRespHeaders(c) hp := http2.HeadersFrameParam{ @@ -55,7 +55,7 @@ func Data() *spec.ClientTestGroup { tg.AddTestCase(&spec.ClientTestCase{ Desc: "Sends a DATA frame with invalid pad length", Requirement: "The endpoint MUST treat this as a connection error of type PROTOCOL_ERROR.", - Run: func(c *config.ClientSpecConfig, conn *spec.Conn, req *spec.Request) error { + Run: func(c *config.Config, conn *spec.Conn, req *spec.Request) error { headers := spec.CommonRespHeaders(c) headers = append(headers, spec.HeaderField("content-length", "4")) diff --git a/client/6_2_headers.go b/client/6_2_headers.go index d21d700..b6977b8 100644 --- a/client/6_2_headers.go +++ b/client/6_2_headers.go @@ -21,7 +21,7 @@ func Headers() *spec.ClientTestGroup { tg.AddTestCase(&spec.ClientTestCase{ Desc: "Sends a HEADERS frame without the END_HEADERS flag, and a PRIORITY frame", Requirement: "The endpoint MUST treat this as a connection error of type PROTOCOL_ERROR.", - Run: func(c *config.ClientSpecConfig, conn *spec.Conn, req *spec.Request) error { + Run: func(c *config.Config, conn *spec.Conn, req *spec.Request) error { headers := spec.CommonRespHeaders(c) hp := http2.HeadersFrameParam{ StreamID: req.StreamID, @@ -52,7 +52,7 @@ func Headers() *spec.ClientTestGroup { tg.AddTestCase(&spec.ClientTestCase{ Desc: "Sends a HEADERS frame with 0x0 stream identifier", Requirement: "The endpoint MUST respond with a connection error of type PROTOCOL_ERROR.", - Run: func(c *config.ClientSpecConfig, conn *spec.Conn, req *spec.Request) error { + Run: func(c *config.Config, conn *spec.Conn, req *spec.Request) error { headers := spec.CommonRespHeaders(c) hp := http2.HeadersFrameParam{ @@ -75,7 +75,7 @@ func Headers() *spec.ClientTestGroup { tg.AddTestCase(&spec.ClientTestCase{ Desc: "Sends a HEADERS frame with invalid pad length", Requirement: "The endpoint MUST treat this as a connection error of type PROTOCOL_ERROR.", - Run: func(c *config.ClientSpecConfig, conn *spec.Conn, req *spec.Request) error { + Run: func(c *config.Config, conn *spec.Conn, req *spec.Request) error { headers := spec.CommonRespHeaders(c) // HEADERS frame: diff --git a/client/6_3_priority.go b/client/6_3_priority.go index 89caec9..737abbf 100644 --- a/client/6_3_priority.go +++ b/client/6_3_priority.go @@ -17,7 +17,7 @@ func Priority() *spec.ClientTestGroup { tg.AddTestCase(&spec.ClientTestCase{ Desc: "Sends a PRIORITY frame with 0x0 stream identifier", Requirement: "The endpoint MUST respond with a connection error of type PROTOCOL_ERROR.", - Run: func(c *config.ClientSpecConfig, conn *spec.Conn, req *spec.Request) error { + Run: func(c *config.Config, conn *spec.Conn, req *spec.Request) error { pp := http2.PriorityParam{ StreamDep: 0, Exclusive: false, @@ -35,7 +35,7 @@ func Priority() *spec.ClientTestGroup { tg.AddTestCase(&spec.ClientTestCase{ Desc: "Sends a PRIORITY frame with a length other than 5 octets", Requirement: "The endpoint MUST respond with a stream error of type FRAME_SIZE_ERROR.", - Run: func(c *config.ClientSpecConfig, conn *spec.Conn, req *spec.Request) error { + Run: func(c *config.Config, conn *spec.Conn, req *spec.Request) error { headers := spec.CommonRespHeaders(c) hp := http2.HeadersFrameParam{ StreamID: req.StreamID, diff --git a/client/6_4_rst_stream.go b/client/6_4_rst_stream.go index 841fc09..6aea50c 100644 --- a/client/6_4_rst_stream.go +++ b/client/6_4_rst_stream.go @@ -17,7 +17,7 @@ func RSTStream() *spec.ClientTestGroup { tg.AddTestCase(&spec.ClientTestCase{ Desc: "Sends a RST_STREAM frame with 0x0 stream identifier", Requirement: "The endpoint MUST respond with a connection error of type PROTOCOL_ERROR.", - Run: func(c *config.ClientSpecConfig, conn *spec.Conn, req *spec.Request) error { + Run: func(c *config.Config, conn *spec.Conn, req *spec.Request) error { conn.WriteRSTStream(0, http2.ErrCodeCancel) return spec.VerifyConnectionError(conn, http2.ErrCodeProtocol) @@ -31,7 +31,7 @@ func RSTStream() *spec.ClientTestGroup { tg.AddTestCase(&spec.ClientTestCase{ Desc: "Sends a RST_STREAM frame on a idle stream", Requirement: "The endpoint MUST respond with a connection error of type PROTOCOL_ERROR.", - Run: func(c *config.ClientSpecConfig, conn *spec.Conn, req *spec.Request) error { + Run: func(c *config.Config, conn *spec.Conn, req *spec.Request) error { conn.WriteRSTStream(2, http2.ErrCodeCancel) return spec.VerifyConnectionError(conn, http2.ErrCodeProtocol) @@ -44,7 +44,7 @@ func RSTStream() *spec.ClientTestGroup { tg.AddTestCase(&spec.ClientTestCase{ Desc: "Sends a RST_STREAM frame with a length other than 4 octets", Requirement: "The endpoint MUST respond with a connection error of type FRAME_SIZE_ERROR.", - Run: func(c *config.ClientSpecConfig, conn *spec.Conn, req *spec.Request) error { + Run: func(c *config.Config, conn *spec.Conn, req *spec.Request) error { headers := spec.CommonRespHeaders(c) hp := http2.HeadersFrameParam{ StreamID: req.StreamID, diff --git a/client/6_5_2_defined_settings_parameters.go b/client/6_5_2_defined_settings_parameters.go index 0ef4f05..1f0ceee 100644 --- a/client/6_5_2_defined_settings_parameters.go +++ b/client/6_5_2_defined_settings_parameters.go @@ -17,7 +17,7 @@ func DefinedSETTINGSParameters() *spec.ClientTestGroup { tg.AddTestCase(&spec.ClientTestCase{ Desc: "SETTINGS_INITIAL_WINDOW_SIZE (0x4): Sends the value above the maximum flow control window size", Requirement: "The endpoint MUST treat this as a connection error of type FLOW_CONTROL_ERROR.", - Run: func(c *config.ClientSpecConfig, conn *spec.Conn, req *spec.Request) error { + Run: func(c *config.Config, conn *spec.Conn, req *spec.Request) error { setting := http2.Setting{ ID: http2.SettingInitialWindowSize, Val: 2147483648, @@ -37,7 +37,7 @@ func DefinedSETTINGSParameters() *spec.ClientTestGroup { tg.AddTestCase(&spec.ClientTestCase{ Desc: "SETTINGS_MAX_FRAME_SIZE (0x5): Sends the value below the initial value", Requirement: "The endpoint MUST treat this as a connection error of type PROTOCOL_ERROR.", - Run: func(c *config.ClientSpecConfig, conn *spec.Conn, req *spec.Request) error { + Run: func(c *config.Config, conn *spec.Conn, req *spec.Request) error { setting := http2.Setting{ ID: http2.SettingMaxFrameSize, Val: 16383, @@ -57,7 +57,7 @@ func DefinedSETTINGSParameters() *spec.ClientTestGroup { tg.AddTestCase(&spec.ClientTestCase{ Desc: "SETTINGS_MAX_FRAME_SIZE (0x5): Sends the value above the maximum allowed frame size", Requirement: "The endpoint MUST treat this as a connection error of type PROTOCOL_ERROR.", - Run: func(c *config.ClientSpecConfig, conn *spec.Conn, req *spec.Request) error { + Run: func(c *config.Config, conn *spec.Conn, req *spec.Request) error { setting := http2.Setting{ ID: http2.SettingMaxFrameSize, Val: 16777216, @@ -73,7 +73,7 @@ func DefinedSETTINGSParameters() *spec.ClientTestGroup { tg.AddTestCase(&spec.ClientTestCase{ Desc: "Sends a SETTINGS frame with unknown identifier", Requirement: "The endpoint MUST ignore that setting.", - Run: func(c *config.ClientSpecConfig, conn *spec.Conn, req *spec.Request) error { + Run: func(c *config.Config, conn *spec.Conn, req *spec.Request) error { setting := http2.Setting{ ID: 0xFF, Val: 1, diff --git a/client/6_5_3_settings_synchronization.go b/client/6_5_3_settings_synchronization.go index e6e463f..ecaf505 100644 --- a/client/6_5_3_settings_synchronization.go +++ b/client/6_5_3_settings_synchronization.go @@ -15,7 +15,7 @@ func SettingsSynchronization() *spec.ClientTestGroup { tg.AddTestCase(&spec.ClientTestCase{ Desc: "Sends a SETTINGS frame without ACK flag", Requirement: "The endpoint MUST immediately emit a SETTINGS frame with the ACK flag set.", - Run: func(c *config.ClientSpecConfig, conn *spec.Conn, req *spec.Request) error { + Run: func(c *config.Config, conn *spec.Conn, req *spec.Request) error { setting := http2.Setting{ ID: http2.SettingEnablePush, Val: 0, diff --git a/client/6_5_settings.go b/client/6_5_settings.go index 0231881..64b4a6d 100644 --- a/client/6_5_settings.go +++ b/client/6_5_settings.go @@ -20,7 +20,7 @@ func Settings() *spec.ClientTestGroup { tg.AddTestCase(&spec.ClientTestCase{ Desc: "Sends a SETTINGS frame with ACK flag and payload", Requirement: "The endpoint MUST respond with a connection error of type FRAME_SIZE_ERROR.", - Run: func(c *config.ClientSpecConfig, conn *spec.Conn, req *spec.Request) error { + Run: func(c *config.Config, conn *spec.Conn, req *spec.Request) error { // SETTINGS frame: // length: 0, flags: 0x1, stream_id: 0x0 conn.Send([]byte("\x00\x00\x01\x04\x01\x00\x00\x00\x00")) @@ -39,7 +39,7 @@ func Settings() *spec.ClientTestGroup { tg.AddTestCase(&spec.ClientTestCase{ Desc: "Sends a SETTINGS frame with a stream identifier other than 0x0", Requirement: "The endpoint MUST respond with a connection error of type PROTOCOL_ERROR.", - Run: func(c *config.ClientSpecConfig, conn *spec.Conn, req *spec.Request) error { + Run: func(c *config.Config, conn *spec.Conn, req *spec.Request) error { // SETTINGS frame: // length: 6, flags: 0x0, stream_id: 0x1 conn.Send([]byte("\x00\x00\x06\x04\x00\x00\x00\x00\x01")) @@ -59,7 +59,7 @@ func Settings() *spec.ClientTestGroup { tg.AddTestCase(&spec.ClientTestCase{ Desc: "Sends a SETTINGS frame with a length other than a multiple of 6 octets", Requirement: "The endpoint MUST respond with a connection error of type FRAME_SIZE_ERROR.", - Run: func(c *config.ClientSpecConfig, conn *spec.Conn, req *spec.Request) error { + Run: func(c *config.Config, conn *spec.Conn, req *spec.Request) error { // SETTINGS frame: // length: 3, flags: 0x0, stream_id: 0x0 conn.Send([]byte("\x00\x00\x03\x04\x00\x00\x00\x00\x00")) diff --git a/client/6_7_ping.go b/client/6_7_ping.go index fc4f7e0..b12d8a8 100644 --- a/client/6_7_ping.go +++ b/client/6_7_ping.go @@ -16,7 +16,7 @@ func Ping() *spec.ClientTestGroup { tg.AddTestCase(&spec.ClientTestCase{ Desc: "Sends a PING frame", Requirement: "The endpoint MUST sends a PING frame with ACK, with an identical payload.", - Run: func(c *config.ClientSpecConfig, conn *spec.Conn, req *spec.Request) error { + Run: func(c *config.Config, conn *spec.Conn, req *spec.Request) error { data := [8]byte{'h', '2', 's', 'p', 'e', 'c'} conn.WritePing(false, data) @@ -32,7 +32,7 @@ func Ping() *spec.ClientTestGroup { tg.AddTestCase(&spec.ClientTestCase{ Desc: "Sends a PING frame with ACK", Requirement: "The endpoint MUST NOT respond to PING frames with ACK.", - Run: func(c *config.ClientSpecConfig, conn *spec.Conn, req *spec.Request) error { + Run: func(c *config.Config, conn *spec.Conn, req *spec.Request) error { unexpectedData := [8]byte{'i', 'n', 'v', 'a', 'l', 'i', 'd'} expectedData := [8]byte{'h', '2', 's', 'p', 'e', 'c'} conn.WritePing(true, unexpectedData) @@ -48,7 +48,7 @@ func Ping() *spec.ClientTestGroup { tg.AddTestCase(&spec.ClientTestCase{ Desc: "Sends a PING frame with a stream identifier field value other than 0x0", Requirement: "The endpoint MUST respond with a connection error of type PROTOCOL_ERROR.", - Run: func(c *config.ClientSpecConfig, conn *spec.Conn, req *spec.Request) error { + Run: func(c *config.Config, conn *spec.Conn, req *spec.Request) error { // PING frame: // length: 8, flags: 0x0, stream_id: 1 conn.Send([]byte("\x00\x00\x08\x06\x00\x00\x00\x00\x01")) @@ -64,7 +64,7 @@ func Ping() *spec.ClientTestGroup { tg.AddTestCase(&spec.ClientTestCase{ Desc: "Sends a PING frame with a length field value other than 8", Requirement: "The endpoint MUST treat this as a connection error of type FRAME_SIZE_ERROR.", - Run: func(c *config.ClientSpecConfig, conn *spec.Conn, req *spec.Request) error { + Run: func(c *config.Config, conn *spec.Conn, req *spec.Request) error { // PING frame: // length: 8, flags: 0x0, stream_id: 1 conn.Send([]byte("\x00\x00\x06\x06\x00\x00\x00\x00\x00")) diff --git a/client/6_8_goaway.go b/client/6_8_goaway.go index 8c1e7ea..6698bd8 100644 --- a/client/6_8_goaway.go +++ b/client/6_8_goaway.go @@ -16,7 +16,7 @@ func GoAway() *spec.ClientTestGroup { tg.AddTestCase(&spec.ClientTestCase{ Desc: "Sends a GOAWAY frame with a stream identifier other than 0x0", Requirement: "The endpoint MUST treat this as a connection error of type PROTOCOL_ERROR.", - Run: func(c *config.ClientSpecConfig, conn *spec.Conn, req *spec.Request) error { + Run: func(c *config.Config, conn *spec.Conn, req *spec.Request) error { // GOAWAY frame: // length: 8, flags: 0x0, stream_id: 1 conn.Send([]byte("\x00\x00\x08\x07\x00\x00\x00\x00\x01")) diff --git a/client/6_9_1_the_flow_control_window.go b/client/6_9_1_the_flow_control_window.go index 3b2e64c..4a2d0f7 100644 --- a/client/6_9_1_the_flow_control_window.go +++ b/client/6_9_1_the_flow_control_window.go @@ -22,7 +22,7 @@ func TheFlowControlWindow() *spec.ClientTestGroup { tg.AddTestCase(&spec.ClientTestCase{ Desc: "Sends multiple WINDOW_UPDATE frames increasing the flow control window to above 2^31-1", Requirement: "The endpoint MUST sends a GOAWAY frame with a FLOW_CONTROL_ERROR code.", - Run: func(c *config.ClientSpecConfig, conn *spec.Conn, req *spec.Request) error { + Run: func(c *config.Config, conn *spec.Conn, req *spec.Request) error { conn.WriteWindowUpdate(0, 2147483647) conn.WriteWindowUpdate(0, 2147483647) @@ -59,7 +59,7 @@ func TheFlowControlWindow() *spec.ClientTestGroup { tg.AddTestCase(&spec.ClientTestCase{ Desc: "Sends multiple WINDOW_UPDATE frames increasing the flow control window to above 2^31-1 on a stream", Requirement: "The endpoint MUST sends a RST_STREAM frame with a FLOW_CONTROL_ERROR code.", - Run: func(c *config.ClientSpecConfig, conn *spec.Conn, req *spec.Request) error { + Run: func(c *config.Config, conn *spec.Conn, req *spec.Request) error { headers := spec.CommonRespHeaders(c) hp := http2.HeadersFrameParam{ StreamID: req.StreamID, diff --git a/client/6_9_window_update.go b/client/6_9_window_update.go index 4857437..87aed30 100644 --- a/client/6_9_window_update.go +++ b/client/6_9_window_update.go @@ -18,7 +18,7 @@ func WindowUpdate() *spec.ClientTestGroup { tg.AddTestCase(&spec.ClientTestCase{ Desc: "Sends a WINDOW_UPDATE frame with a flow control window increment of 0", Requirement: "The endpoint MUST treat this as a connection error of type PROTOCOL_ERROR.", - Run: func(c *config.ClientSpecConfig, conn *spec.Conn, req *spec.Request) error { + Run: func(c *config.Config, conn *spec.Conn, req *spec.Request) error { conn.WriteWindowUpdate(0, 0) return spec.VerifyConnectionError(conn, http2.ErrCodeProtocol) @@ -33,7 +33,7 @@ func WindowUpdate() *spec.ClientTestGroup { tg.AddTestCase(&spec.ClientTestCase{ Desc: "Sends a WINDOW_UPDATE frame with a flow control window increment of 0 on a stream", Requirement: "The endpoint MUST treat this as a connection error of type PROTOCOL_ERROR.", - Run: func(c *config.ClientSpecConfig, conn *spec.Conn, req *spec.Request) error { + Run: func(c *config.Config, conn *spec.Conn, req *spec.Request) error { headers := spec.CommonRespHeaders(c) hp := http2.HeadersFrameParam{ StreamID: req.StreamID, @@ -55,7 +55,7 @@ func WindowUpdate() *spec.ClientTestGroup { tg.AddTestCase(&spec.ClientTestCase{ Desc: "Sends a WINDOW_UPDATE frame with a length other than 4 octets", Requirement: "The endpoint MUST treat this as a connection error of type FRAME_SIZE_ERROR.", - Run: func(c *config.ClientSpecConfig, conn *spec.Conn, req *spec.Request) error { + Run: func(c *config.Config, conn *spec.Conn, req *spec.Request) error { // WINDOW_UPDATE frame: // length: 3, flags: 0x0, stream_id: 0 conn.Send([]byte("\x00\x00\x03\x08\x00\x00\x00\x00\x00")) diff --git a/cmd/h2spec/h2specd.go b/cmd/h2spec/h2specd.go index 215cc82..195b411 100644 --- a/cmd/h2spec/h2specd.go +++ b/cmd/h2spec/h2specd.go @@ -132,7 +132,7 @@ func run(cmd *cobra.Command, args []string) error { } } - c := &config.ClientSpecConfig{ + c := &config.Config{ Host: host, Port: port, Timeout: time.Duration(timeout) * time.Second, diff --git a/config/client_config.go b/config/client_config.go deleted file mode 100644 index 4e20fe5..0000000 --- a/config/client_config.go +++ /dev/null @@ -1,56 +0,0 @@ -package config - -import ( - "crypto/tls" - "fmt" - "time" -) - -// Config represents the configuration of h2spec. -type ClientSpecConfig struct { - Host string - Port int - Timeout time.Duration - MaxHeaderLen int - JUnitReport string - Strict bool - DryRun bool - TLS bool - Verbose bool - Sections []string - CertFile string - CertKeyFile string - Exec string -} - -// Addr returns the string concatinated with hostname and port number. -func (c *ClientSpecConfig) Addr() string { - return fmt.Sprintf("%s:%d", c.Host, c.Port) -} - -func (c *ClientSpecConfig) Scheme() string { - if c.TLS { - return "https" - } else { - return "http" - } -} - -// TLSConfig returns a tls.Config based on the configuration of h2spec. -func (c *ClientSpecConfig) TLSConfig() (*tls.Config, error) { - if !c.TLS { - return nil, nil - } - - cert, err := tls.LoadX509KeyPair(c.CertFile, c.CertKeyFile) - if err != nil { - return nil, err - } - - config := tls.Config{ - Certificates: []tls.Certificate{cert}, - NextProtos: []string{"h2", "h2-16"}, - } - - return &config, nil -} diff --git a/config/config.go b/config/config.go index 4a77e36..efeaac7 100644 --- a/config/config.go +++ b/config/config.go @@ -27,6 +27,9 @@ type Config struct { Verbose bool Sections []string targetMap map[string]bool + CertFile string + CertKeyFile string + Exec string } // Addr returns the string concatinated with hostname and port number. @@ -34,10 +37,18 @@ func (c *Config) Addr() string { return fmt.Sprintf("%s:%d", c.Host, c.Port) } +func (c *Config) Scheme() string { + if c.TLS { + return "https" + } else { + return "http" + } +} + // TLSConfig returns a tls.Config based on the configuration of h2spec. -func (c *Config) TLSConfig() *tls.Config { +func (c *Config) TLSConfig() (*tls.Config, error) { if !c.TLS { - return nil + return nil, nil } config := tls.Config{ @@ -48,7 +59,15 @@ func (c *Config) TLSConfig() *tls.Config { config.NextProtos = append(config.NextProtos, "h2", "h2-16") } - return &config + if c.CertFile != "" && c.CertKeyFile != "" { + cert, err := tls.LoadX509KeyPair(c.CertFile, c.CertKeyFile) + if err != nil { + return nil, err + } + config.Certificates = []tls.Certificate{cert} + } + + return &config, nil } // RunMode returns a run mode of specified the section number. diff --git a/h2spec.go b/h2spec.go index 787d052..138359f 100644 --- a/h2spec.go +++ b/h2spec.go @@ -68,7 +68,7 @@ func Run(c *config.Config) error { return nil } -func RunClientSpec(c *config.ClientSpecConfig) error { +func RunClientSpec(c *config.Config) error { s := client.Spec() server, _ := spec.Listen(c, s) diff --git a/spec/connection.go b/spec/connection.go index e5e4d66..62755c5 100644 --- a/spec/connection.go +++ b/spec/connection.go @@ -58,7 +58,12 @@ func Dial(c *config.Config) (*Conn, error) { dialer := &net.Dialer{} dialer.Timeout = c.Timeout - tlsConn, err := tls.DialWithDialer(dialer, "tcp", c.Addr(), c.TLSConfig()) + tlsConfig, err := c.TLSConfig() + if err != nil { + return nil, err + } + + tlsConn, err := tls.DialWithDialer(dialer, "tcp", c.Addr(), tlsConfig) if err != nil { return nil, err } @@ -115,7 +120,7 @@ func Dial(c *config.Config) (*Conn, error) { return &conn, nil } -func Accept(c *config.ClientSpecConfig, baseConn net.Conn) (*Conn, error) { +func Accept(c *config.Config, baseConn net.Conn) (*Conn, error) { settings := map[http2.SettingID]uint32{} framer := http2.NewFramer(baseConn, baseConn) @@ -332,7 +337,7 @@ func (conn *Conn) WriteRawFrame(t http2.FrameType, flags http2.Flags, streamID u return conn.framer.WriteRawFrame(t, flags, streamID, payload) } -func (conn *Conn) WriteSuccessResponse(streamID uint32, c *config.ClientSpecConfig) { +func (conn *Conn) WriteSuccessResponse(streamID uint32, c *config.Config) { hp := http2.HeadersFrameParam{ StreamID: streamID, EndStream: false, diff --git a/spec/server.go b/spec/server.go index d95d324..d996d6b 100644 --- a/spec/server.go +++ b/spec/server.go @@ -17,12 +17,12 @@ import ( type Server struct { net.Listener - config *config.ClientSpecConfig + config *config.Config testCases map[string]*ClientTestCase spec *ClientTestGroup } -func Listen(c *config.ClientSpecConfig, tg *ClientTestGroup) (*Server, error) { +func Listen(c *config.Config, tg *ClientTestGroup) (*Server, error) { var err error var listener net.Listener if c.TLS { diff --git a/spec/specd.go b/spec/specd.go index b5e6963..339547c 100644 --- a/spec/specd.go +++ b/spec/specd.go @@ -59,7 +59,7 @@ func (tg *ClientTestGroup) Level() int { } // Test runs all the tests included in this group. -func (tg *ClientTestGroup) Test(c *config.ClientSpecConfig) { +func (tg *ClientTestGroup) Test(c *config.Config) { level := tg.Level() log.SetIndentLevel(level) @@ -132,11 +132,11 @@ type ClientTestCase struct { Requirement string Parent *ClientTestGroup Result *ClientTestResult - Run func(c *config.ClientSpecConfig, conn *Conn, req *Request) error + Run func(c *config.Config, conn *Conn, req *Request) error } // Test runs itself as a test case. -func (tc *ClientTestCase) Test(c *config.ClientSpecConfig) error { +func (tc *ClientTestCase) Test(c *config.Config) error { done := make(chan error) go func() { split := strings.Split(c.Exec, " ") @@ -168,7 +168,7 @@ func (tc *ClientTestCase) Path() string { return fmt.Sprintf("/%s/%d", tc.Parent.ID(), tc.Seq) } -func (tc *ClientTestCase) FullPath(c *config.ClientSpecConfig) string { +func (tc *ClientTestCase) FullPath(c *config.Config) string { return fmt.Sprintf("%s://%s:%d%s", c.Scheme(), c.Host, c.Port, tc.Path()) } diff --git a/spec/util.go b/spec/util.go index 75e774f..b816cdf 100644 --- a/spec/util.go +++ b/spec/util.go @@ -78,7 +78,7 @@ func CommonHeaders(c *config.Config) []hpack.HeaderField { // CommonHeaders returns a array of header field of HPACK contained // common http headers used in various test case. -func CommonRespHeaders(c *config.ClientSpecConfig) []hpack.HeaderField { +func CommonRespHeaders(c *config.Config) []hpack.HeaderField { return []hpack.HeaderField{ HeaderField(":status", "200"), } @@ -98,7 +98,7 @@ func DummyHeaders(c *config.Config, len int) []hpack.HeaderField { return headers } -func DummyRespHeaders(c *config.ClientSpecConfig, len int) []hpack.HeaderField { +func DummyRespHeaders(c *config.Config, len int) []hpack.HeaderField { headers := make([]hpack.HeaderField, 0, len) dummy := DummyString(c.MaxHeaderLen)