From 2f716a0f04ad80003e2b3ac678ad9d27b7e1411e Mon Sep 17 00:00:00 2001 From: Steven Martin Date: Wed, 18 Oct 2023 12:23:08 -0400 Subject: [PATCH 1/2] allow https:// in proxy parameter in tsh --- tool/tsh/tsh.go | 4 ++++ tool/tsh/tsh_test.go | 39 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+) diff --git a/tool/tsh/tsh.go b/tool/tsh/tsh.go index ee4857a127140..bb433552c4501 100644 --- a/tool/tsh/tsh.go +++ b/tool/tsh/tsh.go @@ -1012,6 +1012,10 @@ func Run(ctx context.Context, args []string, opts ...cliOption) error { } } + // Remove HTTPS:// in proxy parameter as https is automatically added + cf.Proxy = strings.TrimPrefix(cf.Proxy, "https://") + cf.Proxy = strings.TrimPrefix(cf.Proxy, "HTTPS://") + // prevent Kingpin from calling os.Exit(), we want to handle errors ourselves. // shouldTerminate will be checked after app.Parse() call. var shouldTerminate *int diff --git a/tool/tsh/tsh_test.go b/tool/tsh/tsh_test.go index 96a7e6bfd5834..0b7c4576bbcc7 100644 --- a/tool/tsh/tsh_test.go +++ b/tool/tsh/tsh_test.go @@ -4794,3 +4794,42 @@ func TestMakeProfileInfo_NoInternalLogins(t *testing.T) { }) } } + +// Test when https:// is included in --proxy address +func TestIgnoreHTTPSPrefix(t *testing.T) { + t.Parallel() + + tmpHomePath := t.TempDir() + + connector := mockConnector(t) + + alice, err := types.NewUser("alice@example.com") + require.NoError(t, err) + alice.SetRoles([]string{"access"}) + + authProcess, proxyProcess := makeTestServers(t, + withBootstrap(connector, alice), + ) + + authServer := authProcess.GetAuthServer() + require.NotNil(t, authServer) + + proxyAddr, err := proxyProcess.ProxyWebAddr() + require.NoError(t, err) + + var buf bytes.Buffer + + proxyAddress := "https://" + proxyAddr.String() + err = Run(context.Background(), []string{ + "login", + "--insecure", + "--debug", + "--auth", connector.GetName(), + "--proxy", proxyAddress, + }, setHomePath(tmpHomePath), func(cf *CLIConf) error { + cf.MockSSOLogin = mockSSOLogin(t, authServer, alice) + cf.overrideStderr = &buf + return nil + }) + require.NoError(t, err) +} From fd3ace47f6e101424bd00d872b61d9e64bbf4d17 Mon Sep 17 00:00:00 2001 From: Steven Martin Date: Wed, 18 Oct 2023 12:41:24 -0400 Subject: [PATCH 2/2] fix tsh https test --- tool/tsh/tsh_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tool/tsh/tsh_test.go b/tool/tsh/tsh_test.go index 0b7c4576bbcc7..bfb4a4d75885d 100644 --- a/tool/tsh/tsh_test.go +++ b/tool/tsh/tsh_test.go @@ -4827,7 +4827,7 @@ func TestIgnoreHTTPSPrefix(t *testing.T) { "--auth", connector.GetName(), "--proxy", proxyAddress, }, setHomePath(tmpHomePath), func(cf *CLIConf) error { - cf.MockSSOLogin = mockSSOLogin(t, authServer, alice) + cf.mockSSOLogin = mockSSOLogin(t, authServer, alice) cf.overrideStderr = &buf return nil })