-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for backward compatible API Client behavior (#11567)
- Loading branch information
1 parent
3999b17
commit dc09f6f
Showing
5 changed files
with
160 additions
and
6 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
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
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 |
---|---|---|
|
@@ -36,6 +36,7 @@ import ( | |
|
||
"github.com/gravitational/teleport/api/constants" | ||
apidefaults "github.com/gravitational/teleport/api/defaults" | ||
"github.com/gravitational/teleport/api/profile" | ||
"github.com/gravitational/teleport/api/types" | ||
"github.com/gravitational/teleport/lib" | ||
"github.com/gravitational/teleport/lib/auth" | ||
|
@@ -1234,6 +1235,45 @@ func TestSetX11Config(t *testing.T) { | |
} | ||
} | ||
|
||
// TestAuthClientFromTSHProfile tests if API Client can be successfully created from tsh profile where clusters | ||
// certs are stored separately in CAS directory and in case where legacy certs.pem file was used. | ||
func TestAuthClientFromTSHProfile(t *testing.T) { | ||
tmpHomePath := t.TempDir() | ||
|
||
connector := mockConnector(t) | ||
alice, err := types.NewUser("[email protected]") | ||
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) | ||
|
||
err = Run([]string{ | ||
"login", | ||
"--insecure", | ||
"--debug", | ||
"--auth", connector.GetName(), | ||
"--proxy", proxyAddr.String(), | ||
}, setHomePath(tmpHomePath), func(cf *CLIConf) error { | ||
cf.mockSSOLogin = mockSSOLogin(t, authServer, alice) | ||
return nil | ||
}) | ||
require.NoError(t, err) | ||
|
||
profile, err := profile.FromDir(tmpHomePath, "") | ||
require.NoError(t, err) | ||
|
||
mustCreateAuthClientFormUserProfile(t, tmpHomePath, proxyAddr.String()) | ||
|
||
// Simulate legacy tsh client behavior where all clusters certs were stored in the certs.pem file. | ||
require.NoError(t, os.RemoveAll(profile.TLSClusterCASDir())) | ||
|
||
// Verify that authClient created from profile will create a valid client in case where cas dir doesn't exit. | ||
mustCreateAuthClientFormUserProfile(t, tmpHomePath, proxyAddr.String()) | ||
} | ||
|
||
type testServersOpts struct { | ||
bootstrap []types.Resource | ||
authConfigFuncs []func(cfg *service.AuthConfig) | ||
|