2020-07-07 07:44:49 -07:00
|
|
|
package authtoken
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"context"
|
|
|
|
|
"testing"
|
|
|
|
|
|
2020-08-10 17:15:02 -04:00
|
|
|
"github.com/hashicorp/boundary/internal/auth/password"
|
|
|
|
|
"github.com/hashicorp/boundary/internal/db"
|
|
|
|
|
"github.com/hashicorp/boundary/internal/iam"
|
2020-08-19 16:47:18 -04:00
|
|
|
"github.com/hashicorp/boundary/internal/kms"
|
2020-07-07 07:44:49 -07:00
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
|
)
|
|
|
|
|
|
2021-09-30 09:17:27 -04:00
|
|
|
func TestAuthToken(t *testing.T, conn *db.DB, kms *kms.Kms, scopeId string, opt ...Option) *AuthToken {
|
2020-07-07 07:44:49 -07:00
|
|
|
t.Helper()
|
2020-07-31 11:43:03 -07:00
|
|
|
authMethod := password.TestAuthMethods(t, conn, scopeId, 1)[0]
|
2020-07-07 07:44:49 -07:00
|
|
|
// 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.
|
2021-04-20 20:33:56 -04:00
|
|
|
acct := password.TestAccount(t, conn, authMethod.GetPublicId(), "name1")
|
2020-07-07 07:44:49 -07:00
|
|
|
|
2020-07-31 11:43:03 -07:00
|
|
|
ctx := context.Background()
|
2020-07-07 07:44:49 -07:00
|
|
|
rw := db.New(conn)
|
2020-08-19 16:47:18 -04:00
|
|
|
iamRepo, err := iam.NewRepository(rw, rw, kms)
|
2020-07-31 11:43:03 -07:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
2021-04-08 20:54:32 -04:00
|
|
|
u := iam.TestUser(t, iamRepo, scopeId, iam.WithAccountIds(acct.PublicId))
|
2020-07-31 11:43:03 -07:00
|
|
|
|
2020-08-19 16:47:18 -04:00
|
|
|
repo, err := NewRepository(rw, rw, kms)
|
2020-07-23 09:53:37 -07:00
|
|
|
require.NoError(t, err)
|
2020-07-07 07:44:49 -07:00
|
|
|
|
2021-04-08 20:54:32 -04:00
|
|
|
at, err := repo.CreateAuthToken(ctx, u, acct.GetPublicId(), opt...)
|
2020-07-23 09:53:37 -07:00
|
|
|
require.NoError(t, err)
|
2020-07-07 07:44:49 -07:00
|
|
|
return at
|
|
|
|
|
}
|