Skip to content

Commit

Permalink
fix: TestHeadlessDoesNotAddKeysToAgent
Browse files Browse the repository at this point in the history
  • Loading branch information
rosstimothy committed Oct 19, 2024
1 parent 6f99b2e commit 47236c1
Showing 1 changed file with 35 additions and 22 deletions.
57 changes: 35 additions & 22 deletions tool/tsh/common/tsh_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2980,32 +2980,45 @@ func TestHeadlessDoesNotAddKeysToAgent(t *testing.T) {
alice.SetRoles([]string{"node-access"})

sshHostname := "test-ssh-host"
rootAuth, rootProxy := makeTestServers(t, withBootstrap(nodeAccess, alice), withConfig(func(cfg *servicecfg.Config) {
cfg.Hostname = sshHostname
cfg.SSH.Enabled = true
cfg.SSH.Addr = utils.NetAddr{AddrNetwork: "tcp", Addr: net.JoinHostPort("127.0.0.1", ports.Pop())}
}))

proxyAddr, err := rootProxy.ProxyWebAddr()
require.NoError(t, err)
server := testserver.MakeTestServer(t,
testserver.WithConfig(func(cfg *servicecfg.Config) {
cfg.Hostname = sshHostname
cfg.Auth.Enabled = true
cfg.Proxy.Enabled = true
cfg.SSH.Enabled = true
cfg.SSH.DisableCreateHostUser = true
cfg.Auth.BootstrapResources = []types.Resource{nodeAccess, alice}
cfg.Auth.Preference = &types.AuthPreferenceV2{
Metadata: types.Metadata{
Labels: map[string]string{types.OriginLabel: types.OriginConfigFile},
},
Spec: types.AuthPreferenceSpecV2{
Type: constants.Local,
SecondFactor: constants.SecondFactorOptional,
Webauthn: &types.Webauthn{
RPID: "127.0.0.1",
},
AllowHeadless: types.NewBoolOption(true),
},
}
}))

_, err = rootAuth.GetAuthServer().UpsertAuthPreference(ctx, &types.AuthPreferenceV2{
Spec: types.AuthPreferenceSpecV2{
Type: constants.Local,
SecondFactor: constants.SecondFactorOptional,
Webauthn: &types.Webauthn{
RPID: "127.0.0.1",
},
},
})
require.EventuallyWithT(t, func(t *assert.CollectT) {
found, err := server.GetAuthServer().GetNodes(ctx, apidefaults.Namespace)
assert.NoError(t, err)
assert.Len(t, found, 1)
}, 10*time.Second, 100*time.Millisecond)

proxyAddr, err := server.ProxyWebAddr()
require.NoError(t, err)

go func() {
if err := approveAllAccessRequests(ctx, rootAuth.GetAuthServer()); err != nil {
// Ensure the context is canceled, so that Run calls don't block
defer cancel()
if err := approveAllAccessRequests(ctx, server.GetAuthServer()); err != nil {
assert.ErrorIs(t, err, context.Canceled, "unexpected error from approveAllAccessRequests")
}
// Cancel the context, so Run calls don't block
cancel()
}()

err = Run(ctx, []string{
Expand All @@ -3018,10 +3031,10 @@ func TestHeadlessDoesNotAddKeysToAgent(t *testing.T) {
"--add-keys-to-agent=yes",
fmt.Sprintf("%s@%s", user.Username, sshHostname),
"echo", "test",
}, CliOption(func(cf *CLIConf) error {
cf.MockHeadlessLogin = mockHeadlessLogin(t, rootAuth.GetAuthServer(), alice)
}, func(cf *CLIConf) error {
cf.MockHeadlessLogin = mockHeadlessLogin(t, server.GetAuthServer(), alice)
return nil
}))
})
require.NoError(t, err)

keys, err := agentKeyring.List()
Expand Down

0 comments on commit 47236c1

Please sign in to comment.