forked from getlantern/fronted
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_support.go
63 lines (54 loc) · 1.77 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
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) {
ConfigureCachingForTest(t, "")
}
func ConfigureCachingForTest(t *testing.T, cacheFile string) {
certs := trustedCACerts(t)
p := testProviders()
Configure(certs, p, testProviderID, cacheFile)
}
func ConfigureHostAlaisesForTest(t *testing.T, hosts map[string]string) {
certs := trustedCACerts(t)
p := testProvidersWithHosts(hosts)
Configure(certs, p, testProviderID, "")
}
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, nil),
}
}
func testProvidersWithHosts(hosts map[string]string) map[string]*Provider {
return map[string]*Provider{
testProviderID: NewProvider(hosts, pingTestURL, testMasquerades, nil, nil, nil, nil),
}
}
func testAkamaiProvidersWithHosts(hosts map[string]string, sniConfig *SNIConfig) map[string]*Provider {
return map[string]*Provider{
"akamai": NewProvider(hosts, "https://fronted-ping.dsa.akamai.getiantem.org/ping", DefaultAkamaiMasquerades, nil, nil, sniConfig, nil),
}
}