-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfig_decode_test.go
More file actions
98 lines (86 loc) · 2.53 KB
/
Copy pathconfig_decode_test.go
File metadata and controls
98 lines (86 loc) · 2.53 KB
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
package cloudflared
import (
"testing"
"time"
"github.com/sagernet/sing-cloudflared/internal/control"
"github.com/sagernet/sing-cloudflared/internal/protocol"
"github.com/sagernet/sing-cloudflared/internal/transport"
)
func TestNewServiceRequiresToken(t *testing.T) {
t.Parallel()
_, err := NewService(ServiceOptions{})
if err == nil {
t.Fatal("expected missing token error")
}
}
func TestValidateRegistrationResultRejectsNonRemoteManaged(t *testing.T) {
t.Parallel()
err := control.ValidateRegistrationResult(&protocol.RegistrationResult{TunnelIsRemotelyManaged: false})
if err == nil {
t.Fatal("expected unsupported tunnel error")
}
if err != control.ErrNonRemoteManagedTunnelUnsupported {
t.Fatalf("unexpected error: %v", err)
}
}
func TestNormalizeProtocolAutoUsesTokenStyleSentinel(t *testing.T) {
t.Parallel()
normalizedProtocol, err := transport.NormalizeProtocol("auto")
if err != nil {
t.Fatal(err)
}
if normalizedProtocol != "" {
t.Fatalf("expected auto protocol to normalize to token-style empty sentinel, got %q", normalizedProtocol)
}
}
func TestNormalizeProtocolH2MUXUsesHTTP2(t *testing.T) {
t.Parallel()
normalizedProtocol, err := transport.NormalizeProtocol(transport.ProtocolH2MUX)
if err != nil {
t.Fatal(err)
}
if normalizedProtocol != transport.ProtocolHTTP2 {
t.Fatalf("expected h2mux to normalize to http2, got %q", normalizedProtocol)
}
}
func TestNewServiceRejectsPostQuantumWithHTTP2(t *testing.T) {
t.Parallel()
_, err := NewService(ServiceOptions{
Token: testToken(t),
Protocol: transport.ProtocolHTTP2,
PostQuantum: true,
})
if err == nil || err.Error() != "post-quantum is only supported with quic transport" {
t.Fatalf("unexpected error %v", err)
}
}
func TestNewServiceAutoPostQuantumUsesQUICOnlySelector(t *testing.T) {
t.Parallel()
service, err := NewService(ServiceOptions{
Token: testToken(t),
Protocol: "auto",
PostQuantum: true,
})
if err != nil {
t.Fatal(err)
}
if service.currentProtocol() != transport.ProtocolQUIC {
t.Fatalf("unexpected current protocol %q", service.currentProtocol())
}
if fallback, ok := service.fallbackProtocol(); ok {
t.Fatalf("expected no fallback for post-quantum selector, got %q", fallback)
}
}
func TestExplicitZeroGracePeriod(t *testing.T) {
t.Parallel()
service, err := NewService(ServiceOptions{
Token: testToken(t),
GracePeriod: 0,
})
if err != nil {
t.Fatal(err)
}
if service.gracePeriod != 30*time.Second {
t.Fatalf("expected zero to use default 30s, got %s", service.gracePeriod)
}
}