forked from summerwind/h2spec
-
Notifications
You must be signed in to change notification settings - Fork 0
/
6_1.go
77 lines (62 loc) · 2.25 KB
/
6_1.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
package h2spec
import (
"fmt"
"github.com/bradfitz/http2"
)
func DataTestGroup(ctx *Context) *TestGroup {
tg := NewTestGroup("6.1", "DATA")
tg.AddTestCase(NewTestCase(
"Sends a DATA frame with 0x0 stream identifier",
"The endpoint MUST respond with a connection error of type PROTOCOL_ERROR.",
func(ctx *Context) (pass bool, expected []Result, actual Result) {
http2Conn := CreateHttp2Conn(ctx, true)
defer http2Conn.conn.Close()
http2Conn.fr.WriteData(0, true, []byte("test"))
actualCodes := []http2.ErrCode{http2.ErrCodeProtocol}
return TestConnectionError(ctx, http2Conn, actualCodes)
},
))
tg.AddTestCase(NewTestCase(
"Sends a DATA frame on the stream that is not opend",
"The endpoint MUST respond with a stream error of type STREAM_CLOSED.",
func(ctx *Context) (pass bool, expected []Result, actual Result) {
http2Conn := CreateHttp2Conn(ctx, true)
defer http2Conn.conn.Close()
hdrs := commonHeaderFields(ctx)
hdrs[0].Value = "POST"
hdrs = append(hdrs, pair("content-type", "4"))
var hp http2.HeadersFrameParam
hp.StreamID = 1
hp.EndStream = true
hp.EndHeaders = true
hp.BlockFragment = http2Conn.EncodeHeader(hdrs)
http2Conn.fr.WriteHeaders(hp)
http2Conn.fr.WriteData(1, true, []byte("test"))
actualCodes := []http2.ErrCode{http2.ErrCodeStreamClosed}
return TestStreamError(ctx, http2Conn, actualCodes)
},
))
tg.AddTestCase(NewTestCase(
"Sends a DATA frame with invalid pad length",
"The endpoint MUST treat this as a connection error of type PROTOCOL_ERROR.",
func(ctx *Context) (pass bool, expected []Result, actual Result) {
http2Conn := CreateHttp2Conn(ctx, true)
defer http2Conn.conn.Close()
hdrs := commonHeaderFields(ctx)
hdrs[0].Value = "POST"
hdrs = append(hdrs, pair("content-type", "4"))
var hp http2.HeadersFrameParam
hp.StreamID = 1
hp.EndStream = false
hp.EndHeaders = true
hp.BlockFragment = http2Conn.EncodeHeader(hdrs)
http2Conn.fr.WriteHeaders(hp)
// Data length: 5, Pad length: 6
fmt.Fprintf(http2Conn.conn, "\x00\x00\x05\x00\x0b\x00\x00\x00\x01")
fmt.Fprintf(http2Conn.conn, "\x06\x54\x65\x73\x74")
actualCodes := []http2.ErrCode{http2.ErrCodeProtocol}
return TestStreamError(ctx, http2Conn, actualCodes)
},
))
return tg
}