refact(e2e): Add WithEnv option to RunCommand
This was done to keep the scope of environment variables to just the command execution
This commit is contained in:
1 parent
1cc2b0b820
commit
a956e8dec9
17 files changed
+487
-266
No files matched your search
@@ -3,7 +3,6 @@ package boundary
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
"github.com/hashicorp/boundary/api"
|
||||
@@ -47,14 +46,17 @@ func CreateNewAccountCli(t testing.TB, loginName string) (string, string) {
|
||||
ctx := context.Background()
|
||||
password, err := base62.Random(16)
|
||||
require.NoError(t, err)
|
||||
os.Setenv("E2E_TEST_ACCOUNT_PASSWORD", password)
|
||||
output := e2e.RunCommand(ctx, "boundary", "accounts", "create", "password",
|
||||
"-auth-method-id", c.AuthMethodId,
|
||||
"-login-name", loginName,
|
||||
"-password", "env://E2E_TEST_ACCOUNT_PASSWORD",
|
||||
"-name", "e2e Account "+loginName,
|
||||
"-description", "e2e Account",
|
||||
"-format", "json",
|
||||
output := e2e.RunCommand(ctx, "boundary",
|
||||
e2e.WithArgs(
|
||||
"accounts", "create", "password",
|
||||
"-auth-method-id", c.AuthMethodId,
|
||||
"-login-name", loginName,
|
||||
"-password", "env://E2E_TEST_ACCOUNT_PASSWORD",
|
||||
"-name", "e2e Account "+loginName,
|
||||
"-description", "e2e Account",
|
||||
"-format", "json",
|
||||
),
|
||||
e2e.WithEnv("E2E_TEST_ACCOUNT_PASSWORD", password),
|
||||
)
|
||||
require.NoError(t, output.Err, string(output.Stderr))
|
||||
|
||||
@@ -65,7 +67,9 @@ func CreateNewAccountCli(t testing.TB, loginName string) (string, string) {
|
||||
newAccountId := newAccountResult.Item.Id
|
||||
t.Cleanup(func() {
|
||||
AuthenticateAdminCli(t)
|
||||
output := e2e.RunCommand(ctx, "boundary", "accounts", "delete", "-id", newAccountId)
|
||||
output := e2e.RunCommand(ctx, "boundary",
|
||||
e2e.WithArgs("accounts", "delete", "-id", newAccountId),
|
||||
)
|
||||
require.NoError(t, output.Err, string(output.Stderr))
|
||||
})
|
||||
|
||||
|
||||
@@ -4,7 +4,6 @@ package boundary
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
"github.com/hashicorp/boundary/api"
|
||||
@@ -73,12 +72,15 @@ func AuthenticateCli(t testing.TB, loginName string, password string) {
|
||||
c, err := loadConfig()
|
||||
require.NoError(t, err)
|
||||
|
||||
os.Setenv("E2E_TEST_BOUNDARY_PASSWORD", password)
|
||||
output := e2e.RunCommand(context.Background(), "boundary", "authenticate", "password",
|
||||
"-addr", c.Address,
|
||||
"-auth-method-id", c.AuthMethodId,
|
||||
"-login-name", loginName,
|
||||
"-password", "env://E2E_TEST_BOUNDARY_PASSWORD",
|
||||
output := e2e.RunCommand(context.Background(), "boundary",
|
||||
e2e.WithArgs(
|
||||
"authenticate", "password",
|
||||
"-addr", c.Address,
|
||||
"-auth-method-id", c.AuthMethodId,
|
||||
"-login-name", loginName,
|
||||
"-password", "env://E2E_TEST_BOUNDARY_PASSWORD",
|
||||
),
|
||||
e2e.WithEnv("E2E_TEST_BOUNDARY_PASSWORD", password),
|
||||
)
|
||||
require.NoError(t, output.Err, string(output.Stderr))
|
||||
}
|
||||
@@ -26,9 +26,12 @@ func CreateNewCredentialStoreStaticApi(t testing.TB, ctx context.Context, client
|
||||
// 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",
|
||||
output := e2e.RunCommand(context.Background(), "boundary",
|
||||
e2e.WithArgs(
|
||||
"credential-stores", "create", "static",
|
||||
"-scope-id", projectId,
|
||||
"-format", "json",
|
||||
),
|
||||
)
|
||||
require.NoError(t, output.Err, string(output.Stderr))
|
||||
var newCredentialStoreResult credentialstores.CredentialStoreCreateResult
|
||||
|
||||
@@ -62,10 +62,13 @@ func AddHostToHostSetApi(t testing.TB, ctx context.Context, client *api.Client,
|
||||
// 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(context.Background(), "boundary", "host-catalogs", "create", "static",
|
||||
"-scope-id", projectId,
|
||||
"-name", "e2e Host Catalog",
|
||||
"-format", "json",
|
||||
output := e2e.RunCommand(context.Background(), "boundary",
|
||||
e2e.WithArgs(
|
||||
"host-catalogs", "create", "static",
|
||||
"-scope-id", projectId,
|
||||
"-name", "e2e Host Catalog",
|
||||
"-format", "json",
|
||||
),
|
||||
)
|
||||
require.NoError(t, output.Err, string(output.Stderr))
|
||||
var newHostCatalogResult hostcatalogs.HostCatalogCreateResult
|
||||
@@ -80,10 +83,13 @@ func CreateNewHostCatalogCli(t testing.TB, projectId string) string {
|
||||
// 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(context.Background(), "boundary", "host-sets", "create", "static",
|
||||
"-host-catalog-id", hostCatalogId,
|
||||
"-name", "e2e Host Set",
|
||||
"-format", "json",
|
||||
output := e2e.RunCommand(context.Background(), "boundary",
|
||||
e2e.WithArgs(
|
||||
"host-sets", "create", "static",
|
||||
"-host-catalog-id", hostCatalogId,
|
||||
"-name", "e2e Host Set",
|
||||
"-format", "json",
|
||||
),
|
||||
)
|
||||
require.NoError(t, output.Err, string(output.Stderr))
|
||||
var newHostSetResult hostsets.HostSetCreateResult
|
||||
@@ -98,11 +104,14 @@ func CreateNewHostSetCli(t testing.TB, hostCatalogId string) string {
|
||||
// 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(context.Background(), "boundary", "hosts", "create", "static",
|
||||
"-host-catalog-id", hostCatalogId,
|
||||
"-name", address,
|
||||
"-address", address,
|
||||
"-format", "json",
|
||||
output := e2e.RunCommand(context.Background(), "boundary",
|
||||
e2e.WithArgs(
|
||||
"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
|
||||
@@ -116,6 +125,8 @@ func CreateNewHostCli(t testing.TB, hostCatalogId string, address string) string
|
||||
|
||||
// AddHostToHostSetCli adds a host to a host set using the cli
|
||||
func AddHostToHostSetCli(t testing.TB, hostSetId string, hostId string) {
|
||||
output := e2e.RunCommand(context.Background(), "boundary", "host-sets", "add-hosts", "-id", hostSetId, "-host", hostId)
|
||||
output := e2e.RunCommand(context.Background(), "boundary",
|
||||
e2e.WithArgs("host-sets", "add-hosts", "-id", hostSetId, "-host", hostId),
|
||||
)
|
||||
require.NoError(t, output.Err, string(output.Stderr))
|
||||
}
|
||||
@@ -45,10 +45,13 @@ func CreateNewProjectApi(t testing.TB, ctx context.Context, client *api.Client,
|
||||
// Returns the id of the new org.
|
||||
func CreateNewOrgCli(t testing.TB) string {
|
||||
ctx := context.Background()
|
||||
output := e2e.RunCommand(ctx, "boundary", "scopes", "create",
|
||||
"-name", "e2e Org",
|
||||
"-scope-id", "global",
|
||||
"-format", "json",
|
||||
output := e2e.RunCommand(ctx, "boundary",
|
||||
e2e.WithArgs(
|
||||
"scopes", "create",
|
||||
"-name", "e2e Org",
|
||||
"-scope-id", "global",
|
||||
"-format", "json",
|
||||
),
|
||||
)
|
||||
require.NoError(t, output.Err, string(output.Stderr))
|
||||
|
||||
@@ -59,7 +62,9 @@ func CreateNewOrgCli(t testing.TB) string {
|
||||
newOrgId := newOrgResult.Item.Id
|
||||
t.Cleanup(func() {
|
||||
AuthenticateAdminCli(t)
|
||||
output := e2e.RunCommand(ctx, "boundary", "scopes", "delete", "-id", newOrgId)
|
||||
output := e2e.RunCommand(ctx, "boundary",
|
||||
e2e.WithArgs("scopes", "delete", "-id", newOrgId),
|
||||
)
|
||||
require.NoError(t, output.Err, string(output.Stderr))
|
||||
})
|
||||
|
||||
@@ -72,10 +77,13 @@ func CreateNewOrgCli(t testing.TB) string {
|
||||
// Returns the id of the new project.
|
||||
func CreateNewProjectCli(t testing.TB, orgId string) string {
|
||||
ctx := context.Background()
|
||||
output := e2e.RunCommand(ctx, "boundary", "scopes", "create",
|
||||
"-name", "e2e Project",
|
||||
"-scope-id", orgId,
|
||||
"-format", "json",
|
||||
output := e2e.RunCommand(ctx, "boundary",
|
||||
e2e.WithArgs(
|
||||
"scopes", "create",
|
||||
"-name", "e2e Project",
|
||||
"-scope-id", orgId,
|
||||
"-format", "json",
|
||||
),
|
||||
)
|
||||
require.NoError(t, output.Err, string(output.Stderr))
|
||||
|
||||
|
||||
@@ -42,11 +42,14 @@ func AddHostSourceToTargetApi(t testing.TB, ctx context.Context, client *api.Cli
|
||||
// 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(context.Background(), "boundary", "targets", "create", "tcp",
|
||||
"-scope-id", projectId,
|
||||
"-default-port", defaultPort,
|
||||
"-name", "e2e Target",
|
||||
"-format", "json",
|
||||
output := e2e.RunCommand(context.Background(), "boundary",
|
||||
e2e.WithArgs(
|
||||
"targets", "create", "tcp",
|
||||
"-scope-id", projectId,
|
||||
"-default-port", defaultPort,
|
||||
"-name", "e2e Target",
|
||||
"-format", "json",
|
||||
),
|
||||
)
|
||||
require.NoError(t, output.Err, string(output.Stderr))
|
||||
var newTargetResult targets.TargetCreateResult
|
||||
@@ -60,9 +63,8 @@ func CreateNewTargetCli(t testing.TB, projectId string, defaultPort string) stri
|
||||
|
||||
// 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(context.Background(), "boundary", "targets", "add-host-sources",
|
||||
"-id", targetId,
|
||||
"-host-source", hostSourceId,
|
||||
output := e2e.RunCommand(context.Background(), "boundary",
|
||||
e2e.WithArgs("targets", "add-host-sources", "-id", targetId, "-host-source", hostSourceId),
|
||||
)
|
||||
require.NoError(t, output.Err, string(output.Stderr))
|
||||
}
|
||||
@@ -31,11 +31,14 @@ func CreateNewUserApi(t testing.TB, ctx context.Context, client *api.Client, sco
|
||||
// Returns the id of the new user
|
||||
func CreateNewUserCli(t testing.TB, scopeId string) string {
|
||||
ctx := context.Background()
|
||||
output := e2e.RunCommand(ctx, "boundary", "users", "create",
|
||||
"-scope-id", scopeId,
|
||||
"-name", "e2e User",
|
||||
"-description", "e2e User",
|
||||
"-format", "json",
|
||||
output := e2e.RunCommand(ctx, "boundary",
|
||||
e2e.WithArgs(
|
||||
"users", "create",
|
||||
"-scope-id", scopeId,
|
||||
"-name", "e2e User",
|
||||
"-description", "e2e User",
|
||||
"-format", "json",
|
||||
),
|
||||
)
|
||||
require.NoError(t, output.Err, string(output.Stderr))
|
||||
|
||||
@@ -46,7 +49,9 @@ func CreateNewUserCli(t testing.TB, scopeId string) string {
|
||||
newUserId := newUserResult.Item.Id
|
||||
t.Cleanup(func() {
|
||||
AuthenticateAdminCli(t)
|
||||
output := e2e.RunCommand(ctx, "boundary", "users", "delete", "-id", newUserId)
|
||||
output := e2e.RunCommand(ctx, "boundary",
|
||||
e2e.WithArgs("users", "delete", "-id", newUserId),
|
||||
)
|
||||
require.NoError(t, output.Err, string(output.Stderr))
|
||||
})
|
||||
t.Logf("Created User: %s", newUserId)
|
||||
@@ -56,9 +61,12 @@ func CreateNewUserCli(t testing.TB, scopeId string) string {
|
||||
|
||||
// SetAccountToUserCli sets an account to a the specified user using the cli.
|
||||
func SetAccountToUserCli(t testing.TB, userId string, accountId string) {
|
||||
output := e2e.RunCommand(context.Background(), "boundary", "users", "set-accounts",
|
||||
"-id", userId,
|
||||
"-account", accountId,
|
||||
output := e2e.RunCommand(context.Background(), "boundary",
|
||||
e2e.WithArgs(
|
||||
"users", "set-accounts",
|
||||
"-id", userId,
|
||||
"-account", accountId,
|
||||
),
|
||||
)
|
||||
require.NoError(t, output.Err, string(output.Stderr))
|
||||
}
|
||||
@@ -66,10 +66,14 @@ func TestCreateVaultCredentialStoreCli(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
vaultAddr, boundaryPolicyName := vault.Setup(t)
|
||||
|
||||
output := e2e.RunCommand(ctx, "vault", "secrets", "enable", "-path="+c.VaultSecretPath, "kv-v2")
|
||||
output := e2e.RunCommand(ctx, "vault",
|
||||
e2e.WithArgs("secrets", "enable", "-path="+c.VaultSecretPath, "kv-v2"),
|
||||
)
|
||||
require.NoError(t, output.Err, string(output.Stderr))
|
||||
t.Cleanup(func() {
|
||||
output := e2e.RunCommand(ctx, "vault", "secrets", "disable", c.VaultSecretPath)
|
||||
output := e2e.RunCommand(ctx, "vault",
|
||||
e2e.WithArgs("secrets", "disable", c.VaultSecretPath),
|
||||
)
|
||||
require.NoError(t, output.Err, string(output.Stderr))
|
||||
})
|
||||
|
||||
@@ -79,14 +83,17 @@ func TestCreateVaultCredentialStoreCli(t *testing.T) {
|
||||
t.Log("Created Vault Credential")
|
||||
|
||||
// Create vault token for boundary
|
||||
output = e2e.RunCommand(ctx, "vault", "token", "create",
|
||||
"-no-default-policy=true",
|
||||
"-policy="+boundaryPolicyName,
|
||||
"-policy="+credentialPolicyName,
|
||||
"-orphan=true",
|
||||
"-period=20m",
|
||||
"-renewable=true",
|
||||
"-format=json",
|
||||
output = e2e.RunCommand(ctx, "vault",
|
||||
e2e.WithArgs(
|
||||
"token", "create",
|
||||
"-no-default-policy=true",
|
||||
"-policy="+boundaryPolicyName,
|
||||
"-policy="+credentialPolicyName,
|
||||
"-orphan=true",
|
||||
"-period=20m",
|
||||
"-renewable=true",
|
||||
"-format=json",
|
||||
),
|
||||
)
|
||||
require.NoError(t, output.Err, string(output.Stderr))
|
||||
var tokenCreateResult createTokenResponse
|
||||
@@ -96,11 +103,14 @@ func TestCreateVaultCredentialStoreCli(t *testing.T) {
|
||||
t.Log("Created Vault Cred Store Token")
|
||||
|
||||
// Create a credential store
|
||||
output = e2e.RunCommand(ctx, "boundary", "credential-stores", "create", "vault",
|
||||
"-scope-id", newProjectId,
|
||||
"-vault-address", vaultAddr,
|
||||
"-vault-token", credStoreToken,
|
||||
"-format", "json",
|
||||
output = e2e.RunCommand(ctx, "boundary",
|
||||
e2e.WithArgs(
|
||||
"credential-stores", "create", "vault",
|
||||
"-scope-id", newProjectId,
|
||||
"-vault-address", vaultAddr,
|
||||
"-vault-token", credStoreToken,
|
||||
"-format", "json",
|
||||
),
|
||||
)
|
||||
require.NoError(t, output.Err, string(output.Stderr))
|
||||
var newCredentialStoreResult credentialstores.CredentialStoreCreateResult
|
||||
@@ -110,12 +120,15 @@ func TestCreateVaultCredentialStoreCli(t *testing.T) {
|
||||
t.Logf("Created Credential Store: %s", newCredentialStoreId)
|
||||
|
||||
// Create a credential library
|
||||
output = e2e.RunCommand(ctx, "boundary", "credential-libraries", "create", "vault",
|
||||
"-credential-store-id", newCredentialStoreId,
|
||||
"-vault-path", c.VaultSecretPath+"/data/"+secretName,
|
||||
"-name", "e2e Automated Test Vault Credential Library",
|
||||
"-credential-type", "ssh_private_key",
|
||||
"-format", "json",
|
||||
output = e2e.RunCommand(ctx, "boundary",
|
||||
e2e.WithArgs(
|
||||
"credential-libraries", "create", "vault",
|
||||
"-credential-store-id", newCredentialStoreId,
|
||||
"-vault-path", c.VaultSecretPath+"/data/"+secretName,
|
||||
"-name", "e2e Automated Test Vault Credential Library",
|
||||
"-credential-type", "ssh_private_key",
|
||||
"-format", "json",
|
||||
),
|
||||
)
|
||||
require.NoError(t, output.Err, string(output.Stderr))
|
||||
var newCredentialLibraryResult credentiallibraries.CredentialLibraryCreateResult
|
||||
@@ -125,14 +138,19 @@ func TestCreateVaultCredentialStoreCli(t *testing.T) {
|
||||
t.Logf("Created Credential Library: %s", newCredentialLibraryId)
|
||||
|
||||
// Add brokered credentials to target
|
||||
output = e2e.RunCommand(ctx, "boundary", "targets", "add-credential-sources",
|
||||
"-id", newTargetId,
|
||||
"-brokered-credential-source", newCredentialLibraryId,
|
||||
output = e2e.RunCommand(ctx, "boundary",
|
||||
e2e.WithArgs(
|
||||
"targets", "add-credential-sources",
|
||||
"-id", newTargetId,
|
||||
"-brokered-credential-source", newCredentialLibraryId,
|
||||
),
|
||||
)
|
||||
require.NoError(t, output.Err, string(output.Stderr))
|
||||
|
||||
// Get credentials for target
|
||||
output = e2e.RunCommand(ctx, "boundary", "targets", "authorize-session", "-id", newTargetId, "-format", "json")
|
||||
output = e2e.RunCommand(ctx, "boundary",
|
||||
e2e.WithArgs("targets", "authorize-session", "-id", newTargetId, "-format", "json"),
|
||||
)
|
||||
require.NoError(t, output.Err, string(output.Stderr))
|
||||
var newSessionAuthorizationResult targets.SessionAuthorizationResult
|
||||
err = json.Unmarshal(output.Stdout, &newSessionAuthorizationResult)
|
||||
@@ -158,17 +176,20 @@ func TestCreateVaultCredentialStoreCli(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
|
||||
// Connect to target and print host's IP address using retrieved credentials
|
||||
output = e2e.RunCommand(ctx, "boundary", "connect",
|
||||
"-target-id", newTargetId,
|
||||
"-exec", "/usr/bin/ssh", "--",
|
||||
"-l", retrievedUser,
|
||||
"-i", retrievedKeyPath,
|
||||
"-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",
|
||||
output = e2e.RunCommand(ctx, "boundary",
|
||||
e2e.WithArgs(
|
||||
"connect",
|
||||
"-target-id", newTargetId,
|
||||
"-exec", "/usr/bin/ssh", "--",
|
||||
"-l", retrievedUser,
|
||||
"-i", retrievedKeyPath,
|
||||
"-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",
|
||||
),
|
||||
)
|
||||
require.NoError(t, output.Err, string(output.Stderr))
|
||||
|
||||
@@ -202,10 +223,14 @@ func TestCreateVaultCredentialStoreApi(t *testing.T) {
|
||||
// Configure vault
|
||||
vaultAddr, boundaryPolicyName := vault.Setup(t)
|
||||
|
||||
output := e2e.RunCommand(ctx, "vault", "secrets", "enable", "-path="+c.VaultSecretPath, "kv-v2")
|
||||
output := e2e.RunCommand(ctx, "vault",
|
||||
e2e.WithArgs("secrets", "enable", "-path="+c.VaultSecretPath, "kv-v2"),
|
||||
)
|
||||
require.NoError(t, output.Err, string(output.Stderr))
|
||||
t.Cleanup(func() {
|
||||
output := e2e.RunCommand(ctx, "vault", "secrets", "disable", c.VaultSecretPath)
|
||||
output := e2e.RunCommand(ctx, "vault",
|
||||
e2e.WithArgs("secrets", "disable", c.VaultSecretPath),
|
||||
)
|
||||
require.NoError(t, output.Err, string(output.Stderr))
|
||||
})
|
||||
|
||||
@@ -215,14 +240,17 @@ func TestCreateVaultCredentialStoreApi(t *testing.T) {
|
||||
t.Log("Created Vault Credential")
|
||||
|
||||
// Create vault token for boundary
|
||||
output = e2e.RunCommand(ctx, "vault", "token", "create",
|
||||
"-no-default-policy=true",
|
||||
"-policy="+boundaryPolicyName,
|
||||
"-policy="+credentialPolicyName,
|
||||
"-orphan=true",
|
||||
"-period=20m",
|
||||
"-renewable=true",
|
||||
"-format=json",
|
||||
output = e2e.RunCommand(ctx, "vault",
|
||||
e2e.WithArgs(
|
||||
"token", "create",
|
||||
"-no-default-policy=true",
|
||||
"-policy="+boundaryPolicyName,
|
||||
"-policy="+credentialPolicyName,
|
||||
"-orphan=true",
|
||||
"-period=20m",
|
||||
"-renewable=true",
|
||||
"-format=json",
|
||||
),
|
||||
)
|
||||
require.NoError(t, output.Err, string(output.Stderr))
|
||||
var tokenCreateResult createTokenResponse
|
||||
|
||||
@@ -23,19 +23,59 @@ type CliError struct {
|
||||
Status int `json:"status"`
|
||||
}
|
||||
|
||||
// Option is a func that sets optional attributes for a call. This does not need
|
||||
// to be used directly, but instead option arguments are built from the
|
||||
// functions in this package. WithX options set a value to that given in the
|
||||
// argument; DefaultX options indicate that the value should be set to its
|
||||
// default. When an API call is made options are processed in ther order they
|
||||
// appear in the function call, so for a given argument X, a succession of WithX
|
||||
// or DefaultX calls will result in the last call taking effect.
|
||||
type Option func(*options)
|
||||
|
||||
type options struct {
|
||||
withArgs []string
|
||||
withEnv map[string]string
|
||||
}
|
||||
|
||||
func getOpts(opt ...Option) options {
|
||||
opts := options{}
|
||||
for _, o := range opt {
|
||||
if o != nil {
|
||||
o(&opts)
|
||||
}
|
||||
}
|
||||
|
||||
return opts
|
||||
}
|
||||
|
||||
const EnvToCheckSkip = "E2E_PASSWORD_AUTH_METHOD_ID"
|
||||
|
||||
// RunCommand executes external commands on the system. Returns the results
|
||||
// of running the provided command.
|
||||
//
|
||||
// RunCommand(context.Background(), "ls")
|
||||
// RunCommand(context.Background(), "ls", "-al", "/path")
|
||||
// RunCommand(context.Background(), "ls", WithArgs("-al", "/path"))
|
||||
//
|
||||
// CommandResult is always valid even if there is an error.
|
||||
func RunCommand(ctx context.Context, name string, args ...string) *CommandResult {
|
||||
func RunCommand(ctx context.Context, command string, opt ...Option) *CommandResult {
|
||||
var cmd *exec.Cmd
|
||||
var outbuf, errbuf bytes.Buffer
|
||||
|
||||
cmd := exec.CommandContext(ctx, name, args...)
|
||||
opts := getOpts(opt...)
|
||||
|
||||
if opts.withArgs == nil {
|
||||
cmd = exec.CommandContext(ctx, command)
|
||||
} else {
|
||||
cmd = exec.CommandContext(ctx, command, opts.withArgs...)
|
||||
}
|
||||
|
||||
if opts.withEnv != nil {
|
||||
cmd.Env = os.Environ()
|
||||
for k, v := range opts.withEnv {
|
||||
cmd.Env = append(cmd.Env, k+"="+v)
|
||||
}
|
||||
}
|
||||
|
||||
cmd.Stdout = &outbuf
|
||||
cmd.Stderr = &errbuf
|
||||
|
||||
@@ -55,6 +95,32 @@ func RunCommand(ctx context.Context, name string, args ...string) *CommandResult
|
||||
}
|
||||
}
|
||||
|
||||
// WithArgs is an option to RunCommand that allows the user to specify arguments
|
||||
// for the provided command. This option can be used multiple times in one command.
|
||||
func WithArgs(args ...string) Option {
|
||||
return func(o *options) {
|
||||
if o.withArgs == nil {
|
||||
o.withArgs = args
|
||||
} else {
|
||||
o.withArgs = append(o.withArgs, args...)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// WithEnv is an option to RunCommand that allows the user to specify environment variables
|
||||
// to be set when running the command. This option can be used multiple times in one command.
|
||||
//
|
||||
// RunCommand(context.Background(), "ls", WithEnv("NAME", "VALUE"), WithEnv("NAME", "VALUE"))
|
||||
func WithEnv(name string, value string) Option {
|
||||
return func(o *options) {
|
||||
if o.withEnv == nil {
|
||||
o.withEnv = map[string]string{name: value}
|
||||
} else {
|
||||
o.withEnv[name] = value
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// MaybeSkipTest is a check used at the start of the test to determine if the test should run
|
||||
func MaybeSkipTest(t testing.TB) {
|
||||
if _, ok := os.LookupEnv(EnvToCheckSkip); !ok {
|
||||
|
||||
@@ -56,14 +56,17 @@ func TestCreateAwsDynamicHostCatalogCli(t *testing.T) {
|
||||
|
||||
// Create a dynamic host catalog
|
||||
ctx := context.Background()
|
||||
output := e2e.RunCommand(ctx, "boundary", "host-catalogs", "create", "plugin",
|
||||
"-scope-id", newProjectId,
|
||||
"-plugin-name", "aws",
|
||||
"-attr", "disable_credential_rotation=true",
|
||||
"-attr", "region=us-east-1",
|
||||
"-secret", "access_key_id=env://E2E_AWS_ACCESS_KEY_ID",
|
||||
"-secret", "secret_access_key=env://E2E_AWS_SECRET_ACCESS_KEY",
|
||||
"-format", "json",
|
||||
output := e2e.RunCommand(ctx, "boundary",
|
||||
e2e.WithArgs(
|
||||
"host-catalogs", "create", "plugin",
|
||||
"-scope-id", newProjectId,
|
||||
"-plugin-name", "aws",
|
||||
"-attr", "disable_credential_rotation=true",
|
||||
"-attr", "region=us-east-1",
|
||||
"-secret", "access_key_id=env://E2E_AWS_ACCESS_KEY_ID",
|
||||
"-secret", "secret_access_key=env://E2E_AWS_SECRET_ACCESS_KEY",
|
||||
"-format", "json",
|
||||
),
|
||||
)
|
||||
require.NoError(t, output.Err, string(output.Stderr))
|
||||
var newHostCatalogResult hostcatalogs.HostCatalogCreateResult
|
||||
@@ -73,11 +76,14 @@ func TestCreateAwsDynamicHostCatalogCli(t *testing.T) {
|
||||
t.Logf("Created Host Catalog: %s", newHostCatalogId)
|
||||
|
||||
// Create a host set
|
||||
output = e2e.RunCommand(ctx, "boundary", "host-sets", "create", "plugin",
|
||||
"-host-catalog-id", newHostCatalogId,
|
||||
"-attr", "filters="+c.AwsHostSetFilter1,
|
||||
"-name", "e2e Automated Test Host Set",
|
||||
"-format", "json",
|
||||
output = e2e.RunCommand(ctx, "boundary",
|
||||
e2e.WithArgs(
|
||||
"host-sets", "create", "plugin",
|
||||
"-host-catalog-id", newHostCatalogId,
|
||||
"-attr", "filters="+c.AwsHostSetFilter1,
|
||||
"-name", "e2e Automated Test Host Set",
|
||||
"-format", "json",
|
||||
),
|
||||
)
|
||||
require.NoError(t, output.Err, string(output.Stderr))
|
||||
var newHostSetResult hostsets.HostSetCreateResult
|
||||
@@ -92,9 +98,12 @@ func TestCreateAwsDynamicHostCatalogCli(t *testing.T) {
|
||||
var actualHostSetCount1 int
|
||||
err = backoff.RetryNotify(
|
||||
func() error {
|
||||
output = e2e.RunCommand(ctx, "boundary", "host-sets", "read",
|
||||
"-id", newHostSetId1,
|
||||
"-format", "json",
|
||||
output = e2e.RunCommand(ctx, "boundary",
|
||||
e2e.WithArgs(
|
||||
"host-sets", "read",
|
||||
"-id", newHostSetId1,
|
||||
"-format", "json",
|
||||
),
|
||||
)
|
||||
if output.Err != nil {
|
||||
return backoff.Permanent(errors.New(string(output.Stderr)))
|
||||
@@ -128,11 +137,14 @@ func TestCreateAwsDynamicHostCatalogCli(t *testing.T) {
|
||||
assert.Equal(t, expectedHostSetCount1, actualHostSetCount1, "Numbers of hosts in host set did not match expected amount")
|
||||
|
||||
// Create another host set
|
||||
output = e2e.RunCommand(ctx, "boundary", "host-sets", "create", "plugin",
|
||||
"-host-catalog-id", newHostCatalogId,
|
||||
"-attr", "filters="+c.AwsHostSetFilter2,
|
||||
"-name", "e2e Automated Test Host Set2",
|
||||
"-format", "json",
|
||||
output = e2e.RunCommand(ctx, "boundary",
|
||||
e2e.WithArgs(
|
||||
"host-sets", "create", "plugin",
|
||||
"-host-catalog-id", newHostCatalogId,
|
||||
"-attr", "filters="+c.AwsHostSetFilter2,
|
||||
"-name", "e2e Automated Test Host Set2",
|
||||
"-format", "json",
|
||||
),
|
||||
)
|
||||
require.NoError(t, output.Err, string(output.Stderr))
|
||||
var newHostSetResult2 hostsets.HostSetCreateResult
|
||||
@@ -146,9 +158,8 @@ func TestCreateAwsDynamicHostCatalogCli(t *testing.T) {
|
||||
var actualHostSetCount2 int
|
||||
err = backoff.RetryNotify(
|
||||
func() error {
|
||||
output = e2e.RunCommand(ctx, "boundary", "host-sets", "read",
|
||||
"-id", newHostSetId2,
|
||||
"-format", "json",
|
||||
output = e2e.RunCommand(ctx, "boundary",
|
||||
e2e.WithArgs("host-sets", "read", "-id", newHostSetId2, "-format", "json"),
|
||||
)
|
||||
if output.Err != nil {
|
||||
return backoff.Permanent(errors.New(string(output.Stderr)))
|
||||
@@ -185,9 +196,8 @@ func TestCreateAwsDynamicHostCatalogCli(t *testing.T) {
|
||||
var actualHostCatalogCount int
|
||||
err = backoff.RetryNotify(
|
||||
func() error {
|
||||
output = e2e.RunCommand(ctx, "boundary", "hosts", "list",
|
||||
"-host-catalog-id", newHostCatalogId,
|
||||
"-format", "json",
|
||||
output = e2e.RunCommand(ctx, "boundary",
|
||||
e2e.WithArgs("hosts", "list", "-host-catalog-id", newHostCatalogId, "-format", "json"),
|
||||
)
|
||||
if output.Err != nil {
|
||||
return backoff.Permanent(errors.New(string(output.Stderr)))
|
||||
@@ -222,17 +232,20 @@ func TestCreateAwsDynamicHostCatalogCli(t *testing.T) {
|
||||
boundary.AddHostSourceToTargetCli(t, newTargetId, newHostSetId1)
|
||||
|
||||
// Connect to target
|
||||
output = e2e.RunCommand(ctx, "boundary", "connect",
|
||||
"-target-id", newTargetId,
|
||||
"-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",
|
||||
output = e2e.RunCommand(ctx, "boundary",
|
||||
e2e.WithArgs(
|
||||
"connect",
|
||||
"-target-id", newTargetId,
|
||||
"-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",
|
||||
),
|
||||
)
|
||||
require.NoError(t, output.Err, string(output.Stderr))
|
||||
|
||||
|
||||
@@ -36,11 +36,14 @@ func TestConnectTargetWithAuthzTokenCli(t *testing.T) {
|
||||
|
||||
// Create credentials
|
||||
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,
|
||||
"-format", "json",
|
||||
output := e2e.RunCommand(ctx, "boundary",
|
||||
e2e.WithArgs(
|
||||
"credentials", "create", "ssh-private-key",
|
||||
"-credential-store-id", newCredentialStoreId,
|
||||
"-username", c.TargetSshUser,
|
||||
"-private-key", "file://"+c.TargetSshKeyPath,
|
||||
"-format", "json",
|
||||
),
|
||||
)
|
||||
require.NoError(t, output.Err, string(output.Stderr))
|
||||
var newCredentialsResult credentials.CredentialCreateResult
|
||||
@@ -50,14 +53,19 @@ func TestConnectTargetWithAuthzTokenCli(t *testing.T) {
|
||||
t.Logf("Created Credentials: %s", newCredentialsId)
|
||||
|
||||
// Add credentials to target
|
||||
output = e2e.RunCommand(ctx, "boundary", "targets", "add-credential-sources",
|
||||
"-id", newTargetId,
|
||||
"-brokered-credential-source", newCredentialsId,
|
||||
output = e2e.RunCommand(ctx, "boundary",
|
||||
e2e.WithArgs(
|
||||
"targets", "add-credential-sources",
|
||||
"-id", newTargetId,
|
||||
"-brokered-credential-source", newCredentialsId,
|
||||
),
|
||||
)
|
||||
require.NoError(t, output.Err, string(output.Stderr))
|
||||
|
||||
// Get credentials for target
|
||||
output = e2e.RunCommand(ctx, "boundary", "targets", "authorize-session", "-id", newTargetId, "-format", "json")
|
||||
output = e2e.RunCommand(ctx, "boundary",
|
||||
e2e.WithArgs("targets", "authorize-session", "-id", newTargetId, "-format", "json"),
|
||||
)
|
||||
require.NoError(t, output.Err, string(output.Stderr))
|
||||
var newSessionAuthorizationResult targets.SessionAuthorizationResult
|
||||
err = json.Unmarshal(output.Stdout, &newSessionAuthorizationResult)
|
||||
@@ -86,17 +94,20 @@ func TestConnectTargetWithAuthzTokenCli(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
|
||||
// Connect to target and print host's IP address using retrieved credentials
|
||||
output = e2e.RunCommand(ctx, "boundary", "connect",
|
||||
"-authz-token", newAuthToken,
|
||||
"-exec", "/usr/bin/ssh", "--",
|
||||
"-l", retrievedUser,
|
||||
"-i", retrievedKeyPath,
|
||||
"-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",
|
||||
output = e2e.RunCommand(ctx, "boundary",
|
||||
e2e.WithArgs(
|
||||
"connect",
|
||||
"-authz-token", newAuthToken,
|
||||
"-exec", "/usr/bin/ssh", "--",
|
||||
"-l", retrievedUser,
|
||||
"-i", retrievedKeyPath,
|
||||
"-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",
|
||||
),
|
||||
)
|
||||
require.NoError(t, output.Err, string(output.Stderr))
|
||||
|
||||
|
||||
@@ -36,11 +36,14 @@ func TestConnectTargetWithSshCli(t *testing.T) {
|
||||
|
||||
// Create credentials
|
||||
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,
|
||||
"-format", "json",
|
||||
output := e2e.RunCommand(ctx, "boundary",
|
||||
e2e.WithArgs(
|
||||
"credentials", "create", "ssh-private-key",
|
||||
"-credential-store-id", newCredentialStoreId,
|
||||
"-username", c.TargetSshUser,
|
||||
"-private-key", "file://"+c.TargetSshKeyPath,
|
||||
"-format", "json",
|
||||
),
|
||||
)
|
||||
require.NoError(t, output.Err, string(output.Stderr))
|
||||
var newCredentialsResult credentials.CredentialCreateResult
|
||||
@@ -50,14 +53,19 @@ func TestConnectTargetWithSshCli(t *testing.T) {
|
||||
t.Logf("Created Credentials: %s", newCredentialsId)
|
||||
|
||||
// Add credentials to target
|
||||
output = e2e.RunCommand(ctx, "boundary", "targets", "add-credential-sources",
|
||||
"-id", newTargetId,
|
||||
"-brokered-credential-source", newCredentialsId,
|
||||
output = e2e.RunCommand(ctx, "boundary",
|
||||
e2e.WithArgs(
|
||||
"targets", "add-credential-sources",
|
||||
"-id", newTargetId,
|
||||
"-brokered-credential-source", newCredentialsId,
|
||||
),
|
||||
)
|
||||
require.NoError(t, output.Err, string(output.Stderr))
|
||||
|
||||
// Get credentials for target
|
||||
output = e2e.RunCommand(ctx, "boundary", "targets", "authorize-session", "-id", newTargetId, "-format", "json")
|
||||
output = e2e.RunCommand(ctx, "boundary",
|
||||
e2e.WithArgs("targets", "authorize-session", "-id", newTargetId, "-format", "json"),
|
||||
)
|
||||
require.NoError(t, output.Err, string(output.Stderr))
|
||||
var newSessionAuthorizationResult targets.SessionAuthorizationResult
|
||||
err = json.Unmarshal(output.Stdout, &newSessionAuthorizationResult)
|
||||
@@ -74,11 +82,14 @@ func TestConnectTargetWithSshCli(t *testing.T) {
|
||||
t.Log("Successfully retrieved credentials for target")
|
||||
|
||||
// Connect to target and print host's IP address using retrieved credentials
|
||||
output = e2e.RunCommand(ctx, "boundary", "connect", "ssh",
|
||||
"-target-id", newTargetId, "--",
|
||||
"-o", "UserKnownHostsFile=/dev/null",
|
||||
"-o", "StrictHostKeyChecking=no",
|
||||
"-o", "IdentitiesOnly=yes", // forces the use of the provided key
|
||||
output = e2e.RunCommand(ctx, "boundary",
|
||||
e2e.WithArgs(
|
||||
"connect", "ssh",
|
||||
"-target-id", newTargetId, "--",
|
||||
"-o", "UserKnownHostsFile=/dev/null",
|
||||
"-o", "StrictHostKeyChecking=no",
|
||||
"-o", "IdentitiesOnly=yes", // forces the use of the provided key
|
||||
),
|
||||
)
|
||||
require.NoError(t, output.Err, string(output.Stderr))
|
||||
t.Log("Successfully connected to target")
|
||||
|
||||
@@ -30,17 +30,20 @@ func TestConnectTargetCli(t *testing.T) {
|
||||
|
||||
// Connect to target and print host's IP address
|
||||
ctx := context.Background()
|
||||
output := e2e.RunCommand(ctx, "boundary", "connect",
|
||||
"-target-id", newTargetId,
|
||||
"-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",
|
||||
output := e2e.RunCommand(ctx, "boundary",
|
||||
e2e.WithArgs(
|
||||
"connect",
|
||||
"-target-id", newTargetId,
|
||||
"-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",
|
||||
),
|
||||
)
|
||||
require.NoError(t, output.Err, string(output.Stderr))
|
||||
|
||||
|
||||
@@ -36,17 +36,20 @@ func TestSessionCancelAdminCli(t *testing.T) {
|
||||
errChan := make(chan *e2e.CommandResult)
|
||||
go func() {
|
||||
t.Log("Starting session...")
|
||||
errChan <- e2e.RunCommand(ctxCancel, "boundary", "connect",
|
||||
"-target-id", newTargetId,
|
||||
"-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",
|
||||
errChan <- e2e.RunCommand(ctxCancel, "boundary",
|
||||
e2e.WithArgs(
|
||||
"connect",
|
||||
"-target-id", newTargetId,
|
||||
"-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)
|
||||
@@ -56,7 +59,9 @@ func TestSessionCancelAdminCli(t *testing.T) {
|
||||
var session *sessions.Session
|
||||
err = backoff.RetryNotify(
|
||||
func() error {
|
||||
output := e2e.RunCommand(ctx, "boundary", "sessions", "list", "-scope-id", newProjectId, "-format", "json")
|
||||
output := e2e.RunCommand(ctx, "boundary",
|
||||
e2e.WithArgs("sessions", "list", "-scope-id", newProjectId, "-format", "json"),
|
||||
)
|
||||
if output.Err != nil {
|
||||
return backoff.Permanent(errors.New(string(output.Stderr)))
|
||||
}
|
||||
@@ -91,10 +96,14 @@ func TestSessionCancelAdminCli(t *testing.T) {
|
||||
require.Equal(t, "active", session.Status)
|
||||
|
||||
// Cancel session
|
||||
output := e2e.RunCommand(ctx, "boundary", "sessions", "cancel", "-id", session.Id)
|
||||
output := e2e.RunCommand(ctx, "boundary",
|
||||
e2e.WithArgs("sessions", "cancel", "-id", session.Id),
|
||||
)
|
||||
require.NoError(t, output.Err, string(output.Stderr))
|
||||
|
||||
output = e2e.RunCommand(ctx, "boundary", "sessions", "read", "-id", session.Id, "-format", "json")
|
||||
output = e2e.RunCommand(ctx, "boundary",
|
||||
e2e.WithArgs("sessions", "read", "-id", session.Id, "-format", "json"),
|
||||
)
|
||||
require.NoError(t, output.Err, string(output.Stderr))
|
||||
var newSessionReadResult sessions.SessionReadResult
|
||||
err = json.Unmarshal(output.Stdout, &newSessionReadResult)
|
||||
|
||||
@@ -42,18 +42,21 @@ func TestSessionCancelUserCli(t *testing.T) {
|
||||
// Try to connect to the target as a user without permissions
|
||||
ctx := context.Background()
|
||||
boundary.AuthenticateCli(t, acctName, acctPassword)
|
||||
output := e2e.RunCommand(ctx, "boundary", "connect",
|
||||
"-target-id", newTargetId,
|
||||
"-format", "json",
|
||||
"-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",
|
||||
output := e2e.RunCommand(ctx, "boundary",
|
||||
e2e.WithArgs(
|
||||
"connect",
|
||||
"-target-id", newTargetId,
|
||||
"-format", "json",
|
||||
"-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",
|
||||
),
|
||||
)
|
||||
require.Error(t, output.Err, string(output.Stdout), string(output.Stderr))
|
||||
var response e2e.CliError
|
||||
@@ -64,10 +67,13 @@ func TestSessionCancelUserCli(t *testing.T) {
|
||||
|
||||
// Create a role
|
||||
boundary.AuthenticateAdminCli(t)
|
||||
output = e2e.RunCommand(ctx, "boundary", "roles", "create",
|
||||
"-scope-id", newProjectId,
|
||||
"-name", "e2e Role",
|
||||
"-format", "json",
|
||||
output = e2e.RunCommand(ctx, "boundary",
|
||||
e2e.WithArgs(
|
||||
"roles", "create",
|
||||
"-scope-id", newProjectId,
|
||||
"-name", "e2e Role",
|
||||
"-format", "json",
|
||||
),
|
||||
)
|
||||
require.NoError(t, output.Err, string(output.Stderr))
|
||||
var newRoleResult roles.RoleCreateResult
|
||||
@@ -77,16 +83,22 @@ func TestSessionCancelUserCli(t *testing.T) {
|
||||
t.Logf("Created Role: %s", newRoleId)
|
||||
|
||||
// Add grant to role
|
||||
output = e2e.RunCommand(ctx, "boundary", "roles", "add-grants",
|
||||
"-id", newRoleId,
|
||||
"-grant", "id=*;type=target;actions=authorize-session",
|
||||
output = e2e.RunCommand(ctx, "boundary",
|
||||
e2e.WithArgs(
|
||||
"roles", "add-grants",
|
||||
"-id", newRoleId,
|
||||
"-grant", "id=*;type=target;actions=authorize-session",
|
||||
),
|
||||
)
|
||||
require.NoError(t, output.Err, string(output.Stderr))
|
||||
|
||||
// Add user to role
|
||||
output = e2e.RunCommand(ctx, "boundary", "roles", "add-principals",
|
||||
"-id", newRoleId,
|
||||
"-principal", newUserId,
|
||||
output = e2e.RunCommand(ctx, "boundary",
|
||||
e2e.WithArgs(
|
||||
"roles", "add-principals",
|
||||
"-id", newRoleId,
|
||||
"-principal", newUserId,
|
||||
),
|
||||
)
|
||||
require.NoError(t, output.Err, string(output.Stderr))
|
||||
|
||||
@@ -96,17 +108,20 @@ func TestSessionCancelUserCli(t *testing.T) {
|
||||
go func() {
|
||||
boundary.AuthenticateCli(t, acctName, acctPassword)
|
||||
t.Log("Starting session as user...")
|
||||
errChan <- e2e.RunCommand(ctxCancel, "boundary", "connect",
|
||||
"-target-id", newTargetId,
|
||||
"-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",
|
||||
errChan <- e2e.RunCommand(ctxCancel, "boundary",
|
||||
e2e.WithArgs(
|
||||
"connect",
|
||||
"-target-id", newTargetId,
|
||||
"-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)
|
||||
@@ -115,7 +130,9 @@ func TestSessionCancelUserCli(t *testing.T) {
|
||||
var session *sessions.Session
|
||||
err = backoff.RetryNotify(
|
||||
func() error {
|
||||
output := e2e.RunCommand(ctx, "boundary", "sessions", "list", "-scope-id", newProjectId, "-format", "json")
|
||||
output := e2e.RunCommand(ctx, "boundary",
|
||||
e2e.WithArgs("sessions", "list", "-scope-id", newProjectId, "-format", "json"),
|
||||
)
|
||||
if output.Err != nil {
|
||||
return backoff.Permanent(errors.New(string(output.Stderr)))
|
||||
}
|
||||
@@ -150,10 +167,14 @@ func TestSessionCancelUserCli(t *testing.T) {
|
||||
require.Equal(t, "active", session.Status)
|
||||
|
||||
// Cancel session
|
||||
output = e2e.RunCommand(ctx, "boundary", "sessions", "cancel", "-id", session.Id)
|
||||
output = e2e.RunCommand(ctx, "boundary",
|
||||
e2e.WithArgs("sessions", "cancel", "-id", session.Id),
|
||||
)
|
||||
require.NoError(t, output.Err, string(output.Stderr))
|
||||
|
||||
output = e2e.RunCommand(ctx, "boundary", "sessions", "read", "-id", session.Id, "-format", "json")
|
||||
output = e2e.RunCommand(ctx, "boundary",
|
||||
e2e.WithArgs("sessions", "read", "-id", session.Id, "-format", "json"),
|
||||
)
|
||||
require.NoError(t, output.Err, string(output.Stderr))
|
||||
var newSessionReadResult sessions.SessionReadResult
|
||||
err = json.Unmarshal(output.Stdout, &newSessionReadResult)
|
||||
|
||||
@@ -4,7 +4,6 @@ import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"os"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
@@ -28,11 +27,14 @@ func TestStaticCredentialStoreCli(t *testing.T) {
|
||||
|
||||
// Create ssh key credentials
|
||||
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,
|
||||
"-format", "json",
|
||||
output := e2e.RunCommand(ctx, "boundary",
|
||||
e2e.WithArgs(
|
||||
"credentials", "create", "ssh-private-key",
|
||||
"-credential-store-id", newCredentialStoreId,
|
||||
"-username", c.TargetSshUser,
|
||||
"-private-key", "file://"+c.TargetSshKeyPath,
|
||||
"-format", "json",
|
||||
),
|
||||
)
|
||||
require.NoError(t, output.Err, string(output.Stderr))
|
||||
var keyCredentialsResult credentials.CredentialCreateResult
|
||||
@@ -42,12 +44,15 @@ func TestStaticCredentialStoreCli(t *testing.T) {
|
||||
t.Logf("Created SSH Private Key Credentials: %s", keyCredentialsId)
|
||||
|
||||
// Create username/password credentials
|
||||
os.Setenv("E2E_CREDENTIALS_PASSWORD", "password")
|
||||
output = e2e.RunCommand(ctx, "boundary", "credentials", "create", "username-password",
|
||||
"-credential-store-id", newCredentialStoreId,
|
||||
"-username", c.TargetSshUser,
|
||||
"-password", "env://E2E_CREDENTIALS_PASSWORD",
|
||||
"-format", "json",
|
||||
output = e2e.RunCommand(ctx, "boundary",
|
||||
e2e.WithArgs(
|
||||
"credentials", "create", "username-password",
|
||||
"-credential-store-id", newCredentialStoreId,
|
||||
"-username", c.TargetSshUser,
|
||||
"-password", "env://E2E_CREDENTIALS_PASSWORD",
|
||||
"-format", "json",
|
||||
),
|
||||
e2e.WithEnv("E2E_CREDENTIALS_PASSWORD", "password"),
|
||||
)
|
||||
require.NoError(t, output.Err, string(output.Stderr))
|
||||
var pwCredentialsResult credentials.CredentialCreateResult
|
||||
@@ -57,11 +62,15 @@ func TestStaticCredentialStoreCli(t *testing.T) {
|
||||
t.Logf("Created Username/Password Credentials: %s", pwCredentialsId)
|
||||
|
||||
// Delete credential store
|
||||
output = e2e.RunCommand(ctx, "boundary", "credential-stores", "delete", "-id", newCredentialStoreId)
|
||||
output = e2e.RunCommand(ctx, "boundary",
|
||||
e2e.WithArgs("credential-stores", "delete", "-id", newCredentialStoreId),
|
||||
)
|
||||
require.NoError(t, output.Err, string(output.Stderr))
|
||||
err = backoff.RetryNotify(
|
||||
func() error {
|
||||
output = e2e.RunCommand(ctx, "boundary", "credential-stores", "read", "-id", newCredentialStoreId, "-format", "json")
|
||||
output = e2e.RunCommand(ctx, "boundary",
|
||||
e2e.WithArgs("credential-stores", "read", "-id", newCredentialStoreId, "-format", "json"),
|
||||
)
|
||||
if output.Err == nil {
|
||||
return fmt.Errorf("Deleted credential can still be read: '%s'", output.Stdout)
|
||||
}
|
||||
|
||||
@@ -39,12 +39,17 @@ func Setup(t testing.TB) (string, string) {
|
||||
require.True(t, ok)
|
||||
ctx := context.Background()
|
||||
policyName := "boundary-controller"
|
||||
output := e2e.RunCommand(ctx, "vault", "policy", "write", policyName,
|
||||
path.Join(path.Dir(filename), "boundary-controller-policy.hcl"),
|
||||
output := e2e.RunCommand(ctx, "vault",
|
||||
e2e.WithArgs(
|
||||
"policy", "write", policyName,
|
||||
path.Join(path.Dir(filename), "boundary-controller-policy.hcl"),
|
||||
),
|
||||
)
|
||||
require.NoError(t, output.Err, string(output.Stderr))
|
||||
t.Cleanup(func() {
|
||||
output := e2e.RunCommand(ctx, "vault", "policy", "delete", policyName)
|
||||
output := e2e.RunCommand(ctx, "vault",
|
||||
e2e.WithArgs("policy", "delete", policyName),
|
||||
)
|
||||
require.NoError(t, output.Err, string(output.Stderr))
|
||||
})
|
||||
|
||||
@@ -69,19 +74,26 @@ func CreateKvPrivateKeyCredential(t testing.TB, secretName string, secretPath st
|
||||
// Add policy to vault
|
||||
ctx := context.Background()
|
||||
policyName := "kv-read"
|
||||
output := e2e.RunCommand(ctx, "vault", "policy", "write", policyName, kvPolicyFilePath)
|
||||
output := e2e.RunCommand(ctx, "vault",
|
||||
e2e.WithArgs("policy", "write", policyName, kvPolicyFilePath),
|
||||
)
|
||||
require.NoError(t, output.Err, string(output.Stderr))
|
||||
t.Cleanup(func() {
|
||||
output := e2e.RunCommand(ctx, "vault", "policy", "delete", policyName)
|
||||
output := e2e.RunCommand(ctx, "vault",
|
||||
e2e.WithArgs("policy", "delete", policyName),
|
||||
)
|
||||
require.NoError(t, output.Err, string(output.Stderr))
|
||||
})
|
||||
|
||||
// Create secret
|
||||
output = e2e.RunCommand(ctx, "vault", "kv", "put",
|
||||
"-mount", secretPath,
|
||||
secretName,
|
||||
"username="+user,
|
||||
"private_key=@"+keyPath,
|
||||
output = e2e.RunCommand(ctx, "vault",
|
||||
e2e.WithArgs(
|
||||
"kv", "put",
|
||||
"-mount", secretPath,
|
||||
secretName,
|
||||
"username="+user,
|
||||
"private_key=@"+keyPath,
|
||||
),
|
||||
)
|
||||
require.NoError(t, output.Err, string(output.Stderr))
|
||||
|
||||
|
||||
Reference in new issue
Block a user