-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathtest_support.go
72 lines (63 loc) · 1.99 KB
/
test_support.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
package fronted
import (
"crypto/x509"
"testing"
"github.com/getlantern/keyman"
)
var (
testProviderID = "cloudfront"
pingTestURL = "https://d157vud77ygy87.cloudfront.net/ping"
testHosts = map[string]string(nil)
testMasquerades = DefaultCloudfrontMasquerades
)
// ConfigureForTest configures fronted for testing using default masquerades and
// certificate authorities.
func ConfigureForTest(t *testing.T) Fronted {
return ConfigureCachingForTest(t, "")
}
func ConfigureCachingForTest(t *testing.T, cacheFile string) Fronted {
certs := trustedCACerts(t)
p := testProviders()
defaultFrontedProviderID = testProviderID
f := NewFronted(WithCacheFile(cacheFile))
f.onNewFronts(certs, p)
return f
}
func ConfigureHostAlaisesForTest(t *testing.T, hosts map[string]string) Fronted {
certs := trustedCACerts(t)
p := testProvidersWithHosts(hosts)
defaultFrontedProviderID = testProviderID
f := NewFronted()
f.onNewFronts(certs, p)
return f
}
func trustedCACerts(t *testing.T) *x509.CertPool {
certs := make([]string, 0, len(DefaultTrustedCAs))
for _, ca := range DefaultTrustedCAs {
certs = append(certs, ca.Cert)
}
pool, err := keyman.PoolContainingCerts(certs...)
if err != nil {
log.Errorf("Could not create pool %v", err)
t.Fatalf("Unable to set up cert pool")
}
return pool
}
func testProviders() map[string]*Provider {
return map[string]*Provider{
testProviderID: NewProvider(testHosts, pingTestURL, testMasquerades, nil, nil, nil, ""),
}
}
func testProvidersWithHosts(hosts map[string]string) map[string]*Provider {
return map[string]*Provider{
testProviderID: NewProvider(hosts, pingTestURL, testMasquerades, nil, nil, nil, ""),
}
}
func testAkamaiProvidersWithHosts(hosts map[string]string, sniConfig *SNIConfig) map[string]*Provider {
frontingSNIs := map[string]*SNIConfig{
"test": sniConfig,
}
return map[string]*Provider{
"akamai": NewProvider(hosts, "https://fronted-ping.dsa.akamai.getiantem.org/ping", DefaultAkamaiMasquerades, nil, frontingSNIs, nil, "test"),
}
}