-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathclient_hello_test.go
82 lines (74 loc) · 1.51 KB
/
client_hello_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
package quicsni
import (
"context"
"crypto/tls"
"net"
"testing"
"github.com/quic-go/quic-go"
)
func TestReadClientHello(t *testing.T) {
tests := []struct {
name string
quicConfig *quic.Config
}{
{
"v1",
&quic.Config{Versions: []quic.Version{quic.Version1}},
},
{
"v2",
&quic.Config{Versions: []quic.Version{quic.Version2}},
},
}
for _, tc := range tests {
tc := tc
t.Run(tc.name, func(t *testing.T) {
t.Parallel()
runTest(t, tc.quicConfig)
})
}
}
func runTest(t *testing.T, quicConfig *quic.Config) {
t.Helper()
testHostname := "cuonglm.xyz"
udpConn, err := net.ListenUDP("udp", nil)
if err != nil {
panic(err)
}
defer udpConn.Close()
go func() {
tlsConf := &tls.Config{
InsecureSkipVerify: true,
NextProtos: []string{"quic"},
ServerName: testHostname,
}
conn, err := net.ListenUDP("udp", nil)
if err != nil {
panic(err)
}
remoteAddr, err := net.ResolveUDPAddr("udp", udpConn.LocalAddr().String())
if err != nil {
panic(err)
}
ea, err := quic.Dial(context.Background(), conn, remoteAddr, tlsConf, quicConfig)
if err != nil {
panic(err)
}
s, err := ea.OpenStream()
if err != nil {
panic(err)
}
s.Close()
}()
buf := make([]byte, 1452)
if _, err := udpConn.Read(buf); err != nil {
t.Fatal(err)
}
clientHello, err := ReadClientHello(buf)
if err != nil {
t.Fatal(err)
}
if clientHello.ServerName != testHostname {
t.Errorf("SNI mismatched, got: %q, want: %q", clientHello.ServerName, testHostname)
}
}