* refact(e2e): Add err to CreateOrgApi * refact(e2e): Add err to CreateProjectApi * refact(e2e): Add err to CreateOrgCli * refact(e2e): Add err to CreateProjectCli * refact(e2e): Add err to CreateHostCatalogApi * refact(e2e): Add err to CreateHostSetApi * refact(e2e): Add err to CreateHostApi * refact(e2e): Add err to AddHostToHostSetApi * refact(e2e): Add err to CreateHostCatalogCli * refact(e2e): Add err to CreateHostSetCli * refact(e2e): Add err to CreateHostCli * refact(e2e): Add err to AddHostToHostSetCli * refact(e2e): Add err to CreateAwsHostCatalogCli * refact(e2e): Add err to CreateAwsHostSetCli * refact(e2e): Add err to CreateTargetApi * refact(e2e): Add err to AddHostSourceToTargetApi * refact(e2e): Add err to CreateTargetCli * refact(e2e): Add err to AddHostSourceToTargetCli * refact(e2e): Add err to SetHostSourceToTargetCli * refact(e2e): Add err to RemoveHostSourceFromTargetCli * refact(e2e): Add err to AddBrokeredCredentialSourceToTargetCli * refact(e2e): Add err to RemoveBrokeredCredentialSourceFromTargetCli * refact(e2e): Add err to CreateUserApi * refact(e2e): Add err to CreateUserCli * refact(e2e): Add err to SetAccountToUserCli * refact(e2e): Add err to CreateRoleApi * refact(e2e): Add err to CreateRoleCli * refact(e2e): Add err to AddGrantToRoleCli * refact(e2e): Add err to AddPrincipalToRoleCli * refact(e2e): Add err to CreateManagedGroupApi * refact(e2e): Add err to CreateGroupApi * refact(e2e): Add err to CreateGroupCli * refact(e2e): Add err to AddUserToGroup * refact(e2e): Add err to CreateCredentialStoreStaticApi * refact(e2e): Add err to CreateCredentialStoreVaultApi * refact(e2e): Add err to CreateCredentialStoreVaultCli * refact(e2e): Add err to CreateCredentialStoreStaticCli * refact(e2e): Add err to CreateVaultGenericCredentialLibraryCli * refact(e2e): Add err to CreateStaticCredentialPrivateKeyCli * refact(e2e): Add err to CreateStaticCredentialPasswordCli * refact(e2e): Add err to CreateStaticCredentialJsonCli * refact(e2e): Add err to CreateStaticCredentialPasswordApi * refact(e2e): Add err to CreateAuthMethodApi * refact(e2e): Add err to CreateOidcAuthMethodApi * refact(e2e): Add err to CreateAccountApi * refact(e2e): Add err to CreateAccountCli
95 lines
3.1 KiB
Go
95 lines
3.1 KiB
Go
// Copyright (c) HashiCorp, Inc.
|
|
// SPDX-License-Identifier: BUSL-1.1
|
|
|
|
package base_test
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/hashicorp/boundary/internal/session"
|
|
"github.com/hashicorp/boundary/testing/internal/e2e"
|
|
"github.com/hashicorp/boundary/testing/internal/e2e/boundary"
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
// TestCliSessionCancelAdmin uses the boundary cli to start and then cancel a session
|
|
func TestCliSessionCancelAdmin(t *testing.T) {
|
|
e2e.MaybeSkipTest(t)
|
|
c, err := loadTestConfig()
|
|
require.NoError(t, err)
|
|
|
|
ctx := context.Background()
|
|
boundary.AuthenticateAdminCli(t, ctx)
|
|
orgId, err := boundary.CreateOrgCli(t, ctx)
|
|
require.NoError(t, err)
|
|
t.Cleanup(func() {
|
|
ctx := context.Background()
|
|
boundary.AuthenticateAdminCli(t, ctx)
|
|
output := e2e.RunCommand(ctx, "boundary", e2e.WithArgs("scopes", "delete", "-id", orgId))
|
|
require.NoError(t, output.Err, string(output.Stderr))
|
|
})
|
|
projectId, err := boundary.CreateProjectCli(t, ctx, orgId)
|
|
require.NoError(t, err)
|
|
hostCatalogId, err := boundary.CreateHostCatalogCli(t, ctx, projectId)
|
|
require.NoError(t, err)
|
|
hostSetId, err := boundary.CreateHostSetCli(t, ctx, hostCatalogId)
|
|
require.NoError(t, err)
|
|
hostId, err := boundary.CreateHostCli(t, ctx, hostCatalogId, c.TargetAddress)
|
|
require.NoError(t, err)
|
|
err = boundary.AddHostToHostSetCli(t, ctx, hostSetId, hostId)
|
|
require.NoError(t, err)
|
|
targetId, err := boundary.CreateTargetCli(t, ctx, projectId, c.TargetPort)
|
|
require.NoError(t, err)
|
|
err = boundary.AddHostSourceToTargetCli(t, ctx, targetId, hostSetId)
|
|
require.NoError(t, err)
|
|
|
|
// Connect to target to create a session
|
|
ctxCancel, cancel := context.WithCancel(context.Background())
|
|
errChan := make(chan *e2e.CommandResult)
|
|
go func() {
|
|
t.Log("Starting session...")
|
|
errChan <- e2e.RunCommand(ctxCancel, "boundary",
|
|
e2e.WithArgs(
|
|
"connect",
|
|
"-target-id", targetId,
|
|
"-exec", "/usr/bin/ssh", "--",
|
|
"-l", c.TargetSshUser,
|
|
"-i", c.TargetSshKeyPath,
|
|
"-o", "UserKnownHostsFile=/dev/null",
|
|
"-o", "StrictHostKeyChecking=no",
|
|
"-o", "IdentitiesOnly=yes", // forces the use of the provided key
|
|
"-p", "{{boundary.port}}", // this is provided by boundary
|
|
"{{boundary.ip}}",
|
|
"hostname -i; sleep 60",
|
|
),
|
|
)
|
|
}()
|
|
t.Cleanup(cancel)
|
|
s := boundary.WaitForSessionCli(t, ctx, projectId)
|
|
boundary.WaitForSessionStatusCli(t, ctx, s.Id, session.StatusActive.String())
|
|
assert.Equal(t, targetId, s.TargetId)
|
|
assert.Equal(t, hostId, s.HostId)
|
|
|
|
// Cancel session
|
|
t.Log("Canceling session...")
|
|
output := e2e.RunCommand(ctx, "boundary",
|
|
e2e.WithArgs("sessions", "cancel", "-id", s.Id),
|
|
)
|
|
require.NoError(t, output.Err, string(output.Stderr))
|
|
boundary.WaitForSessionStatusCli(t, ctx, s.Id, session.StatusTerminated.String())
|
|
|
|
// Check output from session
|
|
select {
|
|
case output := <-errChan:
|
|
// `boundary connect` returns a 255 when cancelled
|
|
require.Equal(t, 255, output.ExitCode, string(output.Stdout), string(output.Stderr))
|
|
case <-time.After(time.Second * 5):
|
|
t.Fatal("Timed out waiting for session command to exit")
|
|
}
|
|
|
|
t.Log("Successfully cancelled session")
|
|
}
|