-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathlogin_ssl_test.go
More file actions
85 lines (73 loc) · 2.48 KB
/
login_ssl_test.go
File metadata and controls
85 lines (73 loc) · 2.48 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
package login_test
import (
"net/http"
"testing"
"github.com/OctopusDeploy/cli/pkg/apiclient"
"github.com/stretchr/testify/assert"
)
// TestSSLIgnoreHandling tests that our SSL ignore logic works with both
// direct http.Transport and SpinnerRoundTripper scenarios
func TestSSLIgnoreHandling(t *testing.T) {
tests := []struct {
name string
transport http.RoundTripper
expectPanic bool
}{
{
name: "Direct http.Transport should work",
transport: &http.Transport{},
expectPanic: false,
},
{
name: "SpinnerRoundTripper with http.Transport should work",
transport: &apiclient.SpinnerRoundTripper{Next: &http.Transport{}},
expectPanic: false,
},
{
name: "SpinnerRoundTripper with default transport should work",
transport: apiclient.NewSpinnerRoundTripper(),
expectPanic: false,
},
{
name: "nil transport should work",
transport: nil,
expectPanic: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
client := &http.Client{Transport: tt.transport}
// This simulates the SSL ignore logic from loginRun function
defer func() {
if r := recover(); r != nil {
if !tt.expectPanic {
t.Errorf("Unexpected panic: %v", r)
}
}
}()
// Apply the SSL ignore logic using the shared utility
apiclient.ApplySSLIgnoreConfiguration(client)
// Verify the SSL configuration was applied correctly
verifySSLConfig(t, client)
})
}
}
// verifySSLConfig checks that the SSL configuration was applied correctly
func verifySSLConfig(t *testing.T, httpClient *http.Client) {
assert.NotNil(t, httpClient.Transport, "Transport should not be nil")
switch transport := httpClient.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 *apiclient.SpinnerRoundTripper:
assert.NotNil(t, transport.Next, "SpinnerRoundTripper.Next should not be nil")
if httpTransport, ok := transport.Next.(*http.Transport); ok {
assert.NotNil(t, httpTransport.TLSClientConfig, "Underlying TLS config should be set")
assert.True(t, httpTransport.TLSClientConfig.InsecureSkipVerify, "Underlying InsecureSkipVerify should be true")
} else {
t.Errorf("SpinnerRoundTripper.Next should be *http.Transport, got %T", transport.Next)
}
default:
t.Errorf("Unexpected transport type: %T", transport)
}
}