-
Notifications
You must be signed in to change notification settings - Fork 1
/
client_config_test.go
119 lines (116 loc) · 3.42 KB
/
client_config_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
package config
import (
"testing"
"github.com/getlantern/fronted"
"github.com/stretchr/testify/assert"
)
func TestFrontedProviders(t *testing.T) {
verifyHostname := "verifyHostname.com"
var tests = []struct {
name string
givenClientConfig *ClientConfig
assert func(t *testing.T, providersMap map[string]*fronted.Provider)
}{
{
name: "empty client config should return a empty providers map",
givenClientConfig: NewClientConfig(),
assert: func(t *testing.T, providersMap map[string]*fronted.Provider) {
assert.Equal(t, 0, len(providersMap))
},
},
{
name: "client config with one provider should return a map with one provider and its config",
givenClientConfig: &ClientConfig{
Fronted: &FrontedConfig{
Providers: map[string]*ProviderConfig{
"provider1": {
HostAliases: map[string]string{
"host1": "alias1",
},
TestURL: "testURL",
Masquerades: []*fronted.Masquerade{
{
Domain: "domain1",
IpAddress: "127.0.0.1",
},
},
Validator: &ValidatorConfig{
RejectStatus: []int{404},
},
PassthroughPatterns: []string{"pattern1"},
VerifyHostname: &verifyHostname,
FrontingSNIs: map[string]*fronted.SNIConfig{
"default": {
UseArbitrarySNIs: false,
ArbitrarySNIs: []string{"sni1"},
},
},
},
},
},
},
assert: func(t *testing.T, providersMap map[string]*fronted.Provider) {
assert.Equal(t, 1, len(providersMap))
provider1 := providersMap["provider1"]
assert.Equal(t, map[string]string{"host1": "alias1"}, provider1.HostAliases)
assert.Equal(t, "testURL", provider1.TestURL)
assert.Equal(t, fronted.Masquerade{
Domain: "domain1",
IpAddress: "127.0.0.1",
VerifyHostname: &verifyHostname,
SNI: "sni1",
}, *provider1.Masquerades[0])
},
},
{
name: "client config with one provider should return a map with one provider and its config without verify hostname",
givenClientConfig: &ClientConfig{
Fronted: &FrontedConfig{
Providers: map[string]*ProviderConfig{
"provider1": {
HostAliases: map[string]string{
"host1": "alias1",
},
TestURL: "testURL",
Masquerades: []*fronted.Masquerade{
{
Domain: "domain1",
IpAddress: "127.0.0.1",
},
},
Validator: &ValidatorConfig{
RejectStatus: []int{404},
},
PassthroughPatterns: []string{"pattern1"},
VerifyHostname: nil,
FrontingSNIs: map[string]*fronted.SNIConfig{
"default": {
UseArbitrarySNIs: false,
ArbitrarySNIs: []string{"sni1"},
},
},
},
},
},
},
assert: func(t *testing.T, providersMap map[string]*fronted.Provider) {
assert.Equal(t, 1, len(providersMap))
provider1 := providersMap["provider1"]
assert.Equal(t, map[string]string{"host1": "alias1"}, provider1.HostAliases)
assert.Equal(t, "testURL", provider1.TestURL)
assert.Equal(t, fronted.Masquerade{
Domain: "domain1",
IpAddress: "127.0.0.1",
VerifyHostname: nil,
SNI: "sni1",
}, *provider1.Masquerades[0])
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
providersMap := tt.givenClientConfig.FrontedProviders()
tt.assert(t, providersMap)
})
}
}