refact(e2e): Create credential store function

pull/2549/head
Michael Li 4 years ago
parent ab223493a3
commit 79bc3d4878

@ -0,0 +1,41 @@
package boundary
import (
"context"
"encoding/json"
"testing"
"github.com/hashicorp/boundary/api"
"github.com/hashicorp/boundary/api/credentialstores"
"github.com/hashicorp/boundary/testing/internal/e2e"
"github.com/stretchr/testify/require"
)
// CreateNewCredentialStoreStaticApi creates a new static credential store using the go api.
// Returns the id of the new credential store
func CreateNewCredentialStoreStaticApi(t testing.TB, ctx context.Context, client *api.Client, projectId string) string {
csClient := credentialstores.NewClient(client)
newCredentialStoreResult, err := csClient.Create(ctx, "static", projectId, credentialstores.WithName("e2e Credential Store"))
require.NoError(t, err)
newCredentialStoreId := newCredentialStoreResult.Item.Id
t.Logf("Created Credential Store: %s", newCredentialStoreId)
return newCredentialStoreId
}
// CreateNewCredentialStoreStaticCli creates a new static credential store using the cli.
// Returns the id of the new credential store
func CreateNewCredentialStoreStaticCli(t testing.TB, projectId string) string {
output := e2e.RunCommand(context.Background(), "boundary", "credential-stores", "create", "static",
"-scope-id", projectId,
"-format", "json",
)
require.NoError(t, output.Err, string(output.Stderr))
var newCredentialStoreResult credentialstores.CredentialStoreCreateResult
err := json.Unmarshal(output.Stdout, &newCredentialStoreResult)
require.NoError(t, err)
newCredentialStoreId := newCredentialStoreResult.Item.Id
t.Logf("Created Credential Store: %s", newCredentialStoreId)
return newCredentialStoreId
}

