Removed redundant ClienetSpecConfig, reused and extend exists config.Config

This commit is contained in:
chhsiao90 2017-02-27 13:28:08 +08:00
Родитель 29ced674e0
Коммит 42eb36f845
28 изменённых файлов: 97 добавлений и 129 удалений

Просмотреть файл

@ -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

Просмотреть файл

@ -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"))

Просмотреть файл

@ -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)...)

Просмотреть файл

@ -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)

Просмотреть файл

@ -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,

Просмотреть файл

@ -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,

Просмотреть файл

@ -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"))

Просмотреть файл

@ -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

Просмотреть файл

@ -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{

Просмотреть файл

@ -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"))

Просмотреть файл

@ -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:

Просмотреть файл

@ -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,

Просмотреть файл

@ -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,

Просмотреть файл

@ -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,

Просмотреть файл

@ -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,

Просмотреть файл

@ -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"))

Просмотреть файл

@ -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"))

Просмотреть файл

@ -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"))

Просмотреть файл

@ -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,

Просмотреть файл

@ -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"))

Просмотреть файл

@ -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,

Просмотреть файл

@ -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
}

Просмотреть файл

@ -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.

Просмотреть файл

@ -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)

Просмотреть файл

@ -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,

Просмотреть файл

@ -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 {

Просмотреть файл

@ -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())
}

Просмотреть файл

@ -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)