refact(e2e): Create functions for commonly used operations
Many tests had duplicate code to create the base level domain objects in a boundary environment. This commit refactors that code to use functions for these commonly used operations.
This commit is contained in:
1 parent
051d337b21
commit
618eca19f5
7 files changed
+258
-451
No files matched your search
@@ -0,0 +1,123 @@
|
||||
package boundary
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"testing"
|
||||
|
||||
"github.com/hashicorp/boundary/api"
|
||||
"github.com/hashicorp/boundary/api/hostcatalogs"
|
||||
"github.com/hashicorp/boundary/api/hosts"
|
||||
"github.com/hashicorp/boundary/api/hostsets"
|
||||
"github.com/hashicorp/boundary/testing/internal/e2e"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
// CreateNewHostCatalogApi creates a new host catalog in boundary using the go api.
|
||||
// Returns the id of the new host catalog.
|
||||
func CreateNewHostCatalogApi(t testing.TB, ctx context.Context, client *api.Client, projectId string) string {
|
||||
hcClient := hostcatalogs.NewClient(client)
|
||||
newHostCatalogResult, err := hcClient.Create(ctx, "static", projectId,
|
||||
hostcatalogs.WithName("e2e Automated Test Host Catalog"),
|
||||
)
|
||||
require.NoError(t, err)
|
||||
newHostCatalogId := newHostCatalogResult.Item.Id
|
||||
t.Logf("Created Host Catalog: %s", newHostCatalogId)
|
||||
|
||||
return newHostCatalogId
|
||||
}
|
||||
|
||||
// CreateNewHostSetApi creates a new host set in boundary using the go api.
|
||||
// Returns the id of the new host set.
|
||||
func CreateNewHostSetApi(t testing.TB, ctx context.Context, client *api.Client, hostCatalogId string) string {
|
||||
hsClient := hostsets.NewClient(client)
|
||||
newHostSetResult, err := hsClient.Create(ctx, hostCatalogId)
|
||||
require.NoError(t, err)
|
||||
newHostSetId := newHostSetResult.Item.Id
|
||||
t.Logf("Created Host Set: %s", newHostSetId)
|
||||
|
||||
return newHostSetId
|
||||
}
|
||||
|
||||
// CreateNewHostApi creates a new host in boundary using the go api
|
||||
// Returns the id of the new host.
|
||||
func CreateNewHostApi(t testing.TB, ctx context.Context, client *api.Client, hostCatalogId string, address string) string {
|
||||
hClient := hosts.NewClient(client)
|
||||
newHostResult, err := hClient.Create(ctx, hostCatalogId,
|
||||
hosts.WithName(address),
|
||||
hosts.WithStaticHostAddress(address),
|
||||
)
|
||||
require.NoError(t, err)
|
||||
newHostId := newHostResult.Item.Id
|
||||
t.Logf("Created Host: %s", newHostId)
|
||||
|
||||
return newHostId
|
||||
}
|
||||
|
||||
// AddHostToHostSetApi adds a host to a host set using the go api
|
||||
func AddHostToHostSetApi(t testing.TB, ctx context.Context, client *api.Client, hostSetId string, hostId string) {
|
||||
hsClient := hostsets.NewClient(client)
|
||||
_, err := hsClient.AddHosts(ctx, hostSetId, 0, []string{hostId}, hostsets.WithAutomaticVersioning(true))
|
||||
require.NoError(t, err)
|
||||
}
|
||||
|
||||
// CreateNewHostCatalogCli creates a new host catalog in boundary using the cli.
|
||||
// Returns the id of the new host catalog.
|
||||
func CreateNewHostCatalogCli(t testing.TB, projectId string) string {
|
||||
output := e2e.RunCommand("boundary", "host-catalogs", "create", "static",
|
||||
"-scope-id", projectId,
|
||||
"-name", "e2e Automated Test Host Catalog",
|
||||
"-format", "json",
|
||||
)
|
||||
require.NoError(t, output.Err, string(output.Stderr))
|
||||
var newHostCatalogResult hostcatalogs.HostCatalogCreateResult
|
||||
err := json.Unmarshal(output.Stdout, &newHostCatalogResult)
|
||||
require.NoError(t, err)
|
||||
newHostCatalogId := newHostCatalogResult.Item.Id
|
||||
|
||||
t.Logf("Created Host Catalog: %s", newHostCatalogId)
|
||||
return newHostCatalogId
|
||||
}
|
||||
|
||||
// CreateNewHostSetCli creates a new host set in boundary using the cli.
|
||||
// Returns the id of the new host set.
|
||||
func CreateNewHostSetCli(t testing.TB, hostCatalogId string) string {
|
||||
output := e2e.RunCommand("boundary", "host-sets", "create", "static",
|
||||
"-host-catalog-id", hostCatalogId,
|
||||
"-name", "e2e Automated Test Host Set",
|
||||
"-format", "json",
|
||||
)
|
||||
require.NoError(t, output.Err, string(output.Stderr))
|
||||
var newHostSetResult hostsets.HostSetCreateResult
|
||||
err := json.Unmarshal(output.Stdout, &newHostSetResult)
|
||||
require.NoError(t, err)
|
||||
newHostSetId := newHostSetResult.Item.Id
|
||||
t.Logf("Created Host Set: %s", newHostSetId)
|
||||
|
||||
return newHostSetId
|
||||
}
|
||||
|
||||
// CreateNewHostCli creates a new host in boundary using the cli.
|
||||
// Returns the id of the new host.
|
||||
func CreateNewHostCli(t testing.TB, hostCatalogId string, address string) string {
|
||||
output := e2e.RunCommand("boundary", "hosts", "create", "static",
|
||||
"-host-catalog-id", hostCatalogId,
|
||||
"-name", address,
|
||||
"-address", address,
|
||||
"-format", "json",
|
||||
)
|
||||
require.NoError(t, output.Err, string(output.Stderr))
|
||||
var newHostResult hosts.HostCreateResult
|
||||
err := json.Unmarshal(output.Stdout, &newHostResult)
|
||||
require.NoError(t, err)
|
||||
newHostId := newHostResult.Item.Id
|
||||
t.Logf("Created Host: %s", newHostId)
|
||||
|
||||
return newHostId
|
||||
}
|
||||
|
||||
// AddHostToHostSetCli adds a host to a host set using the cli
|
||||
func AddHostToHostSetCli(t testing.TB, hostSetId string, hostId string) {
|
||||
output := e2e.RunCommand("boundary", "host-sets", "add-hosts", "-id", hostSetId, "-host", hostId)
|
||||
require.NoError(t, output.Err, string(output.Stderr))
|
||||
}
|
||||
@@ -17,13 +17,15 @@ func CreateNewOrgApi(t testing.TB, ctx context.Context, client *api.Client) stri
|
||||
scopeClient := scopes.NewClient(client)
|
||||
newOrgResult, err := scopeClient.Create(ctx, "global", scopes.WithName("e2e Automated Test Org"))
|
||||
require.NoError(t, err)
|
||||
|
||||
newOrgId := newOrgResult.Item.Id
|
||||
t.Cleanup(func() {
|
||||
_, err := scopeClient.Delete(ctx, newOrgResult.Item.Id)
|
||||
_, err := scopeClient.Delete(ctx, newOrgId)
|
||||
require.NoError(t, err)
|
||||
})
|
||||
|
||||
t.Logf("Created Org Id: %s", newOrgResult.Item.Id)
|
||||
return newOrgResult.Item.Id
|
||||
t.Logf("Created Org Id: %s", newOrgId)
|
||||
return newOrgId
|
||||
}
|
||||
|
||||
// CreateNewProjectApi creates a new project in boundary using the go api. The project will be created
|
||||
@@ -34,8 +36,9 @@ func CreateNewProjectApi(t testing.TB, ctx context.Context, client *api.Client,
|
||||
newProjResult, err := scopeClient.Create(ctx, orgId, scopes.WithName("e2e Automated Test Project"))
|
||||
require.NoError(t, err)
|
||||
|
||||
t.Logf("Created Project Id: %s", newProjResult.Item.Id)
|
||||
return newProjResult.Item.Id
|
||||
newProjectId := newProjResult.Item.Id
|
||||
t.Logf("Created Project Id: %s", newProjectId)
|
||||
return newProjectId
|
||||
}
|
||||
|
||||
// CreateNewOrgCli creates a new organization in boundary using the cli.
|
||||
@@ -52,13 +55,14 @@ func CreateNewOrgCli(t testing.TB) string {
|
||||
err := json.Unmarshal(output.Stdout, &newOrgResult)
|
||||
require.NoError(t, err)
|
||||
|
||||
newOrgId := newOrgResult.Item.Id
|
||||
t.Cleanup(func() {
|
||||
output := e2e.RunCommand("boundary", "scopes", "delete", "-id", newOrgResult.Item.Id)
|
||||
output := e2e.RunCommand("boundary", "scopes", "delete", "-id", newOrgId)
|
||||
require.NoError(t, output.Err, string(output.Stderr))
|
||||
})
|
||||
|
||||
t.Logf("Created Org Id: %s", newOrgResult.Item.Id)
|
||||
return newOrgResult.Item.Id
|
||||
t.Logf("Created Org Id: %s", newOrgId)
|
||||
return newOrgId
|
||||
}
|
||||
|
||||
// CreateNewProjectCli creates a new project in boundary using the cli. The project will be created
|
||||
@@ -76,6 +80,7 @@ func CreateNewProjectCli(t testing.TB, orgId string) string {
|
||||
err := json.Unmarshal(output.Stdout, &newProjResult)
|
||||
require.NoError(t, err)
|
||||
|
||||
t.Logf("Created Project Id: %s", newProjResult.Item.Id)
|
||||
return newProjResult.Item.Id
|
||||
newProjectId := newProjResult.Item.Id
|
||||
t.Logf("Created Project Id: %s", newProjectId)
|
||||
return newProjectId
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
package boundary
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"strconv"
|
||||
"testing"
|
||||
|
||||
"github.com/hashicorp/boundary/api"
|
||||
"github.com/hashicorp/boundary/api/targets"
|
||||
"github.com/hashicorp/boundary/testing/internal/e2e"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
// CreateNewTargetApi creates a new target in boundary using the go api.
|
||||
// Returns the id of the new target.
|
||||
func CreateNewTargetApi(t testing.TB, ctx context.Context, client *api.Client, projectId string, defaultPort string) string {
|
||||
tClient := targets.NewClient(client)
|
||||
targetPort, err := strconv.ParseInt(defaultPort, 10, 32)
|
||||
require.NoError(t, err)
|
||||
newTargetResult, err := tClient.Create(ctx, "tcp", projectId,
|
||||
targets.WithName("e2e Automated Test Target"),
|
||||
targets.WithTcpTargetDefaultPort(uint32(targetPort)),
|
||||
)
|
||||
require.NoError(t, err)
|
||||
newTargetId := newTargetResult.Item.Id
|
||||
t.Logf("Created Target: %s", newTargetId)
|
||||
|
||||
return newTargetId
|
||||
}
|
||||
|
||||
// AddHostSourceToTargetApi adds a host source (host set or host) to a target using the go api
|
||||
func AddHostSourceToTargetApi(t testing.TB, ctx context.Context, client *api.Client, targetId string, hostSourceId string) {
|
||||
tClient := targets.NewClient(client)
|
||||
_, err := tClient.AddHostSources(ctx, targetId, 0,
|
||||
[]string{hostSourceId},
|
||||
targets.WithAutomaticVersioning(true),
|
||||
)
|
||||
require.NoError(t, err)
|
||||
}
|
||||
|
||||
// CreateNewTargetCli creates a new target in boundary using the cli
|
||||
// Returns the id of the new target.
|
||||
func CreateNewTargetCli(t testing.TB, projectId string, defaultPort string) string {
|
||||
output := e2e.RunCommand("boundary", "targets", "create", "tcp",
|
||||
"-scope-id", projectId,
|
||||
"-default-port", defaultPort,
|
||||
"-name", "e2e Automated Test Target",
|
||||
"-format", "json",
|
||||
)
|
||||
require.NoError(t, output.Err, string(output.Stderr))
|
||||
var newTargetResult targets.TargetCreateResult
|
||||
err := json.Unmarshal(output.Stdout, &newTargetResult)
|
||||
require.NoError(t, err)
|
||||
newTargetId := newTargetResult.Item.Id
|
||||
t.Logf("Created Target: %s", newTargetId)
|
||||
|
||||
return newTargetId
|
||||
}
|
||||
|
||||
// AddHostSourceToTargetCli adds a host source (host set or host) to a target using the cli
|
||||
func AddHostSourceToTargetCli(t testing.TB, targetId string, hostSourceId string) {
|
||||
output := e2e.RunCommand("boundary", "targets", "add-host-sources",
|
||||
"-id", targetId,
|
||||
"-host-source", hostSourceId,
|
||||
)
|
||||
require.NoError(t, output.Err, string(output.Stderr))
|
||||
}
|
||||
@@ -5,15 +5,11 @@ import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"os"
|
||||
"strconv"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/hashicorp/boundary/api/credentiallibraries"
|
||||
"github.com/hashicorp/boundary/api/credentialstores"
|
||||
"github.com/hashicorp/boundary/api/hostcatalogs"
|
||||
"github.com/hashicorp/boundary/api/hosts"
|
||||
"github.com/hashicorp/boundary/api/hostsets"
|
||||
"github.com/hashicorp/boundary/api/targets"
|
||||
"github.com/hashicorp/boundary/testing/internal/e2e"
|
||||
"github.com/hashicorp/boundary/testing/internal/e2e/boundary"
|
||||
@@ -56,6 +52,16 @@ func TestCreateVaultCredentialStoreCli(t *testing.T) {
|
||||
c, err := loadConfig()
|
||||
require.NoError(t, err)
|
||||
|
||||
boundary.AuthenticateCli(t)
|
||||
newOrgId := boundary.CreateNewOrgCli(t)
|
||||
newProjectId := boundary.CreateNewProjectCli(t, newOrgId)
|
||||
newHostCatalogId := boundary.CreateNewHostCatalogCli(t, newProjectId)
|
||||
newHostSetId := boundary.CreateNewHostSetCli(t, newHostCatalogId)
|
||||
newHostId := boundary.CreateNewHostCli(t, newHostCatalogId, c.TargetIp)
|
||||
boundary.AddHostToHostSetCli(t, newHostSetId, newHostId)
|
||||
newTargetId := boundary.CreateNewTargetCli(t, newProjectId, c.TargetPort)
|
||||
boundary.AddHostSourceToTargetCli(t, newTargetId, newHostSetId)
|
||||
|
||||
// Configure vault
|
||||
vaultAddr, boundaryPolicyName := vault.Setup(t)
|
||||
|
||||
@@ -88,13 +94,6 @@ func TestCreateVaultCredentialStoreCli(t *testing.T) {
|
||||
credStoreToken := tokenCreateResult.Auth.Client_Token
|
||||
t.Log("Created Vault Cred Store Token")
|
||||
|
||||
// Authenticate boundary cli
|
||||
boundary.AuthenticateCli(t)
|
||||
|
||||
// Create an org and project
|
||||
newOrgId := boundary.CreateNewOrgCli(t)
|
||||
newProjectId := boundary.CreateNewProjectCli(t, newOrgId)
|
||||
|
||||
// Create a credential store
|
||||
output = e2e.RunCommand("boundary", "credential-stores", "create", "vault",
|
||||
"-scope-id", newProjectId,
|
||||
@@ -124,74 +123,6 @@ func TestCreateVaultCredentialStoreCli(t *testing.T) {
|
||||
newCredentialLibraryId := newCredentialLibraryResult.Item.Id
|
||||
t.Logf("Created Credential Library: %s", newCredentialLibraryId)
|
||||
|
||||
// Create a host catalog
|
||||
output = e2e.RunCommand("boundary", "host-catalogs", "create", "static",
|
||||
"-scope-id", newProjectId,
|
||||
"-name", "e2e Automated Test Host Catalog",
|
||||
"-format", "json",
|
||||
)
|
||||
require.NoError(t, output.Err, string(output.Stderr))
|
||||
var newHostCatalogResult hostcatalogs.HostCatalogCreateResult
|
||||
err = json.Unmarshal(output.Stdout, &newHostCatalogResult)
|
||||
require.NoError(t, err)
|
||||
newHostCatalogId := newHostCatalogResult.Item.Id
|
||||
t.Logf("Created Host Catalog: %s", newHostCatalogId)
|
||||
|
||||
// Create a host set and add to catalog
|
||||
output = e2e.RunCommand("boundary", "host-sets", "create", "static",
|
||||
"-host-catalog-id", newHostCatalogId,
|
||||
"-name", "e2e Automated Test Host Set",
|
||||
"-format", "json",
|
||||
)
|
||||
require.NoError(t, output.Err, string(output.Stderr))
|
||||
var newHostSetResult hostsets.HostSetCreateResult
|
||||
err = json.Unmarshal(output.Stdout, &newHostSetResult)
|
||||
require.NoError(t, err)
|
||||
newHostSetId := newHostSetResult.Item.Id
|
||||
t.Logf("Created Host Set: %s", newHostSetId)
|
||||
|
||||
// Create a host
|
||||
output = e2e.RunCommand("boundary", "hosts", "create", "static",
|
||||
"-host-catalog-id", newHostCatalogId,
|
||||
"-name", c.TargetIp,
|
||||
"-address", c.TargetIp,
|
||||
"-format", "json",
|
||||
)
|
||||
require.NoError(t, output.Err, string(output.Stderr))
|
||||
var newHostResult hosts.HostCreateResult
|
||||
err = json.Unmarshal(output.Stdout, &newHostResult)
|
||||
require.NoError(t, err)
|
||||
newHostId := newHostResult.Item.Id
|
||||
t.Logf("Created Host: %s", newHostId)
|
||||
|
||||
// Add host to host set
|
||||
output = e2e.RunCommand("boundary", "host-sets", "add-hosts",
|
||||
"-id", newHostSetId,
|
||||
"-host", newHostId,
|
||||
)
|
||||
require.NoError(t, output.Err, string(output.Stderr))
|
||||
|
||||
// Create Target
|
||||
output = e2e.RunCommand("boundary", "targets", "create", "tcp",
|
||||
"-scope-id", newProjectId,
|
||||
"-default-port", c.TargetPort,
|
||||
"-name", "e2e Automated Test Target",
|
||||
"-format", "json",
|
||||
)
|
||||
require.NoError(t, output.Err, string(output.Stderr))
|
||||
var newTargetResult targets.TargetCreateResult
|
||||
err = json.Unmarshal(output.Stdout, &newTargetResult)
|
||||
require.NoError(t, err)
|
||||
newTargetId := newTargetResult.Item.Id
|
||||
t.Logf("Created Target: %s", newTargetId)
|
||||
|
||||
// Add host set to target
|
||||
output = e2e.RunCommand("boundary", "targets", "add-host-sources",
|
||||
"-id", newTargetId,
|
||||
"-host-source", newHostSetId,
|
||||
)
|
||||
require.NoError(t, output.Err, string(output.Stderr))
|
||||
|
||||
// Add brokered credentials to target
|
||||
output = e2e.RunCommand("boundary", "targets", "add-credential-sources",
|
||||
"-id", newTargetId,
|
||||
@@ -254,6 +185,19 @@ func TestCreateVaultCredentialStoreApi(t *testing.T) {
|
||||
c, err := loadConfig()
|
||||
require.NoError(t, err)
|
||||
|
||||
client, err := boundary.NewApiClient()
|
||||
require.NoError(t, err)
|
||||
ctx := context.Background()
|
||||
|
||||
newOrgId := boundary.CreateNewOrgApi(t, ctx, client)
|
||||
newProjectId := boundary.CreateNewProjectApi(t, ctx, client, newOrgId)
|
||||
newHostCatalogId := boundary.CreateNewHostCatalogApi(t, ctx, client, newProjectId)
|
||||
newHostSetId := boundary.CreateNewHostSetApi(t, ctx, client, newHostCatalogId)
|
||||
newHostId := boundary.CreateNewHostApi(t, ctx, client, newHostCatalogId, c.TargetIp)
|
||||
boundary.AddHostToHostSetApi(t, ctx, client, newHostSetId, newHostId)
|
||||
newTargetId := boundary.CreateNewTargetApi(t, ctx, client, newProjectId, c.TargetPort)
|
||||
boundary.AddHostSourceToTargetApi(t, ctx, client, newTargetId, newHostSetId)
|
||||
|
||||
// Configure vault
|
||||
vaultAddr, boundaryPolicyName := vault.Setup(t)
|
||||
|
||||
@@ -286,15 +230,6 @@ func TestCreateVaultCredentialStoreApi(t *testing.T) {
|
||||
credStoreToken := tokenCreateResult.Auth.Client_Token
|
||||
t.Log("Created Vault Cred Store Token")
|
||||
|
||||
// Create boundary api client
|
||||
client, err := boundary.NewApiClient()
|
||||
require.NoError(t, err)
|
||||
ctx := context.Background()
|
||||
|
||||
// Create an org and project
|
||||
newOrgId := boundary.CreateNewOrgApi(t, ctx, client)
|
||||
newProjectId := boundary.CreateNewProjectApi(t, ctx, client, newOrgId)
|
||||
|
||||
// Create a credential store
|
||||
csClient := credentialstores.NewClient(client)
|
||||
newCredentialStoreResult, err := csClient.Create(ctx, "vault", newProjectId,
|
||||
@@ -315,56 +250,8 @@ func TestCreateVaultCredentialStoreApi(t *testing.T) {
|
||||
newCredentialLibraryId := newCredentialLibraryResult.Item.Id
|
||||
t.Logf("Created Credential Library: %s", newCredentialLibraryId)
|
||||
|
||||
// Create a host catalog
|
||||
hcClient := hostcatalogs.NewClient(client)
|
||||
newHostCatalogResult, err := hcClient.Create(ctx, "static", newProjectId,
|
||||
hostcatalogs.WithName("e2e Automated Test Host Catalog"),
|
||||
)
|
||||
require.NoError(t, err)
|
||||
newHostCatalogId := newHostCatalogResult.Item.Id
|
||||
t.Logf("Created Host Catalog: %s", newHostCatalogId)
|
||||
|
||||
// Create a host set and add to catalog
|
||||
hsClient := hostsets.NewClient(client)
|
||||
newHostSetResult, err := hsClient.Create(ctx, newHostCatalogId)
|
||||
require.NoError(t, err)
|
||||
newHostSetId := newHostSetResult.Item.Id
|
||||
t.Logf("Created Host Set: %s", newHostSetId)
|
||||
|
||||
// Create a host
|
||||
hClient := hosts.NewClient(client)
|
||||
newHostResult, err := hClient.Create(ctx, newHostCatalogId,
|
||||
hosts.WithName(c.TargetIp),
|
||||
hosts.WithStaticHostAddress(c.TargetIp),
|
||||
)
|
||||
require.NoError(t, err)
|
||||
newHostId := newHostResult.Item.Id
|
||||
t.Logf("Created Host: %s", newHostId)
|
||||
|
||||
// Add host to host set
|
||||
_, err = hsClient.AddHosts(ctx, newHostSetId, 0, []string{newHostId}, hostsets.WithAutomaticVersioning(true))
|
||||
require.NoError(t, err)
|
||||
|
||||
// Create a target
|
||||
tClient := targets.NewClient(client)
|
||||
targetPort, err := strconv.ParseInt(c.TargetPort, 10, 32)
|
||||
require.NoError(t, err)
|
||||
newTargetResult, err := tClient.Create(ctx, "tcp", newProjectId,
|
||||
targets.WithName("e2e Automated Test Target"),
|
||||
targets.WithTcpTargetDefaultPort(uint32(targetPort)),
|
||||
)
|
||||
require.NoError(t, err)
|
||||
newTargetId := newTargetResult.Item.Id
|
||||
t.Logf("Created Target: %s", newTargetId)
|
||||
|
||||
// Add host set to target
|
||||
_, err = tClient.AddHostSources(ctx, newTargetId, 0,
|
||||
[]string{newHostSetId},
|
||||
targets.WithAutomaticVersioning(true),
|
||||
)
|
||||
require.NoError(t, err)
|
||||
|
||||
// Add brokered credentials to target
|
||||
tClient := targets.NewClient(client)
|
||||
_, err = tClient.AddCredentialSources(ctx, newTargetId, 0,
|
||||
targets.WithBrokeredCredentialSourceIds([]string{newCredentialLibraryId}),
|
||||
targets.WithAutomaticVersioning(true),
|
||||
|
||||
@@ -13,7 +13,6 @@ import (
|
||||
"github.com/hashicorp/boundary/api/hostcatalogs"
|
||||
"github.com/hashicorp/boundary/api/hosts"
|
||||
"github.com/hashicorp/boundary/api/hostsets"
|
||||
"github.com/hashicorp/boundary/api/targets"
|
||||
"github.com/hashicorp/boundary/testing/internal/e2e"
|
||||
"github.com/hashicorp/boundary/testing/internal/e2e/boundary"
|
||||
"github.com/kelseyhightower/envconfig"
|
||||
@@ -52,8 +51,6 @@ func TestCreateAwsDynamicHostCatalogCli(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
|
||||
boundary.AuthenticateCli(t)
|
||||
|
||||
// Create an org and project
|
||||
newOrgId := boundary.CreateNewOrgCli(t)
|
||||
newProjectId := boundary.CreateNewProjectCli(t, newOrgId)
|
||||
|
||||
@@ -183,7 +180,6 @@ func TestCreateAwsDynamicHostCatalogCli(t *testing.T) {
|
||||
assert.Equal(t, expectedHostSetCount2, actualHostSetCount2, "Numbers of hosts in host set did not match expected amount")
|
||||
|
||||
// Get list of all hosts from host catalog
|
||||
// Retry is needed here since it can take a few tries before hosts start appearing
|
||||
t.Logf("Looking for items in the host catalog...")
|
||||
var actualHostCatalogCount int
|
||||
err = backoff.RetryNotify(
|
||||
@@ -221,25 +217,8 @@ func TestCreateAwsDynamicHostCatalogCli(t *testing.T) {
|
||||
assert.Equal(t, expectedHostCatalogCount, actualHostCatalogCount, "Numbers of hosts in host catalog did not match expected amount")
|
||||
|
||||
// Create target
|
||||
output = e2e.RunCommand("boundary", "targets", "create", "tcp",
|
||||
"-scope-id", newProjectId,
|
||||
"-default-port", c.TargetPort,
|
||||
"-name", "e2e Automated Test Target",
|
||||
"-format", "json",
|
||||
)
|
||||
require.NoError(t, output.Err, string(output.Stderr))
|
||||
var newTargetResult targets.TargetCreateResult
|
||||
err = json.Unmarshal(output.Stdout, &newTargetResult)
|
||||
require.NoError(t, err)
|
||||
newTargetId := newTargetResult.Item.Id
|
||||
t.Logf("Created Target: %s", newTargetId)
|
||||
|
||||
// Add host set to target
|
||||
output = e2e.RunCommand("boundary", "targets", "add-host-sources",
|
||||
"-id", newTargetId,
|
||||
"-host-source", newHostSetId1,
|
||||
)
|
||||
require.NoError(t, output.Err, string(output.Stderr))
|
||||
newTargetId := boundary.CreateNewTargetCli(t, newProjectId, c.TargetPort)
|
||||
boundary.AddHostSourceToTargetCli(t, newTargetId, newHostSetId1)
|
||||
|
||||
// Connect to target
|
||||
output = e2e.RunCommand("boundary", "connect",
|
||||
@@ -278,12 +257,10 @@ func TestCreateAwsDynamicHostCatalogApi(t *testing.T) {
|
||||
c, err := loadConfig()
|
||||
require.NoError(t, err)
|
||||
|
||||
// Create boundary api client
|
||||
client, err := boundary.NewApiClient()
|
||||
require.NoError(t, err)
|
||||
ctx := context.Background()
|
||||
|
||||
// Create an org and project
|
||||
newOrgId := boundary.CreateNewOrgApi(t, ctx, client)
|
||||
newProjectId := boundary.CreateNewProjectApi(t, ctx, client, newOrgId)
|
||||
|
||||
|
||||
@@ -5,14 +5,10 @@ import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"os"
|
||||
"strconv"
|
||||
"testing"
|
||||
|
||||
"github.com/hashicorp/boundary/api/credentials"
|
||||
"github.com/hashicorp/boundary/api/credentialstores"
|
||||
"github.com/hashicorp/boundary/api/hostcatalogs"
|
||||
"github.com/hashicorp/boundary/api/hosts"
|
||||
"github.com/hashicorp/boundary/api/hostsets"
|
||||
"github.com/hashicorp/boundary/api/targets"
|
||||
"github.com/hashicorp/boundary/testing/internal/e2e"
|
||||
"github.com/hashicorp/boundary/testing/internal/e2e/boundary"
|
||||
@@ -29,10 +25,14 @@ func TestConnectTargetWithStaticCredentialStoreCli(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
|
||||
boundary.AuthenticateCli(t)
|
||||
|
||||
// Create an org and project
|
||||
newOrgId := boundary.CreateNewOrgCli(t)
|
||||
newProjectId := boundary.CreateNewProjectCli(t, newOrgId)
|
||||
newHostCatalogId := boundary.CreateNewHostCatalogCli(t, newProjectId)
|
||||
newHostSetId := boundary.CreateNewHostSetCli(t, newHostCatalogId)
|
||||
newHostId := boundary.CreateNewHostCli(t, newHostCatalogId, c.TargetIp)
|
||||
boundary.AddHostToHostSetCli(t, newHostSetId, newHostId)
|
||||
newTargetId := boundary.CreateNewTargetCli(t, newProjectId, c.TargetPort)
|
||||
boundary.AddHostSourceToTargetCli(t, newTargetId, newHostSetId)
|
||||
|
||||
// Create a credential store
|
||||
output := e2e.RunCommand("boundary", "credential-stores", "create", "static",
|
||||
@@ -60,71 +60,6 @@ func TestConnectTargetWithStaticCredentialStoreCli(t *testing.T) {
|
||||
newCredentialsId := newCredentialsResult.Item.Id
|
||||
t.Logf("Created Credentials: %s", newCredentialsId)
|
||||
|
||||
// Create a host catalog
|
||||
output = e2e.RunCommand("boundary", "host-catalogs", "create", "static",
|
||||
"-scope-id", newProjectId,
|
||||
"-name", "e2e Automated Test Host Catalog",
|
||||
"-format", "json",
|
||||
)
|
||||
require.NoError(t, output.Err, string(output.Stderr))
|
||||
var newHostCatalogResult hostcatalogs.HostCatalogCreateResult
|
||||
err = json.Unmarshal(output.Stdout, &newHostCatalogResult)
|
||||
require.NoError(t, err)
|
||||
newHostCatalogId := newHostCatalogResult.Item.Id
|
||||
t.Logf("Created Host Catalog: %s", newHostCatalogId)
|
||||
|
||||
// Create a host set and add to catalog
|
||||
output = e2e.RunCommand("boundary", "host-sets", "create", "static",
|
||||
"-host-catalog-id", newHostCatalogId,
|
||||
"-name", "e2e Automated Test Host Set",
|
||||
"-format", "json",
|
||||
)
|
||||
require.NoError(t, output.Err, string(output.Stderr))
|
||||
var newHostSetResult hostsets.HostSetCreateResult
|
||||
err = json.Unmarshal(output.Stdout, &newHostSetResult)
|
||||
require.NoError(t, err)
|
||||
newHostSetId := newHostSetResult.Item.Id
|
||||
t.Logf("Created Host Set: %s", newHostSetId)
|
||||
|
||||
// Create a host
|
||||
output = e2e.RunCommand("boundary", "hosts", "create", "static",
|
||||
"-host-catalog-id", newHostCatalogId,
|
||||
"-name", c.TargetIp,
|
||||
"-address", c.TargetIp,
|
||||
"-format", "json",
|
||||
)
|
||||
require.NoError(t, output.Err, string(output.Stderr))
|
||||
var newHostResult hosts.HostCreateResult
|
||||
err = json.Unmarshal(output.Stdout, &newHostResult)
|
||||
require.NoError(t, err)
|
||||
newHostId := newHostResult.Item.Id
|
||||
t.Logf("Created Host: %s", newHostId)
|
||||
|
||||
// Add host to host set
|
||||
output = e2e.RunCommand("boundary", "host-sets", "add-hosts", "-id", newHostSetId, "-host", newHostId)
|
||||
require.NoError(t, output.Err, string(output.Stderr))
|
||||
|
||||
// Create a target
|
||||
output = e2e.RunCommand("boundary", "targets", "create", "tcp",
|
||||
"-scope-id", newProjectId,
|
||||
"-default-port", c.TargetPort,
|
||||
"-name", "e2e Automated Test Target",
|
||||
"-format", "json",
|
||||
)
|
||||
require.NoError(t, output.Err, string(output.Stderr))
|
||||
var newTargetResult targets.TargetCreateResult
|
||||
err = json.Unmarshal(output.Stdout, &newTargetResult)
|
||||
require.NoError(t, err)
|
||||
newTargetId := newTargetResult.Item.Id
|
||||
t.Logf("Created Target: %s", newTargetId)
|
||||
|
||||
// Add host set to target
|
||||
output = e2e.RunCommand("boundary", "targets", "add-host-sources",
|
||||
"-id", newTargetId,
|
||||
"-host-source", newHostSetId,
|
||||
)
|
||||
require.NoError(t, output.Err, string(output.Stderr))
|
||||
|
||||
// Add credentials to target
|
||||
output = e2e.RunCommand("boundary", "targets", "add-credential-sources",
|
||||
"-id", newTargetId,
|
||||
@@ -167,14 +102,18 @@ func TestCreateTargetWithStaticCredentialStoreApi(t *testing.T) {
|
||||
c, err := loadConfig()
|
||||
require.NoError(t, err)
|
||||
|
||||
// Create boundary api client
|
||||
client, err := boundary.NewApiClient()
|
||||
require.NoError(t, err)
|
||||
ctx := context.Background()
|
||||
|
||||
// Create an org and project
|
||||
newOrgId := boundary.CreateNewOrgApi(t, ctx, client)
|
||||
newProjectId := boundary.CreateNewProjectApi(t, ctx, client, newOrgId)
|
||||
newHostCatalogId := boundary.CreateNewHostCatalogApi(t, ctx, client, newProjectId)
|
||||
newHostSetId := boundary.CreateNewHostSetApi(t, ctx, client, newHostCatalogId)
|
||||
newHostId := boundary.CreateNewHostApi(t, ctx, client, newHostCatalogId, c.TargetIp)
|
||||
boundary.AddHostToHostSetApi(t, ctx, client, newHostSetId, newHostId)
|
||||
newTargetId := boundary.CreateNewTargetApi(t, ctx, client, newProjectId, c.TargetPort)
|
||||
boundary.AddHostSourceToTargetApi(t, ctx, client, newTargetId, newHostSetId)
|
||||
|
||||
// Create a credential store
|
||||
csClient := credentialstores.NewClient(client)
|
||||
@@ -195,56 +134,8 @@ func TestCreateTargetWithStaticCredentialStoreApi(t *testing.T) {
|
||||
newCredentialsId := newCredentialsResult.Item.Id
|
||||
t.Logf("Created Credentials: %s", newCredentialsId)
|
||||
|
||||
// Create a host catalog
|
||||
hcClient := hostcatalogs.NewClient(client)
|
||||
newHostCatalogResult, err := hcClient.Create(ctx, "static", newProjectId,
|
||||
hostcatalogs.WithName("e2e Automated Test Host Catalog"),
|
||||
)
|
||||
require.NoError(t, err)
|
||||
newHostCatalogId := newHostCatalogResult.Item.Id
|
||||
t.Logf("Created Host Catalog: %s", newHostCatalogId)
|
||||
|
||||
// Create a host set and add to catalog
|
||||
hsClient := hostsets.NewClient(client)
|
||||
newHostSetResult, err := hsClient.Create(ctx, newHostCatalogId)
|
||||
require.NoError(t, err)
|
||||
newHostSetId := newHostSetResult.Item.Id
|
||||
t.Logf("Created Host Set: %s", newHostSetId)
|
||||
|
||||
// Create a host
|
||||
hClient := hosts.NewClient(client)
|
||||
newHostResult, err := hClient.Create(ctx, newHostCatalogId,
|
||||
hosts.WithName(c.TargetIp),
|
||||
hosts.WithStaticHostAddress(c.TargetIp),
|
||||
)
|
||||
require.NoError(t, err)
|
||||
newHostId := newHostResult.Item.Id
|
||||
t.Logf("Created Host: %s", newHostId)
|
||||
|
||||
// Add host to host set
|
||||
_, err = hsClient.AddHosts(ctx, newHostSetId, 0, []string{newHostId}, hostsets.WithAutomaticVersioning(true))
|
||||
require.NoError(t, err)
|
||||
|
||||
// Create a target
|
||||
tClient := targets.NewClient(client)
|
||||
targetPort, err := strconv.ParseInt(c.TargetPort, 10, 32)
|
||||
require.NoError(t, err)
|
||||
newTargetResult, err := tClient.Create(ctx, "tcp", newProjectId,
|
||||
targets.WithName("e2e Automated Test Target"),
|
||||
targets.WithTcpTargetDefaultPort(uint32(targetPort)),
|
||||
)
|
||||
require.NoError(t, err)
|
||||
newTargetId := newTargetResult.Item.Id
|
||||
t.Logf("Created Target: %s", newTargetId)
|
||||
|
||||
// Add host set to target
|
||||
_, err = tClient.AddHostSources(ctx, newTargetId, 0,
|
||||
[]string{newHostSetId},
|
||||
targets.WithAutomaticVersioning(true),
|
||||
)
|
||||
require.NoError(t, err)
|
||||
|
||||
// Add credentials to target
|
||||
tClient := targets.NewClient(client)
|
||||
_, err = tClient.AddCredentialSources(ctx, newTargetId, 0,
|
||||
targets.WithAutomaticVersioning(true),
|
||||
targets.WithBrokeredCredentialSourceIds([]string{newCredentialsId}),
|
||||
|
||||
@@ -2,15 +2,9 @@ package static_test
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"strconv"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/hashicorp/boundary/api/hostcatalogs"
|
||||
"github.com/hashicorp/boundary/api/hosts"
|
||||
"github.com/hashicorp/boundary/api/hostsets"
|
||||
"github.com/hashicorp/boundary/api/targets"
|
||||
"github.com/hashicorp/boundary/testing/internal/e2e"
|
||||
"github.com/hashicorp/boundary/testing/internal/e2e/boundary"
|
||||
"github.com/stretchr/testify/require"
|
||||
@@ -25,94 +19,17 @@ func TestConnectTargetCli(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
|
||||
boundary.AuthenticateCli(t)
|
||||
|
||||
// Create an org and project
|
||||
newOrgId := boundary.CreateNewOrgCli(t)
|
||||
newProjectId := boundary.CreateNewProjectCli(t, newOrgId)
|
||||
|
||||
// Create a host catalog
|
||||
output := e2e.RunCommand("boundary", "host-catalogs", "create", "static",
|
||||
"-scope-id", newProjectId,
|
||||
"-name", "e2e Automated Test Host Catalog",
|
||||
"-format", "json",
|
||||
)
|
||||
require.NoError(t, output.Err, string(output.Stderr))
|
||||
var newHostCatalogResult hostcatalogs.HostCatalogCreateResult
|
||||
err = json.Unmarshal(output.Stdout, &newHostCatalogResult)
|
||||
require.NoError(t, err)
|
||||
newHostCatalogId := newHostCatalogResult.Item.Id
|
||||
t.Cleanup(func() {
|
||||
output := e2e.RunCommand("boundary", "host-catalogs", "delete", "-id", newHostCatalogId)
|
||||
require.NoError(t, output.Err, string(output.Stderr))
|
||||
})
|
||||
t.Logf("Created Host Catalog: %s", newHostCatalogId)
|
||||
|
||||
// Create a host set and add to catalog
|
||||
output = e2e.RunCommand("boundary", "host-sets", "create", "static",
|
||||
"-host-catalog-id", newHostCatalogId,
|
||||
"-name", "e2e Automated Test Host Set",
|
||||
"-format", "json",
|
||||
)
|
||||
require.NoError(t, output.Err, string(output.Stderr))
|
||||
var newHostSetResult hostsets.HostSetCreateResult
|
||||
err = json.Unmarshal(output.Stdout, &newHostSetResult)
|
||||
require.NoError(t, err)
|
||||
newHostSetId := newHostSetResult.Item.Id
|
||||
t.Cleanup(func() {
|
||||
output := e2e.RunCommand("boundary", "host-sets", "delete", "-id", newHostSetId)
|
||||
require.NoError(t, output.Err, string(output.Stderr))
|
||||
})
|
||||
t.Logf("Created Host Set: %s", newHostSetId)
|
||||
|
||||
// Create a host
|
||||
output = e2e.RunCommand("boundary", "hosts", "create", "static",
|
||||
"-host-catalog-id", newHostCatalogId,
|
||||
"-name", c.TargetIp,
|
||||
"-address", c.TargetIp,
|
||||
"-format", "json",
|
||||
)
|
||||
require.NoError(t, output.Err, string(output.Stderr))
|
||||
var newHostResult hosts.HostCreateResult
|
||||
err = json.Unmarshal(output.Stdout, &newHostResult)
|
||||
require.NoError(t, err)
|
||||
newHostId := newHostResult.Item.Id
|
||||
t.Cleanup(func() {
|
||||
output := e2e.RunCommand("boundary", "hosts", "delete", "-id", newHostId)
|
||||
require.NoError(t, output.Err, string(output.Stderr))
|
||||
})
|
||||
t.Logf("Created Host: %s", newHostId)
|
||||
|
||||
// Add host to host set
|
||||
output = e2e.RunCommand("boundary", "host-sets", "add-hosts", "-id", newHostSetId, "-host", newHostId)
|
||||
require.NoError(t, output.Err, string(output.Stderr))
|
||||
|
||||
// Create a target
|
||||
output = e2e.RunCommand("boundary", "targets", "create", "tcp",
|
||||
"-scope-id", newProjectId,
|
||||
"-default-port", c.TargetPort,
|
||||
"-name", "e2e Automated Test Target",
|
||||
"-format", "json",
|
||||
)
|
||||
require.NoError(t, output.Err, string(output.Stderr))
|
||||
var newTargetResult targets.TargetCreateResult
|
||||
err = json.Unmarshal(output.Stdout, &newTargetResult)
|
||||
require.NoError(t, err)
|
||||
newTargetId := newTargetResult.Item.Id
|
||||
t.Cleanup(func() {
|
||||
output := e2e.RunCommand("boundary", "targets", "delete", "-id", newTargetId)
|
||||
require.NoError(t, output.Err, string(output.Stderr))
|
||||
})
|
||||
t.Logf("Created Target: %s", newTargetId)
|
||||
|
||||
// Add host set to target
|
||||
output = e2e.RunCommand("boundary", "targets", "add-host-sources",
|
||||
"-id", newTargetId,
|
||||
"-host-source", newHostSetId,
|
||||
)
|
||||
require.NoError(t, output.Err, string(output.Stderr))
|
||||
newHostCatalogId := boundary.CreateNewHostCatalogCli(t, newProjectId)
|
||||
newHostSetId := boundary.CreateNewHostSetCli(t, newHostCatalogId)
|
||||
newHostId := boundary.CreateNewHostCli(t, newHostCatalogId, c.TargetIp)
|
||||
boundary.AddHostToHostSetCli(t, newHostSetId, newHostId)
|
||||
newTargetId := boundary.CreateNewTargetCli(t, newProjectId, c.TargetPort)
|
||||
boundary.AddHostSourceToTargetCli(t, newTargetId, newHostSetId)
|
||||
|
||||
// Connect to target and print host's IP address
|
||||
output = e2e.RunCommand("boundary", "connect",
|
||||
output := e2e.RunCommand("boundary", "connect",
|
||||
"-target-id", newTargetId,
|
||||
"-exec", "/usr/bin/ssh", "--",
|
||||
"-l", c.TargetSshUser,
|
||||
@@ -140,77 +57,16 @@ func TestCreateTargetApi(t *testing.T) {
|
||||
c, err := loadConfig()
|
||||
require.NoError(t, err)
|
||||
|
||||
// Create boundary api client
|
||||
client, err := boundary.NewApiClient()
|
||||
require.NoError(t, err)
|
||||
ctx := context.Background()
|
||||
|
||||
// Create an org and project
|
||||
newOrgId := boundary.CreateNewOrgApi(t, ctx, client)
|
||||
newProjectId := boundary.CreateNewProjectApi(t, ctx, client, newOrgId)
|
||||
|
||||
// Create a host catalog
|
||||
hcClient := hostcatalogs.NewClient(client)
|
||||
newHostCatalogResult, err := hcClient.Create(ctx, "static", newProjectId,
|
||||
hostcatalogs.WithName("e2e Automated Test Host Catalog"),
|
||||
)
|
||||
require.NoError(t, err)
|
||||
newHostCatalogId := newHostCatalogResult.Item.Id
|
||||
t.Cleanup(func() {
|
||||
_, err := hcClient.Delete(ctx, newHostCatalogId)
|
||||
require.NoError(t, err)
|
||||
})
|
||||
t.Logf("Created Host Catalog: %s", newHostCatalogId)
|
||||
|
||||
// Create a host set and add to catalog
|
||||
hsClient := hostsets.NewClient(client)
|
||||
newHostSetResult, err := hsClient.Create(ctx, newHostCatalogId)
|
||||
require.NoError(t, err)
|
||||
newHostSetId := newHostSetResult.Item.Id
|
||||
t.Cleanup(func() {
|
||||
_, err := hsClient.Delete(ctx, newHostSetId)
|
||||
require.NoError(t, err)
|
||||
})
|
||||
t.Logf("Created Host Set: %s", newHostSetId)
|
||||
|
||||
// Create a host
|
||||
hClient := hosts.NewClient(client)
|
||||
newHostResult, err := hClient.Create(ctx, newHostCatalogId,
|
||||
hosts.WithName(c.TargetIp),
|
||||
hosts.WithStaticHostAddress(c.TargetIp),
|
||||
)
|
||||
require.NoError(t, err)
|
||||
newHostId := newHostResult.Item.Id
|
||||
t.Cleanup(func() {
|
||||
_, err := hClient.Delete(ctx, newHostId)
|
||||
require.NoError(t, err)
|
||||
})
|
||||
t.Logf("Created Host: %s", newHostId)
|
||||
|
||||
// Add host to host set
|
||||
_, err = hsClient.AddHosts(ctx, newHostSetId, 0, []string{newHostId}, hostsets.WithAutomaticVersioning(true))
|
||||
require.NoError(t, err)
|
||||
|
||||
// Create a target
|
||||
tClient := targets.NewClient(client)
|
||||
targetPort, err := strconv.ParseInt(c.TargetPort, 10, 32)
|
||||
require.NoError(t, err)
|
||||
newTargetResult, err := tClient.Create(ctx, "tcp", newProjectId,
|
||||
targets.WithName("e2e Automated Test Target"),
|
||||
targets.WithTcpTargetDefaultPort(uint32(targetPort)),
|
||||
)
|
||||
require.NoError(t, err)
|
||||
newTargetId := newTargetResult.Item.Id
|
||||
t.Cleanup(func() {
|
||||
_, err := tClient.Delete(ctx, newTargetId)
|
||||
require.NoError(t, err)
|
||||
})
|
||||
t.Logf("Created Target: %s", newTargetId)
|
||||
|
||||
// Add host set to target
|
||||
_, err = tClient.AddHostSources(ctx, newTargetId, 0,
|
||||
[]string{newHostSetId},
|
||||
targets.WithAutomaticVersioning(true),
|
||||
)
|
||||
require.NoError(t, err)
|
||||
newHostCatalogId := boundary.CreateNewHostCatalogApi(t, ctx, client, newProjectId)
|
||||
newHostSetId := boundary.CreateNewHostSetApi(t, ctx, client, newHostCatalogId)
|
||||
newHostId := boundary.CreateNewHostApi(t, ctx, client, newHostCatalogId, c.TargetIp)
|
||||
boundary.AddHostToHostSetApi(t, ctx, client, newHostSetId, newHostId)
|
||||
newTargetId := boundary.CreateNewTargetApi(t, ctx, client, newProjectId, c.TargetPort)
|
||||
boundary.AddHostSourceToTargetApi(t, ctx, client, newTargetId, newHostSetId)
|
||||
}
|
||||
Reference in new issue
Block a user