-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathclient_test.go
86 lines (76 loc) · 2.33 KB
/
client_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
package connectip
import (
"context"
"crypto/tls"
"net"
"testing"
"time"
"github.com/quic-go/quic-go"
"github.com/quic-go/quic-go/http3"
"github.com/stretchr/testify/require"
"github.com/yosida95/uritemplate/v3"
)
func TestClientInvalidTemplate(t *testing.T) {
_, _, err := Dial(
context.Background(),
nil,
uritemplate.MustNew("https://example.org/.well-known/masque/ip/{target}/{ipproto}/"),
)
require.ErrorContains(t, err, "connect-ip: IP flow forwarding not supported")
}
func TestClientWaitForSettings(t *testing.T) {
conn, err := net.ListenUDP("udp", &net.UDPAddr{IP: net.IPv4(127, 0, 0, 1), Port: 0})
require.NoError(t, err)
ln, err := quic.Listen(conn, tlsConf, nil)
require.NoError(t, err)
defer ln.Close()
tr := &http3.Transport{}
defer tr.Close()
ctx, cancel := context.WithTimeout(context.Background(), 100*time.Millisecond)
defer cancel()
cconn, err := quic.DialAddr(
ctx,
conn.LocalAddr().String(),
&tls.Config{ServerName: "localhost", RootCAs: certPool, NextProtos: []string{http3.NextProtoH3}},
&quic.Config{EnableDatagrams: true},
)
require.NoError(t, err)
// We're connecting to a QUIC, not an HTTP/3 server.
// We'll never receive any HTTP/3 settings.
_, _, err = Dial(
ctx,
tr.NewClientConn(cconn),
uritemplate.MustNew("https://example.org/.well-known/masque/ip/"),
)
require.ErrorIs(t, err, context.DeadlineExceeded)
}
func TestClientDatagramCheck(t *testing.T) {
s := http3.Server{
TLSConfig: tlsConf,
EnableDatagrams: false,
}
ln, err := net.ListenUDP("udp", &net.UDPAddr{IP: net.IPv4(127, 0, 0, 1), Port: 0})
require.NoError(t, err)
go func() { s.Serve(ln) }()
defer s.Close()
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()
cconn, err := quic.DialAddr(
ctx,
ln.LocalAddr().String(),
&tls.Config{ServerName: "localhost", RootCAs: certPool, NextProtos: []string{http3.NextProtoH3}},
&quic.Config{EnableDatagrams: true},
)
require.NoError(t, err)
defer cconn.CloseWithError(0, "")
// Create a HTTP/3 client and dial the server
tr := &http3.Transport{}
defer tr.Close()
// Now use the QUIC connection in the Dial call
_, _, err = Dial(
context.Background(),
tr.NewClientConn(cconn),
uritemplate.MustNew("https://example.org/.well-known/masque/ip/"),
)
require.ErrorContains(t, err, "connect-ip: server didn't enable datagrams")
}