diff --git a/tool/tsh/common/tsh.go b/tool/tsh/common/tsh.go index 15de42d441aa0..952e8b1cc3adf 100644 --- a/tool/tsh/common/tsh.go +++ b/tool/tsh/common/tsh.go @@ -1120,6 +1120,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://") + // Identity files do not currently contain a proxy address. When loading an // Identity file, a proxy must be passed on the command line as well. if cf.IdentityFileIn != "" && cf.Proxy == "" { diff --git a/tool/tsh/common/tsh_test.go b/tool/tsh/common/tsh_test.go index 0d63b3474d292..ca0e374a36781 100644 --- a/tool/tsh/common/tsh_test.go +++ b/tool/tsh/common/tsh_test.go @@ -687,6 +687,45 @@ func TestRelogin(t *testing.T) { require.NoError(t, err) } +// 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) +} + func TestSwitchingProxies(t *testing.T) { t.Parallel()