-
Notifications
You must be signed in to change notification settings - Fork 147
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds a global
--insecure-skip-tls-verify
flag to the cli (#1660)
* Adds an insecure flag to the cli
- Loading branch information
Showing
3 changed files
with
63 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package root_test | ||
|
||
import ( | ||
"net/http" | ||
"testing" | ||
|
||
"github.com/go-resty/resty/v2" | ||
"github.com/stretchr/testify/assert" | ||
"github.com/weaveworks/weave-gitops/cmd/gitops/root" | ||
) | ||
|
||
func TestInsecureSkipVerifyTrue(t *testing.T) { | ||
client := resty.New() | ||
|
||
cmd := root.RootCmd(client) | ||
cmd.SetArgs([]string{ | ||
"add", "cluster", | ||
"--insecure-skip-tls-verify", | ||
}) | ||
|
||
// Command is incomplete and should raise an error, it helps us short circuit here to quickly | ||
// test that the client has been set | ||
err := cmd.Execute() | ||
assert.Error(t, err) | ||
|
||
transport, ok := client.GetClient().Transport.(*http.Transport) | ||
assert.True(t, ok) | ||
assert.True(t, transport.TLSClientConfig.InsecureSkipVerify, "InsecureSkipVerify wasn't set to true") | ||
} | ||
|
||
func TestInsecureSkipVerifyFalse(t *testing.T) { | ||
client := resty.New() | ||
|
||
cmd := root.RootCmd(client) | ||
cmd.SetArgs([]string{ | ||
"add", "cluster", | ||
}) | ||
|
||
// Command is incomplete and should raise an error, it helps us short circuit here to quickly | ||
// test that the client has been set | ||
err := cmd.Execute() | ||
assert.Error(t, err) | ||
|
||
transport, ok := client.GetClient().Transport.(*http.Transport) | ||
assert.True(t, ok) | ||
// Its set to nil and uses whatever the golang defaults are (InsecureSkipVerify: false) | ||
assert.Nil(t, transport.TLSClientConfig) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters