Files
shadowdaoandClaude Sonnet 5.5 962d708fdd Rename Go module paths to repo.anhonesthost.net/CyberCoveLLC/threshold
Rename root, api and sdk module paths (imports, go.mod, go_package,
ldflags, build scripts, buf configs) and regenerate protobuf/gateway
code with the project's pinned toolchain. Wire identifiers unchanged.
api gets a local replace for sdk; root/api/sdk require v0.1.0.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-10-12 10:33:41 -07:00

96 lines
2.3 KiB
Go

// Copyright IBM Corp. 2020, 2026
// SPDX-License-Identifier: BUSL-1.1
package boundary
import (
"context"
"encoding/json"
"fmt"
"testing"
"repo.anhonesthost.net/CyberCoveLLC/threshold/api"
"repo.anhonesthost.net/CyberCoveLLC/threshold/api/users"
"repo.anhonesthost.net/CyberCoveLLC/threshold/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, opt ...e2e.Option) (string, error) {
name, err := base62.Random(16)
if err != nil {
return "", err
}
var options []e2e.Option
options = append(options,
e2e.WithArgs(
"users", "create",
"-scope-id", scopeId,
"-name", fmt.Sprintf("e2e User %s", name),
"-description", "e2e",
"-format", "json",
),
)
options = append(options, opt...)
output := e2e.RunCommand(ctx, "boundary",
options...,
)
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, opt ...e2e.Option) error {
var options []e2e.Option
options = append(options,
e2e.WithArgs(
"users", "set-accounts",
"-id", userId,
"-account", accountId,
),
)
options = append(options, opt...)
output := e2e.RunCommand(ctx, "boundary",
options...,
)
if output.Err != nil {
return fmt.Errorf("%w: %s", output.Err, string(output.Stderr))
}
return nil
}