Files
threshold/internal/authtoken/testing.go
T
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

49 lines
1.6 KiB
Go

// Copyright IBM Corp. 2020, 2026
// SPDX-License-Identifier: BUSL-1.1
package authtoken
import (
"context"
"testing"
"repo.anhonesthost.net/CyberCoveLLC/threshold/internal/auth/password"
"repo.anhonesthost.net/CyberCoveLLC/threshold/internal/db"
"repo.anhonesthost.net/CyberCoveLLC/threshold/internal/iam"
"repo.anhonesthost.net/CyberCoveLLC/threshold/internal/kms"
"github.com/stretchr/testify/require"
)
// TestAuthToken, despite its name, does more than just return an auth token; it
// also creates an auth method, an account, and a user and binds them together,
// then creates an auth token against it
func TestAuthToken(t testing.TB, conn *db.DB, kms *kms.Kms, scopeId string, opt ...Option) *AuthToken {
t.Helper()
opts := getOpts(opt...)
passwordOpts := password.GetOpts(opts.withPasswordOptions...)
loginName := passwordOpts.WithLoginName
if loginName == "" {
loginName = "name1"
}
authMethod := password.TestAuthMethods(t, conn, scopeId, 1)[0]
// auth account is only used to join auth method to user.
// We don't do anything else with the auth account in the test setup.
acct := password.TestAccount(t, conn, authMethod.GetPublicId(), loginName, opts.withPasswordOptions...)
ctx := context.Background()
rw := db.New(conn)
iamRepo, err := iam.NewRepository(ctx, rw, rw, kms)
require.NoError(t, err)
u := iam.TestUser(t, iamRepo, scopeId, append(opts.withIamOptions, iam.WithAccountIds(acct.PublicId))...)
repo, err := NewRepository(ctx, rw, rw, kms)
require.NoError(t, err)
at, err := repo.CreateAuthToken(ctx, u, acct.GetPublicId(), opt...)
require.NoError(t, err)
return at
}