@ -17,9 +17,7 @@ import (
// 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"),
)
newHostCatalogResult, err := hcClient.Create(ctx, "static", projectId, hostcatalogs.WithName("e2e Host Catalog"))
require.NoError(t, err)
newHostCatalogId := newHostCatalogResult.Item.Id
t.Logf("Created Host Catalog: %s", newHostCatalogId)
@ -31,7 +29,7 @@ func CreateNewHostCatalogApi(t testing.TB, ctx context.Context, client *api.Clie
// 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)
newHostSetResult, err := hsClient.Create(ctx, hostCatalogId, hostsets.WithName("e2e Host"))
require.NoError(t, err)
newHostSetId := newHostSetResult.Item.Id
t.Logf("Created Host Set: %s", newHostSetId)
@ -66,7 +64,7 @@ func AddHostToHostSetApi(t testing.TB, ctx context.Context, client *api.Client,
func CreateNewHostCatalogCli(t testing.TB, projectId string) string {
output := e2e.RunCommand(context.Background(), "boundary", "host-catalogs", "create", "static",
"-scope-id", projectId,
"-name", "e2e Automated Test Host Catalog",
"-name", "e2e Host Catalog",
"-format", "json",
)
require.NoError(t, output.Err, string(output.Stderr))
@ -84,7 +82,7 @@ func CreateNewHostCatalogCli(t testing.TB, projectId string) string {
func CreateNewHostSetCli(t testing.TB, hostCatalogId string) string {
output := e2e.RunCommand(context.Background(), "boundary", "host-sets", "create", "static",
"-host-catalog-id", hostCatalogId,
"-name", "e2e Automated Test Host Set",
"-name", "e2e Host Set",
"-format", "json",
)
require.NoError(t, output.Err, string(output.Stderr))

@ -15,7 +15,7 @@ import (
// Returns the id of the new org.
func CreateNewOrgApi(t testing.TB, ctx context.Context, client *api.Client) string {
scopeClient := scopes.NewClient(client)
newOrgResult, err := scopeClient.Create(ctx, "global", scopes.WithName("e2e Automated Test Org"))
newOrgResult, err := scopeClient.Create(ctx, "global", scopes.WithName("e2e Org"))
require.NoError(t, err)
newOrgId := newOrgResult.Item.Id
@ -33,7 +33,7 @@ func CreateNewOrgApi(t testing.TB, ctx context.Context, client *api.Client) stri
// Returns the id of the new project.
func CreateNewProjectApi(t testing.TB, ctx context.Context, client *api.Client, orgId string) string {
scopeClient := scopes.NewClient(client)
newProjResult, err := scopeClient.Create(ctx, orgId, scopes.WithName("e2e Automated Test Project"))
newProjResult, err := scopeClient.Create(ctx, orgId, scopes.WithName("e2e Project"))
require.NoError(t, err)
newProjectId := newProjResult.Item.Id
@ -46,7 +46,7 @@ func CreateNewProjectApi(t testing.TB, ctx context.Context, client *api.Client,
func CreateNewOrgCli(t testing.TB) string {
ctx := context.Background()
output := e2e.RunCommand(ctx, "boundary", "scopes", "create",
"-name", "e2e Automated Test Org",
"-name", "e2e Org",
"-scope-id", "global",
"-format", "json",
)
@ -72,7 +72,7 @@ func CreateNewOrgCli(t testing.TB) string {
func CreateNewProjectCli(t testing.TB, orgId string) string {
ctx := context.Background()
output := e2e.RunCommand(ctx, "boundary", "scopes", "create",
"-name", "e2e Automated Test Project",
"-name", "e2e Project",
"-scope-id", orgId,
"-format", "json",
)

@ -19,7 +19,7 @@ func CreateNewTargetApi(t testing.TB, ctx context.Context, client *api.Client, p
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.WithName("e2e Target"),
targets.WithTcpTargetDefaultPort(uint32(targetPort)),
)
require.NoError(t, err)
@ -45,7 +45,7 @@ func CreateNewTargetCli(t testing.TB, projectId string, defaultPort string) stri
output := e2e.RunCommand(context.Background(), "boundary", "targets", "create", "tcp",
"-scope-id", projectId,
"-default-port", defaultPort,
"-name", "e2e Automated Test Target",
"-name", "e2e Target",
"-format", "json",
)
require.NoError(t, output.Err, string(output.Stderr))

@ -9,7 +9,6 @@ import (
"testing"
"github.com/hashicorp/boundary/api/credentials"
"github.com/hashicorp/boundary/api/credentialstores"
"github.com/hashicorp/boundary/api/targets"
"github.com/hashicorp/boundary/testing/internal/e2e"
"github.com/hashicorp/boundary/testing/internal/e2e/boundary"
@ -33,22 +32,11 @@ func TestConnectTargetWithAuthzTokenCli(t *testing.T) {
boundary.AddHostToHostSetCli(t, newHostSetId, newHostId)
newTargetId := boundary.CreateNewTargetCli(t, newProjectId, c.TargetPort)
boundary.AddHostSourceToTargetCli(t, newTargetId, newHostSetId)
// Create a credential store
ctx := context.Background()
output := e2e.RunCommand(ctx, "boundary", "credential-stores", "create", "static",
"-scope-id", newProjectId,
"-format", "json",
)
require.NoError(t, output.Err, string(output.Stderr))
var newCredentialStoreResult credentialstores.CredentialStoreCreateResult
err = json.Unmarshal(output.Stdout, &newCredentialStoreResult)
require.NoError(t, err)
newCredentialStoreId := newCredentialStoreResult.Item.Id
t.Logf("Created Credential Store: %s", newCredentialStoreId)
newCredentialStoreId := boundary.CreateNewCredentialStoreStaticCli(t, newProjectId)
// Create credentials
output = e2e.RunCommand(ctx, "boundary", "credentials", "create", "ssh-private-key",
ctx := context.Background()
output := e2e.RunCommand(ctx, "boundary", "credentials", "create", "ssh-private-key",
"-credential-store-id", newCredentialStoreId,
"-username", c.TargetSshUser,
"-private-key", "file://"+c.TargetSshKeyPath,

@ -8,7 +8,6 @@ import (
"testing"
"github.com/hashicorp/boundary/api/credentials"
"github.com/hashicorp/boundary/api/credentialstores"
"github.com/hashicorp/boundary/api/targets"
"github.com/hashicorp/boundary/testing/internal/e2e"
"github.com/hashicorp/boundary/testing/internal/e2e/boundary"
@ -33,22 +32,11 @@ func TestConnectTargetWithSshCli(t *testing.T) {
boundary.AddHostToHostSetCli(t, newHostSetId, newHostId)
newTargetId := boundary.CreateNewTargetCli(t, newProjectId, c.TargetPort)
boundary.AddHostSourceToTargetCli(t, newTargetId, newHostSetId)
// Create a credential store
ctx := context.Background()
output := e2e.RunCommand(ctx, "boundary", "credential-stores", "create", "static",
"-scope-id", newProjectId,
"-format", "json",
)
require.NoError(t, output.Err, string(output.Stderr))
var newCredentialStoreResult credentialstores.CredentialStoreCreateResult
err = json.Unmarshal(output.Stdout, &newCredentialStoreResult)
require.NoError(t, err)
newCredentialStoreId := newCredentialStoreResult.Item.Id
t.Logf("Created Credential Store: %s", newCredentialStoreId)
newCredentialStoreId := boundary.CreateNewCredentialStoreStaticCli(t, newProjectId)
// Create credentials
output = e2e.RunCommand(ctx, "boundary", "credentials", "create", "ssh-private-key",
ctx := context.Background()
output := e2e.RunCommand(ctx, "boundary", "credentials", "create", "ssh-private-key",
"-credential-store-id", newCredentialStoreId,
"-username", c.TargetSshUser,
"-private-key", "file://"+c.TargetSshKeyPath,
@ -115,13 +103,7 @@ func TestCreateTargetWithStaticCredentialStoreApi(t *testing.T) {
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)
newCredentialStoreResult, err := csClient.Create(ctx, "static", newProjectId)
require.NoError(t, err)
newCredentialStoreId := newCredentialStoreResult.Item.Id
t.Logf("Created Credential Store: %s", newCredentialStoreId)
newCredentialStoreId := boundary.CreateNewCredentialStoreStaticApi(t, ctx, client, newProjectId)
// Create credentials
cClient := credentials.NewClient(client)

Loading…
Cancel
Save