-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathssl_test.go
More file actions
109 lines (98 loc) · 2.68 KB
/
ssl_test.go
File metadata and controls
109 lines (98 loc) · 2.68 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
99
100
101
102
103
104
105
106
107
108
109
package apiclient
import (
"crypto/tls"
"net/http"
"testing"
"github.com/stretchr/testify/assert"
)
// TestApplySSLIgnoreConfiguration tests the ApplySSLIgnoreConfiguration function
func TestApplySSLIgnoreConfiguration(t *testing.T) {
tests := []struct {
name string
setupFunc func() *http.Client
}{
{
name: "nil transport",
setupFunc: func() *http.Client {
return &http.Client{}
},
},
{
name: "direct http.Transport with nil TLSClientConfig",
setupFunc: func() *http.Client {
return &http.Client{
Transport: &http.Transport{},
}
},
},
{
name: "direct http.Transport with existing TLSClientConfig",
setupFunc: func() *http.Client {
return &http.Client{
Transport: &http.Transport{
TLSClientConfig: &tls.Config{
ServerName: "example.com",
},
},
}
},
},
{
name: "SpinnerRoundTripper with nil TLSClientConfig",
setupFunc: func() *http.Client {
return &http.Client{
Transport: &SpinnerRoundTripper{
Next: &http.Transport{},
},
}
},
},
{
name: "SpinnerRoundTripper with existing TLSClientConfig",
setupFunc: func() *http.Client {
return &http.Client{
Transport: &SpinnerRoundTripper{
Next: &http.Transport{
TLSClientConfig: &tls.Config{
ServerName: "example.com",
},
},
},
}
},
},
{
name: "SpinnerRoundTripper with default transport",
setupFunc: func() *http.Client {
return &http.Client{
Transport: NewSpinnerRoundTripper(),
}
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
client := tt.setupFunc()
// Apply the SSL ignore configuration
ApplySSLIgnoreConfiguration(client)
// Verify the configuration was applied correctly
verifySSLIgnored(t, client)
})
}
}
func verifySSLIgnored(t *testing.T, client *http.Client) {
assert.NotNil(t, client.Transport, "Transport should not be nil")
switch transport := client.Transport.(type) {
case *http.Transport:
assert.NotNil(t, transport.TLSClientConfig, "TLS config should be set")
assert.True(t, transport.TLSClientConfig.InsecureSkipVerify, "InsecureSkipVerify should be true")
case *SpinnerRoundTripper:
assert.NotNil(t, transport.Next, "SpinnerRoundTripper.Next should not be nil")
httpTransport, ok := transport.Next.(*http.Transport)
assert.True(t, ok, "SpinnerRoundTripper.Next should be *http.Transport")
assert.NotNil(t, httpTransport.TLSClientConfig, "Underlying TLS config should be set")
assert.True(t, httpTransport.TLSClientConfig.InsecureSkipVerify, "Underlying InsecureSkipVerify should be true")
default:
t.Errorf("Unexpected transport type: %T", transport)
}
}