refact(e2e): Add err to helper methods (#4581)

* refact(e2e): Add err to CreateOrgApi

* refact(e2e): Add err to CreateProjectApi

* refact(e2e): Add err to CreateOrgCli

* refact(e2e): Add err to CreateProjectCli

* refact(e2e): Add err to CreateHostCatalogApi

* refact(e2e): Add err to CreateHostSetApi

* refact(e2e): Add err to CreateHostApi

* refact(e2e): Add err to AddHostToHostSetApi

* refact(e2e): Add err to CreateHostCatalogCli

* refact(e2e): Add err to CreateHostSetCli

* refact(e2e): Add err to CreateHostCli

* refact(e2e): Add err to AddHostToHostSetCli

* refact(e2e): Add err to CreateAwsHostCatalogCli

* refact(e2e): Add err to CreateAwsHostSetCli

* refact(e2e): Add err to CreateTargetApi

* refact(e2e): Add err to AddHostSourceToTargetApi

* refact(e2e): Add err to CreateTargetCli

* refact(e2e): Add err to AddHostSourceToTargetCli

* refact(e2e): Add err to SetHostSourceToTargetCli

* refact(e2e): Add err to RemoveHostSourceFromTargetCli

* refact(e2e): Add err to AddBrokeredCredentialSourceToTargetCli

* refact(e2e): Add err to RemoveBrokeredCredentialSourceFromTargetCli

* refact(e2e): Add err to CreateUserApi

* refact(e2e): Add err to CreateUserCli

* refact(e2e): Add err to SetAccountToUserCli

* refact(e2e): Add err to CreateRoleApi

* refact(e2e): Add err to CreateRoleCli

* refact(e2e): Add err to AddGrantToRoleCli

* refact(e2e): Add err to AddPrincipalToRoleCli

* refact(e2e): Add err to CreateManagedGroupApi

* refact(e2e): Add err to CreateGroupApi

* refact(e2e): Add err to CreateGroupCli

* refact(e2e): Add err to AddUserToGroup

* refact(e2e): Add err to CreateCredentialStoreStaticApi

* refact(e2e): Add err to CreateCredentialStoreVaultApi

* refact(e2e): Add err to CreateCredentialStoreVaultCli

* refact(e2e): Add err to CreateCredentialStoreStaticCli

* refact(e2e): Add err to CreateVaultGenericCredentialLibraryCli

* refact(e2e): Add err to CreateStaticCredentialPrivateKeyCli

* refact(e2e): Add err to CreateStaticCredentialPasswordCli

* refact(e2e): Add err to CreateStaticCredentialJsonCli

* refact(e2e): Add err to CreateStaticCredentialPasswordApi

* refact(e2e): Add err to CreateAuthMethodApi

* refact(e2e): Add err to CreateOidcAuthMethodApi

* refact(e2e): Add err to CreateAccountApi

* refact(e2e): Add err to CreateAccountCli
This commit is contained in:
Michael Li authored and GitHub committed 2024-04-03 09:44:44 -04:00
1 parent d4e314cde8
commit 51d33f3393
64 files changed
+2193 -1302

No files matched your search

+37 -17
View File
@@ -6,6 +6,7 @@ package boundary
import (
"context"
"encoding/json"
"fmt"
"testing"
"github.com/hashicorp/boundary/api"
@@ -15,26 +16,41 @@ import (
"github.com/stretchr/testify/require"
)
// CreateNewAccountApi creates a new account using the Go api.
// CreateAccountApi creates a new account using the Go api.
// Returns the id of the new account as well as the password that was generated
func CreateNewAccountApi(t testing.TB, ctx context.Context, client *api.Client, authMethodId string, loginName string) (accountId string, password string) {
func CreateAccountApi(t testing.TB, ctx context.Context, client *api.Client, authMethodId string, loginName string) (string, string, error) {
name, err := base62.Random(16)
if err != nil {
return "", "", err
}
aClient := accounts.NewClient(client)
password, err := base62.Random(16)
require.NoError(t, err)
newAccountResult, err := aClient.Create(ctx, authMethodId,
if err != nil {
return "", "", err
}
createAccountResult, err := aClient.Create(ctx, authMethodId,
accounts.WithPasswordAccountLoginName(loginName),
accounts.WithPasswordAccountPassword(password),
accounts.WithName(fmt.Sprintf("e2e Account %s", name)),
)
require.NoError(t, err)
if err != nil {
return "", "", err
}
accountId = newAccountResult.Item.Id
accountId := createAccountResult.Item.Id
t.Logf("Create Account: %s", accountId)
return
return accountId, password, nil
}
// CreateNewAccountCli creates a new account using the cli.
// CreateAccountCli creates a new account using the cli.
// Returns the id of the new account as well as the password that was generated
func CreateNewAccountCli(t testing.TB, ctx context.Context, authMethodId string, loginName string) (string, string) {
func CreateAccountCli(t testing.TB, ctx context.Context, authMethodId string, loginName string) (string, string, error) {
name, err := base62.Random(16)
if err != nil {
return "", "", err
}
password, err := base62.Random(16)
require.NoError(t, err)
output := e2e.RunCommand(ctx, "boundary",
@@ -43,19 +59,23 @@ func CreateNewAccountCli(t testing.TB, ctx context.Context, authMethodId string,
"-auth-method-id", authMethodId,
"-login-name", loginName,
"-password", "env://E2E_TEST_ACCOUNT_PASSWORD",
"-name", "e2e Account "+loginName,
"-name", fmt.Sprintf("e2e Account %s", name),
"-description", "e2e",
"-format", "json",
),
e2e.WithEnv("E2E_TEST_ACCOUNT_PASSWORD", password),
)
require.NoError(t, output.Err, string(output.Stderr))
if output.Err != nil {
return "", "", fmt.Errorf("%w: %s", output.Err, string(output.Stderr))
}
var newAccountResult accounts.AccountCreateResult
err = json.Unmarshal(output.Stdout, &newAccountResult)
require.NoError(t, err)
var createAccountResult accounts.AccountCreateResult
err = json.Unmarshal(output.Stdout, &createAccountResult)
if err != nil {
return "", "", err
}
newAccountId := newAccountResult.Item.Id
t.Logf("Created Account: %s", newAccountId)
return newAccountId, password
accountId := createAccountResult.Item.Id
t.Logf("Created Account: %s", accountId)
return accountId, password, nil
}
+32 -12
View File
@@ -5,37 +5,57 @@ package boundary
import (
"context"
"fmt"
"testing"
"github.com/hashicorp/boundary/api"
"github.com/hashicorp/boundary/api/authmethods"
"github.com/stretchr/testify/require"
"github.com/hashicorp/go-secure-stdlib/base62"
)
// CreateNewAuthMethodApi creates a new password auth method using the Go api.
// CreateAuthMethodApi creates a new password auth method using the Go api.
// Returns the id of the new auth method
func CreateNewAuthMethodApi(t testing.TB, ctx context.Context, client *api.Client, scopeId string) string {
aClient := authmethods.NewClient(client)
newAMResult, err := aClient.Create(ctx, "password", scopeId)
require.NoError(t, err)
func CreateAuthMethodApi(t testing.TB, ctx context.Context, client *api.Client, scopeId string) (string, error) {
name, err := base62.Random(16)
if err != nil {
return "", err
}
authMethodId := newAMResult.Item.Id
aClient := authmethods.NewClient(client)
createAuthMethodResult, err := aClient.Create(
ctx,
"password",
scopeId,
authmethods.WithName(fmt.Sprintf("e2e Auth Method %s", name)))
if err != nil {
return "", err
}
authMethodId := createAuthMethodResult.Item.Id
t.Logf("Created Auth Method: %s", authMethodId)
return authMethodId
return authMethodId, nil
}
// CreateNewOidcAuthMethodApi creates a new oidc auth method using the Go api.
// CreateOidcAuthMethodApi creates a new oidc auth method using the Go api.
// Returns the id of the new auth method
func CreateNewOidcAuthMethodApi(t testing.TB, ctx context.Context, client *api.Client, scopeId string) string {
func CreateOidcAuthMethodApi(t testing.TB, ctx context.Context, client *api.Client, scopeId string) (string, error) {
name, err := base62.Random(16)
if err != nil {
return "", err
}
aClient := authmethods.NewClient(client)
newAMResult, err := aClient.Create(ctx, "oidc", scopeId,
authmethods.WithOidcAuthMethodApiUrlPrefix("https://some_url_prefix"),
authmethods.WithOidcAuthMethodClientId("some_client_id"),
authmethods.WithOidcAuthMethodClientSecret("some_client_secret"),
authmethods.WithName(fmt.Sprintf("e2e Auth Method %s", name)),
)
require.NoError(t, err)
if err != nil {
return "", err
}
authMethodId := newAMResult.Item.Id
t.Logf("Created Auth Method: %s", authMethodId)
return authMethodId
return authMethodId, nil
}
+154 -71
View File
@@ -15,80 +15,121 @@ import (
"github.com/hashicorp/boundary/api/credentialstores"
"github.com/hashicorp/boundary/testing/internal/e2e"
"github.com/hashicorp/go-secure-stdlib/base62"
"github.com/stretchr/testify/require"
)
// CreateNewCredentialStoreStaticApi uses the Go api to create a new static credential store.
// CreateCredentialStoreStaticApi uses the Go api to create a new static credential store.
// 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)
require.NoError(t, err)
newCredentialStoreId := newCredentialStoreResult.Item.Id
t.Logf("Created Credential Store: %s", newCredentialStoreId)
func CreateCredentialStoreStaticApi(t testing.TB, ctx context.Context, client *api.Client, projectId string) (string, error) {
name, err := base62.Random(16)
if err != nil {
return "", err
}
return newCredentialStoreId
csClient := credentialstores.NewClient(client)
newCredentialStoreResult, err := csClient.Create(
ctx,
"static",
projectId,
credentialstores.WithName(fmt.Sprintf("e2e Credential Store %s", name)),
)
if err != nil {
return "", err
}
credentialStoreId := newCredentialStoreResult.Item.Id
t.Logf("Created Credential Store: %s", credentialStoreId)
return credentialStoreId, nil
}
// CreateNewCredentialStoreVaultApi uses the API to create a Vault credential store
// CreateCredentialStoreVaultApi uses the API to create a Vault credential store
// Returns the id of the new credential store
func CreateNewCredentialStoreVaultApi(t testing.TB, ctx context.Context, client *api.Client, projectId string, vaultAddr string, vaultToken string) string {
func CreateCredentialStoreVaultApi(t testing.TB, ctx context.Context, client *api.Client, projectId string, vaultAddr string, vaultToken string) (string, error) {
name, err := base62.Random(16)
if err != nil {
return "", err
}
c := credentialstores.NewClient(client)
newCredentialStoreResult, err := c.Create(
ctx, "vault", projectId,
credentialstores.WithName("e2e Credential Store"),
credentialstores.WithVaultCredentialStoreAddress(vaultAddr),
credentialstores.WithVaultCredentialStoreToken(vaultToken),
credentialstores.WithName(fmt.Sprintf("e2e Credential Store %s", name)),
)
require.NoError(t, err)
newVaultCredentialStoreId := newCredentialStoreResult.Item.Id
t.Logf("Created Credential Store: %s", newVaultCredentialStoreId)
if err != nil {
return "", err
}
return newVaultCredentialStoreId
credentialStoreId := newCredentialStoreResult.Item.Id
t.Logf("Created Credential Store: %s", credentialStoreId)
return credentialStoreId, nil
}
// CreateNewCredentialStoreVaultCli uses the cli to create a Vault credential store
// CreateCredentialStoreVaultCli uses the cli to create a Vault credential store
// Returns the id of the new credential store
func CreateNewCredentialStoreVaultCli(t testing.TB, ctx context.Context, projectId string, vaultAddr string, vaultToken string) string {
func CreateCredentialStoreVaultCli(t testing.TB, ctx context.Context, projectId string, vaultAddr string, vaultToken string) (string, error) {
name, err := base62.Random(16)
if err != nil {
return "", err
}
output := e2e.RunCommand(ctx, "boundary",
e2e.WithArgs(
"credential-stores", "create", "vault",
"-scope-id", projectId,
"-vault-address", vaultAddr,
"-vault-token", vaultToken,
"-name", fmt.Sprintf("e2e Credential Store %s", name),
"-description", "e2e",
"-format", "json",
),
)
require.NoError(t, output.Err, string(output.Stderr))
var newCredentialStoreResult credentialstores.CredentialStoreCreateResult
err := json.Unmarshal(output.Stdout, &newCredentialStoreResult)
require.NoError(t, err)
newVaultCredentialStoreId := newCredentialStoreResult.Item.Id
t.Logf("Created Credential Store: %s", newVaultCredentialStoreId)
if output.Err != nil {
return "", fmt.Errorf("%w: %s", output.Err, string(output.Stderr))
}
return newVaultCredentialStoreId
var createCredentialStoreResult credentialstores.CredentialStoreCreateResult
err = json.Unmarshal(output.Stdout, &createCredentialStoreResult)
if err != nil {
return "", err
}
credentialStoreId := createCredentialStoreResult.Item.Id
t.Logf("Created Credential Store: %s", credentialStoreId)
return credentialStoreId, nil
}
// CreateNewCredentialStoreStaticCli uses the cli to create a new static credential store.
// CreateCredentialStoreStaticCli uses the cli to create a new static credential store.
// Returns the id of the new credential store
func CreateNewCredentialStoreStaticCli(t testing.TB, ctx context.Context, projectId string) string {
func CreateCredentialStoreStaticCli(t testing.TB, ctx context.Context, projectId string) (string, error) {
name, err := base62.Random(16)
if err != nil {
return "", err
}
output := e2e.RunCommand(ctx, "boundary",
e2e.WithArgs(
"credential-stores", "create", "static",
"-scope-id", projectId,
"-name", fmt.Sprintf("e2e Credential Store %s", name),
"-description", "e2e",
"-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)
if output.Err != nil {
return "", fmt.Errorf("%w: %s", output.Err, string(output.Stderr))
}
return newCredentialStoreId
var createCredentialStoreResult credentialstores.CredentialStoreCreateResult
err = json.Unmarshal(output.Stdout, &createCredentialStoreResult)
if err != nil {
return "", err
}
credentialStoreId := createCredentialStoreResult.Item.Id
t.Logf("Created Credential Store: %s", credentialStoreId)
return credentialStoreId, nil
}
// CreateVaultGenericCredentialLibraryCli creates a vault-generic credential
@@ -112,103 +153,145 @@ func CreateVaultGenericCredentialLibraryCli(t testing.TB, ctx context.Context, c
),
)
if output.Err != nil {
return "", fmt.Errorf("%s", output.Stderr)
return "", fmt.Errorf("%w: %s", output.Err, string(output.Stderr))
}
var newCredentialLibraryResult credentiallibraries.CredentialLibraryCreateResult
err = json.Unmarshal(output.Stdout, &newCredentialLibraryResult)
var createCredentialLibraryResult credentiallibraries.CredentialLibraryCreateResult
err = json.Unmarshal(output.Stdout, &createCredentialLibraryResult)
if err != nil {
return "", err
}
credentialLibraryId := newCredentialLibraryResult.Item.Id
credentialLibraryId := createCredentialLibraryResult.Item.Id
t.Logf("Created Credential Library: %s", credentialLibraryId)
return credentialLibraryId, nil
}
// CreateNewStaticCredentialPrivateKeyCli uses the cli to create a new private key credential in the
// CreateStaticCredentialPrivateKeyCli uses the cli to create a new private key credential in the
// provided static credential store.
// Returns the id of the new credential
func CreateNewStaticCredentialPrivateKeyCli(t testing.TB, ctx context.Context, credentialStoreId string, user string, filePath string) string {
func CreateStaticCredentialPrivateKeyCli(t testing.TB, ctx context.Context, credentialStoreId string, user string, filePath string) (string, error) {
name, err := base62.Random(16)
if err != nil {
return "", err
}
output := e2e.RunCommand(ctx, "boundary",
e2e.WithArgs(
"credentials", "create", "ssh-private-key",
"-credential-store-id", credentialStoreId,
"-username", user,
"-private-key", "file://"+filePath,
"-name", fmt.Sprintf("e2e Credential %s", name),
"-description", "e2e",
"-format", "json",
),
)
require.NoError(t, output.Err, string(output.Stderr))
var newCredentialsResult credentials.CredentialCreateResult
err := json.Unmarshal(output.Stdout, &newCredentialsResult)
require.NoError(t, err)
newCredentialsId := newCredentialsResult.Item.Id
t.Logf("Created SSH Private Key Credentials: %s", newCredentialsId)
if output.Err != nil {
return "", fmt.Errorf("%w: %s", output.Err, string(output.Stderr))
}
return newCredentialsId
var createCredentialResult credentials.CredentialCreateResult
err = json.Unmarshal(output.Stdout, &createCredentialResult)
if err != nil {
return "", err
}
credentialId := createCredentialResult.Item.Id
t.Logf("Created SSH Private Key Credentials: %s", credentialId)
return credentialId, nil
}
// CreateNewStaticCredentialPasswordCli uses the cli to create a new password credential in the
// CreateStaticCredentialPasswordCli uses the cli to create a new password credential in the
// provided static credential store.
// Returns the id of the new credential
func CreateNewStaticCredentialPasswordCli(t testing.TB, ctx context.Context, credentialStoreId string, user string, password string) string {
func CreateStaticCredentialPasswordCli(t testing.TB, ctx context.Context, credentialStoreId string, user string, password string) (string, error) {
name, err := base62.Random(16)
if err != nil {
return "", err
}
output := e2e.RunCommand(ctx, "boundary",
e2e.WithArgs(
"credentials", "create", "username-password",
"-credential-store-id", credentialStoreId,
"-username", user,
"-password", "env://E2E_CREDENTIALS_PASSWORD",
"-name", fmt.Sprintf("e2e Credential %s", name),
"-description", "e2e",
"-format", "json",
),
e2e.WithEnv("E2E_CREDENTIALS_PASSWORD", password),
)
require.NoError(t, output.Err, string(output.Stderr))
var newCredentialsResult credentials.CredentialCreateResult
err := json.Unmarshal(output.Stdout, &newCredentialsResult)
require.NoError(t, err)
newCredentialsId := newCredentialsResult.Item.Id
t.Logf("Created Username/Password Credentials: %s", newCredentialsId)
if output.Err != nil {
return "", fmt.Errorf("%w: %s", output.Err, string(output.Stderr))
}
return newCredentialsId
var createCredentialsResult credentials.CredentialCreateResult
err = json.Unmarshal(output.Stdout, &createCredentialsResult)
if err != nil {
return "", err
}
credentialId := createCredentialsResult.Item.Id
t.Logf("Created Username/Password Credentials: %s", credentialId)
return credentialId, nil
}
// CreateNewStaticCredentialJsonCli uses the cli to create a new json credential in the provided
// CreateStaticCredentialJsonCli uses the cli to create a new json credential in the provided
// static credential store.
// Returns the id of the new credential
func CreateNewStaticCredentialJsonCli(t testing.TB, ctx context.Context, credentialStoreId string, jsonFilePath string) string {
func CreateStaticCredentialJsonCli(t testing.TB, ctx context.Context, credentialStoreId string, jsonFilePath string) (string, error) {
name, err := base62.Random(16)
if err != nil {
return "", err
}
output := e2e.RunCommand(ctx, "boundary",
e2e.WithArgs(
"credentials", "create", "json",
"-credential-store-id", credentialStoreId,
"-object", "file://"+jsonFilePath,
"-name", fmt.Sprintf("e2e Credential %s", name),
"-description", "e2e",
"-format", "json",
),
)
require.NoError(t, output.Err, string(output.Stderr))
var newCredentialsResult credentials.CredentialCreateResult
err := json.Unmarshal(output.Stdout, &newCredentialsResult)
require.NoError(t, err)
newCredentialsId := newCredentialsResult.Item.Id
t.Logf("Created Username/Password Credentials: %s", newCredentialsId)
if output.Err != nil {
return "", fmt.Errorf("%w: %s", output.Err, string(output.Stderr))
}
return newCredentialsId
var createCredentialsResult credentials.CredentialCreateResult
err = json.Unmarshal(output.Stdout, &createCredentialsResult)
if err != nil {
return "", err
}
credentialId := createCredentialsResult.Item.Id
t.Logf("Created Username/Password Credentials: %s", credentialId)
return credentialId, nil
}
// CreateNewStaticCredentialPasswordApi uses the API to create a new password credential in the
// CreateStaticCredentialPasswordApi uses the API to create a new password credential in the
// provided static credential store.
// Returns the id of the new credential
func CreateNewStaticCredentialPasswordApi(t testing.TB, ctx context.Context, client *api.Client, credentialStoreId string, user string, password string) string {
func CreateStaticCredentialPasswordApi(t testing.TB, ctx context.Context, client *api.Client, credentialStoreId string, user string, password string) (string, error) {
name, err := base62.Random(16)
if err != nil {
return "", err
}
c := credentials.NewClient(client)
newCredentialsResult, err := c.Create(ctx, "username_password", credentialStoreId,
createCredentialsResult, err := c.Create(ctx, "username_password", credentialStoreId,
credentials.WithUsernamePasswordCredentialUsername(user),
credentials.WithUsernamePasswordCredentialPassword(password),
credentials.WithName(fmt.Sprintf("e2e Credential %s", name)),
)
require.NoError(t, err)
newCredentialsId := newCredentialsResult.Item.Id
t.Logf("Created Username/Password Credentials: %s", newCredentialsId)
if err != nil {
return "", err
}
return newCredentialsId
credentialId := createCredentialsResult.Item.Id
t.Logf("Created Username/Password Credentials: %s", credentialId)
return credentialId, nil
}
+43 -20
View File
@@ -6,49 +6,68 @@ package boundary
import (
"context"
"encoding/json"
"fmt"
"testing"
"github.com/hashicorp/boundary/api"
"github.com/hashicorp/boundary/api/groups"
"github.com/hashicorp/boundary/testing/internal/e2e"
"github.com/stretchr/testify/require"
"github.com/hashicorp/go-secure-stdlib/base62"
)
// CreateNewGroupApi uses the API to create a new group.
// CreateGroupApi uses the API to create a new group.
// Returns the id of the new group.
func CreateNewGroupApi(t testing.TB, ctx context.Context, client *api.Client, scopeId string) string {
gClient := groups.NewClient(client)
newGroup, err := gClient.Create(ctx, scopeId)
require.NoError(t, err)
func CreateGroupApi(t testing.TB, ctx context.Context, client *api.Client, scopeId string) (string, error) {
name, err := base62.Random(16)
if err != nil {
return "", err
}
newGroupId := newGroup.Item.Id
t.Logf("Created Group: %s", newGroupId)
return newGroupId
gClient := groups.NewClient(client)
newGroup, err := gClient.Create(ctx, scopeId, groups.WithName(fmt.Sprintf("e2e Group %s", name)))
if err != nil {
return "", err
}
groupId := newGroup.Item.Id
t.Logf("Created Group: %s", groupId)
return groupId, nil
}
// CreateNewGroupCli uses the cli to create a new group.
// CreateGroupCli uses the cli to create a new group.
// Returns the id of the new group.
func CreateNewGroupCli(t testing.TB, ctx context.Context, scopeId string) string {
func CreateGroupCli(t testing.TB, ctx context.Context, scopeId string) (string, error) {
name, err := base62.Random(16)
if err != nil {
return "", err
}
output := e2e.RunCommand(ctx, "boundary",
e2e.WithArgs(
"groups", "create",
"-scope-id", "global",
"-name", fmt.Sprintf("e2e Group %s", name),
"-description", "e2e",
"-format", "json",
),
)
require.NoError(t, output.Err, string(output.Stderr))
var newGroupResult groups.GroupCreateResult
err := json.Unmarshal(output.Stdout, &newGroupResult)
require.NoError(t, err)
if output.Err != nil {
return "", fmt.Errorf("%w: %s", output.Err, string(output.Stderr))
}
newGroupId := newGroupResult.Item.Id
t.Logf("Created Group: %s", newGroupId)
return newGroupId
var createGroupResult groups.GroupCreateResult
err = json.Unmarshal(output.Stdout, &createGroupResult)
if err != nil {
return "", err
}
groupId := createGroupResult.Item.Id
t.Logf("Created Group: %s", groupId)
return groupId, nil
}
// AddUserToGroup uses the cli to add a user to a group
func AddUserToGroup(t testing.TB, ctx context.Context, userId string, groupId string) {
func AddUserToGroup(t testing.TB, ctx context.Context, userId string, groupId string) error {
output := e2e.RunCommand(ctx, "boundary",
e2e.WithArgs(
"groups", "add-members",
@@ -56,5 +75,9 @@ func AddUserToGroup(t testing.TB, ctx context.Context, userId string, groupId st
"-member", userId,
),
)
require.NoError(t, output.Err, string(output.Stderr))
if output.Err != nil {
return fmt.Errorf("%w: %s", output.Err, string(output.Stderr))
}
return nil
}
+160 -77
View File
@@ -17,132 +17,198 @@ import (
"github.com/hashicorp/boundary/api/hosts"
"github.com/hashicorp/boundary/api/hostsets"
"github.com/hashicorp/boundary/testing/internal/e2e"
"github.com/hashicorp/go-secure-stdlib/base62"
"github.com/stretchr/testify/require"
)
// CreateNewHostCatalogApi uses the Go api to create a new host catalog.
// CreateHostCatalogApi uses the Go api to create a new host catalog.
// Returns the id of the new host catalog.
func CreateNewHostCatalogApi(t testing.TB, ctx context.Context, client *api.Client, projectId string) string {
func CreateHostCatalogApi(t testing.TB, ctx context.Context, client *api.Client, projectId string) (string, error) {
name, err := base62.Random(16)
if err != nil {
return "", err
}
hcClient := hostcatalogs.NewClient(client)
newHostCatalogResult, err := hcClient.Create(ctx, "static", projectId)
require.NoError(t, err)
newHostCatalogId := newHostCatalogResult.Item.Id
t.Logf("Created Host Catalog: %s", newHostCatalogId)
createHostCatalogResult, err := hcClient.Create(
ctx,
"static",
projectId,
hostcatalogs.WithName(fmt.Sprintf("e2e Host Catalog %s", name)))
if err != nil {
return "", err
}
return newHostCatalogId
hostCatalogId := createHostCatalogResult.Item.Id
t.Logf("Created Host Catalog: %s", hostCatalogId)
return hostCatalogId, nil
}
// CreateNewHostSetApi uses the Go api to create a new host set.
// CreateHostSetApi uses the Go api to create a new host set.
// 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)
func CreateHostSetApi(t testing.TB, ctx context.Context, client *api.Client, hostCatalogId string) (string, error) {
name, err := base62.Random(16)
if err != nil {
return "", err
}
return newHostSetId
hsClient := hostsets.NewClient(client)
createHostSetResult, err := hsClient.Create(ctx, hostCatalogId, hostsets.WithName(fmt.Sprintf("e2e Host Set %s", name)))
if err != nil {
return "", err
}
hostSetId := createHostSetResult.Item.Id
t.Logf("Created Host Set: %s", hostSetId)
return hostSetId, nil
}
// CreateNewHostApi uses the Go api to create a new host.
// CreateHostApi uses the Go api to create a new host.
// 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.WithStaticHostAddress(address),
)
require.NoError(t, err)
newHostId := newHostResult.Item.Id
t.Logf("Created Host: %s", newHostId)
func CreateHostApi(t testing.TB, ctx context.Context, client *api.Client, hostCatalogId string, address string) (string, error) {
name, err := base62.Random(16)
if err != nil {
return "", err
}
return newHostId
hClient := hosts.NewClient(client)
createHostResult, err := hClient.Create(ctx, hostCatalogId,
hosts.WithStaticHostAddress(address),
hosts.WithName(fmt.Sprintf("e2e Host %s", name)),
)
if err != nil {
return "", err
}
hostId := createHostResult.Item.Id
t.Logf("Created Host: %s", hostId)
return hostId, nil
}
// AddHostToHostSetApi uses the Go api to add a host to a host set
func AddHostToHostSetApi(t testing.TB, ctx context.Context, client *api.Client, hostSetId string, hostId string) {
func AddHostToHostSetApi(t testing.TB, ctx context.Context, client *api.Client, hostSetId string, hostId string) error {
hsClient := hostsets.NewClient(client)
_, err := hsClient.AddHosts(ctx, hostSetId, 0, []string{hostId}, hostsets.WithAutomaticVersioning(true))
require.NoError(t, err)
return err
}
// CreateNewHostCatalogCli uses the cli to create a new host catalog.
// CreateHostCatalogCli uses the cli to create a new host catalog.
// Returns the id of the new host catalog.
func CreateNewHostCatalogCli(t testing.TB, ctx context.Context, projectId string) string {
func CreateHostCatalogCli(t testing.TB, ctx context.Context, projectId string) (string, error) {
name, err := base62.Random(16)
if err != nil {
return "", err
}
output := e2e.RunCommand(ctx, "boundary",
e2e.WithArgs(
"host-catalogs", "create", "static",
"-scope-id", projectId,
"-name", "e2e Host Catalog",
"-name", fmt.Sprintf("e2e Host Catalog %s", name),
"-description", "e2e",
"-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
if output.Err != nil {
return "", fmt.Errorf("%w: %s", output.Err, string(output.Stderr))
}
t.Logf("Created Host Catalog: %s", newHostCatalogId)
return newHostCatalogId
var createHostCatalogResult hostcatalogs.HostCatalogCreateResult
err = json.Unmarshal(output.Stdout, &createHostCatalogResult)
if err != nil {
return "", err
}
hostCatalogId := createHostCatalogResult.Item.Id
t.Logf("Created Host Catalog: %s", hostCatalogId)
return hostCatalogId, nil
}
// CreateNewHostSetCli uses the cli to create a new host set.
// CreateHostSetCli uses the cli to create a new host set.
// Returns the id of the new host set.
func CreateNewHostSetCli(t testing.TB, ctx context.Context, hostCatalogId string) string {
func CreateHostSetCli(t testing.TB, ctx context.Context, hostCatalogId string) (string, error) {
name, err := base62.Random(16)
if err != nil {
return "", err
}
output := e2e.RunCommand(ctx, "boundary",
e2e.WithArgs(
"host-sets", "create", "static",
"-host-catalog-id", hostCatalogId,
"-name", "e2e Host Set",
"-name", fmt.Sprintf("e2e Host Set %s", name),
"-description", "e2e",
"-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)
if output.Err != nil {
return "", fmt.Errorf("%w: %s", output.Err, string(output.Stderr))
}
return newHostSetId
var createHostSetResult hostsets.HostSetCreateResult
err = json.Unmarshal(output.Stdout, &createHostSetResult)
if err != nil {
return "", err
}
hostSetId := createHostSetResult.Item.Id
t.Logf("Created Host Set: %s", hostSetId)
return hostSetId, nil
}
// CreateNewHostCli uses the cli to create a new host.
// CreateHostCli uses the cli to create a new host.
// Returns the id of the new host.
func CreateNewHostCli(t testing.TB, ctx context.Context, hostCatalogId string, address string) string {
func CreateHostCli(t testing.TB, ctx context.Context, hostCatalogId string, address string) (string, error) {
name, err := base62.Random(16)
if err != nil {
return "", err
}
output := e2e.RunCommand(ctx, "boundary",
e2e.WithArgs(
"hosts", "create", "static",
"-host-catalog-id", hostCatalogId,
"-name", address,
"-name", fmt.Sprintf("e2e Host %s", name),
"-description", "e2e",
"-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)
if output.Err != nil {
return "", fmt.Errorf("%w: %s", output.Err, string(output.Stderr))
}
return newHostId
var createHostResult hosts.HostCreateResult
err = json.Unmarshal(output.Stdout, &createHostResult)
if err != nil {
return "", err
}
hostId := createHostResult.Item.Id
t.Logf("Created Host: %s", hostId)
return hostId, nil
}
// AddHostToHostSetCli uses the cli to add a host to a host set
func AddHostToHostSetCli(t testing.TB, ctx context.Context, hostSetId string, hostId string) {
func AddHostToHostSetCli(t testing.TB, ctx context.Context, hostSetId string, hostId string) error {
output := e2e.RunCommand(ctx, "boundary",
e2e.WithArgs("host-sets", "add-hosts", "-id", hostSetId, "-host", hostId),
)
require.NoError(t, output.Err, string(output.Stderr))
if output.Err != nil {
return fmt.Errorf("%w: %s", output.Err, string(output.Stderr))
}
return nil
}
// CreateNewAwsHostCatalogCli uses the cli to create a new AWS dynamic host catalog.
// CreateAwsHostCatalogCli uses the cli to create a new AWS dynamic host catalog.
// Returns the id of the new host catalog.
func CreateNewAwsHostCatalogCli(t testing.TB, ctx context.Context, projectId string, accessKeyId string, secretAccessKey string) string {
func CreateAwsHostCatalogCli(t testing.TB, ctx context.Context, projectId string, accessKeyId string, secretAccessKey string) (string, error) {
name, err := base62.Random(16)
if err != nil {
return "", err
}
output := e2e.RunCommand(ctx, "boundary",
e2e.WithArgs(
"host-catalogs", "create", "plugin",
@@ -152,42 +218,59 @@ func CreateNewAwsHostCatalogCli(t testing.TB, ctx context.Context, projectId str
"-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",
"-name", fmt.Sprintf("e2e Host Catalog %s", name),
"-description", "e2e",
"-format", "json",
),
e2e.WithEnv("E2E_AWS_ACCESS_KEY_ID", accessKeyId),
e2e.WithEnv("E2E_AWS_SECRET_ACCESS_KEY", secretAccessKey),
)
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)
if output.Err != nil {
return "", fmt.Errorf("%w: %s", output.Err, string(output.Stderr))
}
return newHostCatalogId
var createHostCatalogResult hostcatalogs.HostCatalogCreateResult
err = json.Unmarshal(output.Stdout, &createHostCatalogResult)
if err != nil {
return "", err
}
hostCatalogId := createHostCatalogResult.Item.Id
t.Logf("Created Host Catalog: %s", hostCatalogId)
return hostCatalogId, nil
}
// CreateNewAwsHostSetCli uses the cli to create a new host set from an AWS dynamic host catalog.
// CreateAwsHostSetCli uses the cli to create a new host set from an AWS dynamic host catalog.
// Returns the id of the new host set.
func CreateNewAwsHostSetCli(t testing.TB, ctx context.Context, hostCatalogId string, filter string) string {
func CreateAwsHostSetCli(t testing.TB, ctx context.Context, hostCatalogId string, filter string) (string, error) {
name, err := base62.Random(16)
if err != nil {
return "", err
}
output := e2e.RunCommand(ctx, "boundary",
e2e.WithArgs(
"host-sets", "create", "plugin",
"-host-catalog-id", hostCatalogId,
"-attr", "filters="+filter,
"-name", fmt.Sprintf("e2e Host Set %s", name),
"-description", "e2e",
"-format", "json",
),
)
require.NoError(t, output.Err, string(output.Stderr))
var newHostSetResult hostsets.HostSetCreateResult
err := json.Unmarshal(output.Stdout, &newHostSetResult)
require.NoError(t, err)
if output.Err != nil {
return "", fmt.Errorf("%w: %s", output.Err, string(output.Stderr))
}
newHostSetId := newHostSetResult.Item.Id
t.Logf("Created Host Set: %s", newHostSetId)
return newHostSetId
var createHostSetResult hostsets.HostSetCreateResult
err = json.Unmarshal(output.Stdout, &createHostSetResult)
if err != nil {
return "", err
}
hostSetId := createHostSetResult.Item.Id
t.Logf("Created Host Set: %s", hostSetId)
return hostSetId, nil
}
// WaitForHostsInHostSetCli uses the cli to check if there are any hosts in a host set. It will check a
+14 -5
View File
@@ -5,23 +5,32 @@ package boundary
import (
"context"
"fmt"
"testing"
"github.com/hashicorp/boundary/api"
"github.com/hashicorp/boundary/api/managedgroups"
"github.com/stretchr/testify/require"
"github.com/hashicorp/go-secure-stdlib/base62"
)
// CreateNewManagedGroupApi creates a new managed group using the Go api.
// CreateManagedGroupApi creates a new managed group using the Go api.
// Returns the id of the new managed group.
func CreateNewManagedGroupApi(t testing.TB, ctx context.Context, client *api.Client, amId string) string {
func CreateManagedGroupApi(t testing.TB, ctx context.Context, client *api.Client, amId string) (string, error) {
name, err := base62.Random(16)
if err != nil {
return "", err
}
mgClient := managedgroups.NewClient(client)
newMGResult, err := mgClient.Create(ctx, amId,
managedgroups.WithOidcManagedGroupFilter(`"/token/zip" == "zap"`),
managedgroups.WithName(fmt.Sprintf("e2e Managed Group %s", name)),
)
require.NoError(t, err)
if err != nil {
return "", err
}
managedGroupId := newMGResult.Item.Id
t.Logf("Created Managed Group: %s", managedGroupId)
return managedGroupId
return managedGroupId, nil
}
+35 -20
View File
@@ -13,19 +13,25 @@ import (
"github.com/hashicorp/boundary/api/roles"
"github.com/hashicorp/boundary/testing/internal/e2e"
"github.com/hashicorp/go-secure-stdlib/base62"
"github.com/stretchr/testify/require"
)
// CreateNewRoleApi creates a new role using the Go api.
// CreateRoleApi creates a new role using the Go api.
// Returns the id of the new role
func CreateNewRoleApi(t testing.TB, ctx context.Context, client *api.Client, scopeId string) string {
rClient := roles.NewClient(client)
newRoleResult, err := rClient.Create(ctx, scopeId)
require.NoError(t, err)
func CreateRoleApi(t testing.TB, ctx context.Context, client *api.Client, scopeId string) (string, error) {
name, err := base62.Random(16)
if err != nil {
return "", err
}
newRoleId := newRoleResult.Item.Id
t.Logf("Created Role: %s", newRoleId)
return newRoleId
rClient := roles.NewClient(client)
createRoleResult, err := rClient.Create(ctx, scopeId, roles.WithName(fmt.Sprintf("e2e Role %s", name)))
if err != nil {
return "", err
}
roleId := createRoleResult.Item.Id
t.Logf("Created Role: %s", roleId)
return roleId, nil
}
// CreateRoleCli creates a new role using the Boundary CLI.
@@ -33,8 +39,9 @@ func CreateNewRoleApi(t testing.TB, ctx context.Context, client *api.Client, sco
func CreateRoleCli(t testing.TB, ctx context.Context, scopeId string) (string, error) {
name, err := base62.Random(16)
if err != nil {
return "", fmt.Errorf("error generating role name: %w", err)
return "", err
}
output := e2e.RunCommand(ctx, "boundary",
e2e.WithArgs(
"roles", "create",
@@ -45,17 +52,17 @@ func CreateRoleCli(t testing.TB, ctx context.Context, scopeId string) (string, e
),
)
if output.Err != nil {
return "", fmt.Errorf("error creating role: %w: %s", output.Err, string(output.Stderr))
return "", fmt.Errorf("%w: %s", output.Err, string(output.Stderr))
}
var newRoleResult roles.RoleCreateResult
if err := json.Unmarshal(output.Stdout, &newRoleResult); err != nil {
var createRoleResult roles.RoleCreateResult
if err := json.Unmarshal(output.Stdout, &createRoleResult); err != nil {
return "", fmt.Errorf("error unmarshalling role creation result: %w", err)
}
newRoleId := newRoleResult.Item.Id
t.Logf("Created Role: %s in scope %s", newRoleId, scopeId)
return newRoleId, nil
roleId := createRoleResult.Item.Id
t.Logf("Created Role: %s in scope %s", roleId, scopeId)
return roleId, nil
}
// ListRolesCli lists roles from the specified scope using the Boundary CLI.
@@ -82,7 +89,7 @@ func ListRolesCli(t testing.TB, ctx context.Context, scopeId string) ([]*roles.R
}
// AddGrantToRoleCli adds a grant/permission to a role using the cli
func AddGrantToRoleCli(t testing.TB, ctx context.Context, roleId string, grant string) {
func AddGrantToRoleCli(t testing.TB, ctx context.Context, roleId string, grant string) error {
output := e2e.RunCommand(ctx, "boundary",
e2e.WithArgs(
"roles", "add-grants",
@@ -90,11 +97,15 @@ func AddGrantToRoleCli(t testing.TB, ctx context.Context, roleId string, grant s
"-grant", grant,
),
)
require.NoError(t, output.Err, string(output.Stderr))
if output.Err != nil {
return fmt.Errorf("%w: %s", output.Err, string(output.Stderr))
}
return nil
}
// AddPrincipalToRoleCli adds a user/group to a role using the cli
func AddPrincipalToRoleCli(t testing.TB, ctx context.Context, roleId string, principal string) {
func AddPrincipalToRoleCli(t testing.TB, ctx context.Context, roleId string, principal string) error {
output := e2e.RunCommand(ctx, "boundary",
e2e.WithArgs(
"roles", "add-principals",
@@ -102,8 +113,12 @@ func AddPrincipalToRoleCli(t testing.TB, ctx context.Context, roleId string, pri
"-principal", principal,
),
)
require.NoError(t, output.Err, string(output.Stderr))
if output.Err != nil {
return fmt.Errorf("%w: %s", output.Err, string(output.Stderr))
}
t.Logf("Principal %s added to role: %s", principal, roleId)
return nil
}
// SetGrantScopesToRoleCli uses Boundary CLI to override grant scopes for the role with the provided ones.
+69 -37
View File
@@ -6,66 +6,90 @@ package boundary
import (
"context"
"encoding/json"
"fmt"
"testing"
"github.com/hashicorp/boundary/api"
"github.com/hashicorp/boundary/api/scopes"
"github.com/hashicorp/boundary/testing/internal/e2e"
"github.com/stretchr/testify/require"
"github.com/hashicorp/go-secure-stdlib/base62"
)
// CreateNewOrgApi creates a new organization in boundary using the Go api.
// CreateOrgApi creates a new organization in boundary using the Go api.
// 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 Org"))
require.NoError(t, err)
func CreateOrgApi(t testing.TB, ctx context.Context, client *api.Client) (string, error) {
name, err := base62.Random(16)
if err != nil {
return "", err
}
newOrgId := newOrgResult.Item.Id
t.Logf("Created Org Id: %s", newOrgId)
return newOrgId
scopeClient := scopes.NewClient(client)
createOrgResult, err := scopeClient.Create(ctx, "global", scopes.WithName(fmt.Sprintf("e2e Org %s", name)))
if err != nil {
return "", err
}
orgId := createOrgResult.Item.Id
t.Logf("Created Org Id: %s", orgId)
return orgId, nil
}
// CreateNewProjectApi creates a new project in boundary using the Go api. The project will be created
// CreateProjectApi creates a new project in boundary using the Go api. The project will be created
// under the provided org id.
// 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)
require.NoError(t, err)
func CreateProjectApi(t testing.TB, ctx context.Context, client *api.Client, orgId string) (string, error) {
name, err := base62.Random(16)
if err != nil {
return "", err
}
newProjectId := newProjResult.Item.Id
t.Logf("Created Project Id: %s", newProjectId)
return newProjectId
scopeClient := scopes.NewClient(client)
createProjResult, err := scopeClient.Create(ctx, orgId, scopes.WithName(fmt.Sprintf("e2e Project %s", name)))
if err != nil {
return "", err
}
projectId := createProjResult.Item.Id
t.Logf("Created Project Id: %s", projectId)
return projectId, nil
}
// CreateNewOrgCli creates a new organization in boundary using the cli.
// CreateOrgCli creates a new organization in boundary using the cli.
// Returns the id of the new org.
func CreateNewOrgCli(t testing.TB, ctx context.Context) string {
func CreateOrgCli(t testing.TB, ctx context.Context) (string, error) {
name, err := base62.Random(16)
if err != nil {
return "", err
}
output := e2e.RunCommand(ctx, "boundary",
e2e.WithArgs(
"scopes", "create",
"-name", "e2e Org",
"-name", fmt.Sprintf("e2e Org %s", name),
"-description", "e2e",
"-scope-id", "global",
"-format", "json",
),
)
require.NoError(t, output.Err, string(output.Stderr))
if output.Err != nil {
return "", fmt.Errorf("%w: %s", output.Err, string(output.Stderr))
}
var newOrgResult scopes.ScopeCreateResult
err := json.Unmarshal(output.Stdout, &newOrgResult)
require.NoError(t, err)
var createOrgResult scopes.ScopeCreateResult
err = json.Unmarshal(output.Stdout, &createOrgResult)
if err != nil {
return "", err
}
newOrgId := newOrgResult.Item.Id
t.Logf("Created Org Id: %s", newOrgId)
return newOrgId
orgId := createOrgResult.Item.Id
t.Logf("Created Org Id: %s", orgId)
return orgId, nil
}
// CreateNewProjectCli creates a new project in boundary using the cli. The project will be created
// CreateProjectCli creates a new project in boundary using the cli. The project will be created
// under the provided org id.
// Returns the id of the new project.
func CreateNewProjectCli(t testing.TB, ctx context.Context, orgId string, opt ...ScopeOption) string {
func CreateProjectCli(t testing.TB, ctx context.Context, orgId string, opt ...ScopeOption) (string, error) {
opts := getScopeOpts(opt...)
var args []string
@@ -79,21 +103,29 @@ func CreateNewProjectCli(t testing.TB, ctx context.Context, orgId string, opt ..
if opts.WithName != "" {
args = append(args, "-name", opts.WithName)
} else {
args = append(args, "-name", "e2e Project")
name, err := base62.Random(16)
if err != nil {
return "", err
}
args = append(args, "-name", fmt.Sprintf("e2e Project %s", name))
}
output := e2e.RunCommand(ctx, "boundary",
e2e.WithArgs(args...),
)
require.NoError(t, output.Err, string(output.Stderr))
if output.Err != nil {
return "", fmt.Errorf("%w: %s", output.Err, string(output.Stderr))
}
var newProjResult scopes.ScopeCreateResult
err := json.Unmarshal(output.Stdout, &newProjResult)
require.NoError(t, err)
var createProjResult scopes.ScopeCreateResult
err := json.Unmarshal(output.Stdout, &createProjResult)
if err != nil {
return "", err
}
newProjectId := newProjResult.Item.Id
t.Logf("Created Project Id: %s", newProjectId)
return newProjectId
projectId := createProjResult.Item.Id
t.Logf("Created Project Id: %s", projectId)
return projectId, nil
}
// getScopeOpts iterates the inbound ScopeOptions and returns a struct
+70 -31
View File
@@ -14,39 +14,54 @@ import (
"github.com/hashicorp/boundary/api/targets"
"github.com/hashicorp/boundary/internal/target"
"github.com/hashicorp/boundary/testing/internal/e2e"
"github.com/stretchr/testify/require"
"github.com/hashicorp/go-secure-stdlib/base62"
)
// CreateNewTargetApi uses the Go api to create a new target in boundary
// CreateTargetApi uses the Go api to create a new target in boundary
// Returns the id of the new target.
func CreateNewTargetApi(t testing.TB, ctx context.Context, client *api.Client, projectId string, defaultPort string) string {
func CreateTargetApi(t testing.TB, ctx context.Context, client *api.Client, projectId string, defaultPort string) (string, error) {
name, err := base62.Random(16)
if err != nil {
return "", err
}
tClient := targets.NewClient(client)
targetPort, err := strconv.ParseInt(defaultPort, 10, 32)
require.NoError(t, err)
if err != nil {
return "", err
}
newTargetResult, err := tClient.Create(ctx, "tcp", projectId,
targets.WithName("e2e Target"),
targets.WithName(fmt.Sprintf("e2e Target %s", name)),
targets.WithTcpTargetDefaultPort(uint32(targetPort)),
)
require.NoError(t, err)
newTargetId := newTargetResult.Item.Id
t.Logf("Created Target: %s", newTargetId)
if err != nil {
return "", err
}
return newTargetId
targetId := newTargetResult.Item.Id
t.Logf("Created Target: %s", targetId)
return targetId, nil
}
// AddHostSourceToTargetApi uses the Go api to add a host source (host set or host) to a target
func AddHostSourceToTargetApi(t testing.TB, ctx context.Context, client *api.Client, targetId string, hostSourceId string) {
func AddHostSourceToTargetApi(t testing.TB, ctx context.Context, client *api.Client, targetId string, hostSourceId string) error {
tClient := targets.NewClient(client)
_, err := tClient.AddHostSources(ctx, targetId, 0,
[]string{hostSourceId},
targets.WithAutomaticVersioning(true),
)
require.NoError(t, err)
return err
}
// CreateNewTargetCli uses the cli to create a new target in boundary
// CreateTargetCli uses the cli to create a new target in boundary
// Returns the id of the new target.
func CreateNewTargetCli(t testing.TB, ctx context.Context, projectId string, defaultPort string, opt ...target.Option) string {
func CreateTargetCli(t testing.TB, ctx context.Context, projectId string, defaultPort string, opt ...target.Option) (string, error) {
name, err := base62.Random(16)
if err != nil {
return "", err
}
opts := target.GetOpts(opt...)
var args []string
@@ -67,7 +82,7 @@ func CreateNewTargetCli(t testing.TB, ctx context.Context, projectId string, def
if opts.WithName != "" {
args = append(args, "-name", opts.WithName)
} else {
args = append(args, "-name", "e2e Target")
args = append(args, "-name", fmt.Sprintf("e2e Target %s", name))
}
if opts.WithAddress != "" {
args = append(args, "-address", opts.WithAddress)
@@ -98,41 +113,53 @@ func CreateNewTargetCli(t testing.TB, ctx context.Context, projectId string, def
e2e.WithArgs("targets", "create"),
e2e.WithArgs(args...),
)
require.NoError(t, output.Err, string(output.Stderr))
if output.Err != nil {
return "", fmt.Errorf("%w: %s", output.Err, string(output.Stderr))
}
var newTargetResult targets.TargetCreateResult
err := json.Unmarshal(output.Stdout, &newTargetResult)
require.NoError(t, err)
var createTargetResult targets.TargetCreateResult
err = json.Unmarshal(output.Stdout, &createTargetResult)
if err != nil {
return "", err
}
newTargetId := newTargetResult.Item.Id
t.Logf("Created Target: %s", newTargetId)
return newTargetId
targetId := createTargetResult.Item.Id
t.Logf("Created Target: %s", targetId)
return targetId, nil
}
// AddHostSourceToTargetCli uses the cli to add a host source (host set or host)
// to a target.
// Boundary's `add-host-sources` functionality appends a new host source to the
// existing set of host sources in the target.
func AddHostSourceToTargetCli(t testing.TB, ctx context.Context, targetId, hostSourceId string) {
func AddHostSourceToTargetCli(t testing.TB, ctx context.Context, targetId, hostSourceId string) error {
output := e2e.RunCommand(ctx, "boundary",
e2e.WithArgs("targets", "add-host-sources", "-id", targetId, "-host-source", hostSourceId),
)
require.NoError(t, output.Err, string(output.Stderr))
if output.Err != nil {
return fmt.Errorf("%w: %s", output.Err, string(output.Stderr))
}
return nil
}
// SetHostSourceToTargetCli uses the cli to set a host source (host set or host)
// to a target.
// Boundary's `set-host-sources` functionality replaces all existing host sets
// on a target with the provided one.
func SetHostSourceToTargetCli(t testing.TB, ctx context.Context, targetId, hostSourceId string) {
func SetHostSourceToTargetCli(t testing.TB, ctx context.Context, targetId, hostSourceId string) error {
output := e2e.RunCommand(ctx, "boundary",
e2e.WithArgs("targets", "set-host-sources", "-id", targetId, "-host-source", hostSourceId),
)
require.NoError(t, output.Err, string(output.Stderr))
if output.Err != nil {
return fmt.Errorf("%w: %s", output.Err, string(output.Stderr))
}
return nil
}
// RemoveHostSourceFromTargetCli uses the cli to remove a host source (host set or host) to a target
func RemoveHostSourceFromTargetCli(t testing.TB, ctx context.Context, targetId, hostSourceId string) {
func RemoveHostSourceFromTargetCli(t testing.TB, ctx context.Context, targetId, hostSourceId string) error {
output := e2e.RunCommand(ctx, "boundary",
e2e.WithArgs(
"targets", "remove-host-sources",
@@ -140,12 +167,16 @@ func RemoveHostSourceFromTargetCli(t testing.TB, ctx context.Context, targetId,
"-host-source", hostSourceId,
),
)
require.NoError(t, output.Err, string(output.Stderr))
if output.Err != nil {
return fmt.Errorf("%w: %s", output.Err, string(output.Stderr))
}
return nil
}
// AddBrokeredCredentialSourceToTargetCli uses the cli to add a credential source (credential library or
// credential) to a target
func AddBrokeredCredentialSourceToTargetCli(t testing.TB, ctx context.Context, targetId string, credentialSourceId string) {
func AddBrokeredCredentialSourceToTargetCli(t testing.TB, ctx context.Context, targetId string, credentialSourceId string) error {
output := e2e.RunCommand(ctx, "boundary",
e2e.WithArgs(
"targets", "add-credential-sources",
@@ -153,12 +184,16 @@ func AddBrokeredCredentialSourceToTargetCli(t testing.TB, ctx context.Context, t
"-brokered-credential-source", credentialSourceId,
),
)
require.NoError(t, output.Err, string(output.Stderr))
if output.Err != nil {
return fmt.Errorf("%w: %s", output.Err, string(output.Stderr))
}
return nil
}
// RemoveBrokeredCredentialSourceFromTargetCli uses the cli to remove a credential source (credential library or
// credential) from a target
func RemoveBrokeredCredentialSourceFromTargetCli(t testing.TB, ctx context.Context, targetId string, credentialSourceId string) {
func RemoveBrokeredCredentialSourceFromTargetCli(t testing.TB, ctx context.Context, targetId string, credentialSourceId string) error {
output := e2e.RunCommand(ctx, "boundary",
e2e.WithArgs(
"targets", "remove-credential-sources",
@@ -166,5 +201,9 @@ func RemoveBrokeredCredentialSourceFromTargetCli(t testing.TB, ctx context.Conte
"-brokered-credential-source", credentialSourceId,
),
)
require.NoError(t, output.Err, string(output.Stderr))
if output.Err != nil {
return fmt.Errorf("%w: %s", output.Err, string(output.Stderr))
}
return nil
}
+42 -21
View File
@@ -6,51 +6,68 @@ package boundary
import (
"context"
"encoding/json"
"fmt"
"testing"
"github.com/hashicorp/boundary/api"
"github.com/hashicorp/boundary/api/users"
"github.com/hashicorp/boundary/testing/internal/e2e"
"github.com/stretchr/testify/require"
"github.com/hashicorp/go-secure-stdlib/base62"
)
// CreateNewUserCli creates a new user using the Go api.
// CreateUserApi creates a new user using the Go api.
// Returns the id of the new user
func CreateNewUserApi(t testing.TB, ctx context.Context, client *api.Client, scopeId string) string {
uClient := users.NewClient(client)
newUserResult, err := uClient.Create(ctx, scopeId)
require.NoError(t, err)
func CreateUserApi(t testing.TB, ctx context.Context, client *api.Client, scopeId string) (string, error) {
name, err := base62.Random(16)
if err != nil {
return "", err
}
newUserId := newUserResult.Item.Id
t.Logf("Created User: %s", newUserId)
return newUserId
uClient := users.NewClient(client)
createUserResult, err := uClient.Create(ctx, scopeId, users.WithName(fmt.Sprintf("e2e User %s", name)))
if err != nil {
return "", err
}
userId := createUserResult.Item.Id
t.Logf("Created User: %s", userId)
return userId, nil
}
// CreateNewUserCli creates a new user using the cli.
// CreateUserCli creates a new user using the cli.
// Returns the id of the new user
func CreateNewUserCli(t testing.TB, ctx context.Context, scopeId string) string {
func CreateUserCli(t testing.TB, ctx context.Context, scopeId string) (string, error) {
name, err := base62.Random(16)
if err != nil {
return "", err
}
output := e2e.RunCommand(ctx, "boundary",
e2e.WithArgs(
"users", "create",
"-scope-id", scopeId,
"-name", "e2e User",
"-name", fmt.Sprintf("e2e User %s", name),
"-description", "e2e",
"-format", "json",
),
)
require.NoError(t, output.Err, string(output.Stderr))
if output.Err != nil {
return "", fmt.Errorf("%w: %s", output.Err, string(output.Stderr))
}
var newUserResult users.UserCreateResult
err := json.Unmarshal(output.Stdout, &newUserResult)
require.NoError(t, err)
var createUserResult users.UserCreateResult
err = json.Unmarshal(output.Stdout, &createUserResult)
if err != nil {
return "", err
}
newUserId := newUserResult.Item.Id
t.Logf("Created User: %s", newUserId)
return newUserId
userId := createUserResult.Item.Id
t.Logf("Created User: %s", userId)
return userId, nil
}
// SetAccountToUserCli sets an account to a the specified user using the cli.
func SetAccountToUserCli(t testing.TB, ctx context.Context, userId string, accountId string) {
func SetAccountToUserCli(t testing.TB, ctx context.Context, userId string, accountId string) error {
output := e2e.RunCommand(ctx, "boundary",
e2e.WithArgs(
"users", "set-accounts",
@@ -58,5 +75,9 @@ func SetAccountToUserCli(t testing.TB, ctx context.Context, userId string, accou
"-account", accountId,
),
)
require.NoError(t, output.Err, string(output.Stderr))
if output.Err != nil {
return fmt.Errorf("%w: %s", output.Err, string(output.Stderr))
}
return nil
}
@@ -28,18 +28,22 @@ func TestCliCreateAwsDynamicHostCatalogWithEmptyHostSet(t *testing.T) {
ctx := context.Background()
boundary.AuthenticateAdminCli(t, ctx)
newOrgId := boundary.CreateNewOrgCli(t, ctx)
orgId, err := boundary.CreateOrgCli(t, ctx)
require.NoError(t, err)
t.Cleanup(func() {
ctx := context.Background()
boundary.AuthenticateAdminCli(t, ctx)
output := e2e.RunCommand(ctx, "boundary", e2e.WithArgs("scopes", "delete", "-id", newOrgId))
output := e2e.RunCommand(ctx, "boundary", e2e.WithArgs("scopes", "delete", "-id", orgId))
require.NoError(t, output.Err, string(output.Stderr))
})
newProjectId := boundary.CreateNewProjectCli(t, ctx, newOrgId)
newHostCatalogId := boundary.CreateNewAwsHostCatalogCli(t, ctx, newProjectId, c.AwsAccessKeyId, c.AwsSecretAccessKey)
projectId, err := boundary.CreateProjectCli(t, ctx, orgId)
require.NoError(t, err)
hostCatalogId, err := boundary.CreateAwsHostCatalogCli(t, ctx, projectId, c.AwsAccessKeyId, c.AwsSecretAccessKey)
require.NoError(t, err)
// Set up a host set
newHostSetId := boundary.CreateNewAwsHostSetCli(t, ctx, newHostCatalogId, "tag:empty_test=true")
hostSetId, err := boundary.CreateAwsHostSetCli(t, ctx, hostCatalogId, "tag:empty_test=true")
require.NoError(t, err)
// Check that there are no hosts in the host set
t.Logf("Looking for items in the host set...")
@@ -52,7 +56,7 @@ func TestCliCreateAwsDynamicHostCatalogWithEmptyHostSet(t *testing.T) {
output := e2e.RunCommand(ctx, "boundary",
e2e.WithArgs(
"host-sets", "read",
"-id", newHostSetId,
"-id", hostSetId,
"-format", "json",
),
)
@@ -77,7 +81,7 @@ func TestCliCreateAwsDynamicHostCatalogWithEmptyHostSet(t *testing.T) {
}
output := e2e.RunCommand(ctx, "boundary",
e2e.WithArgs("hosts", "list", "-host-catalog-id", newHostCatalogId, "-format", "json"),
e2e.WithArgs("hosts", "list", "-host-catalog-id", hostCatalogId, "-format", "json"),
)
require.NoError(t, output.Err, string(output.Stderr))
var hostCatalogListResult hostcatalogs.HostCatalogListResult
@@ -92,14 +96,16 @@ func TestCliCreateAwsDynamicHostCatalogWithEmptyHostSet(t *testing.T) {
t.Log("Successfully detected zero hosts in the host catalog")
// Create target
newTargetId := boundary.CreateNewTargetCli(t, ctx, newProjectId, c.TargetPort)
boundary.AddHostSourceToTargetCli(t, ctx, newTargetId, newHostSetId)
targetId, err := boundary.CreateTargetCli(t, ctx, projectId, c.TargetPort)
require.NoError(t, err)
err = boundary.AddHostSourceToTargetCli(t, ctx, targetId, hostSetId)
require.NoError(t, err)
// Attempt to connect to target
output := e2e.RunCommand(ctx, "boundary",
e2e.WithArgs(
"connect",
"-target-id", newTargetId,
"-target-id", targetId,
"-format", "json",
"-exec", "/usr/bin/ssh", "--",
"-l", c.TargetSshUser,
@@ -33,43 +33,48 @@ func TestCliCreateAwsDynamicHostCatalogWithHostSet(t *testing.T) {
ctx := context.Background()
boundary.AuthenticateAdminCli(t, ctx)
newOrgId := boundary.CreateNewOrgCli(t, ctx)
orgId, err := boundary.CreateOrgCli(t, ctx)
require.NoError(t, err)
t.Cleanup(func() {
ctx := context.Background()
boundary.AuthenticateAdminCli(t, ctx)
output := e2e.RunCommand(ctx, "boundary", e2e.WithArgs("scopes", "delete", "-id", newOrgId))
output := e2e.RunCommand(ctx, "boundary", e2e.WithArgs("scopes", "delete", "-id", orgId))
require.NoError(t, output.Err, string(output.Stderr))
})
newProjectId := boundary.CreateNewProjectCli(t, ctx, newOrgId)
newHostCatalogId := boundary.CreateNewAwsHostCatalogCli(t, ctx, newProjectId, c.AwsAccessKeyId, c.AwsSecretAccessKey)
projectId, err := boundary.CreateProjectCli(t, ctx, orgId)
require.NoError(t, err)
hostCatalogId, err := boundary.CreateAwsHostCatalogCli(t, ctx, projectId, c.AwsAccessKeyId, c.AwsSecretAccessKey)
require.NoError(t, err)
// Set up a host set
newHostSetId1 := boundary.CreateNewAwsHostSetCli(t, ctx, newHostCatalogId, c.AwsHostSetFilter1)
hostSetId1, err := boundary.CreateAwsHostSetCli(t, ctx, hostCatalogId, c.AwsHostSetFilter1)
require.NoError(t, err)
var targetIps1 []string
err = json.Unmarshal([]byte(c.AwsHostSetIps1), &targetIps1)
expectedHostSetCount1 := len(targetIps1)
require.NoError(t, err)
boundary.WaitForNumberOfHostsInHostSetCli(t, ctx, newHostSetId1, expectedHostSetCount1)
boundary.WaitForNumberOfHostsInHostSetCli(t, ctx, hostSetId1, expectedHostSetCount1)
// Set up another host set
newHostSetId2 := boundary.CreateNewAwsHostSetCli(t, ctx, newHostCatalogId, c.AwsHostSetFilter2)
hostSetId2, err := boundary.CreateAwsHostSetCli(t, ctx, hostCatalogId, c.AwsHostSetFilter2)
require.NoError(t, err)
var targetIps2 []string
err = json.Unmarshal([]byte(c.AwsHostSetIps2), &targetIps2)
require.NoError(t, err)
expectedHostSetCount2 := len(targetIps2)
boundary.WaitForNumberOfHostsInHostSetCli(t, ctx, newHostSetId2, expectedHostSetCount2)
boundary.WaitForNumberOfHostsInHostSetCli(t, ctx, hostSetId2, expectedHostSetCount2)
// Update host set with a different filter
t.Log("Updating host set 2 with host set 1's filter...")
output := e2e.RunCommand(ctx, "boundary",
e2e.WithArgs(
"host-sets", "update", "plugin",
"-id", newHostSetId2,
"-id", hostSetId2,
"-attr", fmt.Sprintf("filters=%s", c.AwsHostSetFilter1),
),
)
require.NoError(t, output.Err, string(output.Stderr))
boundary.WaitForNumberOfHostsInHostSetCli(t, ctx, newHostSetId2, expectedHostSetCount1)
boundary.WaitForNumberOfHostsInHostSetCli(t, ctx, hostSetId2, expectedHostSetCount1)
// Get list of all hosts from host catalog
t.Logf("Looking for items in the host catalog...")
@@ -77,7 +82,7 @@ func TestCliCreateAwsDynamicHostCatalogWithHostSet(t *testing.T) {
err = backoff.RetryNotify(
func() error {
output := e2e.RunCommand(ctx, "boundary",
e2e.WithArgs("hosts", "list", "-host-catalog-id", newHostCatalogId, "-format", "json"),
e2e.WithArgs("hosts", "list", "-host-catalog-id", hostCatalogId, "-format", "json"),
)
if output.Err != nil {
return backoff.Permanent(errors.New(string(output.Stderr)))
@@ -107,14 +112,16 @@ func TestCliCreateAwsDynamicHostCatalogWithHostSet(t *testing.T) {
assert.Equal(t, expectedHostCatalogCount, actualHostCatalogCount, "Numbers of hosts in host catalog did not match expected amount")
// Create target
newTargetId := boundary.CreateNewTargetCli(t, ctx, newProjectId, c.TargetPort)
boundary.AddHostSourceToTargetCli(t, ctx, newTargetId, newHostSetId1)
targetId, err := boundary.CreateTargetCli(t, ctx, projectId, c.TargetPort)
require.NoError(t, err)
err = boundary.AddHostSourceToTargetCli(t, ctx, targetId, hostSetId1)
require.NoError(t, err)
// Connect to target
output = e2e.RunCommand(ctx, "boundary",
e2e.WithArgs(
"connect",
"-target-id", newTargetId,
"-target-id", targetId,
"-exec", "/usr/bin/ssh", "--",
"-l", c.TargetSshUser,
"-i", c.TargetSshKeyPath,
@@ -154,17 +161,19 @@ func TestApiCreateAwsDynamicHostCatalog(t *testing.T) {
require.NoError(t, err)
ctx := context.Background()
newOrgId := boundary.CreateNewOrgApi(t, ctx, client)
orgId, err := boundary.CreateOrgApi(t, ctx, client)
require.NoError(t, err)
t.Cleanup(func() {
scopeClient := scopes.NewClient(client)
_, err := scopeClient.Delete(ctx, newOrgId)
_, err := scopeClient.Delete(ctx, orgId)
require.NoError(t, err)
})
newProjectId := boundary.CreateNewProjectApi(t, ctx, client, newOrgId)
projectId, err := boundary.CreateProjectApi(t, ctx, client, orgId)
require.NoError(t, err)
// Create a dynamic host catalog
hcClient := hostcatalogs.NewClient(client)
newHostCatalogResult, err := hcClient.Create(ctx, "plugin", newProjectId,
newHostCatalogResult, err := hcClient.Create(ctx, "plugin", projectId,
hostcatalogs.WithName("e2e Automated Test Host Catalog"),
hostcatalogs.WithPluginName("aws"),
hostcatalogs.WithAttributes(map[string]any{
+11 -8
View File
@@ -22,22 +22,25 @@ func TestCliWorker(t *testing.T) {
ctx := context.Background()
boundary.AuthenticateAdminCli(t, ctx)
newOrgId := boundary.CreateNewOrgCli(t, ctx)
orgId, err := boundary.CreateOrgCli(t, ctx)
require.NoError(t, err)
t.Cleanup(func() {
ctx := context.Background()
boundary.AuthenticateAdminCli(t, ctx)
output := e2e.RunCommand(ctx, "boundary", e2e.WithArgs("scopes", "delete", "-id", newOrgId))
output := e2e.RunCommand(ctx, "boundary", e2e.WithArgs("scopes", "delete", "-id", orgId))
require.NoError(t, output.Err, string(output.Stderr))
})
newProjectId := boundary.CreateNewProjectCli(t, ctx, newOrgId)
newTargetId := boundary.CreateNewTargetCli(t, ctx, newProjectId, c.TargetPort, target.WithAddress(c.TargetAddress))
projectId, err := boundary.CreateProjectCli(t, ctx, orgId)
require.NoError(t, err)
targetId, err := boundary.CreateTargetCli(t, ctx, projectId, c.TargetPort, target.WithAddress(c.TargetAddress))
require.NoError(t, err)
// Set incorrect worker filter, expect connection failure
t.Logf("Setting incorrect worker filter...")
output := e2e.RunCommand(ctx, "boundary",
e2e.WithArgs(
"targets", "update", "tcp",
"-id", newTargetId,
"-id", targetId,
"-egress-worker-filter", `"prod" in "/tags/type"`,
"-format", "json",
),
@@ -47,7 +50,7 @@ func TestCliWorker(t *testing.T) {
output = e2e.RunCommand(ctx, "boundary",
e2e.WithArgs(
"connect",
"-target-id", newTargetId,
"-target-id", targetId,
"-exec", "/usr/bin/ssh", "--",
"-l", c.TargetSshUser,
"-i", c.TargetSshKeyPath,
@@ -70,7 +73,7 @@ func TestCliWorker(t *testing.T) {
output = e2e.RunCommand(ctx, "boundary",
e2e.WithArgs(
"targets", "update", "tcp",
"-id", newTargetId,
"-id", targetId,
"-egress-worker-filter", fmt.Sprintf(`"%s" in "/tags/type"`, c.WorkerTagEgress),
"-format", "json",
),
@@ -80,7 +83,7 @@ func TestCliWorker(t *testing.T) {
output = e2e.RunCommand(ctx, "boundary",
e2e.WithArgs(
"connect",
"-target-id", newTargetId,
"-target-id", targetId,
"-exec", "/usr/bin/ssh", "--",
"-l", c.TargetSshUser,
"-i", c.TargetSshKeyPath,
+23 -14
View File
@@ -27,30 +27,33 @@ func TestCliAlias(t *testing.T) {
// Set up the test
ctx := context.Background()
boundary.AuthenticateAdminCli(t, ctx)
newOrgId := boundary.CreateNewOrgCli(t, ctx)
orgId, err := boundary.CreateOrgCli(t, ctx)
require.NoError(t, err)
t.Cleanup(func() {
ctx := context.Background()
boundary.AuthenticateAdminCli(t, ctx)
output := e2e.RunCommand(ctx, "boundary", e2e.WithArgs("scopes", "delete", "-id", newOrgId))
output := e2e.RunCommand(ctx, "boundary", e2e.WithArgs("scopes", "delete", "-id", orgId))
require.NoError(t, output.Err, string(output.Stderr))
})
newProjectId := boundary.CreateNewProjectCli(t, ctx, newOrgId)
projectId, err := boundary.CreateProjectCli(t, ctx, orgId)
require.NoError(t, err)
// Create an alias for a target
newTargetId := boundary.CreateNewTargetCli(
targetId, err := boundary.CreateTargetCli(
t,
ctx,
newProjectId,
projectId,
c.TargetPort,
target.WithAddress(c.TargetAddress),
)
require.NoError(t, err)
aliasTargetAddress := "example.alias.boundary"
output := e2e.RunCommand(ctx, "boundary",
e2e.WithArgs(
"aliases", "create", "target",
"-scope-id", "global",
"-value", aliasTargetAddress,
"-destination-id", newTargetId,
"-destination-id", targetId,
"-format", "json",
),
)
@@ -111,18 +114,24 @@ func TestCliAlias(t *testing.T) {
require.NoError(t, err)
// Create another alias that uses a target with a host set
newHostCatalogId := boundary.CreateNewHostCatalogCli(t, ctx, newProjectId)
newHostSetId := boundary.CreateNewHostSetCli(t, ctx, newHostCatalogId)
newHostId := boundary.CreateNewHostCli(t, ctx, newHostCatalogId, c.TargetAddress)
boundary.AddHostToHostSetCli(t, ctx, newHostSetId, newHostId)
targetWithHost := boundary.CreateNewTargetCli(
hostCatalogId, err := boundary.CreateHostCatalogCli(t, ctx, projectId)
require.NoError(t, err)
hostSetId, err := boundary.CreateHostSetCli(t, ctx, hostCatalogId)
require.NoError(t, err)
hostId, err := boundary.CreateHostCli(t, ctx, hostCatalogId, c.TargetAddress)
require.NoError(t, err)
err = boundary.AddHostToHostSetCli(t, ctx, hostSetId, hostId)
require.NoError(t, err)
targetWithHost, err := boundary.CreateTargetCli(
t,
ctx,
newProjectId,
projectId,
c.TargetPort,
target.WithName("targetWithHost"),
)
boundary.AddHostSourceToTargetCli(t, ctx, targetWithHost, newHostSetId)
require.NoError(t, err)
err = boundary.AddHostSourceToTargetCli(t, ctx, targetWithHost, hostSetId)
require.NoError(t, err)
aliasTargetHost := "aliasTargetHost"
output = e2e.RunCommand(ctx, "boundary",
e2e.WithArgs(
@@ -161,7 +170,7 @@ func TestCliAlias(t *testing.T) {
e2e.WithArgs(
"aliases", "update", "target",
"-id", aliasTargetHostId,
"-authorize-session-host-id", newHostId,
"-authorize-session-host-id", hostId,
"-format", "json",
),
)
@@ -28,11 +28,12 @@ func TestCliAuthMethodPassword(t *testing.T) {
ctx := context.Background()
boundary.AuthenticateAdminCli(t, ctx)
newOrgId := boundary.CreateNewOrgCli(t, ctx)
orgId, err := boundary.CreateOrgCli(t, ctx)
require.NoError(t, err)
t.Cleanup(func() {
ctx := context.Background()
boundary.AuthenticateAdminCli(t, ctx)
output := e2e.RunCommand(ctx, "boundary", e2e.WithArgs("scopes", "delete", "-id", newOrgId))
output := e2e.RunCommand(ctx, "boundary", e2e.WithArgs("scopes", "delete", "-id", orgId))
require.NoError(t, output.Err, string(output.Stderr))
})
@@ -40,14 +41,14 @@ func TestCliAuthMethodPassword(t *testing.T) {
output := e2e.RunCommand(ctx, "boundary",
e2e.WithArgs(
"auth-methods", "create", "password",
"-scope-id", newOrgId,
"-scope-id", orgId,
"-name", "e2e Auth Method",
"-format", "json",
),
)
require.NoError(t, output.Err, string(output.Stderr))
var newAuthMethodResult authmethods.AuthMethodCreateResult
err := json.Unmarshal(output.Stdout, &newAuthMethodResult)
err = json.Unmarshal(output.Stdout, &newAuthMethodResult)
require.NoError(t, err)
newAuthMethodId := newAuthMethodResult.Item.Id
// Need to manually clean up auth method until ICU-7833 is addressed
@@ -61,13 +62,14 @@ func TestCliAuthMethodPassword(t *testing.T) {
// Create account in auth method
testAccountName := "test-account"
newAccountId, acctPassword := boundary.CreateNewAccountCli(t, ctx, newAuthMethodId, testAccountName)
accountId, acctPassword, err := boundary.CreateAccountCli(t, ctx, newAuthMethodId, testAccountName)
require.NoError(t, err)
// Set new auth method as primary auth method for the new org
output = e2e.RunCommand(ctx, "boundary",
e2e.WithArgs(
"scopes", "update",
"-id", newOrgId,
"-id", orgId,
"-primary-auth-method-id", newAuthMethodId,
"-format", "json",
),
@@ -82,7 +84,7 @@ func TestCliAuthMethodPassword(t *testing.T) {
output = e2e.RunCommand(ctx, "boundary",
e2e.WithArgs(
"authenticate", "password",
"-scope-id", newOrgId,
"-scope-id", orgId,
"-login-name", testAccountName,
"-password", "env://E2E_TEST_BOUNDARY_PASSWORD",
"-format", "json",
@@ -96,7 +98,7 @@ func TestCliAuthMethodPassword(t *testing.T) {
output = e2e.RunCommand(ctx, "boundary",
e2e.WithArgs(
"users", "list",
"-scope-id", newOrgId,
"-scope-id", orgId,
"-format", "json",
),
)
@@ -104,7 +106,7 @@ func TestCliAuthMethodPassword(t *testing.T) {
var usersListResult users.UserListResult
err = json.Unmarshal(output.Stdout, &usersListResult)
require.NoError(t, err)
require.Equal(t, newAccountId, usersListResult.Items[0].PrimaryAccountId)
require.Equal(t, accountId, usersListResult.Items[0].PrimaryAccountId)
userId := usersListResult.Items[0].Id
output = e2e.RunCommand(ctx, "boundary",
@@ -118,20 +120,23 @@ func TestCliAuthMethodPassword(t *testing.T) {
var usersReadResult users.UserReadResult
err = json.Unmarshal(output.Stdout, &usersReadResult)
require.NoError(t, err)
require.Equal(t, newAccountId, usersReadResult.Item.PrimaryAccountId)
require.Contains(t, usersReadResult.Item.AccountIds, newAccountId)
require.Equal(t, accountId, usersReadResult.Item.PrimaryAccountId)
require.Contains(t, usersReadResult.Item.AccountIds, accountId)
// Create a new account and manually attach it to a new user
newUserId := boundary.CreateNewUserCli(t, ctx, newOrgId)
newUserId, err := boundary.CreateUserCli(t, ctx, orgId)
require.NoError(t, err)
testAccountName = "test-account2"
newAccountId, acctPassword = boundary.CreateNewAccountCli(t, ctx, newAuthMethodId, testAccountName)
boundary.SetAccountToUserCli(t, ctx, newUserId, newAccountId)
accountId, acctPassword, err = boundary.CreateAccountCli(t, ctx, newAuthMethodId, testAccountName)
require.NoError(t, err)
err = boundary.SetAccountToUserCli(t, ctx, newUserId, accountId)
require.NoError(t, err)
// Log in with the new account
output = e2e.RunCommand(ctx, "boundary",
e2e.WithArgs(
"authenticate", "password",
"-scope-id", newOrgId,
"-scope-id", orgId,
"-login-name", testAccountName,
"-password", "env://E2E_TEST_BOUNDARY_PASSWORD",
"-format", "json",
@@ -152,18 +157,20 @@ func TestCliPaginateAuthMethods(t *testing.T) {
boundary.AuthenticateAdminCli(t, ctx)
client, err := boundary.NewApiClient()
require.NoError(t, err)
newOrgId := boundary.CreateNewOrgCli(t, ctx)
orgId, err := boundary.CreateOrgCli(t, ctx)
require.NoError(t, err)
t.Cleanup(func() {
ctx := context.Background()
boundary.AuthenticateAdminCli(t, ctx)
output := e2e.RunCommand(ctx, "boundary", e2e.WithArgs("scopes", "delete", "-id", newOrgId))
output := e2e.RunCommand(ctx, "boundary", e2e.WithArgs("scopes", "delete", "-id", orgId))
require.NoError(t, output.Err, string(output.Stderr))
})
// Create enough auth methods to overflow a single page.
var authMethodIds []string
for i := 0; i < c.MaxPageSize+1; i++ {
authMethodId := boundary.CreateNewAuthMethodApi(t, ctx, client, newOrgId)
authMethodId, err := boundary.CreateAuthMethodApi(t, ctx, client, orgId)
require.NoError(t, err)
authMethodIds = append(authMethodIds, authMethodId)
}
@@ -171,7 +178,7 @@ func TestCliPaginateAuthMethods(t *testing.T) {
output := e2e.RunCommand(ctx, "boundary",
e2e.WithArgs(
"auth-methods", "list",
"-scope-id", newOrgId,
"-scope-id", orgId,
"-format=json",
),
)
@@ -191,7 +198,8 @@ func TestCliPaginateAuthMethods(t *testing.T) {
assert.Empty(t, initialAuthMethods.ListToken)
// Create a new auth method and destroy one of the other auth methods
newAuthMethodId := boundary.CreateNewAuthMethodApi(t, ctx, client, newOrgId)
authMethodId, err := boundary.CreateAuthMethodApi(t, ctx, client, orgId)
require.NoError(t, err)
output = e2e.RunCommand(ctx, "boundary",
e2e.WithArgs(
"auth-methods", "delete",
@@ -204,7 +212,7 @@ func TestCliPaginateAuthMethods(t *testing.T) {
output = e2e.RunCommand(ctx, "boundary",
e2e.WithArgs(
"auth-methods", "list",
"-scope-id", newOrgId,
"-scope-id", orgId,
"-format=json",
),
)
@@ -218,7 +226,7 @@ func TestCliPaginateAuthMethods(t *testing.T) {
// The first item should be the most recently created,
// which should be the new auth method
firstItem := newAuthMethods.Items[0]
assert.Equal(t, newAuthMethodId, firstItem.Id)
assert.Equal(t, authMethodId, firstItem.Id)
assert.Empty(t, initialAuthMethods.ResponseType)
assert.Empty(t, initialAuthMethods.RemovedIds)
assert.Empty(t, initialAuthMethods.ListToken)
@@ -241,22 +249,25 @@ func TestApiPaginateAuthMethods(t *testing.T) {
ctx := context.Background()
sClient := scopes.NewClient(client)
amClient := authmethods.NewClient(client)
newOrgId := boundary.CreateNewOrgApi(t, ctx, client)
orgId, err := boundary.CreateOrgApi(t, ctx, client)
require.NoError(t, err)
t.Cleanup(func() {
ctx := context.Background()
client.SetToken(adminToken)
_, err = sClient.Delete(ctx, newOrgId)
_, err = sClient.Delete(ctx, orgId)
require.NoError(t, err)
})
// Create enough auth methods to overflow a single page.
var authMethodIds []string
for i := 0; i < c.MaxPageSize+1; i++ {
authMethodIds = append(authMethodIds, boundary.CreateNewAuthMethodApi(t, ctx, client, newOrgId))
authMethodId, err := boundary.CreateAuthMethodApi(t, ctx, client, orgId)
require.NoError(t, err)
authMethodIds = append(authMethodIds, authMethodId)
}
// List auth methods
initialAuthMethods, err := amClient.List(ctx, newOrgId)
initialAuthMethods, err := amClient.List(ctx, orgId)
require.NoError(t, err)
var returnedIds []string
@@ -276,12 +287,13 @@ func TestApiPaginateAuthMethods(t *testing.T) {
assert.Len(t, mapSliceItems, c.MaxPageSize+1)
// Create a new auth method and destroy one of the other auth methods
newAuthMethodId := boundary.CreateNewAuthMethodApi(t, ctx, client, newOrgId)
authMethodId, err := boundary.CreateAuthMethodApi(t, ctx, client, orgId)
require.NoError(t, err)
_, err = amClient.Delete(ctx, initialAuthMethods.Items[0].Id)
require.NoError(t, err)
// List auth methods again, should have new one but not old one
newAuthMethods, err := amClient.List(ctx, newOrgId, authmethods.WithListToken(initialAuthMethods.ListToken))
newAuthMethods, err := amClient.List(ctx, orgId, authmethods.WithListToken(initialAuthMethods.ListToken))
require.NoError(t, err)
// Note that this will likely contain all the auth methods,
@@ -292,7 +304,7 @@ func TestApiPaginateAuthMethods(t *testing.T) {
// The first item should be the most recently created, which
// should be our new auth method
firstItem := newAuthMethods.Items[0]
assert.Equal(t, newAuthMethodId, firstItem.Id)
assert.Equal(t, authMethodId, firstItem.Id)
assert.Equal(t, "complete", newAuthMethods.ResponseType)
// Note that the removed IDs may contain entries from other tests,
// so just check that there is at least 1 entry and that our entry
@@ -28,23 +28,26 @@ func TestUserIsLoggedOutWhenAuthTokenIsDeletedCli(t *testing.T) {
ctx := context.Background()
boundary.AuthenticateAdminCli(t, ctx)
newAccountId, acctPassword := boundary.CreateNewAccountCli(t, ctx, bc.AuthMethodId, testAccountName)
accountid, acctPassword, err := boundary.CreateAccountCli(t, ctx, bc.AuthMethodId, testAccountName)
require.NoError(t, err)
t.Cleanup(func() {
boundary.AuthenticateAdminCli(t, context.Background())
output := e2e.RunCommand(ctx, "boundary",
e2e.WithArgs("accounts", "delete", "-id", newAccountId),
e2e.WithArgs("accounts", "delete", "-id", accountid),
)
require.NoError(t, output.Err, string(output.Stderr))
})
newUserId := boundary.CreateNewUserCli(t, ctx, "global")
userId, err := boundary.CreateUserCli(t, ctx, "global")
require.NoError(t, err)
t.Cleanup(func() {
boundary.AuthenticateAdminCli(t, context.Background())
output := e2e.RunCommand(ctx, "boundary",
e2e.WithArgs("users", "delete", "-id", newUserId),
e2e.WithArgs("users", "delete", "-id", userId),
)
require.NoError(t, output.Err, string(output.Stderr))
})
boundary.SetAccountToUserCli(t, ctx, newUserId, newAccountId)
err = boundary.SetAccountToUserCli(t, ctx, userId, accountid)
require.NoError(t, err)
// Authenticate user and assign a name to its auth token
boundary.AuthenticateCli(t, context.Background(), bc.AuthMethodId, testAccountName, acctPassword,
@@ -25,20 +25,28 @@ func TestCliBytesUpDownEmpty(t *testing.T) {
ctx := context.Background()
boundary.AuthenticateAdminCli(t, ctx)
newOrgId := boundary.CreateNewOrgCli(t, ctx)
orgId, err := boundary.CreateOrgCli(t, ctx)
require.NoError(t, err)
t.Cleanup(func() {
ctx := context.Background()
boundary.AuthenticateAdminCli(t, ctx)
output := e2e.RunCommand(ctx, "boundary", e2e.WithArgs("scopes", "delete", "-id", newOrgId))
output := e2e.RunCommand(ctx, "boundary", e2e.WithArgs("scopes", "delete", "-id", orgId))
require.NoError(t, output.Err, string(output.Stderr))
})
newProjectId := boundary.CreateNewProjectCli(t, ctx, newOrgId)
newHostCatalogId := boundary.CreateNewHostCatalogCli(t, ctx, newProjectId)
newHostSetId := boundary.CreateNewHostSetCli(t, ctx, newHostCatalogId)
newHostId := boundary.CreateNewHostCli(t, ctx, newHostCatalogId, c.TargetAddress)
boundary.AddHostToHostSetCli(t, ctx, newHostSetId, newHostId)
newTargetId := boundary.CreateNewTargetCli(t, ctx, newProjectId, c.TargetPort)
boundary.AddHostSourceToTargetCli(t, ctx, newTargetId, newHostSetId)
projectId, err := boundary.CreateProjectCli(t, ctx, orgId)
require.NoError(t, err)
hostCatalogId, err := boundary.CreateHostCatalogCli(t, ctx, projectId)
require.NoError(t, err)
hostSetId, err := boundary.CreateHostSetCli(t, ctx, hostCatalogId)
require.NoError(t, err)
hostId, err := boundary.CreateHostCli(t, ctx, hostCatalogId, c.TargetAddress)
require.NoError(t, err)
err = boundary.AddHostToHostSetCli(t, ctx, hostSetId, hostId)
require.NoError(t, err)
targetId, err := boundary.CreateTargetCli(t, ctx, projectId, c.TargetPort)
require.NoError(t, err)
err = boundary.AddHostSourceToTargetCli(t, ctx, targetId, hostSetId)
require.NoError(t, err)
// Create a session where no additional commands are run
ctxCancel, cancel := context.WithCancel(context.Background())
@@ -48,7 +56,7 @@ func TestCliBytesUpDownEmpty(t *testing.T) {
errChan <- e2e.RunCommand(ctxCancel, "boundary",
e2e.WithArgs(
"connect",
"-target-id", newTargetId,
"-target-id", targetId,
"-exec", "/usr/bin/ssh", "--",
"-l", c.TargetSshUser,
"-i", c.TargetSshKeyPath,
@@ -62,9 +70,9 @@ func TestCliBytesUpDownEmpty(t *testing.T) {
}()
t.Cleanup(cancel)
session := boundary.WaitForSessionCli(t, ctx, newProjectId)
assert.Equal(t, newTargetId, session.TargetId)
assert.Equal(t, newHostId, session.HostId)
session := boundary.WaitForSessionCli(t, ctx, projectId)
assert.Equal(t, targetId, session.TargetId)
assert.Equal(t, hostId, session.HostId)
// Confirm that bytesUp and bytesDown do not change
bytesUp := 0
@@ -26,20 +26,28 @@ func TestCliBytesUpDownTransferData(t *testing.T) {
ctx := context.Background()
boundary.AuthenticateAdminCli(t, ctx)
newOrgId := boundary.CreateNewOrgCli(t, ctx)
orgId, err := boundary.CreateOrgCli(t, ctx)
require.NoError(t, err)
t.Cleanup(func() {
ctx := context.Background()
boundary.AuthenticateAdminCli(t, ctx)
output := e2e.RunCommand(ctx, "boundary", e2e.WithArgs("scopes", "delete", "-id", newOrgId))
output := e2e.RunCommand(ctx, "boundary", e2e.WithArgs("scopes", "delete", "-id", orgId))
require.NoError(t, output.Err, string(output.Stderr))
})
newProjectId := boundary.CreateNewProjectCli(t, ctx, newOrgId)
newHostCatalogId := boundary.CreateNewHostCatalogCli(t, ctx, newProjectId)
newHostSetId := boundary.CreateNewHostSetCli(t, ctx, newHostCatalogId)
newHostId := boundary.CreateNewHostCli(t, ctx, newHostCatalogId, c.TargetAddress)
boundary.AddHostToHostSetCli(t, ctx, newHostSetId, newHostId)
newTargetId := boundary.CreateNewTargetCli(t, ctx, newProjectId, c.TargetPort)
boundary.AddHostSourceToTargetCli(t, ctx, newTargetId, newHostSetId)
projectId, err := boundary.CreateProjectCli(t, ctx, orgId)
require.NoError(t, err)
hostCatalogId, err := boundary.CreateHostCatalogCli(t, ctx, projectId)
require.NoError(t, err)
hostSetId, err := boundary.CreateHostSetCli(t, ctx, hostCatalogId)
require.NoError(t, err)
hostId, err := boundary.CreateHostCli(t, ctx, hostCatalogId, c.TargetAddress)
require.NoError(t, err)
err = boundary.AddHostToHostSetCli(t, ctx, hostSetId, hostId)
require.NoError(t, err)
targetId, err := boundary.CreateTargetCli(t, ctx, projectId, c.TargetPort)
require.NoError(t, err)
err = boundary.AddHostSourceToTargetCli(t, ctx, targetId, hostSetId)
require.NoError(t, err)
// Create a session where no additional commands are run
ctxCancel, cancel := context.WithCancel(context.Background())
@@ -51,7 +59,7 @@ func TestCliBytesUpDownTransferData(t *testing.T) {
errChan <- e2e.RunCommand(ctxCancel, "boundary",
e2e.WithArgs(
"connect",
"-target-id", newTargetId,
"-target-id", targetId,
"-exec", "/usr/bin/ssh", "--",
"-l", c.TargetSshUser,
"-i", c.TargetSshKeyPath,
@@ -65,10 +73,10 @@ func TestCliBytesUpDownTransferData(t *testing.T) {
)
}()
t.Cleanup(cancel)
s := boundary.WaitForSessionCli(t, ctx, newProjectId)
s := boundary.WaitForSessionCli(t, ctx, projectId)
boundary.WaitForSessionStatusCli(t, ctx, s.Id, session.StatusActive.String())
assert.Equal(t, newTargetId, s.TargetId)
assert.Equal(t, newHostId, s.HostId)
assert.Equal(t, targetId, s.TargetId)
assert.Equal(t, hostId, s.HostId)
bytesUp := 0
bytesDown := 0
@@ -40,20 +40,28 @@ func TestCliStaticCredentialStore(t *testing.T) {
ctx := context.Background()
boundary.AuthenticateAdminCli(t, ctx)
newOrgId := boundary.CreateNewOrgCli(t, ctx)
orgId, err := boundary.CreateOrgCli(t, ctx)
require.NoError(t, err)
t.Cleanup(func() {
ctx := context.Background()
boundary.AuthenticateAdminCli(t, ctx)
output := e2e.RunCommand(ctx, "boundary", e2e.WithArgs("scopes", "delete", "-id", newOrgId))
output := e2e.RunCommand(ctx, "boundary", e2e.WithArgs("scopes", "delete", "-id", orgId))
require.NoError(t, output.Err, string(output.Stderr))
})
newProjectId := boundary.CreateNewProjectCli(t, ctx, newOrgId)
newHostCatalogId := boundary.CreateNewHostCatalogCli(t, ctx, newProjectId)
newHostSetId := boundary.CreateNewHostSetCli(t, ctx, newHostCatalogId)
newHostId := boundary.CreateNewHostCli(t, ctx, newHostCatalogId, c.TargetAddress)
boundary.AddHostToHostSetCli(t, ctx, newHostSetId, newHostId)
newTargetId := boundary.CreateNewTargetCli(t, ctx, newProjectId, c.TargetPort)
boundary.AddHostSourceToTargetCli(t, ctx, newTargetId, newHostSetId)
projectId, err := boundary.CreateProjectCli(t, ctx, orgId)
require.NoError(t, err)
hostCatalogId, err := boundary.CreateHostCatalogCli(t, ctx, projectId)
require.NoError(t, err)
hostSetId, err := boundary.CreateHostSetCli(t, ctx, hostCatalogId)
require.NoError(t, err)
hostId, err := boundary.CreateHostCli(t, ctx, hostCatalogId, c.TargetAddress)
require.NoError(t, err)
err = boundary.AddHostToHostSetCli(t, ctx, hostSetId, hostId)
require.NoError(t, err)
targetId, err := boundary.CreateTargetCli(t, ctx, projectId, c.TargetPort)
require.NoError(t, err)
err = boundary.AddHostSourceToTargetCli(t, ctx, targetId, hostSetId)
require.NoError(t, err)
err = createPrivateKeyPemFile(testPemFile)
require.NoError(t, err)
@@ -63,14 +71,18 @@ func TestCliStaticCredentialStore(t *testing.T) {
})
// Create static credentials
newCredentialStoreId := boundary.CreateNewCredentialStoreStaticCli(t, ctx, newProjectId)
privateKeyCredentialsId := boundary.CreateNewStaticCredentialPrivateKeyCli(t, ctx, newCredentialStoreId, c.TargetSshUser, testPemFile)
pwCredentialsId := boundary.CreateNewStaticCredentialPasswordCli(t, ctx, newCredentialStoreId, c.TargetSshUser, testPassword)
jsonCredentialsId := boundary.CreateNewStaticCredentialJsonCli(t, ctx, newCredentialStoreId, testCredentialsFile)
storeId, err := boundary.CreateCredentialStoreStaticCli(t, ctx, projectId)
require.NoError(t, err)
privateKeyCredentialsId, err := boundary.CreateStaticCredentialPrivateKeyCli(t, ctx, storeId, c.TargetSshUser, testPemFile)
require.NoError(t, err)
pwCredentialId, err := boundary.CreateStaticCredentialPasswordCli(t, ctx, storeId, c.TargetSshUser, testPassword)
require.NoError(t, err)
jsonCredentialId, err := boundary.CreateStaticCredentialJsonCli(t, ctx, storeId, testCredentialsFile)
require.NoError(t, err)
// Get credentials for target (expect empty)
output := e2e.RunCommand(ctx, "boundary",
e2e.WithArgs("targets", "authorize-session", "-id", newTargetId, "-format", "json"),
e2e.WithArgs("targets", "authorize-session", "-id", targetId, "-format", "json"),
)
require.NoError(t, output.Err, string(output.Stderr))
var newSessionAuthorizationResult targets.SessionAuthorizationResult
@@ -79,13 +91,16 @@ func TestCliStaticCredentialStore(t *testing.T) {
require.True(t, newSessionAuthorizationResult.Item.Credentials == nil)
// Add credentials to target
boundary.AddBrokeredCredentialSourceToTargetCli(t, ctx, newTargetId, privateKeyCredentialsId)
boundary.AddBrokeredCredentialSourceToTargetCli(t, ctx, newTargetId, jsonCredentialsId)
boundary.AddBrokeredCredentialSourceToTargetCli(t, ctx, newTargetId, pwCredentialsId)
err = boundary.AddBrokeredCredentialSourceToTargetCli(t, ctx, targetId, privateKeyCredentialsId)
require.NoError(t, err)
err = boundary.AddBrokeredCredentialSourceToTargetCli(t, ctx, targetId, jsonCredentialId)
require.NoError(t, err)
err = boundary.AddBrokeredCredentialSourceToTargetCli(t, ctx, targetId, pwCredentialId)
require.NoError(t, err)
// Get credentials for target
output = e2e.RunCommand(ctx, "boundary",
e2e.WithArgs("targets", "authorize-session", "-id", newTargetId, "-format", "json"),
e2e.WithArgs("targets", "authorize-session", "-id", targetId, "-format", "json"),
)
require.NoError(t, output.Err, string(output.Stderr))
err = json.Unmarshal(output.Stdout, &newSessionAuthorizationResult)
@@ -117,14 +132,14 @@ func TestCliStaticCredentialStore(t *testing.T) {
// Delete credential store
output = e2e.RunCommand(ctx, "boundary",
e2e.WithArgs("credential-stores", "delete", "-id", newCredentialStoreId),
e2e.WithArgs("credential-stores", "delete", "-id", storeId),
)
require.NoError(t, output.Err, string(output.Stderr))
t.Log("Waiting for credential store to be deleted...")
err = backoff.RetryNotify(
func() error {
output := e2e.RunCommand(ctx, "boundary",
e2e.WithArgs("credential-stores", "read", "-id", newCredentialStoreId, "-format", "json"),
e2e.WithArgs("credential-stores", "read", "-id", storeId, "-format", "json"),
)
if output.Err == nil {
return fmt.Errorf("Deleted credential can still be read: '%s'", output.Stdout)
@@ -182,26 +197,35 @@ func TestApiStaticCredentialStore(t *testing.T) {
require.NoError(t, err)
ctx := context.Background()
newOrgId := boundary.CreateNewOrgApi(t, ctx, client)
orgId, err := boundary.CreateOrgApi(t, ctx, client)
require.NoError(t, err)
t.Cleanup(func() {
scopeClient := scopes.NewClient(client)
_, err := scopeClient.Delete(ctx, newOrgId)
_, err := scopeClient.Delete(ctx, orgId)
require.NoError(t, err)
})
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.TargetAddress)
boundary.AddHostToHostSetApi(t, ctx, client, newHostSetId, newHostId)
newTargetId := boundary.CreateNewTargetApi(t, ctx, client, newProjectId, c.TargetPort)
boundary.AddHostSourceToTargetApi(t, ctx, client, newTargetId, newHostSetId)
newCredentialStoreId := boundary.CreateNewCredentialStoreStaticApi(t, ctx, client, newProjectId)
projectId, err := boundary.CreateProjectApi(t, ctx, client, orgId)
require.NoError(t, err)
hostCatalogId, err := boundary.CreateHostCatalogApi(t, ctx, client, projectId)
require.NoError(t, err)
hostSetId, err := boundary.CreateHostSetApi(t, ctx, client, hostCatalogId)
require.NoError(t, err)
hostId, err := boundary.CreateHostApi(t, ctx, client, hostCatalogId, c.TargetAddress)
require.NoError(t, err)
err = boundary.AddHostToHostSetApi(t, ctx, client, hostSetId, hostId)
require.NoError(t, err)
targetId, err := boundary.CreateTargetApi(t, ctx, client, projectId, c.TargetPort)
require.NoError(t, err)
err = boundary.AddHostSourceToTargetApi(t, ctx, client, targetId, hostSetId)
require.NoError(t, err)
storeId, err := boundary.CreateCredentialStoreStaticApi(t, ctx, client, projectId)
require.NoError(t, err)
// Create credentials
cClient := credentials.NewClient(client)
k, err := os.ReadFile(c.TargetSshKeyPath)
require.NoError(t, err)
newCredentialsResult, err := cClient.Create(ctx, "ssh_private_key", newCredentialStoreId,
newCredentialsResult, err := cClient.Create(ctx, "ssh_private_key", storeId,
credentials.WithSshPrivateKeyCredentialUsername(c.TargetSshUser),
credentials.WithSshPrivateKeyCredentialPrivateKey(string(k)),
)
@@ -211,14 +235,14 @@ func TestApiStaticCredentialStore(t *testing.T) {
// Add credentials to target
tClient := targets.NewClient(client)
_, err = tClient.AddCredentialSources(ctx, newTargetId, 0,
_, err = tClient.AddCredentialSources(ctx, targetId, 0,
targets.WithAutomaticVersioning(true),
targets.WithBrokeredCredentialSourceIds([]string{newCredentialsId}),
)
require.NoError(t, err)
// Authorize Session
newSessionAuthorizationResult, err := tClient.AuthorizeSession(ctx, newTargetId)
newSessionAuthorizationResult, err := tClient.AuthorizeSession(ctx, targetId)
require.NoError(t, err)
newSessionAuthorization := newSessionAuthorizationResult.Item
retrievedUser, ok := newSessionAuthorization.Credentials[0].Credential["username"].(string)
@@ -32,14 +32,16 @@ func TestCliPaginateAccounts(t *testing.T) {
boundary.AuthenticateAdminCli(t, ctx)
client, err := boundary.NewApiClient()
require.NoError(t, err)
newOrgId := boundary.CreateNewOrgCli(t, ctx)
orgId, err := boundary.CreateOrgCli(t, ctx)
require.NoError(t, err)
t.Cleanup(func() {
ctx := context.Background()
boundary.AuthenticateAdminCli(t, ctx)
output := e2e.RunCommand(ctx, "boundary", e2e.WithArgs("scopes", "delete", "-id", newOrgId))
output := e2e.RunCommand(ctx, "boundary", e2e.WithArgs("scopes", "delete", "-id", orgId))
require.NoError(t, output.Err, string(output.Stderr))
})
amId := boundary.CreateNewAuthMethodApi(t, ctx, client, newOrgId)
amId, err := boundary.CreateAuthMethodApi(t, ctx, client, orgId)
require.NoError(t, err)
t.Cleanup(func() {
ctx := context.Background()
boundary.AuthenticateAdminCli(t, ctx)
@@ -50,7 +52,8 @@ func TestCliPaginateAccounts(t *testing.T) {
// Create enough accounts to overflow a single page.
var accountIds []string
for i := 0; i < c.MaxPageSize+1; i++ {
accId, _ := boundary.CreateNewAccountApi(t, ctx, client, amId, "testuser-"+strconv.Itoa(i))
accId, _, err := boundary.CreateAccountApi(t, ctx, client, amId, "testuser-"+strconv.Itoa(i))
require.NoError(t, err)
accountIds = append(accountIds, accId)
}
@@ -80,7 +83,8 @@ func TestCliPaginateAccounts(t *testing.T) {
assert.Empty(t, initialAccounts.ListToken)
// Create a new account and destroy one of the other accounts
newAccountId, _ := boundary.CreateNewAccountApi(t, ctx, client, amId, "newuser")
accountId, _, err := boundary.CreateAccountApi(t, ctx, client, amId, "newuser")
require.NoError(t, err)
output = e2e.RunCommand(ctx, "boundary",
e2e.WithArgs(
"accounts", "delete",
@@ -107,7 +111,7 @@ func TestCliPaginateAccounts(t *testing.T) {
// The first item should be the most recently created, which
// should be our new account
firstItem := newAccounts.Items[0]
assert.Equal(t, newAccountId, firstItem.Id)
assert.Equal(t, accountId, firstItem.Id)
assert.Empty(t, newAccounts.ResponseType)
assert.Empty(t, newAccounts.RemovedIds)
assert.Empty(t, newAccounts.ListToken)
@@ -131,14 +135,16 @@ func TestApiPaginateAccounts(t *testing.T) {
sClient := scopes.NewClient(client)
amClient := authmethods.NewClient(client)
acClient := accounts.NewClient(client)
newOrgId := boundary.CreateNewOrgApi(t, ctx, client)
orgId, err := boundary.CreateOrgApi(t, ctx, client)
require.NoError(t, err)
t.Cleanup(func() {
ctx := context.Background()
client.SetToken(adminToken)
_, err = sClient.Delete(ctx, newOrgId)
_, err = sClient.Delete(ctx, orgId)
require.NoError(t, err)
})
amId := boundary.CreateNewAuthMethodApi(t, ctx, client, newOrgId)
amId, err := boundary.CreateAuthMethodApi(t, ctx, client, orgId)
require.NoError(t, err)
t.Cleanup(func() {
ctx := context.Background()
client.SetToken(adminToken)
@@ -149,7 +155,8 @@ func TestApiPaginateAccounts(t *testing.T) {
// Create enough accounts to overflow a single page.
var accountIds []string
for i := 0; i < c.MaxPageSize+1; i++ {
accId, _ := boundary.CreateNewAccountApi(t, ctx, client, amId, "testuser-"+strconv.Itoa(i))
accId, _, err := boundary.CreateAccountApi(t, ctx, client, amId, "testuser-"+strconv.Itoa(i))
require.NoError(t, err)
accountIds = append(accountIds, accId)
}
@@ -174,7 +181,8 @@ func TestApiPaginateAccounts(t *testing.T) {
assert.Len(t, mapSliceItems, c.MaxPageSize+1)
// Create a new account and destroy one of the other accounts
newAccountId, _ := boundary.CreateNewAccountApi(t, ctx, client, amId, "newuser")
accountId, _, err := boundary.CreateAccountApi(t, ctx, client, amId, "newuser")
require.NoError(t, err)
_, err = acClient.Delete(ctx, initialAccounts.Items[0].Id)
require.NoError(t, err)
@@ -190,7 +198,7 @@ func TestApiPaginateAccounts(t *testing.T) {
// The first item should be the most recently created, which
// should be our new account
firstItem := newAccounts.Items[0]
assert.Equal(t, newAccountId, firstItem.Id)
assert.Equal(t, accountId, firstItem.Id)
assert.Equal(t, "complete", newAccounts.ResponseType)
// Note that the removed IDs may contain entries from other tests,
// so just check that there is at least 1 entry and that our entry
@@ -32,23 +32,28 @@ func TestCliPaginateAuthTokens(t *testing.T) {
boundary.AuthenticateAdminCli(t, ctx)
client, err := boundary.NewApiClient()
require.NoError(t, err)
newOrgId := boundary.CreateNewOrgCli(t, ctx)
orgId, err := boundary.CreateOrgCli(t, ctx)
require.NoError(t, err)
t.Cleanup(func() {
ctx := context.Background()
boundary.AuthenticateAdminCli(t, ctx)
output := e2e.RunCommand(ctx, "boundary", e2e.WithArgs("scopes", "delete", "-id", newOrgId))
output := e2e.RunCommand(ctx, "boundary", e2e.WithArgs("scopes", "delete", "-id", orgId))
require.NoError(t, output.Err, string(output.Stderr))
})
userId := boundary.CreateNewUserApi(t, ctx, client, newOrgId)
amId := boundary.CreateNewAuthMethodApi(t, ctx, client, newOrgId)
userId, err := boundary.CreateUserApi(t, ctx, client, orgId)
require.NoError(t, err)
amId, err := boundary.CreateAuthMethodApi(t, ctx, client, orgId)
require.NoError(t, err)
t.Cleanup(func() {
ctx := context.Background()
boundary.AuthenticateAdminCli(t, ctx)
output := e2e.RunCommand(ctx, "boundary", e2e.WithArgs("auth-methods", "delete", "-id", amId))
require.NoError(t, output.Err, string(output.Stderr))
})
accId, password := boundary.CreateNewAccountCli(t, ctx, amId, "testuser")
boundary.SetAccountToUserCli(t, ctx, userId, accId)
accId, password, err := boundary.CreateAccountCli(t, ctx, amId, "testuser")
require.NoError(t, err)
err = boundary.SetAccountToUserCli(t, ctx, userId, accId)
require.NoError(t, err)
boundary.AuthenticateCli(t, ctx, amId, "testuser", password)
@@ -139,23 +144,28 @@ func TestApiPaginateAuthTokens(t *testing.T) {
sClient := scopes.NewClient(client)
amClient := authmethods.NewClient(client)
atClient := authtokens.NewClient(client)
newOrgId := boundary.CreateNewOrgApi(t, ctx, client)
orgId, err := boundary.CreateOrgApi(t, ctx, client)
require.NoError(t, err)
t.Cleanup(func() {
ctx := context.Background()
client.SetToken(adminToken)
_, err = sClient.Delete(ctx, newOrgId)
_, err = sClient.Delete(ctx, orgId)
require.NoError(t, err)
})
userId := boundary.CreateNewUserApi(t, ctx, client, newOrgId)
amId := boundary.CreateNewAuthMethodApi(t, ctx, client, newOrgId)
userId, err := boundary.CreateUserApi(t, ctx, client, orgId)
require.NoError(t, err)
amId, err := boundary.CreateAuthMethodApi(t, ctx, client, orgId)
require.NoError(t, err)
t.Cleanup(func() {
ctx := context.Background()
client.SetToken(adminToken)
_, err := amClient.Delete(ctx, amId)
require.NoError(t, err)
})
accId, password := boundary.CreateNewAccountCli(t, ctx, amId, "testuser")
boundary.SetAccountToUserCli(t, ctx, userId, accId)
accId, password, err := boundary.CreateAccountCli(t, ctx, amId, "testuser")
require.NoError(t, err)
err = boundary.SetAccountToUserCli(t, ctx, userId, accId)
require.NoError(t, err)
// Authenticate as the user
authenticationResult, err := amClient.Authenticate(ctx, amId, "login",
@@ -180,7 +190,7 @@ func TestApiPaginateAuthTokens(t *testing.T) {
}
// List auth tokens
initialAuthTokens, err := atClient.List(ctx, newOrgId, authtokens.WithRecursive(true))
initialAuthTokens, err := atClient.List(ctx, orgId, authtokens.WithRecursive(true))
require.NoError(t, err)
var returnedIds []string
@@ -206,7 +216,7 @@ func TestApiPaginateAuthTokens(t *testing.T) {
require.NoError(t, err)
// List again, should have the new and deleted auth token
newAuthTokens, err := atClient.List(ctx, newOrgId, authtokens.WithListToken(initialAuthTokens.ListToken), authtokens.WithRecursive(true))
newAuthTokens, err := atClient.List(ctx, orgId, authtokens.WithListToken(initialAuthTokens.ListToken), authtokens.WithRecursive(true))
require.NoError(t, err)
// Note that this will likely contain all the auth tokens,
@@ -28,14 +28,16 @@ func TestCliPaginateCredentialStores(t *testing.T) {
ctx := context.Background()
boundary.AuthenticateAdminCli(t, ctx)
newOrgId := boundary.CreateNewOrgCli(t, ctx)
orgId, err := boundary.CreateOrgCli(t, ctx)
require.NoError(t, err)
t.Cleanup(func() {
ctx := context.Background()
boundary.AuthenticateAdminCli(t, ctx)
output := e2e.RunCommand(ctx, "boundary", e2e.WithArgs("scopes", "delete", "-id", newOrgId))
output := e2e.RunCommand(ctx, "boundary", e2e.WithArgs("scopes", "delete", "-id", orgId))
require.NoError(t, output.Err, string(output.Stderr))
})
newProjectId := boundary.CreateNewProjectCli(t, ctx, newOrgId)
projectId, err := boundary.CreateProjectCli(t, ctx, orgId)
require.NoError(t, err)
// Create enough stores to overflow a single page.
// Use the API to make creation faster.
@@ -43,13 +45,15 @@ func TestCliPaginateCredentialStores(t *testing.T) {
client, err := boundary.NewApiClient()
require.NoError(t, err)
for i := 0; i < c.MaxPageSize+1; i++ {
storeIds = append(storeIds, boundary.CreateNewCredentialStoreStaticApi(t, ctx, client, newProjectId))
storeId, err := boundary.CreateCredentialStoreStaticApi(t, ctx, client, projectId)
require.NoError(t, err)
storeIds = append(storeIds, storeId)
}
output := e2e.RunCommand(ctx, "boundary",
e2e.WithArgs(
"credential-stores", "list",
"-scope-id", newProjectId,
"-scope-id", projectId,
"-format=json",
),
)
@@ -71,7 +75,8 @@ func TestCliPaginateCredentialStores(t *testing.T) {
assert.Empty(t, initialStores.ListToken)
// Create a new store and destroy one of the other stores
newStoreId := boundary.CreateNewCredentialStoreStaticApi(t, ctx, client, newProjectId)
storeId, err := boundary.CreateCredentialStoreStaticApi(t, ctx, client, projectId)
require.NoError(t, err)
output = e2e.RunCommand(ctx, "boundary",
e2e.WithArgs(
"credential-stores", "delete",
@@ -84,7 +89,7 @@ func TestCliPaginateCredentialStores(t *testing.T) {
output = e2e.RunCommand(ctx, "boundary",
e2e.WithArgs(
"credential-stores", "list",
"-scope-id", newProjectId,
"-scope-id", projectId,
"-format=json",
),
)
@@ -98,7 +103,7 @@ func TestCliPaginateCredentialStores(t *testing.T) {
// The first item should be the most recently created, which
// should be our new store
firstItem := newStores.Items[0]
assert.Equal(t, newStoreId, firstItem.Id)
assert.Equal(t, storeId, firstItem.Id)
assert.Empty(t, newStores.ResponseType)
assert.Empty(t, newStores.RemovedIds)
assert.Empty(t, newStores.ListToken)
@@ -120,21 +125,25 @@ func TestApiPaginateCredentialStores(t *testing.T) {
ctx := context.Background()
sClient := scopes.NewClient(client)
cClient := credentialstores.NewClient(client)
newOrgId := boundary.CreateNewOrgApi(t, ctx, client)
orgId, err := boundary.CreateOrgApi(t, ctx, client)
require.NoError(t, err)
t.Cleanup(func() {
ctx := context.Background()
_, err := sClient.Delete(ctx, newOrgId)
_, err := sClient.Delete(ctx, orgId)
require.NoError(t, err)
})
newProjectId := boundary.CreateNewProjectApi(t, ctx, client, newOrgId)
projectId, err := boundary.CreateProjectApi(t, ctx, client, orgId)
require.NoError(t, err)
// Create enough stores to overflow a single page.
var storeIds []string
for i := 0; i < c.MaxPageSize+1; i++ {
storeIds = append(storeIds, boundary.CreateNewCredentialStoreStaticApi(t, ctx, client, newProjectId))
storeId, err := boundary.CreateCredentialStoreStaticApi(t, ctx, client, projectId)
require.NoError(t, err)
storeIds = append(storeIds, storeId)
}
initialStores, err := cClient.List(ctx, newProjectId)
initialStores, err := cClient.List(ctx, projectId)
require.NoError(t, err)
var returnedIds []string
@@ -154,12 +163,13 @@ func TestApiPaginateCredentialStores(t *testing.T) {
assert.Len(t, mapSliceItems, c.MaxPageSize+1)
// Create a new store and destroy one of the other stores
newStoreId := boundary.CreateNewCredentialStoreStaticApi(t, ctx, client, newProjectId)
storeId, err := boundary.CreateCredentialStoreStaticApi(t, ctx, client, projectId)
require.NoError(t, err)
_, err = cClient.Delete(ctx, initialStores.Items[0].Id)
require.NoError(t, err)
// List again, should have the new and deleted store
newStores, err := cClient.List(ctx, newProjectId, credentialstores.WithListToken(initialStores.ListToken))
newStores, err := cClient.List(ctx, projectId, credentialstores.WithListToken(initialStores.ListToken))
require.NoError(t, err)
// Note that this will likely contain all the stores,
@@ -170,7 +180,7 @@ func TestApiPaginateCredentialStores(t *testing.T) {
// The first item should be the most recently created, which
// should be our new store
firstItem := newStores.Items[0]
assert.Equal(t, newStoreId, firstItem.Id)
assert.Equal(t, storeId, firstItem.Id)
assert.Equal(t, "complete", newStores.ResponseType)
// Note that the removed IDs may contain entries from other tests,
// so just check that there is at least 1 entry and that our entry
@@ -28,15 +28,18 @@ func TestCliPaginateCredentials(t *testing.T) {
ctx := context.Background()
boundary.AuthenticateAdminCli(t, ctx)
newOrgId := boundary.CreateNewOrgCli(t, ctx)
orgId, err := boundary.CreateOrgCli(t, ctx)
require.NoError(t, err)
t.Cleanup(func() {
ctx := context.Background()
boundary.AuthenticateAdminCli(t, ctx)
output := e2e.RunCommand(ctx, "boundary", e2e.WithArgs("scopes", "delete", "-id", newOrgId))
output := e2e.RunCommand(ctx, "boundary", e2e.WithArgs("scopes", "delete", "-id", orgId))
require.NoError(t, output.Err, string(output.Stderr))
})
newProjectId := boundary.CreateNewProjectCli(t, ctx, newOrgId)
newStoreId := boundary.CreateNewCredentialStoreStaticCli(t, ctx, newProjectId)
projectId, err := boundary.CreateProjectCli(t, ctx, orgId)
require.NoError(t, err)
storeId, err := boundary.CreateCredentialStoreStaticCli(t, ctx, projectId)
require.NoError(t, err)
// Create enough credentials to overflow a single page.
client, err := boundary.NewApiClient()
@@ -47,7 +50,7 @@ func TestCliPaginateCredentials(t *testing.T) {
resp, err := cClient.Create(
ctx,
"username_password",
newStoreId,
storeId,
credentials.WithUsernamePasswordCredentialUsername("user"),
credentials.WithUsernamePasswordCredentialPassword("password"),
)
@@ -62,7 +65,7 @@ func TestCliPaginateCredentials(t *testing.T) {
output := e2e.RunCommand(ctx, "boundary",
e2e.WithArgs(
"credentials", "list",
"-credential-store-id", newStoreId,
"-credential-store-id", storeId,
"-format=json",
),
)
@@ -84,7 +87,8 @@ func TestCliPaginateCredentials(t *testing.T) {
assert.Empty(t, initialCredentials.ListToken)
// Create a new credential and destroy one of the other credentials
newCredentialId := boundary.CreateNewStaticCredentialPasswordCli(t, ctx, newStoreId, "user", "password")
credentialId, err := boundary.CreateStaticCredentialPasswordCli(t, ctx, storeId, "user", "password")
require.NoError(t, err)
output = e2e.RunCommand(ctx, "boundary",
e2e.WithArgs(
"credentials", "delete",
@@ -97,7 +101,7 @@ func TestCliPaginateCredentials(t *testing.T) {
output = e2e.RunCommand(ctx, "boundary",
e2e.WithArgs(
"credentials", "list",
"-credential-store-id", newStoreId,
"-credential-store-id", storeId,
"-format=json",
),
)
@@ -111,7 +115,7 @@ func TestCliPaginateCredentials(t *testing.T) {
// The first item should be the most recently created, which
// should be our new credential
firstItem := newCredentials.Items[0]
assert.Equal(t, newCredentialId, firstItem.Id)
assert.Equal(t, credentialId, firstItem.Id)
assert.Empty(t, newCredentials.ResponseType)
assert.Empty(t, newCredentials.RemovedIds)
assert.Empty(t, newCredentials.ListToken)
@@ -133,14 +137,17 @@ func TestApiPaginateCredentials(t *testing.T) {
ctx := context.Background()
sClient := scopes.NewClient(client)
cClient := credentials.NewClient(client)
newOrgId := boundary.CreateNewOrgApi(t, ctx, client)
orgId, err := boundary.CreateOrgApi(t, ctx, client)
require.NoError(t, err)
t.Cleanup(func() {
ctx := context.Background()
_, err := sClient.Delete(ctx, newOrgId)
_, err := sClient.Delete(ctx, orgId)
require.NoError(t, err)
})
newProjectId := boundary.CreateNewProjectApi(t, ctx, client, newOrgId)
newStoreId := boundary.CreateNewCredentialStoreStaticApi(t, ctx, client, newProjectId)
projectId, err := boundary.CreateProjectApi(t, ctx, client, orgId)
require.NoError(t, err)
storeId, err := boundary.CreateCredentialStoreStaticApi(t, ctx, client, projectId)
require.NoError(t, err)
// Create enough credentials to overflow a single page.
var credentialIds []string
@@ -148,7 +155,7 @@ func TestApiPaginateCredentials(t *testing.T) {
resp, err := cClient.Create(
ctx,
"username_password",
newStoreId,
storeId,
credentials.WithUsernamePasswordCredentialUsername("user"),
credentials.WithUsernamePasswordCredentialPassword("password"),
)
@@ -160,7 +167,7 @@ func TestApiPaginateCredentials(t *testing.T) {
}
// List Credentials
initialCredentials, err := cClient.List(ctx, newStoreId)
initialCredentials, err := cClient.List(ctx, storeId)
require.NoError(t, err)
var returnedIds []string
@@ -180,12 +187,13 @@ func TestApiPaginateCredentials(t *testing.T) {
assert.Len(t, mapSliceItems, c.MaxPageSize+1)
// Create a new credential and destroy one of the other Credentials
newCredentialId := boundary.CreateNewStaticCredentialPasswordApi(t, ctx, client, newStoreId, "user", "password")
credentialId, err := boundary.CreateStaticCredentialPasswordApi(t, ctx, client, storeId, "user", "password")
require.NoError(t, err)
_, err = cClient.Delete(ctx, initialCredentials.Items[0].Id)
require.NoError(t, err)
// List again, should have the new and deleted credential
newCredentials, err := cClient.List(ctx, newStoreId, credentials.WithListToken(initialCredentials.ListToken))
newCredentials, err := cClient.List(ctx, storeId, credentials.WithListToken(initialCredentials.ListToken))
require.NoError(t, err)
// Note that this will likely contain all the credentials,
@@ -196,7 +204,7 @@ func TestApiPaginateCredentials(t *testing.T) {
// The first item should be the most recently created, which
// should be our new credential
firstItem := newCredentials.Items[0]
assert.Equal(t, newCredentialId, firstItem.Id)
assert.Equal(t, credentialId, firstItem.Id)
assert.Equal(t, "complete", newCredentials.ResponseType)
// Note that the removed IDs may contain entries from other tests,
// so just check that there is at least 1 entry and that our entry
@@ -28,11 +28,12 @@ func TestCliPaginateGroups(t *testing.T) {
ctx := context.Background()
boundary.AuthenticateAdminCli(t, ctx)
newOrgId := boundary.CreateNewOrgCli(t, ctx)
orgId, err := boundary.CreateOrgCli(t, ctx)
require.NoError(t, err)
t.Cleanup(func() {
ctx := context.Background()
boundary.AuthenticateAdminCli(t, ctx)
output := e2e.RunCommand(ctx, "boundary", e2e.WithArgs("scopes", "delete", "-id", newOrgId))
output := e2e.RunCommand(ctx, "boundary", e2e.WithArgs("scopes", "delete", "-id", orgId))
require.NoError(t, output.Err, string(output.Stderr))
})
@@ -41,14 +42,16 @@ func TestCliPaginateGroups(t *testing.T) {
require.NoError(t, err)
var groupIds []string
for i := 0; i < c.MaxPageSize+1; i++ {
groupIds = append(groupIds, boundary.CreateNewGroupApi(t, ctx, client, newOrgId))
groupId, err := boundary.CreateGroupApi(t, ctx, client, orgId)
require.NoError(t, err)
groupIds = append(groupIds, groupId)
}
// List groups
output := e2e.RunCommand(ctx, "boundary",
e2e.WithArgs(
"groups", "list",
"-scope-id", newOrgId,
"-scope-id", orgId,
"-format=json",
),
)
@@ -70,7 +73,8 @@ func TestCliPaginateGroups(t *testing.T) {
assert.Empty(t, initialGroups.ListToken)
// Create a new group and destroy one of the other groups
newGroupId := boundary.CreateNewGroupApi(t, ctx, client, newOrgId)
groupId, err := boundary.CreateGroupApi(t, ctx, client, orgId)
require.NoError(t, err)
output = e2e.RunCommand(ctx, "boundary",
e2e.WithArgs(
"groups", "delete",
@@ -83,7 +87,7 @@ func TestCliPaginateGroups(t *testing.T) {
output = e2e.RunCommand(ctx, "boundary",
e2e.WithArgs(
"groups", "list",
"-scope-id", newOrgId,
"-scope-id", orgId,
"-format=json",
),
)
@@ -97,7 +101,7 @@ func TestCliPaginateGroups(t *testing.T) {
// The first item should be the most recently created, which
// should be our new group
firstItem := newGroups.Items[0]
assert.Equal(t, newGroupId, firstItem.Id)
assert.Equal(t, groupId, firstItem.Id)
assert.Empty(t, newGroups.ResponseType)
assert.Empty(t, newGroups.RemovedIds)
assert.Empty(t, newGroups.ListToken)
@@ -119,20 +123,23 @@ func TestApiPaginateGroups(t *testing.T) {
ctx := context.Background()
sClient := scopes.NewClient(client)
uClient := groups.NewClient(client)
newOrgId := boundary.CreateNewOrgApi(t, ctx, client)
orgId, err := boundary.CreateOrgApi(t, ctx, client)
require.NoError(t, err)
t.Cleanup(func() {
ctx := context.Background()
_, err := sClient.Delete(ctx, newOrgId)
_, err := sClient.Delete(ctx, orgId)
require.NoError(t, err)
})
var groupIds []string
for i := 0; i < c.MaxPageSize+1; i++ {
groupIds = append(groupIds, boundary.CreateNewGroupApi(t, ctx, client, newOrgId))
groupId, err := boundary.CreateGroupApi(t, ctx, client, orgId)
require.NoError(t, err)
groupIds = append(groupIds, groupId)
}
// List groups
initialGroups, err := uClient.List(ctx, newOrgId)
initialGroups, err := uClient.List(ctx, orgId)
require.NoError(t, err)
var returnedIds []string
@@ -153,12 +160,13 @@ func TestApiPaginateGroups(t *testing.T) {
assert.Len(t, mapSliceItems, c.MaxPageSize+1)
// Create a new group and destroy one of the other groups
newGroupId := boundary.CreateNewGroupApi(t, ctx, client, newOrgId)
groupId, err := boundary.CreateGroupApi(t, ctx, client, orgId)
require.NoError(t, err)
_, err = uClient.Delete(ctx, initialGroups.Items[0].Id)
require.NoError(t, err)
// List again, should have the new and deleted group
newGroups, err := uClient.List(ctx, newOrgId, groups.WithListToken(initialGroups.ListToken))
newGroups, err := uClient.List(ctx, orgId, groups.WithListToken(initialGroups.ListToken))
require.NoError(t, err)
// Note that this will likely contain all the groups,
@@ -169,7 +177,7 @@ func TestApiPaginateGroups(t *testing.T) {
// The first item should be the most recently created, which
// should be our new group
firstItem := newGroups.Items[0]
assert.Equal(t, newGroupId, firstItem.Id)
assert.Equal(t, groupId, firstItem.Id)
assert.Equal(t, "complete", newGroups.ResponseType)
// Note that the removed IDs may contain entries from other tests,
// so just check that there is at least 1 entry and that our entry
@@ -28,28 +28,32 @@ func TestCliPaginateHostCatalogs(t *testing.T) {
ctx := context.Background()
boundary.AuthenticateAdminCli(t, ctx)
newOrgId := boundary.CreateNewOrgCli(t, ctx)
orgId, err := boundary.CreateOrgCli(t, ctx)
require.NoError(t, err)
t.Cleanup(func() {
ctx := context.Background()
boundary.AuthenticateAdminCli(t, ctx)
output := e2e.RunCommand(ctx, "boundary", e2e.WithArgs("scopes", "delete", "-id", newOrgId))
output := e2e.RunCommand(ctx, "boundary", e2e.WithArgs("scopes", "delete", "-id", orgId))
require.NoError(t, output.Err, string(output.Stderr))
})
newProjectId := boundary.CreateNewProjectCli(t, ctx, newOrgId)
projectId, err := boundary.CreateProjectCli(t, ctx, orgId)
require.NoError(t, err)
// Create enough host catalogs to overflow a single page.
client, err := boundary.NewApiClient()
require.NoError(t, err)
var hostCatalogIds []string
for i := 0; i < c.MaxPageSize+1; i++ {
hostCatalogIds = append(hostCatalogIds, boundary.CreateNewHostCatalogApi(t, ctx, client, newProjectId))
hostCatalogId, err := boundary.CreateHostCatalogApi(t, ctx, client, projectId)
require.NoError(t, err)
hostCatalogIds = append(hostCatalogIds, hostCatalogId)
}
// List host catalogs
output := e2e.RunCommand(ctx, "boundary",
e2e.WithArgs(
"host-catalogs", "list",
"-scope-id", newProjectId,
"-scope-id", projectId,
"-format=json",
),
)
@@ -71,7 +75,8 @@ func TestCliPaginateHostCatalogs(t *testing.T) {
assert.Empty(t, initialHostCatalogs.ListToken)
// Create a new host catalog and destroy one of the other host catalogs
newHostCatalogId := boundary.CreateNewHostCatalogApi(t, ctx, client, newProjectId)
hostCatalogId, err := boundary.CreateHostCatalogApi(t, ctx, client, projectId)
require.NoError(t, err)
output = e2e.RunCommand(ctx, "boundary",
e2e.WithArgs(
"host-catalogs", "delete",
@@ -84,7 +89,7 @@ func TestCliPaginateHostCatalogs(t *testing.T) {
output = e2e.RunCommand(ctx, "boundary",
e2e.WithArgs(
"host-catalogs", "list",
"-scope-id", newProjectId,
"-scope-id", projectId,
"-format=json",
),
)
@@ -98,7 +103,7 @@ func TestCliPaginateHostCatalogs(t *testing.T) {
// The first item should be the most recently created, which
// should be our new host catalog
firstItem := newHostCatalogs.Items[0]
assert.Equal(t, newHostCatalogId, firstItem.Id)
assert.Equal(t, hostCatalogId, firstItem.Id)
assert.Empty(t, newHostCatalogs.ResponseType)
assert.Empty(t, newHostCatalogs.RemovedIds)
assert.Empty(t, newHostCatalogs.ListToken)
@@ -120,22 +125,26 @@ func TestApiPaginateHostCatalogs(t *testing.T) {
ctx := context.Background()
sClient := scopes.NewClient(client)
hcClient := hostcatalogs.NewClient(client)
newOrgId := boundary.CreateNewOrgApi(t, ctx, client)
orgId, err := boundary.CreateOrgApi(t, ctx, client)
require.NoError(t, err)
t.Cleanup(func() {
ctx := context.Background()
_, err := sClient.Delete(ctx, newOrgId)
_, err := sClient.Delete(ctx, orgId)
require.NoError(t, err)
})
newProjectId := boundary.CreateNewProjectApi(t, ctx, client, newOrgId)
projectId, err := boundary.CreateProjectApi(t, ctx, client, orgId)
require.NoError(t, err)
// Create enough host catalogs to overflow a single page.
var hostCatalogIds []string
for i := 0; i < c.MaxPageSize+1; i++ {
hostCatalogIds = append(hostCatalogIds, boundary.CreateNewHostCatalogApi(t, ctx, client, newProjectId))
hostCatalogId, err := boundary.CreateHostCatalogApi(t, ctx, client, projectId)
require.NoError(t, err)
hostCatalogIds = append(hostCatalogIds, hostCatalogId)
}
// List host catalogs
initialHostCatalogs, err := hcClient.List(ctx, newProjectId)
initialHostCatalogs, err := hcClient.List(ctx, projectId)
require.NoError(t, err)
var returnedIds []string
@@ -155,12 +164,13 @@ func TestApiPaginateHostCatalogs(t *testing.T) {
assert.Len(t, mapSliceItems, c.MaxPageSize+1)
// Create a new host catalog and destroy one of the other host catalogs
newHostCatalogId := boundary.CreateNewHostCatalogApi(t, ctx, client, newProjectId)
hostCatalogId, err := boundary.CreateHostCatalogApi(t, ctx, client, projectId)
require.NoError(t, err)
_, err = hcClient.Delete(ctx, initialHostCatalogs.Items[0].Id)
require.NoError(t, err)
// List again, should have the new and deleted host catalog
newHostCatalogs, err := hcClient.List(ctx, newProjectId, hostcatalogs.WithListToken(initialHostCatalogs.ListToken))
newHostCatalogs, err := hcClient.List(ctx, projectId, hostcatalogs.WithListToken(initialHostCatalogs.ListToken))
require.NoError(t, err)
// Note that this will likely contain all the host catalogs,
@@ -171,7 +181,7 @@ func TestApiPaginateHostCatalogs(t *testing.T) {
// The first item should be the most recently created, which
// should be our new host catalog
firstItem := newHostCatalogs.Items[0]
assert.Equal(t, newHostCatalogId, firstItem.Id)
assert.Equal(t, hostCatalogId, firstItem.Id)
assert.Equal(t, "complete", newHostCatalogs.ResponseType)
// Note that the removed IDs may contain entries from other tests,
// so just check that there is at least 1 entry and that our entry
@@ -28,29 +28,34 @@ func TestCliPaginateHostSets(t *testing.T) {
ctx := context.Background()
boundary.AuthenticateAdminCli(t, ctx)
newOrgId := boundary.CreateNewOrgCli(t, ctx)
orgId, err := boundary.CreateOrgCli(t, ctx)
require.NoError(t, err)
t.Cleanup(func() {
ctx := context.Background()
boundary.AuthenticateAdminCli(t, ctx)
output := e2e.RunCommand(ctx, "boundary", e2e.WithArgs("scopes", "delete", "-id", newOrgId))
output := e2e.RunCommand(ctx, "boundary", e2e.WithArgs("scopes", "delete", "-id", orgId))
require.NoError(t, output.Err, string(output.Stderr))
})
newProjectId := boundary.CreateNewProjectCli(t, ctx, newOrgId)
newHostCatalogId := boundary.CreateNewHostCatalogCli(t, ctx, newProjectId)
projectId, err := boundary.CreateProjectCli(t, ctx, orgId)
require.NoError(t, err)
hostCatalogId, err := boundary.CreateHostCatalogCli(t, ctx, projectId)
require.NoError(t, err)
// Create enough host sets to overflow a single page.
client, err := boundary.NewApiClient()
require.NoError(t, err)
var hostSetIds []string
for i := 0; i < c.MaxPageSize+1; i++ {
hostSetIds = append(hostSetIds, boundary.CreateNewHostSetApi(t, ctx, client, newHostCatalogId))
hostSetId, err := boundary.CreateHostSetApi(t, ctx, client, hostCatalogId)
require.NoError(t, err)
hostSetIds = append(hostSetIds, hostSetId)
}
// List host sets
output := e2e.RunCommand(ctx, "boundary",
e2e.WithArgs(
"host-sets", "list",
"-host-catalog-id", newHostCatalogId,
"-host-catalog-id", hostCatalogId,
"-format=json",
),
)
@@ -72,7 +77,8 @@ func TestCliPaginateHostSets(t *testing.T) {
assert.Empty(t, initialHostSets.ListToken)
// Create a new host set and destroy one of the other host sets
newHostSetId := boundary.CreateNewHostSetApi(t, ctx, client, newHostCatalogId)
hostSetId, err := boundary.CreateHostSetApi(t, ctx, client, hostCatalogId)
require.NoError(t, err)
output = e2e.RunCommand(ctx, "boundary",
e2e.WithArgs(
"host-sets", "delete",
@@ -85,7 +91,7 @@ func TestCliPaginateHostSets(t *testing.T) {
output = e2e.RunCommand(ctx, "boundary",
e2e.WithArgs(
"host-sets", "list",
"-host-catalog-id", newHostCatalogId,
"-host-catalog-id", hostCatalogId,
"-format=json",
),
)
@@ -99,7 +105,7 @@ func TestCliPaginateHostSets(t *testing.T) {
// The first item should be the most recently created, which
// should be our new host set
firstItem := newHostSets.Items[0]
assert.Equal(t, newHostSetId, firstItem.Id)
assert.Equal(t, hostSetId, firstItem.Id)
assert.Empty(t, newHostSets.ResponseType)
assert.Empty(t, newHostSets.RemovedIds)
assert.Empty(t, newHostSets.ListToken)
@@ -121,23 +127,28 @@ func TestApiPaginateHostSets(t *testing.T) {
ctx := context.Background()
sClient := scopes.NewClient(client)
hsClient := hostsets.NewClient(client)
newOrgId := boundary.CreateNewOrgApi(t, ctx, client)
orgId, err := boundary.CreateOrgApi(t, ctx, client)
require.NoError(t, err)
t.Cleanup(func() {
ctx := context.Background()
_, err := sClient.Delete(ctx, newOrgId)
_, err := sClient.Delete(ctx, orgId)
require.NoError(t, err)
})
newProjectId := boundary.CreateNewProjectApi(t, ctx, client, newOrgId)
newHostCatalogId := boundary.CreateNewHostCatalogApi(t, ctx, client, newProjectId)
projectId, err := boundary.CreateProjectApi(t, ctx, client, orgId)
require.NoError(t, err)
hostCatalogId, err := boundary.CreateHostCatalogApi(t, ctx, client, projectId)
require.NoError(t, err)
// Create enough host sets to overflow a single page.
var hostSetIds []string
for i := 0; i < c.MaxPageSize+1; i++ {
hostSetIds = append(hostSetIds, boundary.CreateNewHostSetApi(t, ctx, client, newHostCatalogId))
hostSetId, err := boundary.CreateHostSetApi(t, ctx, client, hostCatalogId)
require.NoError(t, err)
hostSetIds = append(hostSetIds, hostSetId)
}
// List host sets
initialHostSets, err := hsClient.List(ctx, newHostCatalogId)
initialHostSets, err := hsClient.List(ctx, hostCatalogId)
require.NoError(t, err)
var returnedIds []string
@@ -157,12 +168,13 @@ func TestApiPaginateHostSets(t *testing.T) {
assert.Len(t, mapSliceItems, c.MaxPageSize+1)
// Create a new host set and destroy one of the other host sets
newHostSetId := boundary.CreateNewHostSetApi(t, ctx, client, newHostCatalogId)
hostSetId, err := boundary.CreateHostSetApi(t, ctx, client, hostCatalogId)
require.NoError(t, err)
_, err = hsClient.Delete(ctx, initialHostSets.Items[0].Id)
require.NoError(t, err)
// List again, should have the new and deleted host set
newHostSets, err := hsClient.List(ctx, newHostCatalogId, hostsets.WithListToken(initialHostSets.ListToken))
newHostSets, err := hsClient.List(ctx, hostCatalogId, hostsets.WithListToken(initialHostSets.ListToken))
require.NoError(t, err)
// Note that this will likely contain all the host sets,
@@ -173,7 +185,7 @@ func TestApiPaginateHostSets(t *testing.T) {
// The first item should be the most recently created, which
// should be our new host set
firstItem := newHostSets.Items[0]
assert.Equal(t, newHostSetId, firstItem.Id)
assert.Equal(t, hostSetId, firstItem.Id)
assert.Equal(t, "complete", newHostSets.ResponseType)
// Note that the removed IDs may contain entries from other tests,
// so just check that there is at least 1 entry and that our entry
@@ -28,29 +28,34 @@ func TestCliPaginateHosts(t *testing.T) {
ctx := context.Background()
boundary.AuthenticateAdminCli(t, ctx)
newOrgId := boundary.CreateNewOrgCli(t, ctx)
orgId, err := boundary.CreateOrgCli(t, ctx)
require.NoError(t, err)
t.Cleanup(func() {
ctx := context.Background()
boundary.AuthenticateAdminCli(t, ctx)
output := e2e.RunCommand(ctx, "boundary", e2e.WithArgs("scopes", "delete", "-id", newOrgId))
output := e2e.RunCommand(ctx, "boundary", e2e.WithArgs("scopes", "delete", "-id", orgId))
require.NoError(t, output.Err, string(output.Stderr))
})
newProjectId := boundary.CreateNewProjectCli(t, ctx, newOrgId)
newHostCatalogId := boundary.CreateNewHostCatalogCli(t, ctx, newProjectId)
projectId, err := boundary.CreateProjectCli(t, ctx, orgId)
require.NoError(t, err)
hostCatalogId, err := boundary.CreateHostCatalogCli(t, ctx, projectId)
require.NoError(t, err)
// Create enough hosts to overflow a single page.
client, err := boundary.NewApiClient()
require.NoError(t, err)
var hostIds []string
for i := 0; i < c.MaxPageSize+1; i++ {
hostIds = append(hostIds, boundary.CreateNewHostApi(t, ctx, client, newHostCatalogId, c.TargetAddress))
hostId, err := boundary.CreateHostApi(t, ctx, client, hostCatalogId, c.TargetAddress)
require.NoError(t, err)
hostIds = append(hostIds, hostId)
}
// List hosts
output := e2e.RunCommand(ctx, "boundary",
e2e.WithArgs(
"hosts", "list",
"-host-catalog-id", newHostCatalogId,
"-host-catalog-id", hostCatalogId,
"-format=json",
),
)
@@ -72,7 +77,8 @@ func TestCliPaginateHosts(t *testing.T) {
assert.Empty(t, initialHosts.ListToken)
// Create a new host and destroy one of the other hosts
newHostId := boundary.CreateNewHostApi(t, ctx, client, newHostCatalogId, c.TargetAddress)
hostId, err := boundary.CreateHostApi(t, ctx, client, hostCatalogId, c.TargetAddress)
require.NoError(t, err)
output = e2e.RunCommand(ctx, "boundary",
e2e.WithArgs(
"hosts", "delete",
@@ -85,7 +91,7 @@ func TestCliPaginateHosts(t *testing.T) {
output = e2e.RunCommand(ctx, "boundary",
e2e.WithArgs(
"hosts", "list",
"-host-catalog-id", newHostCatalogId,
"-host-catalog-id", hostCatalogId,
"-format=json",
),
)
@@ -99,7 +105,7 @@ func TestCliPaginateHosts(t *testing.T) {
// The first item should be the most recently created, which
// should be our new host
firstItem := newHosts.Items[0]
assert.Equal(t, newHostId, firstItem.Id)
assert.Equal(t, hostId, firstItem.Id)
assert.Empty(t, newHosts.ResponseType)
assert.Empty(t, newHosts.RemovedIds)
assert.Empty(t, newHosts.ListToken)
@@ -121,23 +127,28 @@ func TestApiPaginateHosts(t *testing.T) {
ctx := context.Background()
sClient := scopes.NewClient(client)
hClient := hosts.NewClient(client)
newOrgId := boundary.CreateNewOrgApi(t, ctx, client)
orgId, err := boundary.CreateOrgApi(t, ctx, client)
require.NoError(t, err)
t.Cleanup(func() {
ctx := context.Background()
_, err := sClient.Delete(ctx, newOrgId)
_, err := sClient.Delete(ctx, orgId)
require.NoError(t, err)
})
newProjectId := boundary.CreateNewProjectApi(t, ctx, client, newOrgId)
newHostCatalogId := boundary.CreateNewHostCatalogApi(t, ctx, client, newProjectId)
projectId, err := boundary.CreateProjectApi(t, ctx, client, orgId)
require.NoError(t, err)
hostCatalogId, err := boundary.CreateHostCatalogApi(t, ctx, client, projectId)
require.NoError(t, err)
// Create enough hosts to overflow a single page.
var hostIds []string
for i := 0; i < c.MaxPageSize+1; i++ {
hostIds = append(hostIds, boundary.CreateNewHostApi(t, ctx, client, newHostCatalogId, c.TargetAddress))
hostId, err := boundary.CreateHostApi(t, ctx, client, hostCatalogId, c.TargetAddress)
require.NoError(t, err)
hostIds = append(hostIds, hostId)
}
// List hosts
initialHosts, err := hClient.List(ctx, newHostCatalogId)
initialHosts, err := hClient.List(ctx, hostCatalogId)
require.NoError(t, err)
var returnedIds []string
@@ -157,12 +168,13 @@ func TestApiPaginateHosts(t *testing.T) {
assert.Len(t, mapSliceItems, c.MaxPageSize+1)
// Create a new host and destroy one of the other hosts
newHostId := boundary.CreateNewHostApi(t, ctx, client, newHostCatalogId, c.TargetAddress)
hostId, err := boundary.CreateHostApi(t, ctx, client, hostCatalogId, c.TargetAddress)
require.NoError(t, err)
_, err = hClient.Delete(ctx, initialHosts.Items[0].Id)
require.NoError(t, err)
// List again, should have the new and deleted host
newHosts, err := hClient.List(ctx, newHostCatalogId, hosts.WithListToken(initialHosts.ListToken))
newHosts, err := hClient.List(ctx, hostCatalogId, hosts.WithListToken(initialHosts.ListToken))
require.NoError(t, err)
// Note that this will likely contain all the hosts,
@@ -173,7 +185,7 @@ func TestApiPaginateHosts(t *testing.T) {
// The first item should be the most recently created, which
// should be our new host
firstItem := newHosts.Items[0]
assert.Equal(t, newHostId, firstItem.Id)
assert.Equal(t, hostId, firstItem.Id)
assert.Equal(t, "complete", newHosts.ResponseType)
// Note that the removed IDs may contain entries from other tests,
// so just check that there is at least 1 entry and that our entry
@@ -31,14 +31,16 @@ func TestCliPaginateManagedGroups(t *testing.T) {
boundary.AuthenticateAdminCli(t, ctx)
client, err := boundary.NewApiClient()
require.NoError(t, err)
newOrgId := boundary.CreateNewOrgCli(t, ctx)
orgId, err := boundary.CreateOrgCli(t, ctx)
require.NoError(t, err)
t.Cleanup(func() {
ctx := context.Background()
boundary.AuthenticateAdminCli(t, ctx)
output := e2e.RunCommand(ctx, "boundary", e2e.WithArgs("scopes", "delete", "-id", newOrgId))
output := e2e.RunCommand(ctx, "boundary", e2e.WithArgs("scopes", "delete", "-id", orgId))
require.NoError(t, output.Err, string(output.Stderr))
})
amId := boundary.CreateNewOidcAuthMethodApi(t, ctx, client, newOrgId)
amId, err := boundary.CreateOidcAuthMethodApi(t, ctx, client, orgId)
require.NoError(t, err)
t.Cleanup(func() {
ctx := context.Background()
boundary.AuthenticateAdminCli(t, ctx)
@@ -49,7 +51,9 @@ func TestCliPaginateManagedGroups(t *testing.T) {
// Create enough managedgroups to overflow a single page.
var managedgroupIds []string
for i := 0; i < c.MaxPageSize+1; i++ {
managedgroupIds = append(managedgroupIds, boundary.CreateNewManagedGroupApi(t, ctx, client, amId))
managedGroupId, err := boundary.CreateManagedGroupApi(t, ctx, client, amId)
require.NoError(t, err)
managedgroupIds = append(managedgroupIds, managedGroupId)
}
// List managedgroups
@@ -78,7 +82,8 @@ func TestCliPaginateManagedGroups(t *testing.T) {
assert.Empty(t, initialManagedGroups.ListToken)
// Create a new managedgroup and destroy one of the other managed groups
newManagedGroupId := boundary.CreateNewManagedGroupApi(t, ctx, client, amId)
managedGroupId, err := boundary.CreateManagedGroupApi(t, ctx, client, amId)
require.NoError(t, err)
output = e2e.RunCommand(ctx, "boundary",
e2e.WithArgs(
"managed-groups", "delete",
@@ -105,7 +110,7 @@ func TestCliPaginateManagedGroups(t *testing.T) {
// The first item should be the most recently created, which
// should be our new managedgroup
firstItem := newManagedGroups.Items[0]
assert.Equal(t, newManagedGroupId, firstItem.Id)
assert.Equal(t, managedGroupId, firstItem.Id)
assert.Empty(t, newManagedGroups.ResponseType)
assert.Empty(t, newManagedGroups.RemovedIds)
assert.Empty(t, newManagedGroups.ListToken)
@@ -129,14 +134,16 @@ func TestApiPaginateManagedGroups(t *testing.T) {
sClient := scopes.NewClient(client)
amClient := authmethods.NewClient(client)
mgClient := managedgroups.NewClient(client)
newOrgId := boundary.CreateNewOrgApi(t, ctx, client)
orgId, err := boundary.CreateOrgApi(t, ctx, client)
require.NoError(t, err)
t.Cleanup(func() {
ctx := context.Background()
client.SetToken(adminToken)
_, err = sClient.Delete(ctx, newOrgId)
_, err = sClient.Delete(ctx, orgId)
require.NoError(t, err)
})
amId := boundary.CreateNewOidcAuthMethodApi(t, ctx, client, newOrgId)
amId, err := boundary.CreateOidcAuthMethodApi(t, ctx, client, orgId)
require.NoError(t, err)
t.Cleanup(func() {
ctx := context.Background()
client.SetToken(adminToken)
@@ -147,7 +154,9 @@ func TestApiPaginateManagedGroups(t *testing.T) {
// Create enough managedgroups to overflow a single page.
var managedgroupIds []string
for i := 0; i < c.MaxPageSize+1; i++ {
managedgroupIds = append(managedgroupIds, boundary.CreateNewManagedGroupApi(t, ctx, client, amId))
managedGroupId, err := boundary.CreateManagedGroupApi(t, ctx, client, amId)
require.NoError(t, err)
managedgroupIds = append(managedgroupIds, managedGroupId)
}
// List managedgroups
@@ -171,7 +180,8 @@ func TestApiPaginateManagedGroups(t *testing.T) {
assert.Len(t, mapSliceItems, c.MaxPageSize+1)
// Create a new managedgroup and destroy one of the other managed groups
newManagedGroupId := boundary.CreateNewManagedGroupApi(t, ctx, client, amId)
managedGroupId, err := boundary.CreateManagedGroupApi(t, ctx, client, amId)
require.NoError(t, err)
_, err = mgClient.Delete(ctx, initialManagedGroups.Items[0].Id)
require.NoError(t, err)
@@ -187,7 +197,7 @@ func TestApiPaginateManagedGroups(t *testing.T) {
// The first item should be the most recently created, which
// should be our new managedgroup
firstItem := newManagedGroups.Items[0]
assert.Equal(t, newManagedGroupId, firstItem.Id)
assert.Equal(t, managedGroupId, firstItem.Id)
assert.Equal(t, "complete", newManagedGroups.ResponseType)
// Note that the removed IDs may contain entries from other tests,
// so just check that there is at least 1 entry and that our entry
@@ -28,11 +28,12 @@ func TestCliPaginateRoles(t *testing.T) {
ctx := context.Background()
boundary.AuthenticateAdminCli(t, ctx)
newOrgId := boundary.CreateNewOrgCli(t, ctx)
orgId, err := boundary.CreateOrgCli(t, ctx)
require.NoError(t, err)
t.Cleanup(func() {
ctx := context.Background()
boundary.AuthenticateAdminCli(t, ctx)
output := e2e.RunCommand(ctx, "boundary", e2e.WithArgs("scopes", "delete", "-id", newOrgId))
output := e2e.RunCommand(ctx, "boundary", e2e.WithArgs("scopes", "delete", "-id", orgId))
require.NoError(t, output.Err, string(output.Stderr))
})
@@ -45,14 +46,16 @@ func TestCliPaginateRoles(t *testing.T) {
numPrecreatedRoles := 2
var roleIds []string
for i := 0; i < c.MaxPageSize+1-numPrecreatedRoles; i++ {
roleIds = append(roleIds, boundary.CreateNewRoleApi(t, ctx, client, newOrgId))
roleId, err := boundary.CreateRoleApi(t, ctx, client, orgId)
require.NoError(t, err)
roleIds = append(roleIds, roleId)
}
// List roles
output := e2e.RunCommand(ctx, "boundary",
e2e.WithArgs(
"roles", "list",
"-scope-id", newOrgId,
"-scope-id", orgId,
"-format=json",
),
)
@@ -75,7 +78,8 @@ func TestCliPaginateRoles(t *testing.T) {
assert.Empty(t, initialRoles.ListToken)
// Create a new role and destroy one of the other roles
newRoleId := boundary.CreateNewRoleApi(t, ctx, client, newOrgId)
roleId, err := boundary.CreateRoleApi(t, ctx, client, orgId)
require.NoError(t, err)
output = e2e.RunCommand(ctx, "boundary",
e2e.WithArgs(
"roles", "delete",
@@ -88,7 +92,7 @@ func TestCliPaginateRoles(t *testing.T) {
output = e2e.RunCommand(ctx, "boundary",
e2e.WithArgs(
"roles", "list",
"-scope-id", newOrgId,
"-scope-id", orgId,
"-format=json",
),
)
@@ -102,7 +106,7 @@ func TestCliPaginateRoles(t *testing.T) {
// The first item should be the most recently created, which
// should be our new role
firstItem := newRoles.Items[0]
assert.Equal(t, newRoleId, firstItem.Id)
assert.Equal(t, roleId, firstItem.Id)
assert.Empty(t, newRoles.ResponseType)
assert.Empty(t, newRoles.RemovedIds)
assert.Empty(t, newRoles.ListToken)
@@ -124,10 +128,11 @@ func TestApiPaginateRoles(t *testing.T) {
ctx := context.Background()
sClient := scopes.NewClient(client)
uClient := roles.NewClient(client)
newOrgId := boundary.CreateNewOrgApi(t, ctx, client)
orgId, err := boundary.CreateOrgApi(t, ctx, client)
require.NoError(t, err)
t.Cleanup(func() {
ctx := context.Background()
_, err := sClient.Delete(ctx, newOrgId)
_, err := sClient.Delete(ctx, orgId)
require.NoError(t, err)
})
@@ -138,11 +143,13 @@ func TestApiPaginateRoles(t *testing.T) {
numPrecreatedRoles := 2
var roleIds []string
for i := 0; i < c.MaxPageSize+1-numPrecreatedRoles; i++ {
roleIds = append(roleIds, boundary.CreateNewRoleApi(t, ctx, client, newOrgId))
roleId, err := boundary.CreateRoleApi(t, ctx, client, orgId)
require.NoError(t, err)
roleIds = append(roleIds, roleId)
}
// List roles
initialRoles, err := uClient.List(ctx, newOrgId)
initialRoles, err := uClient.List(ctx, orgId)
require.NoError(t, err)
var returnedIds []string
@@ -163,12 +170,13 @@ func TestApiPaginateRoles(t *testing.T) {
assert.Len(t, mapSliceItems, c.MaxPageSize+1)
// Create a new role and destroy one of the other roles
newRoleId := boundary.CreateNewRoleApi(t, ctx, client, newOrgId)
roleId, err := boundary.CreateRoleApi(t, ctx, client, orgId)
require.NoError(t, err)
_, err = uClient.Delete(ctx, initialRoles.Items[0].Id)
require.NoError(t, err)
// List again, should have the new and deleted role
newRoles, err := uClient.List(ctx, newOrgId, roles.WithListToken(initialRoles.ListToken))
newRoles, err := uClient.List(ctx, orgId, roles.WithListToken(initialRoles.ListToken))
require.NoError(t, err)
// Note that this will likely contain all the roles,
@@ -179,7 +187,7 @@ func TestApiPaginateRoles(t *testing.T) {
// The first item should be the most recently created, which
// should be our new role
firstItem := newRoles.Items[0]
assert.Equal(t, newRoleId, firstItem.Id)
assert.Equal(t, roleId, firstItem.Id)
assert.Equal(t, "complete", newRoles.ResponseType)
// Note that the removed IDs may contain entries from other tests,
// so just check that there is at least 1 entry and that our entry
@@ -26,11 +26,12 @@ func TestCliPaginateScopes(t *testing.T) {
ctx := context.Background()
boundary.AuthenticateAdminCli(t, ctx)
newOrgId := boundary.CreateNewOrgCli(t, ctx)
orgId, err := boundary.CreateOrgCli(t, ctx)
require.NoError(t, err)
t.Cleanup(func() {
ctx := context.Background()
boundary.AuthenticateAdminCli(t, ctx)
output := e2e.RunCommand(ctx, "boundary", e2e.WithArgs("scopes", "delete", "-id", newOrgId))
output := e2e.RunCommand(ctx, "boundary", e2e.WithArgs("scopes", "delete", "-id", orgId))
require.NoError(t, output.Err, string(output.Stderr))
})
@@ -39,14 +40,16 @@ func TestCliPaginateScopes(t *testing.T) {
require.NoError(t, err)
var scopeIds []string
for i := 0; i < c.MaxPageSize+1; i++ {
scopeIds = append(scopeIds, boundary.CreateNewProjectApi(t, ctx, client, newOrgId))
projectId, err := boundary.CreateProjectApi(t, ctx, client, orgId)
require.NoError(t, err)
scopeIds = append(scopeIds, projectId)
}
// List scopes
output := e2e.RunCommand(ctx, "boundary",
e2e.WithArgs(
"scopes", "list",
"-scope-id", newOrgId,
"-scope-id", orgId,
"-format=json",
),
)
@@ -68,7 +71,8 @@ func TestCliPaginateScopes(t *testing.T) {
assert.Empty(t, initialScopes.ListToken)
// Create a new scope and destroy one of the other scopes
newScopeId := boundary.CreateNewProjectApi(t, ctx, client, newOrgId)
newScopeId, err := boundary.CreateProjectApi(t, ctx, client, orgId)
require.NoError(t, err)
output = e2e.RunCommand(ctx, "boundary",
e2e.WithArgs(
"scopes", "delete",
@@ -81,7 +85,7 @@ func TestCliPaginateScopes(t *testing.T) {
output = e2e.RunCommand(ctx, "boundary",
e2e.WithArgs(
"scopes", "list",
"-scope-id", newOrgId,
"-scope-id", orgId,
"-format=json",
),
)
@@ -116,21 +120,24 @@ func TestApiPaginateScopes(t *testing.T) {
require.NoError(t, err)
ctx := context.Background()
sClient := scopes.NewClient(client)
newOrgId := boundary.CreateNewOrgApi(t, ctx, client)
orgId, err := boundary.CreateOrgApi(t, ctx, client)
require.NoError(t, err)
t.Cleanup(func() {
ctx := context.Background()
_, err := sClient.Delete(ctx, newOrgId)
_, err := sClient.Delete(ctx, orgId)
require.NoError(t, err)
})
// Create enough scopes to overflow a single page.
var scopeIds []string
for i := 0; i < c.MaxPageSize+1; i++ {
scopeIds = append(scopeIds, boundary.CreateNewProjectApi(t, ctx, client, newOrgId))
projectId, err := boundary.CreateProjectApi(t, ctx, client, orgId)
require.NoError(t, err)
scopeIds = append(scopeIds, projectId)
}
// List scopes
initialScopes, err := sClient.List(ctx, newOrgId)
initialScopes, err := sClient.List(ctx, orgId)
require.NoError(t, err)
var returnedIds []string
@@ -27,34 +27,41 @@ func TestCliPaginateSessions(t *testing.T) {
ctx := context.Background()
boundary.AuthenticateAdminCli(t, ctx)
newOrgId := boundary.CreateNewOrgCli(t, ctx)
orgId, err := boundary.CreateOrgCli(t, ctx)
require.NoError(t, err)
t.Cleanup(func() {
ctx := context.Background()
boundary.AuthenticateAdminCli(t, ctx)
output := e2e.RunCommand(ctx, "boundary", e2e.WithArgs("scopes", "delete", "-id", newOrgId))
output := e2e.RunCommand(ctx, "boundary", e2e.WithArgs("scopes", "delete", "-id", orgId))
require.NoError(t, output.Err, string(output.Stderr))
})
newProjectId := boundary.CreateNewProjectCli(t, ctx, newOrgId)
newHostCatalogId := boundary.CreateNewHostCatalogCli(t, ctx, newProjectId)
newHostSetId := boundary.CreateNewHostSetCli(t, ctx, newHostCatalogId)
newHostId := boundary.CreateNewHostCli(t, ctx, newHostCatalogId, c.TargetAddress)
boundary.AddHostToHostSetCli(t, ctx, newHostSetId, newHostId)
projectId, err := boundary.CreateProjectCli(t, ctx, orgId)
require.NoError(t, err)
hostCatalogId, err := boundary.CreateHostCatalogCli(t, ctx, projectId)
require.NoError(t, err)
hostSetId, err := boundary.CreateHostSetCli(t, ctx, hostCatalogId)
require.NoError(t, err)
hostId, err := boundary.CreateHostCli(t, ctx, hostCatalogId, c.TargetAddress)
require.NoError(t, err)
err = boundary.AddHostToHostSetCli(t, ctx, hostSetId, hostId)
require.NoError(t, err)
targetId, err := boundary.CreateTargetCli(t, ctx, projectId, c.TargetPort)
require.NoError(t, err)
err = boundary.AddHostSourceToTargetCli(t, ctx, targetId, hostSetId)
require.NoError(t, err)
newTargetId := boundary.CreateNewTargetCli(t, ctx, newProjectId, c.TargetPort)
boundary.AddHostSourceToTargetCli(t, ctx, newTargetId, newHostSetId)
// Connect to targets to create a session
// Create enough sessions to overflow a single page
for i := 0; i < c.MaxPageSize+1; i++ {
boundary.ConnectCli(t, ctx, newTargetId)
boundary.ConnectCli(t, ctx, targetId)
}
// List sessions recursively
output := e2e.RunCommand(ctx, "boundary",
e2e.WithArgs(
"sessions", "list",
"-scope-id", newProjectId,
"-scope-id", projectId,
"-format=json",
),
)
@@ -71,13 +78,13 @@ func TestCliPaginateSessions(t *testing.T) {
assert.Empty(t, initialSessions.ListToken)
// Create a new session
boundary.ConnectCli(t, ctx, newTargetId)
boundary.ConnectCli(t, ctx, targetId)
// List again, should have the new session
output = e2e.RunCommand(ctx, "boundary",
e2e.WithArgs(
"sessions", "list",
"-scope-id", newProjectId,
"-scope-id", projectId,
"-format=json",
),
)
@@ -104,35 +111,42 @@ func TestApiPaginateSessions(t *testing.T) {
client, err := boundary.NewApiClient()
require.NoError(t, err)
ctx := context.Background()
newOrgId := boundary.CreateNewOrgApi(t, ctx, client)
orgId, err := boundary.CreateOrgApi(t, ctx, client)
require.NoError(t, err)
sClient := sessions.NewClient(client)
tClient := targets.NewClient(client)
t.Cleanup(func() {
ctx := context.Background()
scopeClient := scopes.NewClient(client)
_, err := scopeClient.Delete(ctx, newOrgId)
_, err := scopeClient.Delete(ctx, orgId)
require.NoError(t, err)
})
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.TargetAddress)
boundary.AddHostToHostSetApi(t, ctx, client, newHostSetId, newHostId)
projectId, err := boundary.CreateProjectApi(t, ctx, client, orgId)
require.NoError(t, err)
hostCatalogId, err := boundary.CreateHostCatalogApi(t, ctx, client, projectId)
require.NoError(t, err)
hostSetId, err := boundary.CreateHostSetApi(t, ctx, client, hostCatalogId)
require.NoError(t, err)
hostId, err := boundary.CreateHostApi(t, ctx, client, hostCatalogId, c.TargetAddress)
require.NoError(t, err)
err = boundary.AddHostToHostSetApi(t, ctx, client, hostSetId, hostId)
require.NoError(t, err)
targetId, err := boundary.CreateTargetApi(t, ctx, client, projectId, c.TargetPort)
require.NoError(t, err)
err = boundary.AddHostSourceToTargetApi(t, ctx, client, targetId, hostSetId)
require.NoError(t, err)
newTargetId := boundary.CreateNewTargetApi(t, ctx, client, newProjectId, c.TargetPort)
boundary.AddHostSourceToTargetApi(t, ctx, client, newTargetId, newHostSetId)
// Connect to targets to create a session
// Create enough sessions to overflow a single page
for i := 0; i < c.MaxPageSize+1; i++ {
// boundary.ConnectCli(t, ctx, newTargetId)
_, err := tClient.AuthorizeSession(ctx, newTargetId)
_, err := tClient.AuthorizeSession(ctx, targetId)
require.NoError(t, err)
}
// List sessions
initialSessions, err := sClient.List(ctx, newProjectId)
initialSessions, err := sClient.List(ctx, projectId)
require.NoError(t, err)
require.Len(t, initialSessions.Items, c.MaxPageSize+1)
@@ -146,10 +160,10 @@ func TestApiPaginateSessions(t *testing.T) {
assert.Len(t, mapSliceItems, c.MaxPageSize+1)
// Create a new session
boundary.ConnectCli(t, ctx, newTargetId)
boundary.ConnectCli(t, ctx, targetId)
// List again, should have the new session
newSessions, err := sClient.List(ctx, newProjectId, sessions.WithListToken(initialSessions.ListToken))
newSessions, err := sClient.List(ctx, projectId, sessions.WithListToken(initialSessions.ListToken))
require.NoError(t, err)
// Note that this will likely contain all the sessions,
@@ -30,14 +30,16 @@ func TestCliPaginateTargets(t *testing.T) {
ctx := context.Background()
boundary.AuthenticateAdminCli(t, ctx)
newOrgId := boundary.CreateNewOrgCli(t, ctx)
orgId, err := boundary.CreateOrgCli(t, ctx)
require.NoError(t, err)
t.Cleanup(func() {
ctx := context.Background()
boundary.AuthenticateAdminCli(t, ctx)
output := e2e.RunCommand(ctx, "boundary", e2e.WithArgs("scopes", "delete", "-id", newOrgId))
output := e2e.RunCommand(ctx, "boundary", e2e.WithArgs("scopes", "delete", "-id", orgId))
require.NoError(t, output.Err, string(output.Stderr))
})
newProjectId := boundary.CreateNewProjectCli(t, ctx, newOrgId)
projectId, err := boundary.CreateProjectCli(t, ctx, orgId)
require.NoError(t, err)
// Create enough targets to overflow a single page.
// Use the API to make creation faster.
@@ -48,7 +50,7 @@ func TestCliPaginateTargets(t *testing.T) {
require.NoError(t, err)
var targetIds []string
for i := 0; i < c.MaxPageSize+1; i++ {
resp, err := tClient.Create(ctx, "tcp", newProjectId,
resp, err := tClient.Create(ctx, "tcp", projectId,
targets.WithName("test-target-"+strconv.Itoa(i)),
targets.WithTcpTargetDefaultPort(uint32(targetPort)),
targets.WithAddress(c.TargetAddress),
@@ -61,7 +63,7 @@ func TestCliPaginateTargets(t *testing.T) {
output := e2e.RunCommand(ctx, "boundary",
e2e.WithArgs(
"targets", "list",
"-scope-id", newProjectId,
"-scope-id", projectId,
"-format=json",
),
)
@@ -83,7 +85,8 @@ func TestCliPaginateTargets(t *testing.T) {
assert.Empty(t, initialTargets.ListToken)
// Create a new target and destroy one of the other targets
newTargetId := boundary.CreateNewTargetCli(t, ctx, newProjectId, c.TargetPort, target.WithAddress(c.TargetAddress))
targetId, err := boundary.CreateTargetCli(t, ctx, projectId, c.TargetPort, target.WithAddress(c.TargetAddress))
require.NoError(t, err)
output = e2e.RunCommand(ctx, "boundary",
e2e.WithArgs(
"targets", "delete",
@@ -96,7 +99,7 @@ func TestCliPaginateTargets(t *testing.T) {
output = e2e.RunCommand(ctx, "boundary",
e2e.WithArgs(
"targets", "list",
"-scope-id", newProjectId,
"-scope-id", projectId,
"-format=json",
),
)
@@ -110,7 +113,7 @@ func TestCliPaginateTargets(t *testing.T) {
// The first item should be the most recently created, which
// should be our new target
firstItem := newTargets.Items[0]
assert.Equal(t, newTargetId, firstItem.Id)
assert.Equal(t, targetId, firstItem.Id)
assert.Empty(t, newTargets.ResponseType)
assert.Empty(t, newTargets.RemovedIds)
assert.Empty(t, newTargets.ListToken)
@@ -132,20 +135,22 @@ func TestApiPaginateTargets(t *testing.T) {
ctx := context.Background()
sClient := scopes.NewClient(client)
tClient := targets.NewClient(client)
newOrgId := boundary.CreateNewOrgApi(t, ctx, client)
orgId, err := boundary.CreateOrgApi(t, ctx, client)
require.NoError(t, err)
t.Cleanup(func() {
ctx := context.Background()
_, err := sClient.Delete(ctx, newOrgId)
_, err := sClient.Delete(ctx, orgId)
require.NoError(t, err)
})
newProjectId := boundary.CreateNewProjectApi(t, ctx, client, newOrgId)
projectId, err := boundary.CreateProjectApi(t, ctx, client, orgId)
require.NoError(t, err)
// Create enough targets to overflow a single page.
targetPort, err := strconv.ParseInt(c.TargetPort, 10, 32)
require.NoError(t, err)
var targetIds []string
for i := 0; i < c.MaxPageSize+1; i++ {
resp, err := tClient.Create(ctx, "tcp", newProjectId,
resp, err := tClient.Create(ctx, "tcp", projectId,
targets.WithName("test-target-"+strconv.Itoa(i)),
targets.WithTcpTargetDefaultPort(uint32(targetPort)),
targets.WithAddress(c.TargetAddress),
@@ -155,7 +160,7 @@ func TestApiPaginateTargets(t *testing.T) {
}
// List targets recursively
initialTargets, err := tClient.List(ctx, newProjectId)
initialTargets, err := tClient.List(ctx, projectId)
require.NoError(t, err)
var returnedIds []string
for _, item := range initialTargets.Items {
@@ -174,7 +179,7 @@ func TestApiPaginateTargets(t *testing.T) {
assert.Len(t, mapSliceItems, c.MaxPageSize+1)
// Create a new target and destroy one of the other targets
newTargetResult, err := tClient.Create(ctx, "tcp", newProjectId,
newTargetResult, err := tClient.Create(ctx, "tcp", projectId,
targets.WithName("test-target-"+strconv.Itoa(c.MaxPageSize+1)),
targets.WithTcpTargetDefaultPort(uint32(targetPort)),
targets.WithAddress(c.TargetAddress),
@@ -184,7 +189,7 @@ func TestApiPaginateTargets(t *testing.T) {
require.NoError(t, err)
// List again, should have the new and deleted target
newTargets, err := tClient.List(ctx, newProjectId, targets.WithListToken(initialTargets.ListToken))
newTargets, err := tClient.List(ctx, projectId, targets.WithListToken(initialTargets.ListToken))
require.NoError(t, err)
// Note that this will likely contain all the targets,
@@ -28,11 +28,12 @@ func TestCliPaginateUsers(t *testing.T) {
ctx := context.Background()
boundary.AuthenticateAdminCli(t, ctx)
newOrgId := boundary.CreateNewOrgCli(t, ctx)
orgId, err := boundary.CreateOrgCli(t, ctx)
require.NoError(t, err)
t.Cleanup(func() {
ctx := context.Background()
boundary.AuthenticateAdminCli(t, ctx)
output := e2e.RunCommand(ctx, "boundary", e2e.WithArgs("scopes", "delete", "-id", newOrgId))
output := e2e.RunCommand(ctx, "boundary", e2e.WithArgs("scopes", "delete", "-id", orgId))
require.NoError(t, output.Err, string(output.Stderr))
})
@@ -41,14 +42,16 @@ func TestCliPaginateUsers(t *testing.T) {
require.NoError(t, err)
var userIds []string
for i := 0; i < c.MaxPageSize+1; i++ {
userIds = append(userIds, boundary.CreateNewUserApi(t, ctx, client, newOrgId))
userId, err := boundary.CreateUserApi(t, ctx, client, orgId)
require.NoError(t, err)
userIds = append(userIds, userId)
}
// List users
output := e2e.RunCommand(ctx, "boundary",
e2e.WithArgs(
"users", "list",
"-scope-id", newOrgId,
"-scope-id", orgId,
"-format=json",
),
)
@@ -70,7 +73,8 @@ func TestCliPaginateUsers(t *testing.T) {
assert.Empty(t, initialUsers.ListToken)
// Create a new user and destroy one of the other users
newUserId := boundary.CreateNewUserApi(t, ctx, client, newOrgId)
userId, err := boundary.CreateUserApi(t, ctx, client, orgId)
require.NoError(t, err)
output = e2e.RunCommand(ctx, "boundary",
e2e.WithArgs(
"users", "delete",
@@ -83,7 +87,7 @@ func TestCliPaginateUsers(t *testing.T) {
output = e2e.RunCommand(ctx, "boundary",
e2e.WithArgs(
"users", "list",
"-scope-id", newOrgId,
"-scope-id", orgId,
"-format=json",
),
)
@@ -97,7 +101,7 @@ func TestCliPaginateUsers(t *testing.T) {
// The first item should be the most recently created, which
// should be our new user
firstItem := newUsers.Items[0]
assert.Equal(t, newUserId, firstItem.Id)
assert.Equal(t, userId, firstItem.Id)
assert.Empty(t, newUsers.ResponseType)
assert.Empty(t, newUsers.RemovedIds)
assert.Empty(t, newUsers.ListToken)
@@ -119,21 +123,24 @@ func TestApiPaginateUsers(t *testing.T) {
ctx := context.Background()
sClient := scopes.NewClient(client)
uClient := users.NewClient(client)
newOrgId := boundary.CreateNewOrgApi(t, ctx, client)
orgId, err := boundary.CreateOrgApi(t, ctx, client)
require.NoError(t, err)
t.Cleanup(func() {
ctx := context.Background()
_, err := sClient.Delete(ctx, newOrgId)
_, err := sClient.Delete(ctx, orgId)
require.NoError(t, err)
})
// Create enough users to overflow a single page.
var userIds []string
for i := 0; i < c.MaxPageSize+1; i++ {
userIds = append(userIds, boundary.CreateNewUserApi(t, ctx, client, newOrgId))
userId, err := boundary.CreateUserApi(t, ctx, client, orgId)
require.NoError(t, err)
userIds = append(userIds, userId)
}
// List users
initialUsers, err := uClient.List(ctx, newOrgId)
initialUsers, err := uClient.List(ctx, orgId)
require.NoError(t, err)
var returnedIds []string
@@ -153,12 +160,13 @@ func TestApiPaginateUsers(t *testing.T) {
assert.Len(t, mapSliceItems, c.MaxPageSize+1)
// Create a new user and destroy one of the other users
newUserId := boundary.CreateNewUserApi(t, ctx, client, newOrgId)
userId, err := boundary.CreateUserApi(t, ctx, client, orgId)
require.NoError(t, err)
_, err = uClient.Delete(ctx, initialUsers.Items[0].Id)
require.NoError(t, err)
// List again, should have the new and deleted user
newUsers, err := uClient.List(ctx, newOrgId, users.WithListToken(initialUsers.ListToken))
newUsers, err := uClient.List(ctx, orgId, users.WithListToken(initialUsers.ListToken))
require.NoError(t, err)
// Note that this will likely contain all the users,
@@ -169,7 +177,7 @@ func TestApiPaginateUsers(t *testing.T) {
// The first item should be the most recently created, which
// should be our new user
firstItem := newUsers.Items[0]
assert.Equal(t, newUserId, firstItem.Id)
assert.Equal(t, userId, firstItem.Id)
assert.Equal(t, "complete", newUsers.ResponseType)
// Note that the removed IDs may contain entries from other tests,
// so just check that there is at least 1 entry and that our entry
@@ -22,18 +22,21 @@ func TestCliApplyGrantsForMultipleScopes(t *testing.T) {
boundary.AuthenticateAdminCli(t, ctx)
// Create Org and Project
orgId := boundary.CreateNewOrgCli(t, ctx)
orgId, err := boundary.CreateOrgCli(t, ctx)
require.NoError(t, err)
t.Cleanup(func() {
ctx := context.Background()
boundary.AuthenticateAdminCli(t, ctx)
output := e2e.RunCommand(ctx, "boundary", e2e.WithArgs("scopes", "delete", "-id", orgId))
require.NoError(t, output.Err, string(output.Stderr))
})
projectId := boundary.CreateNewProjectCli(t, ctx, orgId)
projectId, err := boundary.CreateProjectCli(t, ctx, orgId)
require.NoError(t, err)
// Create Account
acctName := "e2e-account"
accountId, acctPassword := boundary.CreateNewAccountCli(t, ctx, bc.AuthMethodId, acctName)
accountId, acctPassword, err := boundary.CreateAccountCli(t, ctx, bc.AuthMethodId, acctName)
require.NoError(t, err)
t.Cleanup(func() {
boundary.AuthenticateAdminCli(t, ctx)
output := e2e.RunCommand(ctx, "boundary",
@@ -43,7 +46,8 @@ func TestCliApplyGrantsForMultipleScopes(t *testing.T) {
})
// Create User and set Account to it
userId := boundary.CreateNewUserCli(t, ctx, "global")
userId, err := boundary.CreateUserCli(t, ctx, "global")
require.NoError(t, err)
t.Cleanup(func() {
boundary.AuthenticateAdminCli(t, ctx)
output := e2e.RunCommand(ctx, "boundary",
@@ -51,7 +55,8 @@ func TestCliApplyGrantsForMultipleScopes(t *testing.T) {
)
require.NoError(t, output.Err, string(output.Stderr))
})
boundary.SetAccountToUserCli(t, ctx, userId, accountId)
err = boundary.SetAccountToUserCli(t, ctx, userId, accountId)
require.NoError(t, err)
// Authenticate test user and try to:
// - list Roles in global scope: expect error
@@ -79,8 +84,10 @@ func TestCliApplyGrantsForMultipleScopes(t *testing.T) {
)
require.NoError(t, output.Err, string(output.Stderr))
})
boundary.AddGrantToRoleCli(t, ctx, roleId, "ids=*;type=role;actions=list")
boundary.AddPrincipalToRoleCli(t, ctx, roleId, userId)
err = boundary.AddGrantToRoleCli(t, ctx, roleId, "ids=*;type=role;actions=list")
require.NoError(t, err)
err = boundary.AddPrincipalToRoleCli(t, ctx, roleId, userId)
require.NoError(t, err)
// Authenticate User and try to:
// - list Roles in global scope: expect success
@@ -90,14 +90,16 @@ func TestCliSearch(t *testing.T) {
// Set up a new org and project
boundary.AuthenticateAdminCli(t, ctx)
newOrgId := boundary.CreateNewOrgCli(t, ctx)
orgId, err := boundary.CreateOrgCli(t, ctx)
require.NoError(t, err)
t.Cleanup(func() {
ctx := context.Background()
boundary.AuthenticateAdminCli(t, ctx)
output := e2e.RunCommand(ctx, "boundary", e2e.WithArgs("scopes", "delete", "-id", newOrgId))
output := e2e.RunCommand(ctx, "boundary", e2e.WithArgs("scopes", "delete", "-id", orgId))
require.NoError(t, output.Err, string(output.Stderr))
})
newProjectId := boundary.CreateNewProjectCli(t, ctx, newOrgId)
projectId, err := boundary.CreateProjectCli(t, ctx, orgId)
require.NoError(t, err)
// Get current number of targets
output = e2e.RunCommand(ctx, "boundary", e2e.WithArgs("daemon", "status", "-format", "json"))
@@ -125,7 +127,7 @@ func TestCliSearch(t *testing.T) {
var targetIds []string
targetPrefix := "test-target"
for i := 0; i < c.MaxPageSize+1; i++ {
resp, err := tClient.Create(ctx, "tcp", newProjectId,
resp, err := tClient.Create(ctx, "tcp", projectId,
targets.WithName(targetPrefix+strconv.Itoa(i)),
targets.WithTcpTargetDefaultPort(uint32(targetPort)),
targets.WithAddress(c.TargetAddress),
@@ -137,7 +139,7 @@ func TestCliSearch(t *testing.T) {
// List targets.
// This requests data from the controller/database.
t.Log("Listing targets...")
output = e2e.RunCommand(ctx, "boundary", e2e.WithArgs("targets", "list", "-scope-id", newProjectId, "-format", "json"))
output = e2e.RunCommand(ctx, "boundary", e2e.WithArgs("targets", "list", "-scope-id", projectId, "-format", "json"))
require.NoError(t, output.Err, string(output.Stderr))
var targetListResult targets.TargetListResult
err = json.Unmarshal(output.Stdout, &targetListResult)
@@ -205,7 +207,7 @@ func TestCliSearch(t *testing.T) {
"search",
"-resource", "targets",
"-format", "json",
"-query", fmt.Sprintf(`name %% "%s" and scope_id = "%s"`, targetPrefix, newProjectId),
"-query", fmt.Sprintf(`name %% "%s" and scope_id = "%s"`, targetPrefix, projectId),
),
)
require.NoError(t, output.Err, string(output.Stderr))
@@ -224,7 +226,7 @@ func TestCliSearch(t *testing.T) {
"search",
"-resource", "targets",
"-format", "json",
"-query", fmt.Sprintf(`name = "%s1" and scope_id = "%s"`, targetPrefix, newProjectId),
"-query", fmt.Sprintf(`name = "%s1" and scope_id = "%s"`, targetPrefix, projectId),
),
)
require.NoError(t, output.Err, string(output.Stderr))
@@ -23,20 +23,28 @@ func TestCliSessionCancelAdmin(t *testing.T) {
ctx := context.Background()
boundary.AuthenticateAdminCli(t, ctx)
newOrgId := boundary.CreateNewOrgCli(t, ctx)
orgId, err := boundary.CreateOrgCli(t, ctx)
require.NoError(t, err)
t.Cleanup(func() {
ctx := context.Background()
boundary.AuthenticateAdminCli(t, ctx)
output := e2e.RunCommand(ctx, "boundary", e2e.WithArgs("scopes", "delete", "-id", newOrgId))
output := e2e.RunCommand(ctx, "boundary", e2e.WithArgs("scopes", "delete", "-id", orgId))
require.NoError(t, output.Err, string(output.Stderr))
})
newProjectId := boundary.CreateNewProjectCli(t, ctx, newOrgId)
newHostCatalogId := boundary.CreateNewHostCatalogCli(t, ctx, newProjectId)
newHostSetId := boundary.CreateNewHostSetCli(t, ctx, newHostCatalogId)
newHostId := boundary.CreateNewHostCli(t, ctx, newHostCatalogId, c.TargetAddress)
boundary.AddHostToHostSetCli(t, ctx, newHostSetId, newHostId)
newTargetId := boundary.CreateNewTargetCli(t, ctx, newProjectId, c.TargetPort)
boundary.AddHostSourceToTargetCli(t, ctx, newTargetId, newHostSetId)
projectId, err := boundary.CreateProjectCli(t, ctx, orgId)
require.NoError(t, err)
hostCatalogId, err := boundary.CreateHostCatalogCli(t, ctx, projectId)
require.NoError(t, err)
hostSetId, err := boundary.CreateHostSetCli(t, ctx, hostCatalogId)
require.NoError(t, err)
hostId, err := boundary.CreateHostCli(t, ctx, hostCatalogId, c.TargetAddress)
require.NoError(t, err)
err = boundary.AddHostToHostSetCli(t, ctx, hostSetId, hostId)
require.NoError(t, err)
targetId, err := boundary.CreateTargetCli(t, ctx, projectId, c.TargetPort)
require.NoError(t, err)
err = boundary.AddHostSourceToTargetCli(t, ctx, targetId, hostSetId)
require.NoError(t, err)
// Connect to target to create a session
ctxCancel, cancel := context.WithCancel(context.Background())
@@ -46,7 +54,7 @@ func TestCliSessionCancelAdmin(t *testing.T) {
errChan <- e2e.RunCommand(ctxCancel, "boundary",
e2e.WithArgs(
"connect",
"-target-id", newTargetId,
"-target-id", targetId,
"-exec", "/usr/bin/ssh", "--",
"-l", c.TargetSshUser,
"-i", c.TargetSshKeyPath,
@@ -60,10 +68,10 @@ func TestCliSessionCancelAdmin(t *testing.T) {
)
}()
t.Cleanup(cancel)
s := boundary.WaitForSessionCli(t, ctx, newProjectId)
s := boundary.WaitForSessionCli(t, ctx, projectId)
boundary.WaitForSessionStatusCli(t, ctx, s.Id, session.StatusActive.String())
assert.Equal(t, newTargetId, s.TargetId)
assert.Equal(t, newHostId, s.HostId)
assert.Equal(t, targetId, s.TargetId)
assert.Equal(t, hostId, s.HostId)
// Cancel session
t.Log("Canceling session...")
@@ -34,45 +34,56 @@ func TestCliSessionCancelGroup(t *testing.T) {
ctx := context.Background()
boundary.AuthenticateAdminCli(t, ctx)
newOrgId := boundary.CreateNewOrgCli(t, ctx)
orgId, err := boundary.CreateOrgCli(t, ctx)
require.NoError(t, err)
t.Cleanup(func() {
ctx := context.Background()
boundary.AuthenticateAdminCli(t, ctx)
output := e2e.RunCommand(ctx, "boundary", e2e.WithArgs("scopes", "delete", "-id", newOrgId))
output := e2e.RunCommand(ctx, "boundary", e2e.WithArgs("scopes", "delete", "-id", orgId))
require.NoError(t, output.Err, string(output.Stderr))
})
newProjectId := boundary.CreateNewProjectCli(t, ctx, newOrgId)
newHostCatalogId := boundary.CreateNewHostCatalogCli(t, ctx, newProjectId)
newHostSetId := boundary.CreateNewHostSetCli(t, ctx, newHostCatalogId)
newHostId := boundary.CreateNewHostCli(t, ctx, newHostCatalogId, c.TargetAddress)
boundary.AddHostToHostSetCli(t, ctx, newHostSetId, newHostId)
newTargetId := boundary.CreateNewTargetCli(t, ctx, newProjectId, c.TargetPort)
boundary.AddHostSourceToTargetCli(t, ctx, newTargetId, newHostSetId)
projectId, err := boundary.CreateProjectCli(t, ctx, orgId)
require.NoError(t, err)
hostCatalogId, err := boundary.CreateHostCatalogCli(t, ctx, projectId)
require.NoError(t, err)
hostSetId, err := boundary.CreateHostSetCli(t, ctx, hostCatalogId)
require.NoError(t, err)
hostId, err := boundary.CreateHostCli(t, ctx, hostCatalogId, c.TargetAddress)
require.NoError(t, err)
err = boundary.AddHostToHostSetCli(t, ctx, hostSetId, hostId)
require.NoError(t, err)
targetId, err := boundary.CreateTargetCli(t, ctx, projectId, c.TargetPort)
require.NoError(t, err)
err = boundary.AddHostSourceToTargetCli(t, ctx, targetId, hostSetId)
require.NoError(t, err)
acctName := "e2e-account"
newAccountId, acctPassword := boundary.CreateNewAccountCli(t, ctx, bc.AuthMethodId, acctName)
accountId, acctPassword, err := boundary.CreateAccountCli(t, ctx, bc.AuthMethodId, acctName)
require.NoError(t, err)
t.Cleanup(func() {
boundary.AuthenticateAdminCli(t, context.Background())
output := e2e.RunCommand(ctx, "boundary",
e2e.WithArgs("accounts", "delete", "-id", newAccountId),
e2e.WithArgs("accounts", "delete", "-id", accountId),
)
require.NoError(t, output.Err, string(output.Stderr))
})
newUserId := boundary.CreateNewUserCli(t, ctx, "global")
userId, err := boundary.CreateUserCli(t, ctx, "global")
require.NoError(t, err)
t.Cleanup(func() {
boundary.AuthenticateAdminCli(t, context.Background())
output := e2e.RunCommand(ctx, "boundary",
e2e.WithArgs("users", "delete", "-id", newUserId),
e2e.WithArgs("users", "delete", "-id", userId),
)
require.NoError(t, output.Err, string(output.Stderr))
})
boundary.SetAccountToUserCli(t, ctx, newUserId, newAccountId)
err = boundary.SetAccountToUserCli(t, ctx, userId, accountId)
require.NoError(t, err)
// Try to connect to the target as a user without permissions
boundary.AuthenticateCli(t, ctx, bc.AuthMethodId, acctName, acctPassword)
output := e2e.RunCommand(ctx, "boundary",
e2e.WithArgs(
"connect",
"-target-id", newTargetId,
"-target-id", targetId,
"-format", "json",
"-exec", "/usr/bin/ssh", "--",
"-l", c.TargetSshUser,
@@ -94,14 +105,18 @@ func TestCliSessionCancelGroup(t *testing.T) {
// Create a group
boundary.AuthenticateAdminCli(t, ctx)
newGroupId := boundary.CreateNewGroupCli(t, ctx, "global")
boundary.AddUserToGroup(t, ctx, newUserId, newGroupId)
groupId, err := boundary.CreateGroupCli(t, ctx, "global")
require.NoError(t, err)
err = boundary.AddUserToGroup(t, ctx, userId, groupId)
require.NoError(t, err)
// Create a role for a group
newRoleId, err := boundary.CreateRoleCli(t, ctx, newProjectId)
roleId, err := boundary.CreateRoleCli(t, ctx, projectId)
require.NoError(t, err)
err = boundary.AddGrantToRoleCli(t, ctx, roleId, "ids=*;type=target;actions=authorize-session")
require.NoError(t, err)
err = boundary.AddPrincipalToRoleCli(t, ctx, roleId, groupId)
require.NoError(t, err)
boundary.AddGrantToRoleCli(t, ctx, newRoleId, "ids=*;type=target;actions=authorize-session")
boundary.AddPrincipalToRoleCli(t, ctx, newRoleId, newGroupId)
// Connect to target to create a session
ctxCancel, cancel := context.WithCancel(context.Background())
@@ -113,7 +128,7 @@ func TestCliSessionCancelGroup(t *testing.T) {
e2e.WithArgs(
"connect",
"-token", "env://E2E_AUTH_TOKEN",
"-target-id", newTargetId,
"-target-id", targetId,
"-exec", "/usr/bin/ssh", "--",
"-l", c.TargetSshUser,
"-i", c.TargetSshKeyPath,
@@ -128,10 +143,10 @@ func TestCliSessionCancelGroup(t *testing.T) {
)
}()
t.Cleanup(cancel)
s := boundary.WaitForSessionCli(t, ctx, newProjectId)
s := boundary.WaitForSessionCli(t, ctx, projectId)
boundary.WaitForSessionStatusCli(t, ctx, s.Id, session.StatusActive.String())
assert.Equal(t, newTargetId, s.TargetId)
assert.Equal(t, newHostId, s.HostId)
assert.Equal(t, targetId, s.TargetId)
assert.Equal(t, hostId, s.HostId)
// Cancel session
t.Log("Canceling session...")
@@ -165,35 +180,45 @@ func TestApiCreateGroup(t *testing.T) {
require.NoError(t, err)
ctx := context.Background()
newOrgId := boundary.CreateNewOrgApi(t, ctx, client)
orgId, err := boundary.CreateOrgApi(t, ctx, client)
require.NoError(t, err)
t.Cleanup(func() {
scopeClient := scopes.NewClient(client)
_, err := scopeClient.Delete(ctx, newOrgId)
_, err := scopeClient.Delete(ctx, orgId)
require.NoError(t, err)
})
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.TargetAddress)
boundary.AddHostToHostSetApi(t, ctx, client, newHostSetId, newHostId)
newTargetId := boundary.CreateNewTargetApi(t, ctx, client, newProjectId, c.TargetPort)
boundary.AddHostSourceToTargetApi(t, ctx, client, newTargetId, newHostSetId)
projectId, err := boundary.CreateProjectApi(t, ctx, client, orgId)
require.NoError(t, err)
hostCatalogId, err := boundary.CreateHostCatalogApi(t, ctx, client, projectId)
require.NoError(t, err)
hostSetId, err := boundary.CreateHostSetApi(t, ctx, client, hostCatalogId)
require.NoError(t, err)
hostId, err := boundary.CreateHostApi(t, ctx, client, hostCatalogId, c.TargetAddress)
require.NoError(t, err)
err = boundary.AddHostToHostSetApi(t, ctx, client, hostSetId, hostId)
require.NoError(t, err)
targetId, err := boundary.CreateTargetApi(t, ctx, client, projectId, c.TargetPort)
require.NoError(t, err)
err = boundary.AddHostSourceToTargetApi(t, ctx, client, targetId, hostSetId)
require.NoError(t, err)
acctName := "e2e-account"
newAcctId, _ := boundary.CreateNewAccountApi(t, ctx, client, bc.AuthMethodId, acctName)
accountId, _, err := boundary.CreateAccountApi(t, ctx, client, bc.AuthMethodId, acctName)
require.NoError(t, err)
t.Cleanup(func() {
aClient := accounts.NewClient(client)
_, err := aClient.Delete(ctx, newAcctId)
_, err := aClient.Delete(ctx, accountId)
require.NoError(t, err)
})
newUserId := boundary.CreateNewUserApi(t, ctx, client, "global")
userId, err := boundary.CreateUserApi(t, ctx, client, "global")
require.NoError(t, err)
t.Cleanup(func() {
uClient := users.NewClient(client)
_, err := uClient.Delete(ctx, newUserId)
_, err := uClient.Delete(ctx, userId)
require.NoError(t, err)
})
uClient := users.NewClient(client)
_, err = uClient.SetAccounts(ctx, newUserId, 0, []string{newAcctId}, users.WithAutomaticVersioning(true))
_, err = uClient.SetAccounts(ctx, userId, 0, []string{accountId}, users.WithAutomaticVersioning(true))
require.NoError(t, err)
gClient := groups.NewClient(client)
@@ -202,11 +227,11 @@ func TestApiCreateGroup(t *testing.T) {
newGroupId := newGroupResult.Item.Id
t.Logf("Created Group: %s", newGroupId)
_, err = gClient.AddMembers(ctx, newGroupId, 0, []string{newUserId}, groups.WithAutomaticVersioning(true))
_, err = gClient.AddMembers(ctx, newGroupId, 0, []string{userId}, groups.WithAutomaticVersioning(true))
require.NoError(t, err)
rClient := roles.NewClient(client)
newRoleResult, err := rClient.Create(ctx, newProjectId)
newRoleResult, err := rClient.Create(ctx, projectId)
require.NoError(t, err)
newRoleId := newRoleResult.Item.Id
t.Logf("Created Role: %s", newRoleId)
@@ -33,45 +33,56 @@ func TestCliSessionCancelUser(t *testing.T) {
ctx := context.Background()
boundary.AuthenticateAdminCli(t, ctx)
newOrgId := boundary.CreateNewOrgCli(t, ctx)
orgId, err := boundary.CreateOrgCli(t, ctx)
require.NoError(t, err)
t.Cleanup(func() {
ctx := context.Background()
boundary.AuthenticateAdminCli(t, ctx)
output := e2e.RunCommand(ctx, "boundary", e2e.WithArgs("scopes", "delete", "-id", newOrgId))
output := e2e.RunCommand(ctx, "boundary", e2e.WithArgs("scopes", "delete", "-id", orgId))
require.NoError(t, output.Err, string(output.Stderr))
})
newProjectId := boundary.CreateNewProjectCli(t, ctx, newOrgId)
newHostCatalogId := boundary.CreateNewHostCatalogCli(t, ctx, newProjectId)
newHostSetId := boundary.CreateNewHostSetCli(t, ctx, newHostCatalogId)
newHostId := boundary.CreateNewHostCli(t, ctx, newHostCatalogId, c.TargetAddress)
boundary.AddHostToHostSetCli(t, ctx, newHostSetId, newHostId)
newTargetId := boundary.CreateNewTargetCli(t, ctx, newProjectId, c.TargetPort)
boundary.AddHostSourceToTargetCli(t, ctx, newTargetId, newHostSetId)
projectId, err := boundary.CreateProjectCli(t, ctx, orgId)
require.NoError(t, err)
hostCatalogId, err := boundary.CreateHostCatalogCli(t, ctx, projectId)
require.NoError(t, err)
hostSetId, err := boundary.CreateHostSetCli(t, ctx, hostCatalogId)
require.NoError(t, err)
hostId, err := boundary.CreateHostCli(t, ctx, hostCatalogId, c.TargetAddress)
require.NoError(t, err)
err = boundary.AddHostToHostSetCli(t, ctx, hostSetId, hostId)
require.NoError(t, err)
targetId, err := boundary.CreateTargetCli(t, ctx, projectId, c.TargetPort)
require.NoError(t, err)
err = boundary.AddHostSourceToTargetCli(t, ctx, targetId, hostSetId)
require.NoError(t, err)
acctName := "e2e-account"
newAccountId, acctPassword := boundary.CreateNewAccountCli(t, ctx, bc.AuthMethodId, acctName)
accountId, acctPassword, err := boundary.CreateAccountCli(t, ctx, bc.AuthMethodId, acctName)
require.NoError(t, err)
t.Cleanup(func() {
boundary.AuthenticateAdminCli(t, context.Background())
output := e2e.RunCommand(ctx, "boundary",
e2e.WithArgs("accounts", "delete", "-id", newAccountId),
e2e.WithArgs("accounts", "delete", "-id", accountId),
)
require.NoError(t, output.Err, string(output.Stderr))
})
newUserId := boundary.CreateNewUserCli(t, ctx, "global")
userId, err := boundary.CreateUserCli(t, ctx, "global")
require.NoError(t, err)
t.Cleanup(func() {
boundary.AuthenticateAdminCli(t, context.Background())
output := e2e.RunCommand(ctx, "boundary",
e2e.WithArgs("users", "delete", "-id", newUserId),
e2e.WithArgs("users", "delete", "-id", userId),
)
require.NoError(t, output.Err, string(output.Stderr))
})
boundary.SetAccountToUserCli(t, ctx, newUserId, newAccountId)
err = boundary.SetAccountToUserCli(t, ctx, userId, accountId)
require.NoError(t, err)
// Try to connect to the target as a user without permissions
boundary.AuthenticateCli(t, ctx, bc.AuthMethodId, acctName, acctPassword)
output := e2e.RunCommand(ctx, "boundary",
e2e.WithArgs(
"connect",
"-target-id", newTargetId,
"-target-id", targetId,
"-format", "json",
"-exec", "/usr/bin/ssh", "--",
"-l", c.TargetSshUser,
@@ -93,10 +104,12 @@ func TestCliSessionCancelUser(t *testing.T) {
// Create a role for user
boundary.AuthenticateAdminCli(t, ctx)
newRoleId, err := boundary.CreateRoleCli(t, ctx, newProjectId)
roleId, err := boundary.CreateRoleCli(t, ctx, projectId)
require.NoError(t, err)
err = boundary.AddGrantToRoleCli(t, ctx, roleId, "ids=*;type=target;actions=authorize-session")
require.NoError(t, err)
err = boundary.AddPrincipalToRoleCli(t, ctx, roleId, userId)
require.NoError(t, err)
boundary.AddGrantToRoleCli(t, ctx, newRoleId, "ids=*;type=target;actions=authorize-session")
boundary.AddPrincipalToRoleCli(t, ctx, newRoleId, newUserId)
// Connect to target to create a session
ctxCancel, cancel := context.WithCancel(context.Background())
@@ -108,7 +121,7 @@ func TestCliSessionCancelUser(t *testing.T) {
e2e.WithArgs(
"connect",
"-token", "env://E2E_AUTH_TOKEN",
"-target-id", newTargetId,
"-target-id", targetId,
"-exec", "/usr/bin/ssh", "--",
"-l", c.TargetSshUser,
"-i", c.TargetSshKeyPath,
@@ -123,10 +136,10 @@ func TestCliSessionCancelUser(t *testing.T) {
)
}()
t.Cleanup(cancel)
s := boundary.WaitForSessionCli(t, ctx, newProjectId)
s := boundary.WaitForSessionCli(t, ctx, projectId)
boundary.WaitForSessionStatusCli(t, ctx, s.Id, session.StatusActive.String())
assert.Equal(t, newTargetId, s.TargetId)
assert.Equal(t, newHostId, s.HostId)
assert.Equal(t, targetId, s.TargetId)
assert.Equal(t, hostId, s.HostId)
// Cancel session
t.Log("Canceling session...")
@@ -160,39 +173,49 @@ func TestApiCreateUser(t *testing.T) {
require.NoError(t, err)
ctx := context.Background()
newOrgId := boundary.CreateNewOrgApi(t, ctx, client)
orgId, err := boundary.CreateOrgApi(t, ctx, client)
require.NoError(t, err)
t.Cleanup(func() {
scopeClient := scopes.NewClient(client)
_, err := scopeClient.Delete(ctx, newOrgId)
_, err := scopeClient.Delete(ctx, orgId)
require.NoError(t, err)
})
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.TargetAddress)
boundary.AddHostToHostSetApi(t, ctx, client, newHostSetId, newHostId)
newTargetId := boundary.CreateNewTargetApi(t, ctx, client, newProjectId, c.TargetPort)
boundary.AddHostSourceToTargetApi(t, ctx, client, newTargetId, newHostSetId)
projectId, err := boundary.CreateProjectApi(t, ctx, client, orgId)
require.NoError(t, err)
hostCatalogId, err := boundary.CreateHostCatalogApi(t, ctx, client, projectId)
require.NoError(t, err)
hostSetId, err := boundary.CreateHostSetApi(t, ctx, client, hostCatalogId)
require.NoError(t, err)
hostId, err := boundary.CreateHostApi(t, ctx, client, hostCatalogId, c.TargetAddress)
require.NoError(t, err)
err = boundary.AddHostToHostSetApi(t, ctx, client, hostSetId, hostId)
require.NoError(t, err)
targetId, err := boundary.CreateTargetApi(t, ctx, client, projectId, c.TargetPort)
require.NoError(t, err)
err = boundary.AddHostSourceToTargetApi(t, ctx, client, targetId, hostSetId)
require.NoError(t, err)
acctName := "e2e-account"
newAcctId, _ := boundary.CreateNewAccountApi(t, ctx, client, bc.AuthMethodId, acctName)
accountId, _, err := boundary.CreateAccountApi(t, ctx, client, bc.AuthMethodId, acctName)
require.NoError(t, err)
t.Cleanup(func() {
aClient := accounts.NewClient(client)
_, err := aClient.Delete(ctx, newAcctId)
_, err := aClient.Delete(ctx, accountId)
require.NoError(t, err)
})
newUserId := boundary.CreateNewUserApi(t, ctx, client, "global")
userId, err := boundary.CreateUserApi(t, ctx, client, "global")
require.NoError(t, err)
t.Cleanup(func() {
uClient := users.NewClient(client)
_, err := uClient.Delete(ctx, newUserId)
_, err := uClient.Delete(ctx, userId)
require.NoError(t, err)
})
uClient := users.NewClient(client)
_, err = uClient.SetAccounts(ctx, newUserId, 0, []string{newAcctId}, users.WithAutomaticVersioning(true))
_, err = uClient.SetAccounts(ctx, userId, 0, []string{accountId}, users.WithAutomaticVersioning(true))
require.NoError(t, err)
rClient := roles.NewClient(client)
newRoleResult, err := rClient.Create(ctx, newProjectId)
newRoleResult, err := rClient.Create(ctx, projectId)
require.NoError(t, err)
newRoleId := newRoleResult.Item.Id
t.Logf("Created Role: %s", newRoleId)
@@ -202,7 +225,7 @@ func TestApiCreateUser(t *testing.T) {
)
require.NoError(t, err)
_, err = rClient.AddPrincipals(ctx, newRoleId, 0, []string{newUserId},
_, err = rClient.AddPrincipals(ctx, newRoleId, 0, []string{userId},
roles.WithAutomaticVersioning(true),
)
require.NoError(t, err)
@@ -26,42 +26,55 @@ func TestCliSessionEndWhenHostSetIsDeleted(t *testing.T) {
ctx := context.Background()
boundary.AuthenticateAdminCli(t, ctx)
newOrgId := boundary.CreateNewOrgCli(t, ctx)
orgId, err := boundary.CreateOrgCli(t, ctx)
require.NoError(t, err)
t.Cleanup(func() {
ctx := context.Background()
boundary.AuthenticateAdminCli(t, ctx)
output := e2e.RunCommand(ctx, "boundary", e2e.WithArgs("scopes", "delete", "-id", newOrgId))
output := e2e.RunCommand(ctx, "boundary", e2e.WithArgs("scopes", "delete", "-id", orgId))
require.NoError(t, output.Err, string(output.Stderr))
})
newProjectId := boundary.CreateNewProjectCli(t, ctx, newOrgId)
newHostCatalogId := boundary.CreateNewHostCatalogCli(t, ctx, newProjectId)
newHostSetId := boundary.CreateNewHostSetCli(t, ctx, newHostCatalogId)
newHostId := boundary.CreateNewHostCli(t, ctx, newHostCatalogId, c.TargetAddress)
boundary.AddHostToHostSetCli(t, ctx, newHostSetId, newHostId)
newTargetId := boundary.CreateNewTargetCli(t, ctx, newProjectId, c.TargetPort)
boundary.AddHostSourceToTargetCli(t, ctx, newTargetId, newHostSetId)
acctName := "e2e-account"
newAccountId, acctPassword := boundary.CreateNewAccountCli(t, ctx, bc.AuthMethodId, acctName)
t.Cleanup(func() {
boundary.AuthenticateAdminCli(t, context.Background())
output := e2e.RunCommand(ctx, "boundary",
e2e.WithArgs("accounts", "delete", "-id", newAccountId),
)
require.NoError(t, output.Err, string(output.Stderr))
})
newUserId := boundary.CreateNewUserCli(t, ctx, "global")
t.Cleanup(func() {
boundary.AuthenticateAdminCli(t, context.Background())
output := e2e.RunCommand(ctx, "boundary",
e2e.WithArgs("users", "delete", "-id", newUserId),
)
require.NoError(t, output.Err, string(output.Stderr))
})
boundary.SetAccountToUserCli(t, ctx, newUserId, newAccountId)
newRoleId, err := boundary.CreateRoleCli(t, ctx, newProjectId)
projectId, err := boundary.CreateProjectCli(t, ctx, orgId)
require.NoError(t, err)
hostCatalogId, err := boundary.CreateHostCatalogCli(t, ctx, projectId)
require.NoError(t, err)
hostSetId, err := boundary.CreateHostSetCli(t, ctx, hostCatalogId)
require.NoError(t, err)
hostId, err := boundary.CreateHostCli(t, ctx, hostCatalogId, c.TargetAddress)
require.NoError(t, err)
err = boundary.AddHostToHostSetCli(t, ctx, hostSetId, hostId)
require.NoError(t, err)
targetId, err := boundary.CreateTargetCli(t, ctx, projectId, c.TargetPort)
require.NoError(t, err)
err = boundary.AddHostSourceToTargetCli(t, ctx, targetId, hostSetId)
require.NoError(t, err)
acctName := "e2e-account"
accountId, acctPassword, err := boundary.CreateAccountCli(t, ctx, bc.AuthMethodId, acctName)
require.NoError(t, err)
t.Cleanup(func() {
boundary.AuthenticateAdminCli(t, context.Background())
output := e2e.RunCommand(ctx, "boundary",
e2e.WithArgs("accounts", "delete", "-id", accountId),
)
require.NoError(t, output.Err, string(output.Stderr))
})
userId, err := boundary.CreateUserCli(t, ctx, "global")
require.NoError(t, err)
t.Cleanup(func() {
boundary.AuthenticateAdminCli(t, context.Background())
output := e2e.RunCommand(ctx, "boundary",
e2e.WithArgs("users", "delete", "-id", userId),
)
require.NoError(t, output.Err, string(output.Stderr))
})
err = boundary.SetAccountToUserCli(t, ctx, userId, accountId)
require.NoError(t, err)
roleId, err := boundary.CreateRoleCli(t, ctx, projectId)
require.NoError(t, err)
err = boundary.AddGrantToRoleCli(t, ctx, roleId, "ids=*;type=target;actions=authorize-session")
require.NoError(t, err)
err = boundary.AddPrincipalToRoleCli(t, ctx, roleId, userId)
require.NoError(t, err)
boundary.AddGrantToRoleCli(t, ctx, newRoleId, "ids=*;type=target;actions=authorize-session")
boundary.AddPrincipalToRoleCli(t, ctx, newRoleId, newUserId)
// Connect to target to create a session
ctxCancel, cancel := context.WithCancel(context.Background())
@@ -73,7 +86,7 @@ func TestCliSessionEndWhenHostSetIsDeleted(t *testing.T) {
e2e.WithArgs(
"connect",
"-token", "env://E2E_AUTH_TOKEN",
"-target-id", newTargetId,
"-target-id", targetId,
"-exec", "/usr/bin/ssh", "--",
"-l", c.TargetSshUser,
"-i", c.TargetSshKeyPath,
@@ -88,14 +101,14 @@ func TestCliSessionEndWhenHostSetIsDeleted(t *testing.T) {
)
}()
t.Cleanup(cancel)
s := boundary.WaitForSessionCli(t, ctx, newProjectId)
s := boundary.WaitForSessionCli(t, ctx, projectId)
boundary.WaitForSessionStatusCli(t, ctx, s.Id, session.StatusActive.String())
assert.Equal(t, newTargetId, s.TargetId)
assert.Equal(t, newHostId, s.HostId)
assert.Equal(t, targetId, s.TargetId)
assert.Equal(t, hostId, s.HostId)
// Delete Host Set
t.Log("Deleting host set...")
output := e2e.RunCommand(ctx, "boundary", e2e.WithArgs("host-sets", "delete", "-id", newHostSetId))
output := e2e.RunCommand(ctx, "boundary", e2e.WithArgs("host-sets", "delete", "-id", hostSetId))
require.NoError(t, output.Err, string(output.Stderr))
// Check if session has terminated
@@ -26,42 +26,55 @@ func TestCliSessionEndWhenHostIsDeleted(t *testing.T) {
ctx := context.Background()
boundary.AuthenticateAdminCli(t, ctx)
newOrgId := boundary.CreateNewOrgCli(t, ctx)
orgId, err := boundary.CreateOrgCli(t, ctx)
require.NoError(t, err)
t.Cleanup(func() {
ctx := context.Background()
boundary.AuthenticateAdminCli(t, ctx)
output := e2e.RunCommand(ctx, "boundary", e2e.WithArgs("scopes", "delete", "-id", newOrgId))
output := e2e.RunCommand(ctx, "boundary", e2e.WithArgs("scopes", "delete", "-id", orgId))
require.NoError(t, output.Err, string(output.Stderr))
})
newProjectId := boundary.CreateNewProjectCli(t, ctx, newOrgId)
newHostCatalogId := boundary.CreateNewHostCatalogCli(t, ctx, newProjectId)
newHostSetId := boundary.CreateNewHostSetCli(t, ctx, newHostCatalogId)
newHostId := boundary.CreateNewHostCli(t, ctx, newHostCatalogId, c.TargetAddress)
boundary.AddHostToHostSetCli(t, ctx, newHostSetId, newHostId)
newTargetId := boundary.CreateNewTargetCli(t, ctx, newProjectId, c.TargetPort)
boundary.AddHostSourceToTargetCli(t, ctx, newTargetId, newHostSetId)
acctName := "e2e-account"
newAccountId, acctPassword := boundary.CreateNewAccountCli(t, ctx, bc.AuthMethodId, acctName)
t.Cleanup(func() {
boundary.AuthenticateAdminCli(t, context.Background())
output := e2e.RunCommand(ctx, "boundary",
e2e.WithArgs("accounts", "delete", "-id", newAccountId),
)
require.NoError(t, output.Err, string(output.Stderr))
})
newUserId := boundary.CreateNewUserCli(t, ctx, "global")
t.Cleanup(func() {
boundary.AuthenticateAdminCli(t, context.Background())
output := e2e.RunCommand(ctx, "boundary",
e2e.WithArgs("users", "delete", "-id", newUserId),
)
require.NoError(t, output.Err, string(output.Stderr))
})
boundary.SetAccountToUserCli(t, ctx, newUserId, newAccountId)
newRoleId, err := boundary.CreateRoleCli(t, ctx, newProjectId)
projectId, err := boundary.CreateProjectCli(t, ctx, orgId)
require.NoError(t, err)
hostCatalogId, err := boundary.CreateHostCatalogCli(t, ctx, projectId)
require.NoError(t, err)
hostSetId, err := boundary.CreateHostSetCli(t, ctx, hostCatalogId)
require.NoError(t, err)
hostId, err := boundary.CreateHostCli(t, ctx, hostCatalogId, c.TargetAddress)
require.NoError(t, err)
err = boundary.AddHostToHostSetCli(t, ctx, hostSetId, hostId)
require.NoError(t, err)
targetId, err := boundary.CreateTargetCli(t, ctx, projectId, c.TargetPort)
require.NoError(t, err)
err = boundary.AddHostSourceToTargetCli(t, ctx, targetId, hostSetId)
require.NoError(t, err)
acctName := "e2e-account"
accountId, acctPassword, err := boundary.CreateAccountCli(t, ctx, bc.AuthMethodId, acctName)
require.NoError(t, err)
t.Cleanup(func() {
boundary.AuthenticateAdminCli(t, context.Background())
output := e2e.RunCommand(ctx, "boundary",
e2e.WithArgs("accounts", "delete", "-id", accountId),
)
require.NoError(t, output.Err, string(output.Stderr))
})
userId, err := boundary.CreateUserCli(t, ctx, "global")
require.NoError(t, err)
t.Cleanup(func() {
boundary.AuthenticateAdminCli(t, context.Background())
output := e2e.RunCommand(ctx, "boundary",
e2e.WithArgs("users", "delete", "-id", userId),
)
require.NoError(t, output.Err, string(output.Stderr))
})
err = boundary.SetAccountToUserCli(t, ctx, userId, accountId)
require.NoError(t, err)
roleId, err := boundary.CreateRoleCli(t, ctx, projectId)
require.NoError(t, err)
err = boundary.AddGrantToRoleCli(t, ctx, roleId, "ids=*;type=target;actions=authorize-session")
require.NoError(t, err)
err = boundary.AddPrincipalToRoleCli(t, ctx, roleId, userId)
require.NoError(t, err)
boundary.AddGrantToRoleCli(t, ctx, newRoleId, "ids=*;type=target;actions=authorize-session")
boundary.AddPrincipalToRoleCli(t, ctx, newRoleId, newUserId)
// Connect to target to create a session
ctxCancel, cancel := context.WithCancel(context.Background())
@@ -73,7 +86,7 @@ func TestCliSessionEndWhenHostIsDeleted(t *testing.T) {
e2e.WithArgs(
"connect",
"-token", "env://E2E_AUTH_TOKEN",
"-target-id", newTargetId,
"-target-id", targetId,
"-exec", "/usr/bin/ssh", "--",
"-l", c.TargetSshUser,
"-i", c.TargetSshKeyPath,
@@ -88,14 +101,14 @@ func TestCliSessionEndWhenHostIsDeleted(t *testing.T) {
)
}()
t.Cleanup(cancel)
s := boundary.WaitForSessionCli(t, ctx, newProjectId)
s := boundary.WaitForSessionCli(t, ctx, projectId)
boundary.WaitForSessionStatusCli(t, ctx, s.Id, session.StatusActive.String())
assert.Equal(t, newTargetId, s.TargetId)
assert.Equal(t, newHostId, s.HostId)
assert.Equal(t, targetId, s.TargetId)
assert.Equal(t, hostId, s.HostId)
// Delete Host
t.Log("Deleting host...")
output := e2e.RunCommand(ctx, "boundary", e2e.WithArgs("hosts", "delete", "-id", newHostId))
output := e2e.RunCommand(ctx, "boundary", e2e.WithArgs("hosts", "delete", "-id", hostId))
require.NoError(t, output.Err, string(output.Stderr))
// Check if session has terminated
@@ -27,37 +27,45 @@ func TestCliSessionEndWhenProjectIsDeleted(t *testing.T) {
ctx := context.Background()
boundary.AuthenticateAdminCli(t, ctx)
newOrgId := boundary.CreateNewOrgCli(t, ctx)
orgId, err := boundary.CreateOrgCli(t, ctx)
require.NoError(t, err)
t.Cleanup(func() {
ctx := context.Background()
boundary.AuthenticateAdminCli(t, ctx)
output := e2e.RunCommand(ctx, "boundary", e2e.WithArgs("scopes", "delete", "-id", newOrgId))
output := e2e.RunCommand(ctx, "boundary", e2e.WithArgs("scopes", "delete", "-id", orgId))
require.NoError(t, output.Err, string(output.Stderr))
})
newProjectId := boundary.CreateNewProjectCli(t, ctx, newOrgId)
newTargetId := boundary.CreateNewTargetCli(t, ctx, newProjectId, c.TargetPort, target.WithAddress(c.TargetAddress))
acctName := "e2e-account"
newAccountId, acctPassword := boundary.CreateNewAccountCli(t, ctx, bc.AuthMethodId, acctName)
t.Cleanup(func() {
boundary.AuthenticateAdminCli(t, context.Background())
output := e2e.RunCommand(ctx, "boundary",
e2e.WithArgs("accounts", "delete", "-id", newAccountId),
)
require.NoError(t, output.Err, string(output.Stderr))
})
newUserId := boundary.CreateNewUserCli(t, ctx, "global")
t.Cleanup(func() {
boundary.AuthenticateAdminCli(t, context.Background())
output := e2e.RunCommand(ctx, "boundary",
e2e.WithArgs("users", "delete", "-id", newUserId),
)
require.NoError(t, output.Err, string(output.Stderr))
})
boundary.SetAccountToUserCli(t, ctx, newUserId, newAccountId)
newRoleId, err := boundary.CreateRoleCli(t, ctx, newProjectId)
projectId, err := boundary.CreateProjectCli(t, ctx, orgId)
require.NoError(t, err)
targetId, err := boundary.CreateTargetCli(t, ctx, projectId, c.TargetPort, target.WithAddress(c.TargetAddress))
require.NoError(t, err)
acctName := "e2e-account"
accountId, acctPassword, err := boundary.CreateAccountCli(t, ctx, bc.AuthMethodId, acctName)
require.NoError(t, err)
t.Cleanup(func() {
boundary.AuthenticateAdminCli(t, context.Background())
output := e2e.RunCommand(ctx, "boundary",
e2e.WithArgs("accounts", "delete", "-id", accountId),
)
require.NoError(t, output.Err, string(output.Stderr))
})
userId, err := boundary.CreateUserCli(t, ctx, "global")
require.NoError(t, err)
t.Cleanup(func() {
boundary.AuthenticateAdminCli(t, context.Background())
output := e2e.RunCommand(ctx, "boundary",
e2e.WithArgs("users", "delete", "-id", userId),
)
require.NoError(t, output.Err, string(output.Stderr))
})
err = boundary.SetAccountToUserCli(t, ctx, userId, accountId)
require.NoError(t, err)
roleId, err := boundary.CreateRoleCli(t, ctx, projectId)
require.NoError(t, err)
err = boundary.AddGrantToRoleCli(t, ctx, roleId, "ids=*;type=target;actions=authorize-session")
require.NoError(t, err)
err = boundary.AddPrincipalToRoleCli(t, ctx, roleId, userId)
require.NoError(t, err)
boundary.AddGrantToRoleCli(t, ctx, newRoleId, "ids=*;type=target;actions=authorize-session")
boundary.AddPrincipalToRoleCli(t, ctx, newRoleId, newUserId)
// Connect to target to create a session
ctxCancel, cancel := context.WithCancel(context.Background())
@@ -69,7 +77,7 @@ func TestCliSessionEndWhenProjectIsDeleted(t *testing.T) {
e2e.WithArgs(
"connect",
"-token", "env://E2E_AUTH_TOKEN",
"-target-id", newTargetId,
"-target-id", targetId,
"-exec", "/usr/bin/ssh", "--",
"-l", c.TargetSshUser,
"-i", c.TargetSshKeyPath,
@@ -84,13 +92,13 @@ func TestCliSessionEndWhenProjectIsDeleted(t *testing.T) {
)
}()
t.Cleanup(cancel)
s := boundary.WaitForSessionCli(t, ctx, newProjectId)
s := boundary.WaitForSessionCli(t, ctx, projectId)
boundary.WaitForSessionStatusCli(t, ctx, s.Id, session.StatusActive.String())
assert.Equal(t, newTargetId, s.TargetId)
assert.Equal(t, targetId, s.TargetId)
// Delete Project
t.Log("Deleting project...")
output := e2e.RunCommand(ctx, "boundary", e2e.WithArgs("scopes", "delete", "-id", newProjectId))
output := e2e.RunCommand(ctx, "boundary", e2e.WithArgs("scopes", "delete", "-id", projectId))
require.NoError(t, output.Err, string(output.Stderr))
// Check if session has terminated
@@ -26,42 +26,55 @@ func TestCliSessionEndWhenTargetIsDeleted(t *testing.T) {
ctx := context.Background()
boundary.AuthenticateAdminCli(t, ctx)
newOrgId := boundary.CreateNewOrgCli(t, ctx)
orgId, err := boundary.CreateOrgCli(t, ctx)
require.NoError(t, err)
t.Cleanup(func() {
ctx := context.Background()
boundary.AuthenticateAdminCli(t, ctx)
output := e2e.RunCommand(ctx, "boundary", e2e.WithArgs("scopes", "delete", "-id", newOrgId))
output := e2e.RunCommand(ctx, "boundary", e2e.WithArgs("scopes", "delete", "-id", orgId))
require.NoError(t, output.Err, string(output.Stderr))
})
newProjectId := boundary.CreateNewProjectCli(t, ctx, newOrgId)
newHostCatalogId := boundary.CreateNewHostCatalogCli(t, ctx, newProjectId)
newHostSetId := boundary.CreateNewHostSetCli(t, ctx, newHostCatalogId)
newHostId := boundary.CreateNewHostCli(t, ctx, newHostCatalogId, c.TargetAddress)
boundary.AddHostToHostSetCli(t, ctx, newHostSetId, newHostId)
newTargetId := boundary.CreateNewTargetCli(t, ctx, newProjectId, c.TargetPort)
boundary.AddHostSourceToTargetCli(t, ctx, newTargetId, newHostSetId)
acctName := "e2e-account"
newAccountId, acctPassword := boundary.CreateNewAccountCli(t, ctx, bc.AuthMethodId, acctName)
t.Cleanup(func() {
boundary.AuthenticateAdminCli(t, context.Background())
output := e2e.RunCommand(ctx, "boundary",
e2e.WithArgs("accounts", "delete", "-id", newAccountId),
)
require.NoError(t, output.Err, string(output.Stderr))
})
newUserId := boundary.CreateNewUserCli(t, ctx, "global")
t.Cleanup(func() {
boundary.AuthenticateAdminCli(t, context.Background())
output := e2e.RunCommand(ctx, "boundary",
e2e.WithArgs("users", "delete", "-id", newUserId),
)
require.NoError(t, output.Err, string(output.Stderr))
})
boundary.SetAccountToUserCli(t, ctx, newUserId, newAccountId)
newRoleId, err := boundary.CreateRoleCli(t, ctx, newProjectId)
projectId, err := boundary.CreateProjectCli(t, ctx, orgId)
require.NoError(t, err)
hostCatalogId, err := boundary.CreateHostCatalogCli(t, ctx, projectId)
require.NoError(t, err)
hostSetId, err := boundary.CreateHostSetCli(t, ctx, hostCatalogId)
require.NoError(t, err)
hostId, err := boundary.CreateHostCli(t, ctx, hostCatalogId, c.TargetAddress)
require.NoError(t, err)
err = boundary.AddHostToHostSetCli(t, ctx, hostSetId, hostId)
require.NoError(t, err)
targetId, err := boundary.CreateTargetCli(t, ctx, projectId, c.TargetPort)
require.NoError(t, err)
err = boundary.AddHostSourceToTargetCli(t, ctx, targetId, hostSetId)
require.NoError(t, err)
acctName := "e2e-account"
accountId, acctPassword, err := boundary.CreateAccountCli(t, ctx, bc.AuthMethodId, acctName)
require.NoError(t, err)
t.Cleanup(func() {
boundary.AuthenticateAdminCli(t, context.Background())
output := e2e.RunCommand(ctx, "boundary",
e2e.WithArgs("accounts", "delete", "-id", accountId),
)
require.NoError(t, output.Err, string(output.Stderr))
})
userId, err := boundary.CreateUserCli(t, ctx, "global")
require.NoError(t, err)
t.Cleanup(func() {
boundary.AuthenticateAdminCli(t, context.Background())
output := e2e.RunCommand(ctx, "boundary",
e2e.WithArgs("users", "delete", "-id", userId),
)
require.NoError(t, output.Err, string(output.Stderr))
})
err = boundary.SetAccountToUserCli(t, ctx, userId, accountId)
require.NoError(t, err)
roleId, err := boundary.CreateRoleCli(t, ctx, projectId)
require.NoError(t, err)
err = boundary.AddGrantToRoleCli(t, ctx, roleId, "ids=*;type=target;actions=authorize-session")
require.NoError(t, err)
err = boundary.AddPrincipalToRoleCli(t, ctx, roleId, userId)
require.NoError(t, err)
boundary.AddGrantToRoleCli(t, ctx, newRoleId, "ids=*;type=target;actions=authorize-session")
boundary.AddPrincipalToRoleCli(t, ctx, newRoleId, newUserId)
// Connect to target to create a session
ctxCancel, cancel := context.WithCancel(context.Background())
@@ -73,7 +86,7 @@ func TestCliSessionEndWhenTargetIsDeleted(t *testing.T) {
e2e.WithArgs(
"connect",
"-token", "env://E2E_AUTH_TOKEN",
"-target-id", newTargetId,
"-target-id", targetId,
"-exec", "/usr/bin/ssh", "--",
"-l", c.TargetSshUser,
"-i", c.TargetSshKeyPath,
@@ -88,14 +101,14 @@ func TestCliSessionEndWhenTargetIsDeleted(t *testing.T) {
)
}()
t.Cleanup(cancel)
s := boundary.WaitForSessionCli(t, ctx, newProjectId)
s := boundary.WaitForSessionCli(t, ctx, projectId)
boundary.WaitForSessionStatusCli(t, ctx, s.Id, session.StatusActive.String())
assert.Equal(t, newTargetId, s.TargetId)
assert.Equal(t, newHostId, s.HostId)
assert.Equal(t, targetId, s.TargetId)
assert.Equal(t, hostId, s.HostId)
// Delete Target
t.Log("Deleting target...")
output := e2e.RunCommand(ctx, "boundary", e2e.WithArgs("targets", "delete", "-id", newTargetId))
output := e2e.RunCommand(ctx, "boundary", e2e.WithArgs("targets", "delete", "-id", targetId))
require.NoError(t, output.Err, string(output.Stderr))
// Check if session has terminated
@@ -28,45 +28,58 @@ func TestCliSessionEndWhenUserIsDeleted(t *testing.T) {
ctx := context.Background()
boundary.AuthenticateAdminCli(t, ctx)
newOrgId := boundary.CreateNewOrgCli(t, ctx)
orgId, err := boundary.CreateOrgCli(t, ctx)
require.NoError(t, err)
t.Cleanup(func() {
ctx := context.Background()
boundary.AuthenticateAdminCli(t, ctx)
output := e2e.RunCommand(ctx, "boundary", e2e.WithArgs("scopes", "delete", "-id", newOrgId))
output := e2e.RunCommand(ctx, "boundary", e2e.WithArgs("scopes", "delete", "-id", orgId))
require.NoError(t, output.Err, string(output.Stderr))
})
newProjectId := boundary.CreateNewProjectCli(t, ctx, newOrgId)
newHostCatalogId := boundary.CreateNewHostCatalogCli(t, ctx, newProjectId)
newHostSetId := boundary.CreateNewHostSetCli(t, ctx, newHostCatalogId)
newHostId := boundary.CreateNewHostCli(t, ctx, newHostCatalogId, c.TargetAddress)
boundary.AddHostToHostSetCli(t, ctx, newHostSetId, newHostId)
newTargetId := boundary.CreateNewTargetCli(t, ctx, newProjectId, c.TargetPort)
boundary.AddHostSourceToTargetCli(t, ctx, newTargetId, newHostSetId)
projectId, err := boundary.CreateProjectCli(t, ctx, orgId)
require.NoError(t, err)
hostCatalogId, err := boundary.CreateHostCatalogCli(t, ctx, projectId)
require.NoError(t, err)
hostSetId, err := boundary.CreateHostSetCli(t, ctx, hostCatalogId)
require.NoError(t, err)
hostId, err := boundary.CreateHostCli(t, ctx, hostCatalogId, c.TargetAddress)
require.NoError(t, err)
err = boundary.AddHostToHostSetCli(t, ctx, hostSetId, hostId)
require.NoError(t, err)
targetId, err := boundary.CreateTargetCli(t, ctx, projectId, c.TargetPort)
require.NoError(t, err)
err = boundary.AddHostSourceToTargetCli(t, ctx, targetId, hostSetId)
require.NoError(t, err)
acctName := "e2e-account"
newAccountId, acctPassword := boundary.CreateNewAccountCli(t, ctx, bc.AuthMethodId, acctName)
accountId, acctPassword, err := boundary.CreateAccountCli(t, ctx, bc.AuthMethodId, acctName)
require.NoError(t, err)
t.Cleanup(func() {
boundary.AuthenticateAdminCli(t, context.Background())
output := e2e.RunCommand(ctx, "boundary",
e2e.WithArgs("accounts", "delete", "-id", newAccountId),
e2e.WithArgs("accounts", "delete", "-id", accountId),
)
require.NoError(t, output.Err, string(output.Stderr))
})
newUserId := boundary.CreateNewUserCli(t, ctx, "global")
userId, err := boundary.CreateUserCli(t, ctx, "global")
require.NoError(t, err)
t.Cleanup(func() {
if !userIsDeleted {
t.Log("Deleting user...")
boundary.AuthenticateAdminCli(t, context.Background())
output := e2e.RunCommand(ctx, "boundary",
e2e.WithArgs("users", "delete", "-id", newUserId),
e2e.WithArgs("users", "delete", "-id", userId),
)
require.NoError(t, output.Err, string(output.Stderr))
}
})
boundary.SetAccountToUserCli(t, ctx, newUserId, newAccountId)
newRoleId, err := boundary.CreateRoleCli(t, ctx, newProjectId)
err = boundary.SetAccountToUserCli(t, ctx, userId, accountId)
require.NoError(t, err)
roleId, err := boundary.CreateRoleCli(t, ctx, projectId)
require.NoError(t, err)
err = boundary.AddGrantToRoleCli(t, ctx, roleId, "ids=*;type=target;actions=authorize-session")
require.NoError(t, err)
err = boundary.AddPrincipalToRoleCli(t, ctx, roleId, userId)
require.NoError(t, err)
boundary.AddGrantToRoleCli(t, ctx, newRoleId, "ids=*;type=target;actions=authorize-session")
boundary.AddPrincipalToRoleCli(t, ctx, newRoleId, newUserId)
// Connect to target to create a session
ctxCancel, cancel := context.WithCancel(context.Background())
@@ -78,7 +91,7 @@ func TestCliSessionEndWhenUserIsDeleted(t *testing.T) {
e2e.WithArgs(
"connect",
"-token", "env://E2E_AUTH_TOKEN",
"-target-id", newTargetId,
"-target-id", targetId,
"-exec", "/usr/bin/ssh", "--",
"-l", c.TargetSshUser,
"-i", c.TargetSshKeyPath,
@@ -93,14 +106,14 @@ func TestCliSessionEndWhenUserIsDeleted(t *testing.T) {
)
}()
t.Cleanup(cancel)
s := boundary.WaitForSessionCli(t, ctx, newProjectId)
s := boundary.WaitForSessionCli(t, ctx, projectId)
boundary.WaitForSessionStatusCli(t, ctx, s.Id, session.StatusActive.String())
assert.Equal(t, newTargetId, s.TargetId)
assert.Equal(t, newHostId, s.HostId)
assert.Equal(t, targetId, s.TargetId)
assert.Equal(t, hostId, s.HostId)
// Delete User
t.Log("Deleting user...")
output := e2e.RunCommand(ctx, "boundary", e2e.WithArgs("users", "delete", "-id", newUserId))
output := e2e.RunCommand(ctx, "boundary", e2e.WithArgs("users", "delete", "-id", userId))
require.NoError(t, output.Err, string(output.Stderr))
userIsDeleted = true
@@ -25,21 +25,24 @@ func TestCliCreateUpdateTargetAddress(t *testing.T) {
ctx := context.Background()
boundary.AuthenticateAdminCli(t, ctx)
newOrgId := boundary.CreateNewOrgCli(t, ctx)
orgId, err := boundary.CreateOrgCli(t, ctx)
require.NoError(t, err)
t.Cleanup(func() {
ctx := context.Background()
boundary.AuthenticateAdminCli(t, ctx)
output := e2e.RunCommand(ctx, "boundary", e2e.WithArgs("scopes", "delete", "-id", newOrgId))
output := e2e.RunCommand(ctx, "boundary", e2e.WithArgs("scopes", "delete", "-id", orgId))
require.NoError(t, output.Err, string(output.Stderr))
})
newProjectId := boundary.CreateNewProjectCli(t, ctx, newOrgId)
newTargetId := boundary.CreateNewTargetCli(t, ctx, newProjectId, c.TargetPort, target.WithAddress(c.TargetAddress))
projectId, err := boundary.CreateProjectCli(t, ctx, orgId)
require.NoError(t, err)
targetId, err := boundary.CreateTargetCli(t, ctx, projectId, c.TargetPort, target.WithAddress(c.TargetAddress))
require.NoError(t, err)
// Connect to target and print host's IP address
output := e2e.RunCommand(ctx, "boundary",
e2e.WithArgs(
"connect",
"-target-id", newTargetId,
"-target-id", targetId,
"-exec", "/usr/bin/ssh", "--",
"-l", c.TargetSshUser,
"-i", c.TargetSshKeyPath,
@@ -62,7 +65,7 @@ func TestCliCreateUpdateTargetAddress(t *testing.T) {
output = e2e.RunCommand(ctx, "boundary",
e2e.WithArgs(
"targets", "update", "tcp",
"-id", newTargetId,
"-id", targetId,
"-address", "null",
"-format", "json",
),
@@ -74,7 +77,7 @@ func TestCliCreateUpdateTargetAddress(t *testing.T) {
output = e2e.RunCommand(ctx, "boundary",
e2e.WithArgs(
"connect",
"-target-id", newTargetId,
"-target-id", targetId,
"-format", "json",
"-exec", "/usr/bin/ssh", "--",
"-l", c.TargetSshUser,
@@ -97,7 +100,7 @@ func TestCliCreateUpdateTargetAddress(t *testing.T) {
output = e2e.RunCommand(ctx, "boundary",
e2e.WithArgs(
"targets", "update", "tcp",
"-id", newTargetId,
"-id", targetId,
"-address", c.TargetAddress,
"-format", "json",
),
@@ -108,7 +111,7 @@ func TestCliCreateUpdateTargetAddress(t *testing.T) {
output = e2e.RunCommand(ctx, "boundary",
e2e.WithArgs(
"connect",
"-target-id", newTargetId,
"-target-id", targetId,
"-exec", "/usr/bin/ssh", "--",
"-l", c.TargetSshUser,
"-i", c.TargetSshKeyPath,
@@ -140,25 +143,32 @@ func TestCliTargetAddressToHostSource(t *testing.T) {
ctx := context.Background()
boundary.AuthenticateAdminCli(t, ctx)
newOrgId := boundary.CreateNewOrgCli(t, ctx)
orgId, err := boundary.CreateOrgCli(t, ctx)
require.NoError(t, err)
t.Cleanup(func() {
ctx := context.Background()
boundary.AuthenticateAdminCli(t, ctx)
output := e2e.RunCommand(ctx, "boundary", e2e.WithArgs("scopes", "delete", "-id", newOrgId))
output := e2e.RunCommand(ctx, "boundary", e2e.WithArgs("scopes", "delete", "-id", orgId))
require.NoError(t, output.Err, string(output.Stderr))
})
newProjectId := boundary.CreateNewProjectCli(t, ctx, newOrgId)
newHostCatalogId := boundary.CreateNewHostCatalogCli(t, ctx, newProjectId)
newHostSetId := boundary.CreateNewHostSetCli(t, ctx, newHostCatalogId)
newHostId := boundary.CreateNewHostCli(t, ctx, newHostCatalogId, c.TargetAddress)
boundary.AddHostToHostSetCli(t, ctx, newHostSetId, newHostId)
newTargetId := boundary.CreateNewTargetCli(t, ctx, newProjectId, c.TargetPort, target.WithAddress(c.TargetAddress))
projectId, err := boundary.CreateProjectCli(t, ctx, orgId)
require.NoError(t, err)
hostCatalogId, err := boundary.CreateHostCatalogCli(t, ctx, projectId)
require.NoError(t, err)
hostSetId, err := boundary.CreateHostSetCli(t, ctx, hostCatalogId)
require.NoError(t, err)
hostId, err := boundary.CreateHostCli(t, ctx, hostCatalogId, c.TargetAddress)
require.NoError(t, err)
err = boundary.AddHostToHostSetCli(t, ctx, hostSetId, hostId)
require.NoError(t, err)
targetId, err := boundary.CreateTargetCli(t, ctx, projectId, c.TargetPort, target.WithAddress(c.TargetAddress))
require.NoError(t, err)
// Connect to target and print host's IP address
output := e2e.RunCommand(ctx, "boundary",
e2e.WithArgs(
"connect",
"-target-id", newTargetId,
"-target-id", targetId,
"-exec", "/usr/bin/ssh", "--",
"-l", c.TargetSshUser,
"-i", c.TargetSshKeyPath,
@@ -181,8 +191,8 @@ func TestCliTargetAddressToHostSource(t *testing.T) {
output = e2e.RunCommand(ctx, "boundary",
e2e.WithArgs(
"targets", "add-host-sources",
"-id", newTargetId,
"-host-source", newHostSetId,
"-id", targetId,
"-host-source", hostSetId,
"-format", "json",
),
)
@@ -196,8 +206,8 @@ func TestCliTargetAddressToHostSource(t *testing.T) {
output = e2e.RunCommand(ctx, "boundary",
e2e.WithArgs(
"targets", "set-host-sources",
"-id", newTargetId,
"-host-source", newHostSetId,
"-id", targetId,
"-host-source", hostSetId,
"-format", "json",
),
)
@@ -210,21 +220,23 @@ func TestCliTargetAddressToHostSource(t *testing.T) {
output = e2e.RunCommand(ctx, "boundary",
e2e.WithArgs(
"targets", "update", "tcp",
"-id", newTargetId,
"-id", targetId,
"-address", "null",
"-format", "json",
),
)
require.NoError(t, output.Err, string(output.Stderr))
boundary.AddHostSourceToTargetCli(t, ctx, newTargetId, newHostSetId)
boundary.SetHostSourceToTargetCli(t, ctx, newTargetId, newHostSetId)
err = boundary.AddHostSourceToTargetCli(t, ctx, targetId, hostSetId)
require.NoError(t, err)
err = boundary.SetHostSourceToTargetCli(t, ctx, targetId, hostSetId)
require.NoError(t, err)
// Connect to target and print host's IP address, now using the host source.
output = e2e.RunCommand(ctx, "boundary",
e2e.WithArgs(
"connect",
"-target-id", newTargetId,
"-target-id", targetId,
"-exec", "/usr/bin/ssh", "--",
"-l", c.TargetSshUser,
"-i", c.TargetSshKeyPath,
@@ -257,26 +269,34 @@ func TestCliTargetHostSourceToAddress(t *testing.T) {
ctx := context.Background()
boundary.AuthenticateAdminCli(t, ctx)
newOrgId := boundary.CreateNewOrgCli(t, ctx)
orgId, err := boundary.CreateOrgCli(t, ctx)
require.NoError(t, err)
t.Cleanup(func() {
ctx := context.Background()
boundary.AuthenticateAdminCli(t, ctx)
output := e2e.RunCommand(ctx, "boundary", e2e.WithArgs("scopes", "delete", "-id", newOrgId))
output := e2e.RunCommand(ctx, "boundary", e2e.WithArgs("scopes", "delete", "-id", orgId))
require.NoError(t, output.Err, string(output.Stderr))
})
newProjectId := boundary.CreateNewProjectCli(t, ctx, newOrgId)
newHostCatalogId := boundary.CreateNewHostCatalogCli(t, ctx, newProjectId)
newHostSetId := boundary.CreateNewHostSetCli(t, ctx, newHostCatalogId)
newHostId := boundary.CreateNewHostCli(t, ctx, newHostCatalogId, c.TargetAddress)
boundary.AddHostToHostSetCli(t, ctx, newHostSetId, newHostId)
newTargetId := boundary.CreateNewTargetCli(t, ctx, newProjectId, c.TargetPort)
boundary.AddHostSourceToTargetCli(t, ctx, newTargetId, newHostSetId)
projectId, err := boundary.CreateProjectCli(t, ctx, orgId)
require.NoError(t, err)
hostCatalogId, err := boundary.CreateHostCatalogCli(t, ctx, projectId)
require.NoError(t, err)
hostSetId, err := boundary.CreateHostSetCli(t, ctx, hostCatalogId)
require.NoError(t, err)
hostId, err := boundary.CreateHostCli(t, ctx, hostCatalogId, c.TargetAddress)
require.NoError(t, err)
err = boundary.AddHostToHostSetCli(t, ctx, hostSetId, hostId)
require.NoError(t, err)
targetId, err := boundary.CreateTargetCli(t, ctx, projectId, c.TargetPort)
require.NoError(t, err)
err = boundary.AddHostSourceToTargetCli(t, ctx, targetId, hostSetId)
require.NoError(t, err)
// Connect to target and print host's IP address
output := e2e.RunCommand(ctx, "boundary",
e2e.WithArgs(
"connect",
"-target-id", newTargetId,
"-target-id", targetId,
"-exec", "/usr/bin/ssh", "--",
"-l", c.TargetSshUser,
"-i", c.TargetSshKeyPath,
@@ -300,7 +320,7 @@ func TestCliTargetHostSourceToAddress(t *testing.T) {
output = e2e.RunCommand(ctx, "boundary",
e2e.WithArgs(
"targets", "update", "tcp",
"-id", newTargetId,
"-id", targetId,
"-address", c.TargetAddress,
"-format", "json",
),
@@ -311,13 +331,14 @@ func TestCliTargetHostSourceToAddress(t *testing.T) {
require.NoError(t, json.Unmarshal(output.Stderr, &response))
require.Equal(t, http.StatusBadRequest, response.Status, "Expected error when setting address to target with a host source")
boundary.RemoveHostSourceFromTargetCli(t, ctx, newTargetId, newHostSetId)
err = boundary.RemoveHostSourceFromTargetCli(t, ctx, targetId, hostSetId)
require.NoError(t, err)
// Attempt to add an address to the target again - should work
output = e2e.RunCommand(ctx, "boundary",
e2e.WithArgs(
"targets", "update", "tcp",
"-id", newTargetId,
"-id", targetId,
"-address", c.TargetAddress,
"-format", "json",
),
@@ -328,7 +349,7 @@ func TestCliTargetHostSourceToAddress(t *testing.T) {
output = e2e.RunCommand(ctx, "boundary",
e2e.WithArgs(
"connect",
"-target-id", newTargetId,
"-target-id", targetId,
"-exec", "/usr/bin/ssh", "--",
"-l", c.TargetSshUser,
"-i", c.TargetSshKeyPath,
@@ -27,27 +27,38 @@ func TestCliTcpTargetConnectTargetWithAuthzToken(t *testing.T) {
ctx := context.Background()
boundary.AuthenticateAdminCli(t, ctx)
newOrgId := boundary.CreateNewOrgCli(t, ctx)
orgId, err := boundary.CreateOrgCli(t, ctx)
require.NoError(t, err)
t.Cleanup(func() {
ctx := context.Background()
boundary.AuthenticateAdminCli(t, ctx)
output := e2e.RunCommand(ctx, "boundary", e2e.WithArgs("scopes", "delete", "-id", newOrgId))
output := e2e.RunCommand(ctx, "boundary", e2e.WithArgs("scopes", "delete", "-id", orgId))
require.NoError(t, output.Err, string(output.Stderr))
})
newProjectId := boundary.CreateNewProjectCli(t, ctx, newOrgId)
newHostCatalogId := boundary.CreateNewHostCatalogCli(t, ctx, newProjectId)
newHostSetId := boundary.CreateNewHostSetCli(t, ctx, newHostCatalogId)
newHostId := boundary.CreateNewHostCli(t, ctx, newHostCatalogId, c.TargetAddress)
boundary.AddHostToHostSetCli(t, ctx, newHostSetId, newHostId)
newTargetId := boundary.CreateNewTargetCli(t, ctx, newProjectId, c.TargetPort)
boundary.AddHostSourceToTargetCli(t, ctx, newTargetId, newHostSetId)
newCredentialStoreId := boundary.CreateNewCredentialStoreStaticCli(t, ctx, newProjectId)
newCredentialsId := boundary.CreateNewStaticCredentialPrivateKeyCli(t, ctx, newCredentialStoreId, c.TargetSshUser, c.TargetSshKeyPath)
boundary.AddBrokeredCredentialSourceToTargetCli(t, ctx, newTargetId, newCredentialsId)
projectId, err := boundary.CreateProjectCli(t, ctx, orgId)
require.NoError(t, err)
hostCatalogId, err := boundary.CreateHostCatalogCli(t, ctx, projectId)
require.NoError(t, err)
hostSetId, err := boundary.CreateHostSetCli(t, ctx, hostCatalogId)
require.NoError(t, err)
hostId, err := boundary.CreateHostCli(t, ctx, hostCatalogId, c.TargetAddress)
require.NoError(t, err)
err = boundary.AddHostToHostSetCli(t, ctx, hostSetId, hostId)
require.NoError(t, err)
targetId, err := boundary.CreateTargetCli(t, ctx, projectId, c.TargetPort)
require.NoError(t, err)
err = boundary.AddHostSourceToTargetCli(t, ctx, targetId, hostSetId)
require.NoError(t, err)
storeId, err := boundary.CreateCredentialStoreStaticCli(t, ctx, projectId)
require.NoError(t, err)
credentialId, err := boundary.CreateStaticCredentialPrivateKeyCli(t, ctx, storeId, c.TargetSshUser, c.TargetSshKeyPath)
require.NoError(t, err)
err = boundary.AddBrokeredCredentialSourceToTargetCli(t, ctx, targetId, credentialId)
require.NoError(t, err)
// Get credentials for target
output := e2e.RunCommand(ctx, "boundary",
e2e.WithArgs("targets", "authorize-session", "-id", newTargetId, "-format", "json"),
e2e.WithArgs("targets", "authorize-session", "-id", targetId, "-format", "json"),
)
require.NoError(t, output.Err, string(output.Stderr))
var newSessionAuthorizationResult targets.SessionAuthorizationResult
@@ -27,23 +27,26 @@ func TestCliTcpTargetConnectTargetWithConnectionLimits(t *testing.T) {
ctx := context.Background()
boundary.AuthenticateAdminCli(t, ctx)
newOrgId := boundary.CreateNewOrgCli(t, ctx)
orgId, err := boundary.CreateOrgCli(t, ctx)
require.NoError(t, err)
t.Cleanup(func() {
ctx := context.Background()
boundary.AuthenticateAdminCli(t, ctx)
output := e2e.RunCommand(ctx, "boundary", e2e.WithArgs("scopes", "delete", "-id", newOrgId))
output := e2e.RunCommand(ctx, "boundary", e2e.WithArgs("scopes", "delete", "-id", orgId))
require.NoError(t, output.Err, string(output.Stderr))
})
newProjectId := boundary.CreateNewProjectCli(t, ctx, newOrgId)
projectId, err := boundary.CreateProjectCli(t, ctx, orgId)
require.NoError(t, err)
sessionConnectionLimit := 2
newTargetId := boundary.CreateNewTargetCli(
targetId, err := boundary.CreateTargetCli(
t,
ctx,
newProjectId,
projectId,
c.TargetPort,
target.WithAddress(c.TargetAddress),
target.WithSessionConnectionLimit(int32(sessionConnectionLimit)),
)
require.NoError(t, err)
// Start a session
ctxCancel, cancel := context.WithCancel(context.Background())
@@ -54,7 +57,7 @@ func TestCliTcpTargetConnectTargetWithConnectionLimits(t *testing.T) {
sessionChannel <- e2e.RunCommand(ctxCancel, "boundary",
e2e.WithArgs(
"connect",
"-target-id", newTargetId,
"-target-id", targetId,
"-listen-port", port,
"-format", "json",
),
@@ -62,7 +65,7 @@ func TestCliTcpTargetConnectTargetWithConnectionLimits(t *testing.T) {
}()
t.Cleanup(cancel)
boundary.WaitForSessionCli(t, ctx, newProjectId)
boundary.WaitForSessionCli(t, ctx, projectId)
// Start connections. Expect an error once the limit is reached
for i := 0; i <= sessionConnectionLimit; i++ {
@@ -24,29 +24,37 @@ func TestCliTcpTargetConnectTargetWithTargetClientPort(t *testing.T) {
ctx := context.Background()
boundary.AuthenticateAdminCli(t, ctx)
newOrgId := boundary.CreateNewOrgCli(t, ctx)
orgId, err := boundary.CreateOrgCli(t, ctx)
require.NoError(t, err)
t.Cleanup(func() {
ctx := context.Background()
boundary.AuthenticateAdminCli(t, ctx)
output := e2e.RunCommand(ctx, "boundary", e2e.WithArgs("scopes", "delete", "-id", newOrgId))
output := e2e.RunCommand(ctx, "boundary", e2e.WithArgs("scopes", "delete", "-id", orgId))
require.NoError(t, output.Err, string(output.Stderr))
})
var expPort uint32 = 8356
newProjectId := boundary.CreateNewProjectCli(t, ctx, newOrgId)
newHostCatalogId := boundary.CreateNewHostCatalogCli(t, ctx, newProjectId)
newHostSetId := boundary.CreateNewHostSetCli(t, ctx, newHostCatalogId)
newHostId := boundary.CreateNewHostCli(t, ctx, newHostCatalogId, c.TargetAddress)
boundary.AddHostToHostSetCli(t, ctx, newHostSetId, newHostId)
newTargetId := boundary.CreateNewTargetCli(t, ctx, newProjectId, c.TargetPort, target.WithDefaultClientPort(expPort))
boundary.AddHostSourceToTargetCli(t, ctx, newTargetId, newHostSetId)
projectId, err := boundary.CreateProjectCli(t, ctx, orgId)
require.NoError(t, err)
hostCatalogId, err := boundary.CreateHostCatalogCli(t, ctx, projectId)
require.NoError(t, err)
hostSetId, err := boundary.CreateHostSetCli(t, ctx, hostCatalogId)
require.NoError(t, err)
hostId, err := boundary.CreateHostCli(t, ctx, hostCatalogId, c.TargetAddress)
require.NoError(t, err)
err = boundary.AddHostToHostSetCli(t, ctx, hostSetId, hostId)
require.NoError(t, err)
targetId, err := boundary.CreateTargetCli(t, ctx, projectId, c.TargetPort, target.WithDefaultClientPort(expPort))
require.NoError(t, err)
err = boundary.AddHostSourceToTargetCli(t, ctx, targetId, hostSetId)
require.NoError(t, err)
// Connect to target and print host's IP address
output := e2e.RunCommand(ctx, "boundary",
e2e.WithArgs(
"connect",
"-target-id", newTargetId,
"-target-id", targetId,
"-exec", "/bin/echo", "--",
"{{boundary.port}}",
),
@@ -28,28 +28,34 @@ func TestCliTcpTargetConnectExecLongLastingScript(t *testing.T) {
boundary.AuthenticateAdminCli(t, ctx)
// Create test organization
newOrgId := boundary.CreateNewOrgCli(t, ctx)
orgId, err := boundary.CreateOrgCli(t, ctx)
require.NoError(t, err)
// Delete organization after the test is completed
t.Cleanup(func() {
ctx := context.Background()
boundary.AuthenticateAdminCli(t, ctx)
output := e2e.RunCommand(ctx, "boundary", e2e.WithArgs("scopes", "delete", "-id", newOrgId))
output := e2e.RunCommand(ctx, "boundary", e2e.WithArgs("scopes", "delete", "-id", orgId))
require.NoError(t, output.Err, string(output.Stderr))
})
// Create test project
newProjectId := boundary.CreateNewProjectCli(t, ctx, newOrgId)
projectId, err := boundary.CreateProjectCli(t, ctx, orgId)
require.NoError(t, err)
// Create static credentials
newCredentialStoreId := boundary.CreateNewCredentialStoreStaticCli(t, ctx, newProjectId)
newCredentialsId := boundary.CreateNewStaticCredentialPrivateKeyCli(t, ctx, newCredentialStoreId, c.TargetSshUser, c.TargetSshKeyPath)
storeId, err := boundary.CreateCredentialStoreStaticCli(t, ctx, projectId)
require.NoError(t, err)
credentialId, err := boundary.CreateStaticCredentialPrivateKeyCli(t, ctx, storeId, c.TargetSshUser, c.TargetSshKeyPath)
require.NoError(t, err)
// Create TCP target
newTargetId := boundary.CreateNewTargetCli(t, ctx, newProjectId, c.TargetPort,
targetId, err := boundary.CreateTargetCli(t, ctx, projectId, c.TargetPort,
target.WithType("tcp"),
target.WithAddress(c.TargetAddress),
)
boundary.AddBrokeredCredentialSourceToTargetCli(t, ctx, newTargetId, newCredentialsId)
require.NoError(t, err)
err = boundary.AddBrokeredCredentialSourceToTargetCli(t, ctx, targetId, credentialId)
require.NoError(t, err)
// Start a session
ctxCancel, cancel := context.WithCancel(context.Background())
@@ -60,14 +66,14 @@ func TestCliTcpTargetConnectExecLongLastingScript(t *testing.T) {
cmdChan <- e2e.RunCommand(ctxCancel, "boundary",
e2e.WithArgs(
"connect",
"-target-id", newTargetId,
"-target-id", targetId,
"-listen-port", proxyPort,
"-format", "json",
),
)
}()
t.Cleanup(cancel)
boundary.WaitForSessionCli(t, ctx, newProjectId)
boundary.WaitForSessionCli(t, ctx, projectId)
t.Log("Copying script to host...")
output := e2e.RunCommand(ctx, "scp",
@@ -25,15 +25,18 @@ func TestCliTcpTargetConnectGoSsh(t *testing.T) {
ctx := context.Background()
boundary.AuthenticateAdminCli(t, ctx)
newOrgId := boundary.CreateNewOrgCli(t, ctx)
orgId, err := boundary.CreateOrgCli(t, ctx)
require.NoError(t, err)
t.Cleanup(func() {
ctx := context.Background()
boundary.AuthenticateAdminCli(t, ctx)
output := e2e.RunCommand(ctx, "boundary", e2e.WithArgs("scopes", "delete", "-id", newOrgId))
output := e2e.RunCommand(ctx, "boundary", e2e.WithArgs("scopes", "delete", "-id", orgId))
require.NoError(t, output.Err, string(output.Stderr))
})
newProjectId := boundary.CreateNewProjectCli(t, ctx, newOrgId)
newTargetId := boundary.CreateNewTargetCli(t, ctx, newProjectId, c.TargetPort, target.WithAddress(c.TargetAddress))
projectId, err := boundary.CreateProjectCli(t, ctx, orgId)
require.NoError(t, err)
targetId, err := boundary.CreateTargetCli(t, ctx, projectId, c.TargetPort, target.WithAddress(c.TargetAddress))
require.NoError(t, err)
// Start a session
ctxCancel, cancel := context.WithCancel(context.Background())
@@ -44,7 +47,7 @@ func TestCliTcpTargetConnectGoSsh(t *testing.T) {
cmdChan <- e2e.RunCommand(ctxCancel, "boundary",
e2e.WithArgs(
"connect",
"-target-id", newTargetId,
"-target-id", targetId,
"-listen-port", port,
"-format", "json",
),
@@ -52,7 +55,7 @@ func TestCliTcpTargetConnectGoSsh(t *testing.T) {
}()
t.Cleanup(cancel)
boundary.WaitForSessionCli(t, ctx, newProjectId)
boundary.WaitForSessionCli(t, ctx, projectId)
// Connect to the target using the go experimental ssh library
privateKeyRaw, err := os.ReadFile(c.TargetSshKeyPath)
@@ -25,20 +25,28 @@ func TestCliTcpTargetConnectTargetWithLocalhost(t *testing.T) {
ctx := context.Background()
boundary.AuthenticateAdminCli(t, ctx)
newOrgId := boundary.CreateNewOrgCli(t, ctx)
orgId, err := boundary.CreateOrgCli(t, ctx)
require.NoError(t, err)
t.Cleanup(func() {
ctx := context.Background()
boundary.AuthenticateAdminCli(t, ctx)
output := e2e.RunCommand(ctx, "boundary", e2e.WithArgs("scopes", "delete", "-id", newOrgId))
output := e2e.RunCommand(ctx, "boundary", e2e.WithArgs("scopes", "delete", "-id", orgId))
require.NoError(t, output.Err, string(output.Stderr))
})
newProjectId := boundary.CreateNewProjectCli(t, ctx, newOrgId)
newHostCatalogId := boundary.CreateNewHostCatalogCli(t, ctx, newProjectId)
newHostSetId := boundary.CreateNewHostSetCli(t, ctx, newHostCatalogId)
newHostId := boundary.CreateNewHostCli(t, ctx, newHostCatalogId, c.TargetAddress)
boundary.AddHostToHostSetCli(t, ctx, newHostSetId, newHostId)
newTargetId := boundary.CreateNewTargetCli(t, ctx, newProjectId, c.TargetPort)
boundary.AddHostSourceToTargetCli(t, ctx, newTargetId, newHostSetId)
projectId, err := boundary.CreateProjectCli(t, ctx, orgId)
require.NoError(t, err)
hostCatalogId, err := boundary.CreateHostCatalogCli(t, ctx, projectId)
require.NoError(t, err)
hostSetId, err := boundary.CreateHostSetCli(t, ctx, hostCatalogId)
require.NoError(t, err)
hostId, err := boundary.CreateHostCli(t, ctx, hostCatalogId, c.TargetAddress)
require.NoError(t, err)
err = boundary.AddHostToHostSetCli(t, ctx, hostSetId, hostId)
require.NoError(t, err)
targetId, err := boundary.CreateTargetCli(t, ctx, projectId, c.TargetPort)
require.NoError(t, err)
err = boundary.AddHostSourceToTargetCli(t, ctx, targetId, hostSetId)
require.NoError(t, err)
// Start a session
ctxCancel, cancel := context.WithCancel(context.Background())
@@ -49,7 +57,7 @@ func TestCliTcpTargetConnectTargetWithLocalhost(t *testing.T) {
cmdChan <- e2e.RunCommand(ctxCancel, "boundary",
e2e.WithArgs(
"connect",
"-target-id", newTargetId,
"-target-id", targetId,
"-listen-port", port,
"-format", "json",
),
@@ -57,7 +65,7 @@ func TestCliTcpTargetConnectTargetWithLocalhost(t *testing.T) {
}()
t.Cleanup(cancel)
boundary.WaitForSessionCli(t, ctx, newProjectId)
boundary.WaitForSessionCli(t, ctx, projectId)
// Connect to target and print host's IP address
output := e2e.RunCommand(ctx, "ssh",
@@ -28,21 +28,24 @@ func TestCliTcpTargetConnectTargetAndScp(t *testing.T) {
ctx := context.Background()
boundary.AuthenticateAdminCli(t, ctx)
newOrgId := boundary.CreateNewOrgCli(t, ctx)
orgId, err := boundary.CreateOrgCli(t, ctx)
require.NoError(t, err)
t.Cleanup(func() {
ctx := context.Background()
boundary.AuthenticateAdminCli(t, ctx)
output := e2e.RunCommand(ctx, "boundary", e2e.WithArgs("scopes", "delete", "-id", newOrgId))
output := e2e.RunCommand(ctx, "boundary", e2e.WithArgs("scopes", "delete", "-id", orgId))
require.NoError(t, output.Err, string(output.Stderr))
})
newProjectId := boundary.CreateNewProjectCli(t, ctx, newOrgId)
newTargetId := boundary.CreateNewTargetCli(
projectId, err := boundary.CreateProjectCli(t, ctx, orgId)
require.NoError(t, err)
targetId, err := boundary.CreateTargetCli(
t,
ctx,
newProjectId,
projectId,
c.TargetPort,
target.WithAddress(c.TargetAddress),
)
require.NoError(t, err)
// Start a session
ctxCancel, cancel := context.WithCancel(context.Background())
@@ -53,7 +56,7 @@ func TestCliTcpTargetConnectTargetAndScp(t *testing.T) {
cmdChan <- e2e.RunCommand(ctxCancel, "boundary",
e2e.WithArgs(
"connect",
"-target-id", newTargetId,
"-target-id", targetId,
"-listen-port", port,
"-format", "json",
),
@@ -61,7 +64,7 @@ func TestCliTcpTargetConnectTargetAndScp(t *testing.T) {
}()
t.Cleanup(cancel)
boundary.WaitForSessionCli(t, ctx, newProjectId)
boundary.WaitForSessionCli(t, ctx, projectId)
// Create file to scp
testDir := t.TempDir()
@@ -25,23 +25,26 @@ func TestCliTcpTargetConnectTargetWithSessionMaxSecondsTearDown(t *testing.T) {
ctx := context.Background()
boundary.AuthenticateAdminCli(t, ctx)
newOrgId := boundary.CreateNewOrgCli(t, ctx)
orgId, err := boundary.CreateOrgCli(t, ctx)
require.NoError(t, err)
t.Cleanup(func() {
ctx := context.Background()
boundary.AuthenticateAdminCli(t, ctx)
output := e2e.RunCommand(ctx, "boundary", e2e.WithArgs("scopes", "delete", "-id", newOrgId))
output := e2e.RunCommand(ctx, "boundary", e2e.WithArgs("scopes", "delete", "-id", orgId))
require.NoError(t, output.Err, string(output.Stderr))
})
newProjectId := boundary.CreateNewProjectCli(t, ctx, newOrgId)
projectId, err := boundary.CreateProjectCli(t, ctx, orgId)
require.NoError(t, err)
sessionMaxSeconds := 7
newTargetId := boundary.CreateNewTargetCli(
targetId, err := boundary.CreateTargetCli(
t,
ctx,
newProjectId,
projectId,
c.TargetPort,
target.WithAddress(c.TargetAddress),
target.WithSessionMaxSeconds(uint32(sessionMaxSeconds)),
)
require.NoError(t, err)
// Start a long-running session
var start time.Time
@@ -52,7 +55,7 @@ func TestCliTcpTargetConnectTargetWithSessionMaxSecondsTearDown(t *testing.T) {
sessionChannel <- e2e.RunCommand(ctxCancel, "boundary",
e2e.WithArgs(
"connect",
"-target-id", newTargetId,
"-target-id", targetId,
"-exec", "/usr/bin/ssh", "--",
"-l", c.TargetSshUser,
"-i", c.TargetSshKeyPath,
@@ -66,7 +69,7 @@ func TestCliTcpTargetConnectTargetWithSessionMaxSecondsTearDown(t *testing.T) {
)
}()
t.Cleanup(cancel)
s := boundary.WaitForSessionCli(t, ctx, newProjectId)
s := boundary.WaitForSessionCli(t, ctx, projectId)
boundary.WaitForSessionStatusCli(t, ctx, s.Id, session.StatusActive.String())
// Check that session was closed once time limit is reached
@@ -94,23 +97,26 @@ func TestCliTcpTargetConnectTargetWithSessionMaxSecondsRejectNew(t *testing.T) {
ctx := context.Background()
boundary.AuthenticateAdminCli(t, ctx)
newOrgId := boundary.CreateNewOrgCli(t, ctx)
orgId, err := boundary.CreateOrgCli(t, ctx)
require.NoError(t, err)
t.Cleanup(func() {
ctx := context.Background()
boundary.AuthenticateAdminCli(t, ctx)
output := e2e.RunCommand(ctx, "boundary", e2e.WithArgs("scopes", "delete", "-id", newOrgId))
output := e2e.RunCommand(ctx, "boundary", e2e.WithArgs("scopes", "delete", "-id", orgId))
require.NoError(t, output.Err, string(output.Stderr))
})
newProjectId := boundary.CreateNewProjectCli(t, ctx, newOrgId)
projectId, err := boundary.CreateProjectCli(t, ctx, orgId)
require.NoError(t, err)
sessionMaxSeconds := 7
newTargetId := boundary.CreateNewTargetCli(
targetId, err := boundary.CreateTargetCli(
t,
ctx,
newProjectId,
projectId,
c.TargetPort,
target.WithAddress(c.TargetAddress),
target.WithSessionMaxSeconds(uint32(sessionMaxSeconds)),
)
require.NoError(t, err)
// Start a session
var start time.Time
@@ -123,14 +129,14 @@ func TestCliTcpTargetConnectTargetWithSessionMaxSecondsRejectNew(t *testing.T) {
sessionChannel <- e2e.RunCommand(ctxCancel, "boundary",
e2e.WithArgs(
"connect",
"-target-id", newTargetId,
"-target-id", targetId,
"-listen-port", port,
"-format", "json",
),
)
}()
t.Cleanup(cancel)
boundary.WaitForSessionCli(t, ctx, newProjectId)
boundary.WaitForSessionCli(t, ctx, projectId)
// Start connections. Expect an error once the time limit is reached
t.Log("Creating connections...")
@@ -26,27 +26,38 @@ func TestCliTcpTargetConnectTargetWithSsh(t *testing.T) {
ctx := context.Background()
boundary.AuthenticateAdminCli(t, ctx)
newOrgId := boundary.CreateNewOrgCli(t, ctx)
orgId, err := boundary.CreateOrgCli(t, ctx)
require.NoError(t, err)
t.Cleanup(func() {
ctx := context.Background()
boundary.AuthenticateAdminCli(t, ctx)
output := e2e.RunCommand(ctx, "boundary", e2e.WithArgs("scopes", "delete", "-id", newOrgId))
output := e2e.RunCommand(ctx, "boundary", e2e.WithArgs("scopes", "delete", "-id", orgId))
require.NoError(t, output.Err, string(output.Stderr))
})
newProjectId := boundary.CreateNewProjectCli(t, ctx, newOrgId)
newHostCatalogId := boundary.CreateNewHostCatalogCli(t, ctx, newProjectId)
newHostSetId := boundary.CreateNewHostSetCli(t, ctx, newHostCatalogId)
newHostId := boundary.CreateNewHostCli(t, ctx, newHostCatalogId, c.TargetAddress)
boundary.AddHostToHostSetCli(t, ctx, newHostSetId, newHostId)
newTargetId := boundary.CreateNewTargetCli(t, ctx, newProjectId, c.TargetPort)
boundary.AddHostSourceToTargetCli(t, ctx, newTargetId, newHostSetId)
newCredentialStoreId := boundary.CreateNewCredentialStoreStaticCli(t, ctx, newProjectId)
newCredentialsId := boundary.CreateNewStaticCredentialPrivateKeyCli(t, ctx, newCredentialStoreId, c.TargetSshUser, c.TargetSshKeyPath)
boundary.AddBrokeredCredentialSourceToTargetCli(t, ctx, newTargetId, newCredentialsId)
projectId, err := boundary.CreateProjectCli(t, ctx, orgId)
require.NoError(t, err)
hostCatalogId, err := boundary.CreateHostCatalogCli(t, ctx, projectId)
require.NoError(t, err)
hostSetId, err := boundary.CreateHostSetCli(t, ctx, hostCatalogId)
require.NoError(t, err)
hostId, err := boundary.CreateHostCli(t, ctx, hostCatalogId, c.TargetAddress)
require.NoError(t, err)
err = boundary.AddHostToHostSetCli(t, ctx, hostSetId, hostId)
require.NoError(t, err)
targetId, err := boundary.CreateTargetCli(t, ctx, projectId, c.TargetPort)
require.NoError(t, err)
err = boundary.AddHostSourceToTargetCli(t, ctx, targetId, hostSetId)
require.NoError(t, err)
storeId, err := boundary.CreateCredentialStoreStaticCli(t, ctx, projectId)
require.NoError(t, err)
credentialId, err := boundary.CreateStaticCredentialPrivateKeyCli(t, ctx, storeId, c.TargetSshUser, c.TargetSshKeyPath)
require.NoError(t, err)
err = boundary.AddBrokeredCredentialSourceToTargetCli(t, ctx, targetId, credentialId)
require.NoError(t, err)
// Get credentials for target
output := e2e.RunCommand(ctx, "boundary",
e2e.WithArgs("targets", "authorize-session", "-id", newTargetId, "-format", "json"),
e2e.WithArgs("targets", "authorize-session", "-id", targetId, "-format", "json"),
)
require.NoError(t, output.Err, string(output.Stderr))
var newSessionAuthorizationResult targets.SessionAuthorizationResult
@@ -70,7 +81,7 @@ func TestCliTcpTargetConnectTargetWithSsh(t *testing.T) {
output = e2e.RunCommand(ctx, "boundary",
e2e.WithArgs(
"connect", "ssh",
"-target-id", newTargetId, "--",
"-target-id", targetId, "--",
"-o", "UserKnownHostsFile=/dev/null",
"-o", "StrictHostKeyChecking=no",
"-o", "IdentitiesOnly=yes", // forces the use of the provided key
@@ -83,7 +94,7 @@ func TestCliTcpTargetConnectTargetWithSsh(t *testing.T) {
output = e2e.RunCommand(ctx, "boundary",
e2e.WithArgs(
"connect", "ssh",
"-target-id", newTargetId,
"-target-id", targetId,
"-remote-command", "hostname -i",
"--",
"-o", "UserKnownHostsFile=/dev/null",
@@ -25,26 +25,34 @@ func TestCliTcpTargetConnectTargetBasic(t *testing.T) {
ctx := context.Background()
boundary.AuthenticateAdminCli(t, ctx)
newOrgId := boundary.CreateNewOrgCli(t, ctx)
orgId, err := boundary.CreateOrgCli(t, ctx)
require.NoError(t, err)
t.Cleanup(func() {
ctx := context.Background()
boundary.AuthenticateAdminCli(t, ctx)
output := e2e.RunCommand(ctx, "boundary", e2e.WithArgs("scopes", "delete", "-id", newOrgId))
output := e2e.RunCommand(ctx, "boundary", e2e.WithArgs("scopes", "delete", "-id", orgId))
require.NoError(t, output.Err, string(output.Stderr))
})
newProjectId := boundary.CreateNewProjectCli(t, ctx, newOrgId)
newHostCatalogId := boundary.CreateNewHostCatalogCli(t, ctx, newProjectId)
newHostSetId := boundary.CreateNewHostSetCli(t, ctx, newHostCatalogId)
newHostId := boundary.CreateNewHostCli(t, ctx, newHostCatalogId, c.TargetAddress)
boundary.AddHostToHostSetCli(t, ctx, newHostSetId, newHostId)
newTargetId := boundary.CreateNewTargetCli(t, ctx, newProjectId, c.TargetPort)
boundary.AddHostSourceToTargetCli(t, ctx, newTargetId, newHostSetId)
projectId, err := boundary.CreateProjectCli(t, ctx, orgId)
require.NoError(t, err)
hostCatalogId, err := boundary.CreateHostCatalogCli(t, ctx, projectId)
require.NoError(t, err)
hostSetId, err := boundary.CreateHostSetCli(t, ctx, hostCatalogId)
require.NoError(t, err)
hostId, err := boundary.CreateHostCli(t, ctx, hostCatalogId, c.TargetAddress)
require.NoError(t, err)
err = boundary.AddHostToHostSetCli(t, ctx, hostSetId, hostId)
require.NoError(t, err)
targetId, err := boundary.CreateTargetCli(t, ctx, projectId, c.TargetPort)
require.NoError(t, err)
err = boundary.AddHostSourceToTargetCli(t, ctx, targetId, hostSetId)
require.NoError(t, err)
// Connect to target and print host's IP address
output := e2e.RunCommand(ctx, "boundary",
e2e.WithArgs(
"connect",
"-target-id", newTargetId,
"-target-id", targetId,
"-exec", "/usr/bin/ssh", "--",
"-l", c.TargetSshUser,
"-i", c.TargetSshKeyPath,
@@ -75,22 +83,30 @@ func TestCliTcpTargetConnectTargetViaTargetAndScopeNames(t *testing.T) {
ctx := context.Background()
boundary.AuthenticateAdminCli(t, ctx)
newOrgId := boundary.CreateNewOrgCli(t, ctx)
orgId, err := boundary.CreateOrgCli(t, ctx)
require.NoError(t, err)
t.Cleanup(func() {
ctx := context.Background()
boundary.AuthenticateAdminCli(t, ctx)
output := e2e.RunCommand(ctx, "boundary", e2e.WithArgs("scopes", "delete", "-id", newOrgId))
output := e2e.RunCommand(ctx, "boundary", e2e.WithArgs("scopes", "delete", "-id", orgId))
require.NoError(t, output.Err, string(output.Stderr))
})
testProjectName := `E2E/Project-With\Name`
testTargetName := `E2E/Test-Target-With\Name`
newProjectId := boundary.CreateNewProjectCli(t, ctx, newOrgId, boundary.WithName(testProjectName))
newHostCatalogId := boundary.CreateNewHostCatalogCli(t, ctx, newProjectId)
newHostSetId := boundary.CreateNewHostSetCli(t, ctx, newHostCatalogId)
newHostId := boundary.CreateNewHostCli(t, ctx, newHostCatalogId, c.TargetAddress)
boundary.AddHostToHostSetCli(t, ctx, newHostSetId, newHostId)
newTargetId := boundary.CreateNewTargetCli(t, ctx, newProjectId, c.TargetPort, target.WithName(testTargetName))
boundary.AddHostSourceToTargetCli(t, ctx, newTargetId, newHostSetId)
projectId, err := boundary.CreateProjectCli(t, ctx, orgId, boundary.WithName(testProjectName))
require.NoError(t, err)
hostCatalogId, err := boundary.CreateHostCatalogCli(t, ctx, projectId)
require.NoError(t, err)
hostSetId, err := boundary.CreateHostSetCli(t, ctx, hostCatalogId)
require.NoError(t, err)
hostId, err := boundary.CreateHostCli(t, ctx, hostCatalogId, c.TargetAddress)
require.NoError(t, err)
err = boundary.AddHostToHostSetCli(t, ctx, hostSetId, hostId)
require.NoError(t, err)
targetId, err := boundary.CreateTargetCli(t, ctx, projectId, c.TargetPort, target.WithName(testTargetName))
require.NoError(t, err)
err = boundary.AddHostSourceToTargetCli(t, ctx, targetId, hostSetId)
require.NoError(t, err)
// Connect to target via target and scope names, and print host's IP address
output := e2e.RunCommand(ctx, "boundary",
@@ -121,7 +137,7 @@ func TestCliTcpTargetConnectTargetViaTargetAndScopeNames(t *testing.T) {
e2e.WithArgs(
"connect",
"-target-name", testTargetName,
"-target-scope-id", newProjectId,
"-target-scope-id", projectId,
"-exec", "/usr/bin/ssh", "--",
"-l", c.TargetSshUser,
"-i", c.TargetSshKeyPath,
@@ -27,11 +27,12 @@ func TestCliLdap(t *testing.T) {
ctx := context.Background()
boundary.AuthenticateAdminCli(t, ctx)
newOrgId := boundary.CreateNewOrgCli(t, ctx)
orgId, err := boundary.CreateOrgCli(t, ctx)
require.NoError(t, err)
t.Cleanup(func() {
ctx := context.Background()
boundary.AuthenticateAdminCli(t, ctx)
output := e2e.RunCommand(ctx, "boundary", e2e.WithArgs("scopes", "delete", "-id", newOrgId))
output := e2e.RunCommand(ctx, "boundary", e2e.WithArgs("scopes", "delete", "-id", orgId))
require.NoError(t, output.Err, string(output.Stderr))
})
@@ -39,7 +40,7 @@ func TestCliLdap(t *testing.T) {
output := e2e.RunCommand(ctx, "boundary",
e2e.WithArgs(
"auth-methods", "create", "ldap",
"-scope-id", newOrgId,
"-scope-id", orgId,
"-name", "e2e LDAP",
"-urls", c.LdapAddress,
"-user-dn", c.LdapDomainDn,
@@ -79,8 +80,10 @@ func TestCliLdap(t *testing.T) {
t.Logf("Created Account: %s", newAccountId)
// Create a user and attach the LDAP account
newUserId := boundary.CreateNewUserCli(t, ctx, newOrgId)
boundary.SetAccountToUserCli(t, ctx, newUserId, newAccountId)
userId, err := boundary.CreateUserCli(t, ctx, orgId)
require.NoError(t, err)
err = boundary.SetAccountToUserCli(t, ctx, userId, newAccountId)
require.NoError(t, err)
// Try to log in with the wrong password
output = e2e.RunCommand(ctx, "boundary",
@@ -155,10 +158,12 @@ func TestCliLdap(t *testing.T) {
require.Contains(t, managedGroupReadResult.Item.MemberIds, newAccountId)
// Add managed group as a principal to a role with permissions to read auth methods
newRoleId, err := boundary.CreateRoleCli(t, ctx, newOrgId)
roleId, err := boundary.CreateRoleCli(t, ctx, orgId)
require.NoError(t, err)
err = boundary.AddPrincipalToRoleCli(t, ctx, roleId, managedGroupId)
require.NoError(t, err)
err = boundary.AddGrantToRoleCli(t, ctx, roleId, "ids=*;type=auth-method;actions=read")
require.NoError(t, err)
boundary.AddPrincipalToRoleCli(t, ctx, newRoleId, managedGroupId)
boundary.AddGrantToRoleCli(t, ctx, newRoleId, "ids=*;type=auth-method;actions=read")
// Log in as the LDAP user again
output = e2e.RunCommand(ctx, "boundary",
@@ -34,16 +34,20 @@ func TestHttpRateLimit(t *testing.T) {
ctx := context.Background()
boundary.AuthenticateAdminCli(t, ctx)
newOrgId := boundary.CreateNewOrgCli(t, ctx)
orgId, err := boundary.CreateOrgCli(t, ctx)
require.NoError(t, err)
t.Cleanup(func() {
ctx := context.Background()
boundary.AuthenticateAdminCli(t, ctx)
output := e2e.RunCommand(ctx, "boundary", e2e.WithArgs("scopes", "delete", "-id", newOrgId))
output := e2e.RunCommand(ctx, "boundary", e2e.WithArgs("scopes", "delete", "-id", orgId))
require.NoError(t, output.Err, string(output.Stderr))
})
newProjectId := boundary.CreateNewProjectCli(t, ctx, newOrgId)
newHostCatalogId := boundary.CreateNewHostCatalogCli(t, ctx, newProjectId)
newHostId := boundary.CreateNewHostCli(t, ctx, newHostCatalogId, c.TargetAddress)
projectId, err := boundary.CreateProjectCli(t, ctx, orgId)
require.NoError(t, err)
hostCatalogId, err := boundary.CreateHostCatalogCli(t, ctx, projectId)
require.NoError(t, err)
hostId, err := boundary.CreateHostCli(t, ctx, hostCatalogId, c.TargetAddress)
require.NoError(t, err)
// Authenticate over HTTP
res, err := boundary.AuthenticateHttp(t, ctx, bc.Address, bc.AuthMethodId, bc.AdminLoginName, bc.AdminLoginPassword)
@@ -59,7 +63,7 @@ func TestHttpRateLimit(t *testing.T) {
// Make initial API request
t.Log("Sending API requests until quota is hit...")
requestURL := fmt.Sprintf("%s/v1/hosts/%s", bc.Address, newHostId)
requestURL := fmt.Sprintf("%s/v1/hosts/%s", bc.Address, hostId)
req, err := http.NewRequest(http.MethodGet, requestURL, nil)
require.NoError(t, err)
req.Header.Set("Authorization", fmt.Sprintf("Bearer %s", tokenAdmin))
@@ -71,7 +75,7 @@ func TestHttpRateLimit(t *testing.T) {
require.NoError(t, err)
res.Body.Close()
require.NotEmpty(t, body)
require.Contains(t, string(body), newHostId)
require.Contains(t, string(body), hostId)
// Check that the limit from the policy matches the actual limit
rateLimitPolicyHeader := res.Header.Get("Ratelimit-Policy")
@@ -92,7 +96,7 @@ func TestHttpRateLimit(t *testing.T) {
quota, err := getRateLimitStat(rateLimitHeader, "remaining")
require.NoError(t, err)
for quota > 0 {
requestURL = fmt.Sprintf("%s/v1/hosts/%s", bc.Address, newHostId)
requestURL = fmt.Sprintf("%s/v1/hosts/%s", bc.Address, hostId)
req, err = http.NewRequest(http.MethodGet, requestURL, nil)
require.NoError(t, err)
req.Header.Set("Authorization", fmt.Sprintf("Bearer %s", tokenAdmin))
@@ -113,7 +117,7 @@ func TestHttpRateLimit(t *testing.T) {
// Do another request after the quota is exhausted
// Verify that the request is not successful (HTTP 429: Too Many Requests)
t.Log("Checking that next API request is rate limited...")
requestURL = fmt.Sprintf("%s/v1/hosts/%s", bc.Address, newHostId)
requestURL = fmt.Sprintf("%s/v1/hosts/%s", bc.Address, hostId)
req, err = http.NewRequest(http.MethodGet, requestURL, nil)
require.NoError(t, err)
req.Header.Set("Authorization", fmt.Sprintf("Bearer %s", tokenAdmin))
@@ -136,7 +140,7 @@ func TestHttpRateLimit(t *testing.T) {
// Do another request. Verify that request is successful
t.Log("Retrying...")
requestURL = fmt.Sprintf("%s/v1/hosts/%s", bc.Address, newHostId)
requestURL = fmt.Sprintf("%s/v1/hosts/%s", bc.Address, hostId)
req, err = http.NewRequest(http.MethodGet, requestURL, nil)
require.NoError(t, err)
req.Header.Set("Authorization", fmt.Sprintf("Bearer %s", tokenAdmin))
@@ -148,33 +152,38 @@ func TestHttpRateLimit(t *testing.T) {
require.NoError(t, err)
res.Body.Close()
require.NotEmpty(t, body)
require.Contains(t, string(body), newHostId)
require.Contains(t, string(body), hostId)
t.Log("Successfully sent request after waiting")
// Create a user
acctName := "e2e-account"
newAccountId, acctPassword := boundary.CreateNewAccountCli(t, ctx, bc.AuthMethodId, acctName)
t.Cleanup(func() {
boundary.AuthenticateAdminCli(t, context.Background())
output := e2e.RunCommand(ctx, "boundary",
e2e.WithArgs("accounts", "delete", "-id", newAccountId),
)
require.NoError(t, output.Err, string(output.Stderr))
})
newUserId := boundary.CreateNewUserCli(t, ctx, "global")
t.Cleanup(func() {
boundary.AuthenticateAdminCli(t, context.Background())
output := e2e.RunCommand(ctx, "boundary",
e2e.WithArgs("users", "delete", "-id", newUserId),
)
require.NoError(t, output.Err, string(output.Stderr))
})
boundary.SetAccountToUserCli(t, ctx, newUserId, newAccountId)
newRoleId, err := boundary.CreateRoleCli(t, ctx, newProjectId)
accountId, acctPassword, err := boundary.CreateAccountCli(t, ctx, bc.AuthMethodId, acctName)
require.NoError(t, err)
t.Cleanup(func() {
boundary.AuthenticateAdminCli(t, context.Background())
output := e2e.RunCommand(ctx, "boundary",
e2e.WithArgs("accounts", "delete", "-id", accountId),
)
require.NoError(t, output.Err, string(output.Stderr))
})
userId, err := boundary.CreateUserCli(t, ctx, "global")
require.NoError(t, err)
t.Cleanup(func() {
boundary.AuthenticateAdminCli(t, context.Background())
output := e2e.RunCommand(ctx, "boundary",
e2e.WithArgs("users", "delete", "-id", userId),
)
require.NoError(t, output.Err, string(output.Stderr))
})
err = boundary.SetAccountToUserCli(t, ctx, userId, accountId)
require.NoError(t, err)
roleId, err := boundary.CreateRoleCli(t, ctx, projectId)
require.NoError(t, err)
err = boundary.AddGrantToRoleCli(t, ctx, roleId, "ids=*;type=*;actions=*")
require.NoError(t, err)
err = boundary.AddPrincipalToRoleCli(t, ctx, roleId, userId)
require.NoError(t, err)
boundary.AddGrantToRoleCli(t, ctx, newRoleId, "ids=*;type=*;actions=*")
boundary.AddPrincipalToRoleCli(t, ctx, newRoleId, newUserId)
// Get auth token for second user
res, err = boundary.AuthenticateHttp(t, ctx, bc.Address, bc.AuthMethodId, acctName, acctPassword)
@@ -189,7 +198,7 @@ func TestHttpRateLimit(t *testing.T) {
// Make request until quota is hit again using the first user
t.Log("Sending API requests until quota is hit...")
requestURL = fmt.Sprintf("%s/v1/hosts/%s", bc.Address, newHostId)
requestURL = fmt.Sprintf("%s/v1/hosts/%s", bc.Address, hostId)
req, err = http.NewRequest(http.MethodGet, requestURL, nil)
require.NoError(t, err)
req.Header.Set("Authorization", fmt.Sprintf("Bearer %s", tokenAdmin))
@@ -202,7 +211,7 @@ func TestHttpRateLimit(t *testing.T) {
quota, err = getRateLimitStat(rateLimitHeader, "remaining")
require.NoError(t, err)
for quota > 0 {
requestURL = fmt.Sprintf("%s/v1/hosts/%s", bc.Address, newHostId)
requestURL = fmt.Sprintf("%s/v1/hosts/%s", bc.Address, hostId)
req, err = http.NewRequest(http.MethodGet, requestURL, nil)
require.NoError(t, err)
req.Header.Set("Authorization", fmt.Sprintf("Bearer %s", tokenAdmin))
@@ -223,7 +232,7 @@ func TestHttpRateLimit(t *testing.T) {
// Confirm that a request from the second user results in a HTTP 503 due to
// exceeding the quota limit
t.Log("Checking that next API request is rejected...")
requestURL = fmt.Sprintf("%s/v1/hosts/%s", bc.Address, newHostId)
requestURL = fmt.Sprintf("%s/v1/hosts/%s", bc.Address, hostId)
req, err = http.NewRequest(http.MethodGet, requestURL, nil)
require.NoError(t, err)
req.Header.Set("Authorization", fmt.Sprintf("Bearer %s", tokenUser))
@@ -248,7 +257,7 @@ func TestHttpRateLimit(t *testing.T) {
// Do another request. Verify that request is successful
t.Log("Retrying...")
requestURL = fmt.Sprintf("%s/v1/hosts/%s", bc.Address, newHostId)
requestURL = fmt.Sprintf("%s/v1/hosts/%s", bc.Address, hostId)
req, err = http.NewRequest(http.MethodGet, requestURL, nil)
require.NoError(t, err)
req.Header.Set("Authorization", fmt.Sprintf("Bearer %s", tokenUser))
@@ -277,40 +286,49 @@ func TestCliRateLimit(t *testing.T) {
ctx := context.Background()
boundary.AuthenticateAdminCli(t, ctx)
newOrgId := boundary.CreateNewOrgCli(t, ctx)
orgId, err := boundary.CreateOrgCli(t, ctx)
require.NoError(t, err)
t.Cleanup(func() {
ctx := context.Background()
boundary.AuthenticateAdminCli(t, ctx)
output := e2e.RunCommand(ctx, "boundary", e2e.WithArgs("scopes", "delete", "-id", newOrgId))
output := e2e.RunCommand(ctx, "boundary", e2e.WithArgs("scopes", "delete", "-id", orgId))
require.NoError(t, output.Err, string(output.Stderr))
})
newProjectId := boundary.CreateNewProjectCli(t, ctx, newOrgId)
newHostCatalogId := boundary.CreateNewHostCatalogCli(t, ctx, newProjectId)
newHostId := boundary.CreateNewHostCli(t, ctx, newHostCatalogId, c.TargetAddress)
projectId, err := boundary.CreateProjectCli(t, ctx, orgId)
require.NoError(t, err)
hostCatalogId, err := boundary.CreateHostCatalogCli(t, ctx, projectId)
require.NoError(t, err)
hostId, err := boundary.CreateHostCli(t, ctx, hostCatalogId, c.TargetAddress)
require.NoError(t, err)
// Create a user
acctName := "e2e-account"
newAccountId, acctPassword := boundary.CreateNewAccountCli(t, ctx, bc.AuthMethodId, acctName)
t.Cleanup(func() {
boundary.AuthenticateAdminCli(t, context.Background())
output := e2e.RunCommand(ctx, "boundary",
e2e.WithArgs("accounts", "delete", "-id", newAccountId),
)
require.NoError(t, output.Err, string(output.Stderr))
})
newUserId := boundary.CreateNewUserCli(t, ctx, "global")
t.Cleanup(func() {
boundary.AuthenticateAdminCli(t, context.Background())
output := e2e.RunCommand(ctx, "boundary",
e2e.WithArgs("users", "delete", "-id", newUserId),
)
require.NoError(t, output.Err, string(output.Stderr))
})
boundary.SetAccountToUserCli(t, ctx, newUserId, newAccountId)
newRoleId, err := boundary.CreateRoleCli(t, ctx, newProjectId)
accountId, acctPassword, err := boundary.CreateAccountCli(t, ctx, bc.AuthMethodId, acctName)
require.NoError(t, err)
t.Cleanup(func() {
boundary.AuthenticateAdminCli(t, context.Background())
output := e2e.RunCommand(ctx, "boundary",
e2e.WithArgs("accounts", "delete", "-id", accountId),
)
require.NoError(t, output.Err, string(output.Stderr))
})
userId, err := boundary.CreateUserCli(t, ctx, "global")
require.NoError(t, err)
t.Cleanup(func() {
boundary.AuthenticateAdminCli(t, context.Background())
output := e2e.RunCommand(ctx, "boundary",
e2e.WithArgs("users", "delete", "-id", userId),
)
require.NoError(t, output.Err, string(output.Stderr))
})
err = boundary.SetAccountToUserCli(t, ctx, userId, accountId)
require.NoError(t, err)
roleId, err := boundary.CreateRoleCli(t, ctx, projectId)
require.NoError(t, err)
err = boundary.AddGrantToRoleCli(t, ctx, roleId, "ids=*;type=*;actions=*")
require.NoError(t, err)
err = boundary.AddPrincipalToRoleCli(t, ctx, roleId, userId)
require.NoError(t, err)
boundary.AddGrantToRoleCli(t, ctx, newRoleId, "ids=*;type=*;actions=*")
boundary.AddPrincipalToRoleCli(t, ctx, newRoleId, newUserId)
// Authenticate over HTTP
res, err := boundary.AuthenticateHttp(t, ctx, bc.Address, bc.AuthMethodId, bc.AdminLoginName, bc.AdminLoginPassword)
@@ -326,7 +344,7 @@ func TestCliRateLimit(t *testing.T) {
// Make initial API request
t.Log("Getting rate limit info...")
requestURL := fmt.Sprintf("%s/v1/hosts/%s", bc.Address, newHostId)
requestURL := fmt.Sprintf("%s/v1/hosts/%s", bc.Address, hostId)
req, err := http.NewRequest(http.MethodGet, requestURL, nil)
require.NoError(t, err)
req.Header.Set("Authorization", fmt.Sprintf("Bearer %s", tokenAdmin))
@@ -345,7 +363,7 @@ func TestCliRateLimit(t *testing.T) {
t.Log("Sending multiple CLI requests to hit rate limit...")
var output *e2e.CommandResult
for i := 0; i <= policyLimit; i++ {
output = e2e.RunCommand(ctx, "boundary", e2e.WithArgs("hosts", "read", "-id", newHostId))
output = e2e.RunCommand(ctx, "boundary", e2e.WithArgs("hosts", "read", "-id", hostId))
t.Log(output.Duration)
if output.Err != nil {
break
@@ -362,7 +380,7 @@ func TestCliRateLimit(t *testing.T) {
t.Log("Logging in as another user...")
boundary.AuthenticateCli(t, ctx, bc.AuthMethodId, acctName, acctPassword)
for i := 0; i <= policyLimit; i++ {
output = e2e.RunCommand(ctx, "boundary", e2e.WithArgs("hosts", "read", "-id", newHostId))
output = e2e.RunCommand(ctx, "boundary", e2e.WithArgs("hosts", "read", "-id", hostId))
t.Log(output.Duration)
if output.Err != nil {
break
@@ -389,7 +407,7 @@ func TestCliRateLimit(t *testing.T) {
// command will take longer to return)
t.Log("Sending multiple CLI requests to hit rate limit...")
for i := 0; i <= policyLimit; i++ {
output = e2e.RunCommand(ctx, "boundary", e2e.WithArgs("hosts", "read", "-id", newHostId))
output = e2e.RunCommand(ctx, "boundary", e2e.WithArgs("hosts", "read", "-id", hostId))
t.Log(output.Duration)
require.NoError(t, output.Err, string(output.Stderr))
require.Equal(t, 0, output.ExitCode)
@@ -27,36 +27,42 @@ func TestCliTcpTargetConnectPostgres(t *testing.T) {
ctx := context.Background()
boundary.AuthenticateAdminCli(t, ctx)
newOrgId := boundary.CreateNewOrgCli(t, ctx)
orgId, err := boundary.CreateOrgCli(t, ctx)
require.NoError(t, err)
t.Cleanup(func() {
ctx := context.Background()
boundary.AuthenticateAdminCli(t, ctx)
output := e2e.RunCommand(ctx, "boundary", e2e.WithArgs("scopes", "delete", "-id", newOrgId))
output := e2e.RunCommand(ctx, "boundary", e2e.WithArgs("scopes", "delete", "-id", orgId))
require.NoError(t, output.Err, string(output.Stderr))
})
newProjectId := boundary.CreateNewProjectCli(t, ctx, newOrgId)
newTargetId := boundary.CreateNewTargetCli(
projectId, err := boundary.CreateProjectCli(t, ctx, orgId)
require.NoError(t, err)
targetId, err := boundary.CreateTargetCli(
t,
ctx,
newProjectId,
projectId,
c.TargetPort,
target.WithAddress(c.TargetAddress),
)
newCredentialStoreId := boundary.CreateNewCredentialStoreStaticCli(t, ctx, newProjectId)
newCredentialsId := boundary.CreateNewStaticCredentialPasswordCli(
require.NoError(t, err)
storeId, err := boundary.CreateCredentialStoreStaticCli(t, ctx, projectId)
require.NoError(t, err)
credentialId, err := boundary.CreateStaticCredentialPasswordCli(
t,
ctx,
newCredentialStoreId,
storeId,
c.PostgresUser,
c.PostgresPassword,
)
boundary.AddBrokeredCredentialSourceToTargetCli(t, ctx, newTargetId, newCredentialsId)
require.NoError(t, err)
err = boundary.AddBrokeredCredentialSourceToTargetCli(t, ctx, targetId, credentialId)
require.NoError(t, err)
var cmd *exec.Cmd
cmd = exec.CommandContext(ctx,
"boundary",
"connect", "postgres",
"-target-id", newTargetId,
"-target-id", targetId,
"-dbname", c.PostgresDbName,
)
f, err := pty.Start(cmd)
@@ -30,20 +30,28 @@ func TestCliVaultCredentialStore(t *testing.T) {
ctx := context.Background()
boundary.AuthenticateAdminCli(t, ctx)
newOrgId := boundary.CreateNewOrgCli(t, ctx)
orgId, err := boundary.CreateOrgCli(t, ctx)
require.NoError(t, err)
t.Cleanup(func() {
ctx := context.Background()
boundary.AuthenticateAdminCli(t, ctx)
output := e2e.RunCommand(ctx, "boundary", e2e.WithArgs("scopes", "delete", "-id", newOrgId))
output := e2e.RunCommand(ctx, "boundary", e2e.WithArgs("scopes", "delete", "-id", orgId))
require.NoError(t, output.Err, string(output.Stderr))
})
newProjectId := boundary.CreateNewProjectCli(t, ctx, newOrgId)
newHostCatalogId := boundary.CreateNewHostCatalogCli(t, ctx, newProjectId)
newHostSetId := boundary.CreateNewHostSetCli(t, ctx, newHostCatalogId)
newHostId := boundary.CreateNewHostCli(t, ctx, newHostCatalogId, c.TargetAddress)
boundary.AddHostToHostSetCli(t, ctx, newHostSetId, newHostId)
newTargetId := boundary.CreateNewTargetCli(t, ctx, newProjectId, c.TargetPort)
boundary.AddHostSourceToTargetCli(t, ctx, newTargetId, newHostSetId)
projectId, err := boundary.CreateProjectCli(t, ctx, orgId)
require.NoError(t, err)
hostCatalogId, err := boundary.CreateHostCatalogCli(t, ctx, projectId)
require.NoError(t, err)
hostSetId, err := boundary.CreateHostSetCli(t, ctx, hostCatalogId)
require.NoError(t, err)
hostId, err := boundary.CreateHostCli(t, ctx, hostCatalogId, c.TargetAddress)
require.NoError(t, err)
err = boundary.AddHostToHostSetCli(t, ctx, hostSetId, hostId)
require.NoError(t, err)
targetId, err := boundary.CreateTargetCli(t, ctx, projectId, c.TargetPort)
require.NoError(t, err)
err = boundary.AddHostSourceToTargetCli(t, ctx, targetId, hostSetId)
require.NoError(t, err)
// Configure vault
boundaryPolicyName, kvPolicyFilePath := vault.Setup(t, "testdata/boundary-controller-policy.hcl")
@@ -98,23 +106,24 @@ func TestCliVaultCredentialStore(t *testing.T) {
t.Log("Created Vault Cred Store Token")
// Create a credential store
newCredentialStoreId := boundary.CreateNewCredentialStoreVaultCli(t, ctx, newProjectId, c.VaultAddr, credStoreToken)
storeId, err := boundary.CreateCredentialStoreVaultCli(t, ctx, projectId, c.VaultAddr, credStoreToken)
require.NoError(t, err)
// Create a credential library for the private key
newPrivateKeyCredentialLibraryId, err := boundary.CreateVaultGenericCredentialLibraryCli(
privateKeyCredentialLibraryId, err := boundary.CreateVaultGenericCredentialLibraryCli(
t,
ctx,
newCredentialStoreId,
storeId,
fmt.Sprintf("%s/data/%s", c.VaultSecretPath, privateKeySecretName),
"ssh_private_key",
)
require.NoError(t, err)
// Create a credential library for the password
newPasswordCredentialLibraryId, err := boundary.CreateVaultGenericCredentialLibraryCli(
passwordCredentialLibraryId, err := boundary.CreateVaultGenericCredentialLibraryCli(
t,
ctx,
newCredentialStoreId,
storeId,
fmt.Sprintf("%s/data/%s", c.VaultSecretPath, passwordSecretName),
"username_password",
)
@@ -122,7 +131,7 @@ func TestCliVaultCredentialStore(t *testing.T) {
// Get credentials for target (expect empty)
output = e2e.RunCommand(ctx, "boundary",
e2e.WithArgs("targets", "authorize-session", "-id", newTargetId, "-format", "json"),
e2e.WithArgs("targets", "authorize-session", "-id", targetId, "-format", "json"),
)
require.NoError(t, output.Err, string(output.Stderr))
var newSessionAuthorizationResult targets.SessionAuthorizationResult
@@ -131,12 +140,14 @@ func TestCliVaultCredentialStore(t *testing.T) {
require.True(t, newSessionAuthorizationResult.Item.Credentials == nil)
// Add credentials to target
boundary.AddBrokeredCredentialSourceToTargetCli(t, ctx, newTargetId, newPrivateKeyCredentialLibraryId)
boundary.AddBrokeredCredentialSourceToTargetCli(t, ctx, newTargetId, newPasswordCredentialLibraryId)
err = boundary.AddBrokeredCredentialSourceToTargetCli(t, ctx, targetId, privateKeyCredentialLibraryId)
require.NoError(t, err)
err = boundary.AddBrokeredCredentialSourceToTargetCli(t, ctx, targetId, passwordCredentialLibraryId)
require.NoError(t, err)
// Get credentials for target
output = e2e.RunCommand(ctx, "boundary",
e2e.WithArgs("targets", "authorize-session", "-id", newTargetId, "-format", "json"),
e2e.WithArgs("targets", "authorize-session", "-id", targetId, "-format", "json"),
)
require.NoError(t, output.Err, string(output.Stderr))
err = json.Unmarshal(output.Stdout, &newSessionAuthorizationResult)
@@ -180,19 +191,27 @@ func TestApiVaultCredentialStore(t *testing.T) {
require.NoError(t, err)
ctx := context.Background()
newOrgId := boundary.CreateNewOrgApi(t, ctx, client)
orgId, err := boundary.CreateOrgApi(t, ctx, client)
require.NoError(t, err)
t.Cleanup(func() {
scopeClient := scopes.NewClient(client)
_, err := scopeClient.Delete(ctx, newOrgId)
_, err := scopeClient.Delete(ctx, orgId)
require.NoError(t, err)
})
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.TargetAddress)
boundary.AddHostToHostSetApi(t, ctx, client, newHostSetId, newHostId)
newTargetId := boundary.CreateNewTargetApi(t, ctx, client, newProjectId, c.TargetPort)
boundary.AddHostSourceToTargetApi(t, ctx, client, newTargetId, newHostSetId)
projectId, err := boundary.CreateProjectApi(t, ctx, client, orgId)
require.NoError(t, err)
hostCatalogId, err := boundary.CreateHostCatalogApi(t, ctx, client, projectId)
require.NoError(t, err)
hostSetId, err := boundary.CreateHostSetApi(t, ctx, client, hostCatalogId)
require.NoError(t, err)
hostId, err := boundary.CreateHostApi(t, ctx, client, hostCatalogId, c.TargetAddress)
require.NoError(t, err)
err = boundary.AddHostToHostSetApi(t, ctx, client, hostSetId, hostId)
require.NoError(t, err)
targetId, err := boundary.CreateTargetApi(t, ctx, client, projectId, c.TargetPort)
require.NoError(t, err)
err = boundary.AddHostSourceToTargetApi(t, ctx, client, targetId, hostSetId)
require.NoError(t, err)
// Configure vault
boundaryPolicyName, kvPolicyFilePath := vault.Setup(t, "testdata/boundary-controller-policy.hcl")
@@ -235,7 +254,7 @@ func TestApiVaultCredentialStore(t *testing.T) {
// Create a credential store
csClient := credentialstores.NewClient(client)
newCredentialStoreResult, err := csClient.Create(ctx, "vault", newProjectId,
newCredentialStoreResult, err := csClient.Create(ctx, "vault", projectId,
credentialstores.WithVaultCredentialStoreAddress(c.VaultAddr),
credentialstores.WithVaultCredentialStoreToken(credStoreToken),
)
@@ -264,21 +283,21 @@ func TestApiVaultCredentialStore(t *testing.T) {
// Add private key brokered credentials to target
tClient := targets.NewClient(client)
_, err = tClient.AddCredentialSources(ctx, newTargetId, 0,
_, err = tClient.AddCredentialSources(ctx, targetId, 0,
targets.WithBrokeredCredentialSourceIds([]string{newPrivateKeyCredentialLibraryId}),
targets.WithAutomaticVersioning(true),
)
require.NoError(t, err)
// Add password brokered credentials to target
_, err = tClient.AddCredentialSources(ctx, newTargetId, 0,
_, err = tClient.AddCredentialSources(ctx, targetId, 0,
targets.WithBrokeredCredentialSourceIds([]string{newPasswordCredentialLibraryId}),
targets.WithAutomaticVersioning(true),
)
require.NoError(t, err)
// Get credentials for target
newSessionAuthorizationResult, err := tClient.AuthorizeSession(ctx, newTargetId)
newSessionAuthorizationResult, err := tClient.AuthorizeSession(ctx, targetId)
require.NoError(t, err)
newSessionAuthorization := newSessionAuthorizationResult.Item
require.Len(t, newSessionAuthorization.Credentials, 2)
@@ -29,14 +29,16 @@ func TestCliPaginateCredentialLibraries(t *testing.T) {
ctx := context.Background()
boundary.AuthenticateAdminCli(t, ctx)
newOrgId := boundary.CreateNewOrgCli(t, ctx)
orgId, err := boundary.CreateOrgCli(t, ctx)
require.NoError(t, err)
t.Cleanup(func() {
ctx := context.Background()
boundary.AuthenticateAdminCli(t, ctx)
output := e2e.RunCommand(ctx, "boundary", e2e.WithArgs("scopes", "delete", "-id", newOrgId))
output := e2e.RunCommand(ctx, "boundary", e2e.WithArgs("scopes", "delete", "-id", orgId))
require.NoError(t, output.Err, string(output.Stderr))
})
newProjectId := boundary.CreateNewProjectCli(t, ctx, newOrgId)
projectId, err := boundary.CreateProjectCli(t, ctx, orgId)
require.NoError(t, err)
// Configure vault
boundaryPolicyName, kvPolicyFilePath := vault.Setup(t, "testdata/boundary-controller-policy.hcl")
@@ -89,7 +91,8 @@ func TestCliPaginateCredentialLibraries(t *testing.T) {
t.Log("Created Vault Cred Store Token")
// Create a credential store
newStoreId := boundary.CreateNewCredentialStoreVaultCli(t, ctx, newProjectId, c.VaultAddr, credStoreToken)
storeId, err := boundary.CreateCredentialStoreVaultCli(t, ctx, projectId, c.VaultAddr, credStoreToken)
require.NoError(t, err)
// Create enough credential libraries to overflow a single page.
client, err := boundary.NewApiClient()
@@ -98,7 +101,7 @@ func TestCliPaginateCredentialLibraries(t *testing.T) {
var libraryIds []string
for i := 0; i < c.MaxPageSize+1; i++ {
resp, err := cClient.Create(
ctx, "vault-generic", newStoreId,
ctx, "vault-generic", storeId,
credentiallibraries.WithVaultCredentialLibraryPath(c.VaultSecretPath+"/data/"+privateKeySecretName),
credentiallibraries.WithCredentialType("ssh_private_key"),
)
@@ -109,7 +112,7 @@ func TestCliPaginateCredentialLibraries(t *testing.T) {
output = e2e.RunCommand(ctx, "boundary",
e2e.WithArgs(
"credential-libraries", "list",
"-credential-store-id", newStoreId,
"-credential-store-id", storeId,
"-format=json",
),
)
@@ -131,7 +134,7 @@ func TestCliPaginateCredentialLibraries(t *testing.T) {
assert.Empty(t, initialCredentialLibraries.ListToken)
resp, err := cClient.Create(
ctx, "vault-generic", newStoreId,
ctx, "vault-generic", storeId,
credentiallibraries.WithVaultCredentialLibraryPath(c.VaultSecretPath+"/data/"+privateKeySecretName),
credentiallibraries.WithCredentialType("ssh_private_key"),
)
@@ -144,7 +147,7 @@ func TestCliPaginateCredentialLibraries(t *testing.T) {
output = e2e.RunCommand(ctx, "boundary",
e2e.WithArgs(
"credential-libraries", "list",
"-credential-store-id", newStoreId,
"-credential-store-id", storeId,
"-format=json",
),
)
@@ -180,13 +183,15 @@ func TestApiPaginateCredentialLibraries(t *testing.T) {
ctx := context.Background()
sClient := scopes.NewClient(client)
cClient := credentiallibraries.NewClient(client)
newOrgId := boundary.CreateNewOrgApi(t, ctx, client)
orgId, err := boundary.CreateOrgApi(t, ctx, client)
require.NoError(t, err)
t.Cleanup(func() {
ctx := context.Background()
_, err := sClient.Delete(ctx, newOrgId)
_, err := sClient.Delete(ctx, orgId)
require.NoError(t, err)
})
newProjectId := boundary.CreateNewProjectApi(t, ctx, client, newOrgId)
projectId, err := boundary.CreateProjectApi(t, ctx, client, orgId)
require.NoError(t, err)
// Configure vault
boundaryPolicyName, kvPolicyFilePath := vault.Setup(t, "testdata/boundary-controller-policy.hcl")
@@ -239,13 +244,14 @@ func TestApiPaginateCredentialLibraries(t *testing.T) {
t.Log("Created Vault Cred Store Token")
// Create a credential store
newStoreId := boundary.CreateNewCredentialStoreVaultApi(t, ctx, client, newProjectId, c.VaultAddr, credStoreToken)
storeId, err := boundary.CreateCredentialStoreVaultApi(t, ctx, client, projectId, c.VaultAddr, credStoreToken)
require.NoError(t, err)
// Create enough credential libraries to overflow a single page.
var libraryIds []string
for i := 0; i < c.MaxPageSize+1; i++ {
resp, err := cClient.Create(
ctx, "vault-generic", newStoreId,
ctx, "vault-generic", storeId,
credentiallibraries.WithVaultCredentialLibraryPath(c.VaultSecretPath+"/data/"+privateKeySecretName),
credentiallibraries.WithCredentialType("ssh_private_key"),
)
@@ -253,7 +259,7 @@ func TestApiPaginateCredentialLibraries(t *testing.T) {
libraryIds = append(libraryIds, resp.Item.Id)
}
initialCredentialLibraries, err := cClient.List(ctx, newStoreId)
initialCredentialLibraries, err := cClient.List(ctx, storeId)
require.NoError(t, err)
var returnedIds []string
@@ -274,7 +280,7 @@ func TestApiPaginateCredentialLibraries(t *testing.T) {
// Create a new library and destroy one of the others
resp, err := cClient.Create(
ctx, "vault-generic", newStoreId,
ctx, "vault-generic", storeId,
credentiallibraries.WithVaultCredentialLibraryPath(c.VaultSecretPath+"/data/"+privateKeySecretName),
credentiallibraries.WithCredentialType("ssh_private_key"),
)
@@ -284,7 +290,7 @@ func TestApiPaginateCredentialLibraries(t *testing.T) {
require.NoError(t, err)
// List again, should have the new and deleted library
newCredentialLibraries, err := cClient.List(ctx, newStoreId, credentiallibraries.WithListToken(initialCredentialLibraries.ListToken))
newCredentialLibraries, err := cClient.List(ctx, storeId, credentiallibraries.WithListToken(initialCredentialLibraries.ListToken))
require.NoError(t, err)
// Note that this will likely contain all the credential libraries,
@@ -29,20 +29,28 @@ func TestCliTcpTargetVaultGenericConnectTargetWithAuthzToken(t *testing.T) {
ctx := context.Background()
boundary.AuthenticateAdminCli(t, ctx)
newOrgId := boundary.CreateNewOrgCli(t, ctx)
orgId, err := boundary.CreateOrgCli(t, ctx)
require.NoError(t, err)
t.Cleanup(func() {
ctx := context.Background()
boundary.AuthenticateAdminCli(t, ctx)
output := e2e.RunCommand(ctx, "boundary", e2e.WithArgs("scopes", "delete", "-id", newOrgId))
output := e2e.RunCommand(ctx, "boundary", e2e.WithArgs("scopes", "delete", "-id", orgId))
require.NoError(t, output.Err, string(output.Stderr))
})
newProjectId := boundary.CreateNewProjectCli(t, ctx, newOrgId)
newHostCatalogId := boundary.CreateNewHostCatalogCli(t, ctx, newProjectId)
newHostSetId := boundary.CreateNewHostSetCli(t, ctx, newHostCatalogId)
newHostId := boundary.CreateNewHostCli(t, ctx, newHostCatalogId, c.TargetAddress)
boundary.AddHostToHostSetCli(t, ctx, newHostSetId, newHostId)
newTargetId := boundary.CreateNewTargetCli(t, ctx, newProjectId, c.TargetPort)
boundary.AddHostSourceToTargetCli(t, ctx, newTargetId, newHostSetId)
projectId, err := boundary.CreateProjectCli(t, ctx, orgId)
require.NoError(t, err)
hostCatalogId, err := boundary.CreateHostCatalogCli(t, ctx, projectId)
require.NoError(t, err)
hostSetId, err := boundary.CreateHostSetCli(t, ctx, hostCatalogId)
require.NoError(t, err)
hostId, err := boundary.CreateHostCli(t, ctx, hostCatalogId, c.TargetAddress)
require.NoError(t, err)
err = boundary.AddHostToHostSetCli(t, ctx, hostSetId, hostId)
require.NoError(t, err)
targetId, err := boundary.CreateTargetCli(t, ctx, projectId, c.TargetPort)
require.NoError(t, err)
err = boundary.AddHostSourceToTargetCli(t, ctx, targetId, hostSetId)
require.NoError(t, err)
// Configure vault
boundaryPolicyName, kvPolicyFilePath := vault.Setup(t, "testdata/boundary-controller-policy.hcl")
@@ -96,23 +104,25 @@ func TestCliTcpTargetVaultGenericConnectTargetWithAuthzToken(t *testing.T) {
t.Log("Created Vault Cred Store Token")
// Create a credential store
newCredentialStoreId := boundary.CreateNewCredentialStoreVaultCli(t, ctx, newProjectId, c.VaultAddr, credStoreToken)
storeId, err := boundary.CreateCredentialStoreVaultCli(t, ctx, projectId, c.VaultAddr, credStoreToken)
require.NoError(t, err)
// Create a credential library
newCredentialLibraryId, err := boundary.CreateVaultGenericCredentialLibraryCli(
libraryId, err := boundary.CreateVaultGenericCredentialLibraryCli(
t,
ctx,
newCredentialStoreId,
storeId,
fmt.Sprintf("%s/data/%s", c.VaultSecretPath, privateKeySecretName),
"ssh_private_key",
)
require.NoError(t, err)
boundary.AddBrokeredCredentialSourceToTargetCli(t, ctx, newTargetId, newCredentialLibraryId)
err = boundary.AddBrokeredCredentialSourceToTargetCli(t, ctx, targetId, libraryId)
require.NoError(t, err)
// Get credentials for target
output = e2e.RunCommand(ctx, "boundary",
e2e.WithArgs("targets", "authorize-session", "-id", newTargetId, "-format", "json"),
e2e.WithArgs("targets", "authorize-session", "-id", targetId, "-format", "json"),
)
require.NoError(t, output.Err, string(output.Stderr))
var newSessionAuthorizationResult targets.SessionAuthorizationResult
@@ -29,20 +29,28 @@ func TestCliTcpTargetVaultGenericConnectTargetWithSsh(t *testing.T) {
ctx := context.Background()
boundary.AuthenticateAdminCli(t, ctx)
newOrgId := boundary.CreateNewOrgCli(t, ctx)
orgId, err := boundary.CreateOrgCli(t, ctx)
require.NoError(t, err)
t.Cleanup(func() {
ctx := context.Background()
boundary.AuthenticateAdminCli(t, ctx)
output := e2e.RunCommand(ctx, "boundary", e2e.WithArgs("scopes", "delete", "-id", newOrgId))
output := e2e.RunCommand(ctx, "boundary", e2e.WithArgs("scopes", "delete", "-id", orgId))
require.NoError(t, output.Err, string(output.Stderr))
})
newProjectId := boundary.CreateNewProjectCli(t, ctx, newOrgId)
newHostCatalogId := boundary.CreateNewHostCatalogCli(t, ctx, newProjectId)
newHostSetId := boundary.CreateNewHostSetCli(t, ctx, newHostCatalogId)
newHostId := boundary.CreateNewHostCli(t, ctx, newHostCatalogId, c.TargetAddress)
boundary.AddHostToHostSetCli(t, ctx, newHostSetId, newHostId)
newTargetId := boundary.CreateNewTargetCli(t, ctx, newProjectId, c.TargetPort)
boundary.AddHostSourceToTargetCli(t, ctx, newTargetId, newHostSetId)
projectId, err := boundary.CreateProjectCli(t, ctx, orgId)
require.NoError(t, err)
hostCatalogId, err := boundary.CreateHostCatalogCli(t, ctx, projectId)
require.NoError(t, err)
hostSetId, err := boundary.CreateHostSetCli(t, ctx, hostCatalogId)
require.NoError(t, err)
hostId, err := boundary.CreateHostCli(t, ctx, hostCatalogId, c.TargetAddress)
require.NoError(t, err)
err = boundary.AddHostToHostSetCli(t, ctx, hostSetId, hostId)
require.NoError(t, err)
targetId, err := boundary.CreateTargetCli(t, ctx, projectId, c.TargetPort)
require.NoError(t, err)
err = boundary.AddHostSourceToTargetCli(t, ctx, targetId, hostSetId)
require.NoError(t, err)
// Configure vault
boundaryPolicyName, kvPolicyFilePath := vault.Setup(t, "testdata/boundary-controller-policy.hcl")
@@ -96,24 +104,26 @@ func TestCliTcpTargetVaultGenericConnectTargetWithSsh(t *testing.T) {
t.Log("Created Vault Cred Store Token")
// Create a credential store
newCredentialStoreId := boundary.CreateNewCredentialStoreVaultCli(t, ctx, newProjectId, c.VaultAddr, credStoreToken)
storeId, err := boundary.CreateCredentialStoreVaultCli(t, ctx, projectId, c.VaultAddr, credStoreToken)
require.NoError(t, err)
// Create a credential library
newCredentialLibraryId, err := boundary.CreateVaultGenericCredentialLibraryCli(
libraryId, err := boundary.CreateVaultGenericCredentialLibraryCli(
t,
ctx,
newCredentialStoreId,
storeId,
fmt.Sprintf("%s/data/%s", c.VaultSecretPath, privateKeySecretName),
"ssh_private_key",
)
require.NoError(t, err)
// Add brokered credentials to target
boundary.AddBrokeredCredentialSourceToTargetCli(t, ctx, newTargetId, newCredentialLibraryId)
err = boundary.AddBrokeredCredentialSourceToTargetCli(t, ctx, targetId, libraryId)
require.NoError(t, err)
// Get credentials for target
output = e2e.RunCommand(ctx, "boundary",
e2e.WithArgs("targets", "authorize-session", "-id", newTargetId, "-format", "json"),
e2e.WithArgs("targets", "authorize-session", "-id", targetId, "-format", "json"),
)
require.NoError(t, output.Err, string(output.Stderr))
var newSessionAuthorizationResult targets.SessionAuthorizationResult
@@ -136,7 +146,7 @@ func TestCliTcpTargetVaultGenericConnectTargetWithSsh(t *testing.T) {
output = e2e.RunCommand(ctx, "boundary",
e2e.WithArgs(
"connect", "ssh",
"-target-id", newTargetId, "--",
"-target-id", targetId, "--",
"-o", "UserKnownHostsFile=/dev/null",
"-o", "StrictHostKeyChecking=no",
"-o", "IdentitiesOnly=yes", // forces the use of the provided key
@@ -30,20 +30,28 @@ func TestCliTcpTargetVaultGenericConnectTarget(t *testing.T) {
ctx := context.Background()
boundary.AuthenticateAdminCli(t, ctx)
newOrgId := boundary.CreateNewOrgCli(t, ctx)
orgId, err := boundary.CreateOrgCli(t, ctx)
require.NoError(t, err)
t.Cleanup(func() {
ctx := context.Background()
boundary.AuthenticateAdminCli(t, ctx)
output := e2e.RunCommand(ctx, "boundary", e2e.WithArgs("scopes", "delete", "-id", newOrgId))
output := e2e.RunCommand(ctx, "boundary", e2e.WithArgs("scopes", "delete", "-id", orgId))
require.NoError(t, output.Err, string(output.Stderr))
})
newProjectId := boundary.CreateNewProjectCli(t, ctx, newOrgId)
newHostCatalogId := boundary.CreateNewHostCatalogCli(t, ctx, newProjectId)
newHostSetId := boundary.CreateNewHostSetCli(t, ctx, newHostCatalogId)
newHostId := boundary.CreateNewHostCli(t, ctx, newHostCatalogId, c.TargetAddress)
boundary.AddHostToHostSetCli(t, ctx, newHostSetId, newHostId)
newTargetId := boundary.CreateNewTargetCli(t, ctx, newProjectId, c.TargetPort)
boundary.AddHostSourceToTargetCli(t, ctx, newTargetId, newHostSetId)
projectId, err := boundary.CreateProjectCli(t, ctx, orgId)
require.NoError(t, err)
hostCatalogId, err := boundary.CreateHostCatalogCli(t, ctx, projectId)
require.NoError(t, err)
hostSetId, err := boundary.CreateHostSetCli(t, ctx, hostCatalogId)
require.NoError(t, err)
hostId, err := boundary.CreateHostCli(t, ctx, hostCatalogId, c.TargetAddress)
require.NoError(t, err)
err = boundary.AddHostToHostSetCli(t, ctx, hostSetId, hostId)
require.NoError(t, err)
targetId, err := boundary.CreateTargetCli(t, ctx, projectId, c.TargetPort)
require.NoError(t, err)
err = boundary.AddHostSourceToTargetCli(t, ctx, targetId, hostSetId)
require.NoError(t, err)
// Configure vault
boundaryPolicyName, kvPolicyFilePath := vault.Setup(t, "testdata/boundary-controller-policy.hcl")
@@ -97,24 +105,26 @@ func TestCliTcpTargetVaultGenericConnectTarget(t *testing.T) {
t.Log("Created Vault Cred Store Token")
// Create a credential store
newCredentialStoreId := boundary.CreateNewCredentialStoreVaultCli(t, ctx, newProjectId, c.VaultAddr, credStoreToken)
storeId, err := boundary.CreateCredentialStoreVaultCli(t, ctx, projectId, c.VaultAddr, credStoreToken)
require.NoError(t, err)
// Create a credential library
newCredentialLibraryId, err := boundary.CreateVaultGenericCredentialLibraryCli(
libraryId, err := boundary.CreateVaultGenericCredentialLibraryCli(
t,
ctx,
newCredentialStoreId,
storeId,
fmt.Sprintf("%s/data/%s", c.VaultSecretPath, privateKeySecretName),
"ssh_private_key",
)
require.NoError(t, err)
// Add brokered credentials to target
boundary.AddBrokeredCredentialSourceToTargetCli(t, ctx, newTargetId, newCredentialLibraryId)
err = boundary.AddBrokeredCredentialSourceToTargetCli(t, ctx, targetId, libraryId)
require.NoError(t, err)
// Get credentials for target
output = e2e.RunCommand(ctx, "boundary",
e2e.WithArgs("targets", "authorize-session", "-id", newTargetId, "-format", "json"),
e2e.WithArgs("targets", "authorize-session", "-id", targetId, "-format", "json"),
)
require.NoError(t, output.Err, string(output.Stderr))
var newSessionAuthorizationResult targets.SessionAuthorizationResult
@@ -146,7 +156,7 @@ func TestCliTcpTargetVaultGenericConnectTarget(t *testing.T) {
output = e2e.RunCommand(ctx, "boundary",
e2e.WithArgs(
"connect",
"-target-id", newTargetId,
"-target-id", targetId,
"-exec", "/usr/bin/ssh", "--",
"-l", retrievedUser,
"-i", retrievedKeyPath,
@@ -33,14 +33,16 @@ func TestCliTcpTargetWorkerConnectTarget(t *testing.T) {
ctx := context.Background()
boundary.AuthenticateAdminCli(t, ctx)
newOrgId := boundary.CreateNewOrgCli(t, ctx)
orgId, err := boundary.CreateOrgCli(t, ctx)
require.NoError(t, err)
t.Cleanup(func() {
ctx := context.Background()
boundary.AuthenticateAdminCli(t, ctx)
output := e2e.RunCommand(ctx, "boundary", e2e.WithArgs("scopes", "delete", "-id", newOrgId))
output := e2e.RunCommand(ctx, "boundary", e2e.WithArgs("scopes", "delete", "-id", orgId))
require.NoError(t, output.Err, string(output.Stderr))
})
newProjectId := boundary.CreateNewProjectCli(t, ctx, newOrgId)
projectId, err := boundary.CreateProjectCli(t, ctx, orgId)
require.NoError(t, err)
// Configure vault
boundaryPolicyName, kvPolicyFilePath := vault.Setup(t, "testdata/boundary-controller-policy.hcl")
@@ -94,13 +96,14 @@ func TestCliTcpTargetWorkerConnectTarget(t *testing.T) {
t.Log("Created Vault Cred Store Token")
// Create a credential store
newCredentialStoreId := boundary.CreateNewCredentialStoreVaultCli(t, ctx, newProjectId, c.VaultAddr, credStoreToken)
storeId, err := boundary.CreateCredentialStoreVaultCli(t, ctx, projectId, c.VaultAddr, credStoreToken)
require.NoError(t, err)
// Create a credential library
newCredentialLibraryId, err := boundary.CreateVaultGenericCredentialLibraryCli(
libraryId, err := boundary.CreateVaultGenericCredentialLibraryCli(
t,
ctx,
newCredentialStoreId,
storeId,
fmt.Sprintf("%s/data/%s", c.VaultSecretPath, privateKeySecretName),
"ssh_private_key",
)
@@ -110,7 +113,7 @@ func TestCliTcpTargetWorkerConnectTarget(t *testing.T) {
output = e2e.RunCommand(ctx, "boundary",
e2e.WithArgs(
"credential-stores", "update", "vault",
"-id", newCredentialStoreId,
"-id", storeId,
"worker-filter", fmt.Sprintf(`"%s" in "/tags/type"`, c.WorkerTagEgress),
),
)
@@ -118,23 +121,25 @@ func TestCliTcpTargetWorkerConnectTarget(t *testing.T) {
require.Equal(t, 1, output.ExitCode)
// Create a target
newTargetId := boundary.CreateNewTargetCli(
targetId, err := boundary.CreateTargetCli(
t,
ctx,
newProjectId,
projectId,
c.TargetPort,
target.WithAddress("openssh-server"),
target.WithEgressWorkerFilter(fmt.Sprintf(`"%s" in "/tags/type"`, c.WorkerTagEgress)),
)
require.NoError(t, err)
// Add brokered credentials to target
boundary.AddBrokeredCredentialSourceToTargetCli(t, ctx, newTargetId, newCredentialLibraryId)
err = boundary.AddBrokeredCredentialSourceToTargetCli(t, ctx, targetId, libraryId)
require.NoError(t, err)
// Connect to target and print host's IP address using retrieved credentials
output = e2e.RunCommand(ctx, "boundary",
e2e.WithArgs(
"connect", "ssh",
"-target-id", newTargetId,
"-target-id", targetId,
"-remote-command", "hostname -i",
"--",
"-o", "UserKnownHostsFile=/dev/null",
@@ -153,7 +158,7 @@ func TestCliTcpTargetWorkerConnectTarget(t *testing.T) {
output = e2e.RunCommand(ctx, "boundary",
e2e.WithArgs(
"targets", "update", "tcp",
"-id", newTargetId,
"-id", targetId,
"-egress-worker-filter", fmt.Sprintf(`"%s" in "/tags/type"`, c.WorkerTagCollocated),
),
)
@@ -161,7 +166,7 @@ func TestCliTcpTargetWorkerConnectTarget(t *testing.T) {
output = e2e.RunCommand(ctx, "boundary",
e2e.WithArgs(
"connect", "ssh",
"-target-id", newTargetId,
"-target-id", targetId,
"-remote-command", "hostname -i",
"--",
"-o", "UserKnownHostsFile=/dev/null",
@@ -179,7 +184,7 @@ func TestCliTcpTargetWorkerConnectTarget(t *testing.T) {
e2e.WithArgs(
"targets", "create", "tcp",
"-name", "Target with Ingress Filter",
"-scope-id", newProjectId,
"-scope-id", projectId,
"-default-port", c.TargetPort,
"-ingress-worker-filter", `"tag" in "/tags/type"`,
),
@@ -190,7 +195,7 @@ func TestCliTcpTargetWorkerConnectTarget(t *testing.T) {
e2e.WithArgs(
"targets", "create", "tcp",
"-name", "Target with Ingress Filter",
"-scope-id", newProjectId,
"-scope-id", projectId,
"-default-port", c.TargetPort,
"-ingress-worker-filter", `"tag" in "/tags/type"`,
"-egress-worker-filter", fmt.Sprintf(`"%s" in "/tags/type"`, c.WorkerTagEgress),
@@ -211,47 +211,70 @@ func populateBoundaryDatabase(t testing.TB, ctx context.Context, c *config, te T
// While the CLI version used won't necessarily match the controller version, it should be (and is
// supposed to be) backwards compatible
boundary.AuthenticateCli(t, ctx, te.DbInitInfo.AuthMethod.AuthMethodId, te.DbInitInfo.AuthMethod.LoginName, te.DbInitInfo.AuthMethod.Password)
newOrgId := boundary.CreateNewOrgCli(t, ctx)
newProjectId := boundary.CreateNewProjectCli(t, ctx, newOrgId)
newHostCatalogId := boundary.CreateNewHostCatalogCli(t, ctx, newProjectId)
newHostSetId := boundary.CreateNewHostSetCli(t, ctx, newHostCatalogId)
newHostId := boundary.CreateNewHostCli(t, ctx, newHostCatalogId, te.Target.UriNetwork)
boundary.AddHostToHostSetCli(t, ctx, newHostSetId, newHostId)
newTargetId := boundary.CreateNewTargetCli(t, ctx, newProjectId, "2222") // openssh-server uses port 2222
boundary.AddHostSourceToTargetCli(t, ctx, newTargetId, newHostSetId)
orgId, err := boundary.CreateOrgCli(t, ctx)
require.NoError(t, err)
projectId, err := boundary.CreateProjectCli(t, ctx, orgId)
require.NoError(t, err)
hostCatalogId, err := boundary.CreateHostCatalogCli(t, ctx, projectId)
require.NoError(t, err)
hostSetId, err := boundary.CreateHostSetCli(t, ctx, hostCatalogId)
require.NoError(t, err)
hostId, err := boundary.CreateHostCli(t, ctx, hostCatalogId, te.Target.UriNetwork)
require.NoError(t, err)
err = boundary.AddHostToHostSetCli(t, ctx, hostSetId, hostId)
require.NoError(t, err)
targetId, err := boundary.CreateTargetCli(t, ctx, projectId, "2222") // openssh-server uses port 2222
require.NoError(t, err)
err = boundary.AddHostSourceToTargetCli(t, ctx, targetId, hostSetId)
require.NoError(t, err)
// Create a target with an address attached
_ = boundary.CreateNewTargetCli(
_, err = boundary.CreateTargetCli(
t,
ctx,
newProjectId,
projectId,
"2222",
target.WithName("e2e target with address"),
target.WithAddress(te.Target.UriNetwork),
)
require.NoError(t, err)
// Create AWS dynamic host catalog
newAwsHostCatalogId := boundary.CreateNewAwsHostCatalogCli(t, ctx, newProjectId, c.AwsAccessKeyId, c.AwsSecretAccessKey)
newAwsHostSetId := boundary.CreateNewAwsHostSetCli(t, ctx, newAwsHostCatalogId, c.AwsHostSetFilter)
boundary.WaitForHostsInHostSetCli(t, ctx, newAwsHostSetId)
awsHostCatalogId, err := boundary.CreateAwsHostCatalogCli(t, ctx, projectId, c.AwsAccessKeyId, c.AwsSecretAccessKey)
require.NoError(t, err)
awsHostSetId, err := boundary.CreateAwsHostSetCli(t, ctx, awsHostCatalogId, c.AwsHostSetFilter)
require.NoError(t, err)
boundary.WaitForHostsInHostSetCli(t, ctx, awsHostSetId)
// Create a user/group and add role to group
newAccountId, _ := boundary.CreateNewAccountCli(t, ctx, te.DbInitInfo.AuthMethod.AuthMethodId, "test-account")
newUserId := boundary.CreateNewUserCli(t, ctx, "global")
boundary.SetAccountToUserCli(t, ctx, newUserId, newAccountId)
newGroupId := boundary.CreateNewGroupCli(t, ctx, "global")
boundary.AddUserToGroup(t, ctx, newUserId, newGroupId)
newRoleId, err := boundary.CreateRoleCli(t, ctx, newProjectId)
accountId, _, err := boundary.CreateAccountCli(t, ctx, te.DbInitInfo.AuthMethod.AuthMethodId, "test-account")
require.NoError(t, err)
userId, err := boundary.CreateUserCli(t, ctx, "global")
require.NoError(t, err)
err = boundary.SetAccountToUserCli(t, ctx, userId, accountId)
require.NoError(t, err)
groupId, err := boundary.CreateGroupCli(t, ctx, "global")
require.NoError(t, err)
err = boundary.AddUserToGroup(t, ctx, userId, groupId)
require.NoError(t, err)
roleId, err := boundary.CreateRoleCli(t, ctx, projectId)
require.NoError(t, err)
err = boundary.AddGrantToRoleCli(t, ctx, roleId, "ids=*;type=target;actions=authorize-session")
require.NoError(t, err)
err = boundary.AddPrincipalToRoleCli(t, ctx, roleId, groupId)
require.NoError(t, err)
boundary.AddGrantToRoleCli(t, ctx, newRoleId, "ids=*;type=target;actions=authorize-session")
boundary.AddPrincipalToRoleCli(t, ctx, newRoleId, newGroupId)
// Create static credentials
newCredentialStoreId := boundary.CreateNewCredentialStoreStaticCli(t, ctx, newProjectId)
boundary.CreateNewStaticCredentialPasswordCli(t, ctx, newCredentialStoreId, c.TargetSshUser, "password")
boundary.CreateNewStaticCredentialJsonCli(t, ctx, newCredentialStoreId, "testdata/credential.json")
newCredentialsId := boundary.CreateNewStaticCredentialPrivateKeyCli(t, ctx, newCredentialStoreId, c.TargetSshUser, c.TargetSshKeyPath)
boundary.AddBrokeredCredentialSourceToTargetCli(t, ctx, newTargetId, newCredentialsId)
storeId, err := boundary.CreateCredentialStoreStaticCli(t, ctx, projectId)
require.NoError(t, err)
_, err = boundary.CreateStaticCredentialPasswordCli(t, ctx, storeId, c.TargetSshUser, "password")
require.NoError(t, err)
_, err = boundary.CreateStaticCredentialJsonCli(t, ctx, storeId, "testdata/credential.json")
require.NoError(t, err)
credentialsId, err := boundary.CreateStaticCredentialPrivateKeyCli(t, ctx, storeId, c.TargetSshUser, c.TargetSshKeyPath)
require.NoError(t, err)
err = boundary.AddBrokeredCredentialSourceToTargetCli(t, ctx, targetId, credentialsId)
require.NoError(t, err)
// Create vault credentials
boundaryPolicyName, kvPolicyFilePath := vault.Setup(t, "testdata/boundary-controller-policy.hcl")
@@ -284,13 +307,14 @@ func populateBoundaryDatabase(t testing.TB, ctx context.Context, c *config, te T
t.Log("Created Vault Cred Store Token")
// Create a credential store for vault
newVaultCredentialStoreId := boundary.CreateNewCredentialStoreVaultCli(t, ctx, newProjectId, te.Vault.UriNetwork, credStoreToken)
vaultStoreId, err := boundary.CreateCredentialStoreVaultCli(t, ctx, projectId, te.Vault.UriNetwork, credStoreToken)
require.NoError(t, err)
// Create a credential library for the private key in vault
_, err = boundary.CreateVaultGenericCredentialLibraryCli(
t,
ctx,
newVaultCredentialStoreId,
vaultStoreId,
fmt.Sprintf("%s/data/%s", c.VaultSecretPath, privateKeySecretName),
"ssh_private_key",
)
@@ -300,7 +324,7 @@ func populateBoundaryDatabase(t testing.TB, ctx context.Context, c *config, te T
_, err = boundary.CreateVaultGenericCredentialLibraryCli(
t,
ctx,
newVaultCredentialStoreId,
vaultStoreId,
fmt.Sprintf("%s/data/%s", c.VaultSecretPath, passwordSecretName),
"username_password",
)
@@ -359,7 +383,7 @@ func populateBoundaryDatabase(t testing.TB, ctx context.Context, c *config, te T
boundaryTag,
te.Boundary.UriNetwork,
auth_token,
newTargetId,
targetId,
)
t.Cleanup(func() {
if err := te.Pool.Purge(connectTarget.Resource); err != nil {