test(authtoken): Associate test account with a user

This test started failing now that the data warehouse records a auth
token fact when an auth token is issued and it requires that the auth
token has a user associated with it.

Since this test is testing the interaction with the database directly,
and not via the repository, it by-passes the application checks that
would prevent an auth token without an associated user being inserted.

This test is updated to meet this same pre-condition prior to attempting
to insert into the database.
tmessi-cp-monthly-active-users
Timothy Messier 2 years ago
parent b2ece14f0d
commit fd1988e07f
No known key found for this signature in database
GPG Key ID: EFD2F184F7600572

@ -131,13 +131,16 @@ func TestAuthToken_DbCreate(t *testing.T) {
ctx := context.Background()
conn, _ := db.TestSetup(t, "postgres")
rootWrapper := db.TestWrapper(t)
iamRepo := iam.TestRepo(t, conn, rootWrapper)
kms := kms.TestKms(t, conn, rootWrapper)
org, _ := iam.TestScopes(t, iam.TestRepo(t, conn, rootWrapper))
org, _ := iam.TestScopes(t, iamRepo)
wrapper, err := kms.GetWrapper(context.Background(), org.GetPublicId(), 1)
require.NoError(t, err)
user := iam.TestUser(t, iamRepo, org.GetPublicId())
am := password.TestAuthMethods(t, conn, org.GetPublicId(), 1)[0]
acct := password.TestAccount(t, conn, am.GetPublicId(), "name1")
createdAuthToken := TestAuthToken(t, conn, kms, org.GetPublicId())
iamRepo.AddUserAccounts(ctx, user.GetPublicId(), user.GetVersion(), []string{acct.GetPublicId()})
testAuthTokenId := func() string {
id, err := NewAuthTokenId(ctx)

@ -899,7 +899,9 @@ func Test_CloseExpiredPendingTokens(t *testing.T) {
repo, err := NewRepository(ctx, rw, rw, kmsCache)
require.NoError(t, err)
org, _ := iam.TestScopes(t, iam.TestRepo(t, conn, rootWrapper))
iamRepo := iam.TestRepo(t, conn, rootWrapper)
org, _ := iam.TestScopes(t, iamRepo)
user := iam.TestUser(t, iamRepo, org.GetPublicId())
databaseWrapper, err := kmsCache.GetWrapper(ctx, org.PublicId, kms.KeyPurposeDatabase)
require.NoError(t, err)
@ -909,6 +911,11 @@ func Test_CloseExpiredPendingTokens(t *testing.T) {
accts := password.TestMultipleAccounts(t, conn, authMethodId, cnt)
for i := 0; i < cnt; i++ {
user, _, err = iamRepo.LookupUser(ctx, user.GetPublicId())
require.NoError(t, err)
iamRepo.AddUserAccounts(ctx, user.GetPublicId(), user.GetVersion(), []string{accts[i].GetPublicId()})
at := allocAuthToken()
id, err := NewAuthTokenId(ctx)
require.NoError(t, err)

Loading…
Cancel
Save