* 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
84 lines
2.0 KiB
Go
84 lines
2.0 KiB
Go
// Copyright (c) HashiCorp, Inc.
|
|
// SPDX-License-Identifier: BUSL-1.1
|
|
|
|
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/hashicorp/go-secure-stdlib/base62"
|
|
)
|
|
|
|
// CreateUserApi creates a new user using the Go api.
|
|
// Returns the id of the new user
|
|
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
|
|
}
|
|
|
|
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
|
|
}
|
|
|
|
// CreateUserCli creates a new user using the cli.
|
|
// Returns the id of the new user
|
|
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", fmt.Sprintf("e2e User %s", name),
|
|
"-description", "e2e",
|
|
"-format", "json",
|
|
),
|
|
)
|
|
if output.Err != nil {
|
|
return "", fmt.Errorf("%w: %s", output.Err, string(output.Stderr))
|
|
}
|
|
|
|
var createUserResult users.UserCreateResult
|
|
err = json.Unmarshal(output.Stdout, &createUserResult)
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
|
|
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) error {
|
|
output := e2e.RunCommand(ctx, "boundary",
|
|
e2e.WithArgs(
|
|
"users", "set-accounts",
|
|
"-id", userId,
|
|
"-account", accountId,
|
|
),
|
|
)
|
|
if output.Err != nil {
|
|
return fmt.Errorf("%w: %s", output.Err, string(output.Stderr))
|
|
}
|
|
|
|
return nil
|
|
}
|