diff --git a/testing/internal/e2e/tests/base/target_tcp_connect_default_client_port_test.go b/testing/internal/e2e/tests/base/target_tcp_connect_default_client_port_test.go new file mode 100644 index 0000000000..48c4a36a08 --- /dev/null +++ b/testing/internal/e2e/tests/base/target_tcp_connect_default_client_port_test.go @@ -0,0 +1,60 @@ +// Copyright (c) HashiCorp, Inc. +// SPDX-License-Identifier: BUSL-1.1 + +package base_test + +import ( + "context" + "fmt" + "strings" + "testing" + + "github.com/hashicorp/boundary/internal/target" + "github.com/hashicorp/boundary/testing/internal/e2e" + "github.com/hashicorp/boundary/testing/internal/e2e/boundary" + "github.com/stretchr/testify/require" +) + +// TestCliTcpTargetConnectTargetWithTargetClientPort connects to a target with a +// specified default client port and verifies the port is used +func TestCliTcpTargetConnectTargetWithTargetClientPort(t *testing.T) { + e2e.MaybeSkipTest(t) + c, err := loadTestConfig() + require.NoError(t, err) + + ctx := context.Background() + boundary.AuthenticateAdminCli(t, ctx) + newOrgId := boundary.CreateNewOrgCli(t, ctx) + t.Cleanup(func() { + ctx := context.Background() + boundary.AuthenticateAdminCli(t, ctx) + output := e2e.RunCommand(ctx, "boundary", e2e.WithArgs("scopes", "delete", "-id", newOrgId)) + require.NoError(t, output.Err, string(output.Stderr)) + }) + + var expPort uint32 = 8356 + + newProjectId := boundary.CreateNewProjectCli(t, ctx, newOrgId) + newHostCatalogId := boundary.CreateNewHostCatalogCli(t, ctx, newProjectId) + newHostSetId := boundary.CreateNewHostSetCli(t, ctx, newHostCatalogId) + newHostId := boundary.CreateNewHostCli(t, ctx, newHostCatalogId, c.TargetAddress) + boundary.AddHostToHostSetCli(t, ctx, newHostSetId, newHostId) + newTargetId := boundary.CreateNewTargetCli(t, ctx, newProjectId, c.TargetPort, target.WithDefaultClientPort(expPort)) + boundary.AddHostSourceToTargetCli(t, ctx, newTargetId, newHostSetId) + + // Connect to target and print host's IP address + output := e2e.RunCommand(ctx, "boundary", + e2e.WithArgs( + "connect", + "-target-id", newTargetId, + "-exec", "/bin/echo", "--", + "{{boundary.port}}", + ), + ) + require.NoError(t, output.Err, string(output.Stderr)) + + parts := strings.Fields(string(output.Stdout)) + port := parts[len(parts)-1] + + require.Equal(t, fmt.Sprintf("%d", expPort), port, "specified port was not found") +} diff --git a/testing/internal/e2e/tests/base/target_tcp_connect_test.go b/testing/internal/e2e/tests/base/target_tcp_connect_test.go index 28d0d0dbfc..e9b92e2f33 100644 --- a/testing/internal/e2e/tests/base/target_tcp_connect_test.go +++ b/testing/internal/e2e/tests/base/target_tcp_connect_test.go @@ -5,7 +5,6 @@ package base_test import ( "context" - "fmt" "strings" "testing" @@ -141,45 +140,3 @@ func TestCliTcpTargetConnectTargetViaTargetAndScopeNames(t *testing.T) { require.Equal(t, c.TargetAddress, hostIp, "SSH session did not return expected output") t.Log("Successfully connected to target by its name and scope ID") } - -func TestCliTcpTargetConnectTargetWithTargetClientPort(t *testing.T) { - e2e.MaybeSkipTest(t) - c, err := loadTestConfig() - require.NoError(t, err) - - ctx := context.Background() - boundary.AuthenticateAdminCli(t, ctx) - newOrgId := boundary.CreateNewOrgCli(t, ctx) - t.Cleanup(func() { - ctx := context.Background() - boundary.AuthenticateAdminCli(t, ctx) - output := e2e.RunCommand(ctx, "boundary", e2e.WithArgs("scopes", "delete", "-id", newOrgId)) - require.NoError(t, output.Err, string(output.Stderr)) - }) - - var expPort uint32 = 8356 - - newProjectId := boundary.CreateNewProjectCli(t, ctx, newOrgId) - newHostCatalogId := boundary.CreateNewHostCatalogCli(t, ctx, newProjectId) - newHostSetId := boundary.CreateNewHostSetCli(t, ctx, newHostCatalogId) - newHostId := boundary.CreateNewHostCli(t, ctx, newHostCatalogId, c.TargetAddress) - boundary.AddHostToHostSetCli(t, ctx, newHostSetId, newHostId) - newTargetId := boundary.CreateNewTargetCli(t, ctx, newProjectId, c.TargetPort, target.WithDefaultClientPort(expPort)) - boundary.AddHostSourceToTargetCli(t, ctx, newTargetId, newHostSetId) - - // Connect to target and print host's IP address - output := e2e.RunCommand(ctx, "boundary", - e2e.WithArgs( - "connect", - "-target-id", newTargetId, - "-exec", "/bin/echo", "--", - "{{boundary.port}}", - ), - ) - require.NoError(t, output.Err, string(output.Stderr)) - - parts := strings.Fields(string(output.Stdout)) - port := parts[len(parts)-1] - - require.Equal(t, fmt.Sprintf("%d", expPort), port, "specified port was not found") -}