This repository was archived by the owner on Nov 4, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathpackets_test.go
149 lines (132 loc) · 2.62 KB
/
packets_test.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
package spdy
import (
"bytes"
"net/http"
"net/url"
"reflect"
"testing"
)
type tester struct {
t *testing.T
data []byte
buf bytes.Buffer
zip compressor
unzip decompressor
}
func newTester(t *testing.T) *tester {
return &tester{t: t}
}
func (s *tester) test(f frame, parse func() (frame, error)) {
s.buf.Reset()
if err := f.WriteFrame(&s.buf, &s.zip); err != nil {
s.t.Fatalf("%v %+v", err, f)
}
s.data = s.buf.Bytes()
f2, err := parse()
if err != nil {
s.t.Fatalf("%v %+v", err, f)
}
if !reflect.DeepEqual(f, f2) {
if g, ok := f.(*synStreamFrame); ok {
s.t.Logf("%#v %#v", g.URL, f2.(*synStreamFrame).URL)
}
s.t.Fatalf("\nWant: %#v\n\nGot: %#v\n\n", f, f2)
}
}
var testurl, _ = url.Parse("https://www.example.com/foo?bar=3")
var requests = []synStreamFrame{
{
Finished: true,
Unidirectional: true,
StreamId: 3,
AssociatedStreamId: 2,
URL: testurl,
Proto: "HTTP/1.1",
ProtoMajor: 1,
ProtoMinor: 1,
Method: "GET",
},
{
Finished: false,
Unidirectional: false,
URL: testurl,
Proto: "HTTP/1.1",
ProtoMajor: 1,
ProtoMinor: 1,
},
}
var replies = []synReplyFrame{
{
Finished: true,
StreamId: 50,
Status: "202 OK",
Proto: "HTTP/1.1",
ProtoMajor: 1,
ProtoMinor: 1,
Header: nil,
},
{
StreamId: 50,
Status: "202 OK",
Proto: "HTTP/1.1",
ProtoMajor: 1,
ProtoMinor: 1,
Header: http.Header{
"Foo": {"bar", "bar3"},
"Foo2": {"bar5", "bar6"},
},
},
}
var headers = []headersFrame{
{
Finished: false,
StreamId: 5,
Header: http.Header{},
},
{
Finished: false,
StreamId: 7,
Header: http.Header{
"Foo": {"bar", "bar2"},
},
},
}
func TestSynStreamFrame(t *testing.T) {
s := newTester(t)
for _, f := range requests {
f.Version = 2
s.test(&f, func() (frame, error) {
return parseSynStream(s.data, &s.unzip)
})
f.Version = 3
s.test(&f, func() (frame, error) {
return parseSynStream(s.data, &s.unzip)
})
}
}
func TestSynReplyFrame(t *testing.T) {
s := newTester(t)
for _, f := range replies {
f.Version = 2
s.test(&f, func() (frame, error) {
return parseSynReply(s.data, &s.unzip)
})
f.Version = 3
s.test(&f, func() (frame, error) {
return parseSynReply(s.data, &s.unzip)
})
}
}
func TestHeadersFrame(t *testing.T) {
s := newTester(t)
for _, f := range headers {
f.Version = 2
s.test(&f, func() (frame, error) {
return parseHeaders(s.data, &s.unzip)
})
f.Version = 3
s.test(&f, func() (frame, error) {
return parseHeaders(s.data, &s.unzip)
})
}
}