From fd1988e07ff95553b0a9eba253ced4ac510f3fb1 Mon Sep 17 00:00:00 2001 From: Timothy Messier Date: Thu, 11 Jan 2024 18:05:15 +0000 Subject: [PATCH] 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. --- internal/authtoken/authtoken_test.go | 5 ++++- internal/authtoken/repository_test.go | 9 ++++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/internal/authtoken/authtoken_test.go b/internal/authtoken/authtoken_test.go index debefc7bc5..6bc4e9451c 100644 --- a/internal/authtoken/authtoken_test.go +++ b/internal/authtoken/authtoken_test.go @@ -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) diff --git a/internal/authtoken/repository_test.go b/internal/authtoken/repository_test.go index b74b5e2c5f..8ad38c330e 100644 --- a/internal/authtoken/repository_test.go +++ b/internal/authtoken/repository_test.go @@ -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)