forked from remind101/empire
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain_test.go
73 lines (61 loc) · 1.52 KB
/
main_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
package main
import (
"net/http"
"os"
"testing"
)
func init() {
os.Setenv("EMPIRE_API_URL", "http://localhost:8080")
}
func TestSSLEnabled(t *testing.T) {
initClients()
if client.HTTP == nil {
// No http.Client means the client defaults to SSL enabled
return
}
if client.HTTP.Transport == nil {
// No transport means the client defaults to SSL enabled
return
}
conf := client.HTTP.Transport.(*http.Transport).TLSClientConfig
if conf == nil {
// No TLSClientConfig means the client defaults to SSL enabled
return
}
if conf.InsecureSkipVerify {
t.Errorf("expected InsecureSkipVerify == false")
}
client = nil
}
func TestSSLDisable(t *testing.T) {
os.Setenv("HEROKU_SSL_VERIFY", "disable")
initClients()
if client.HTTP == nil {
t.Fatalf("client.HTTP not set, expected http.Client")
}
if client.HTTP.Transport == nil {
t.Fatalf("client.HTTP.Transport not set")
}
conf := client.HTTP.Transport.(*http.Transport).TLSClientConfig
if conf == nil {
t.Fatalf("client.HTTP.Transport's TLSClientConfig is nil")
}
if !conf.InsecureSkipVerify {
t.Errorf("expected InsecureSkipVerify == true")
}
os.Setenv("HEROKU_SSL_VERIFY", "")
client = nil
}
func TestHerokuAPIURL(t *testing.T) {
newURL := "https://api.otherheroku.com"
os.Setenv("EMPIRE_API_URL", newURL)
initClients()
if client.URL != newURL {
t.Errorf("expected client.URL to be %q, got %q", newURL, client.URL)
}
if apiURL != newURL {
t.Errorf("expected apiURL to be %q, got %q", newURL, apiURL)
}
// cleanup
os.Setenv("EMPIRE_API_URL", "")
}