-
Notifications
You must be signed in to change notification settings - Fork 2
/
quic_common_test.go
156 lines (139 loc) · 4.11 KB
/
quic_common_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
150
151
152
153
154
155
156
package clienthellod_test
import (
"bytes"
"testing"
_ "embed"
. "github.com/gaukas/clienthellod"
)
var mapValueToVLI = map[uint64][]byte{
0: {0x00},
26: {0x1a},
110: {0x40, 0x6e},
158: {0x40, 0x9e},
184: {0x40, 0xb8},
1212: {0x44, 0xbc},
30000: {0x80, 0x00, 0x75, 0x30},
6291456: {0x80, 0x60, 0x00, 0x00},
0x22d01138870c6f9f: {0xe2, 0xd0, 0x11, 0x38, 0x87, 0x0c, 0x6f, 0x9f},
}
func TestReadNextVLI(t *testing.T) {
for v, vli := range mapValueToVLI {
val, n, err := ReadNextVLI(bytes.NewReader(vli))
if err != nil {
t.Errorf("ReadNextVLI(%v) error: %v", vli, err)
}
if val != v {
t.Errorf("ReadNextVLI(%v) = %v, want %v", vli, val, v)
}
if n != len(vli) {
t.Errorf("ReadNextVLI(%v) = %v, want %v", vli, n, len(vli))
}
}
}
func TestDecodeVLI(t *testing.T) {
for v, vli := range mapValueToVLI {
val, err := DecodeVLI(vli)
if err != nil {
t.Errorf("DecodeVLI(%v) error: %v", vli, err)
}
if val != v {
t.Errorf("DecodeVLI(%v) = %v, want %v", vli, val, v)
}
}
}
var mapQUICGREASEValues = map[uint64]bool{
0x01: false,
0x02: false,
0x03: false,
0x04: false,
0x05: false,
0x06: false,
0x07: false,
0x08: false,
0x09: false,
0x0a: false,
0x0b: false,
0x0c: false,
0x0d: false,
0x0e: false,
0x0f: false,
0x10: false,
0x11: false,
0x12: false,
0x13: false,
0x14: false,
0x15: false,
0x16: false,
0x17: false,
0x18: false,
0x19: false,
0x1a: false,
27: true,
31: false,
58: true,
89: true,
2508523926926946207: true,
}
func TestIsGREASETransportParameter(t *testing.T) {
for v, grease := range mapQUICGREASEValues {
if IsGREASETransportParameter(v) != grease {
t.Errorf("IsGREASETransportParameter(%v) = %v, want %v", v, !grease, grease)
}
}
}
var (
//go:embed internal/testdata/QUIC_IETF_Chrome_125_PKN1.bin
quicIETFData_Chrome125_PKN1 []byte
//go:embed internal/testdata/QUIC_IETF_Chrome_125_PKN2.bin
quicIETFData_Chrome125_PKN2 []byte
//go:embed internal/testdata/QUIC_IETF_Firefox_126.bin
quicIETFData_Firefox126 []byte
//go:embed internal/testdata/QUIC_IETF_Firefox_126_0-RTT.bin
quicIETFData_Firefox126_0_RTT []byte
)
var mapTestDecodeQUICHeaderAndFrames = map[string]struct {
data []byte
headerTruth *QUICHeader
framesTruth QUICFrames
}{
"Chrome125_PKN1": {
data: quicIETFData_Chrome125_PKN1,
headerTruth: quicHeaderTruth_Chrome125_PKN1,
framesTruth: quicFramesTruth_Chrome125_PKN1,
},
"Chrome125_PKN2": {
data: quicIETFData_Chrome125_PKN2,
headerTruth: quicHeaderTruth_Chrome125_PKN2,
framesTruth: quicFramesTruth_Chrome125_PKN2,
},
"Firefox126": {
data: quicIETFData_Firefox126,
headerTruth: quicHeaderTruth_Firefox126,
framesTruth: quicFramesTruth_Firefox126,
},
"Firefox126_with_0-RTT": {
data: quicIETFData_Firefox126_0_RTT,
headerTruth: quicHeaderTruth_Firefox126_0_RTT,
framesTruth: quicFramesTruth_Firefox126_0_RTT,
},
}
func TestDecodeQUICHeaderAndFrames(t *testing.T) {
for name, test := range mapTestDecodeQUICHeaderAndFrames {
t.Run(name, func(t *testing.T) {
testDecodeQUICHeaderAndFramesWithTruth(t, test.data, test.headerTruth, test.framesTruth)
})
}
}
func testDecodeQUICHeaderAndFramesWithTruth(t *testing.T, data []byte, headerTruth *QUICHeader, framesTruth QUICFrames) {
decodedHeader, decodedFrames, err := DecodeQUICHeaderAndFrames(data)
if err != nil {
t.Fatal(err)
}
t.Run("header", func(t *testing.T) {
testQUICHeaderEqualsTruth(t, decodedHeader, headerTruth)
})
t.Run("frames", func(t *testing.T) {
testQUICFramesEqualsTruth(t, decodedFrames, framesTruth)
})
t.Skip("skipping testing decoded frames")
}