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.
This commit is contained in:
2 files changed
+12
-2
No files matched your search
@@ -130,13 +130,16 @@ func TestAuthToken_DbCreate(t *testing.T) {
|
|||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
conn, _ := db.TestSetup(t, "postgres")
|
conn, _ := db.TestSetup(t, "postgres")
|
||||||
rootWrapper := db.TestWrapper(t)
|
rootWrapper := db.TestWrapper(t)
|
||||||
|
iamRepo := iam.TestRepo(t, conn, rootWrapper)
|
||||||
kms := kms.TestKms(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)
|
wrapper, err := kms.GetWrapper(context.Background(), org.GetPublicId(), 1)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
user := iam.TestUser(t, iamRepo, org.GetPublicId())
|
||||||
am := password.TestAuthMethods(t, conn, org.GetPublicId(), 1)[0]
|
am := password.TestAuthMethods(t, conn, org.GetPublicId(), 1)[0]
|
||||||
acct := password.TestAccount(t, conn, am.GetPublicId(), "name1")
|
acct := password.TestAccount(t, conn, am.GetPublicId(), "name1")
|
||||||
createdAuthToken := TestAuthToken(t, conn, kms, org.GetPublicId())
|
createdAuthToken := TestAuthToken(t, conn, kms, org.GetPublicId())
|
||||||
|
iamRepo.AddUserAccounts(ctx, user.GetPublicId(), user.GetVersion(), []string{acct.GetPublicId()})
|
||||||
|
|
||||||
testAuthTokenId := func() string {
|
testAuthTokenId := func() string {
|
||||||
id, err := NewAuthTokenId(ctx)
|
id, err := NewAuthTokenId(ctx)
|
||||||
|
|||||||
@@ -890,7 +890,9 @@ func Test_CloseExpiredPendingTokens(t *testing.T) {
|
|||||||
repo, err := NewRepository(ctx, rw, rw, kmsCache)
|
repo, err := NewRepository(ctx, rw, rw, kmsCache)
|
||||||
require.NoError(t, err)
|
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)
|
databaseWrapper, err := kmsCache.GetWrapper(ctx, org.PublicId, kms.KeyPurposeDatabase)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
@@ -900,6 +902,11 @@ func Test_CloseExpiredPendingTokens(t *testing.T) {
|
|||||||
|
|
||||||
accts := password.TestMultipleAccounts(t, conn, authMethodId, cnt)
|
accts := password.TestMultipleAccounts(t, conn, authMethodId, cnt)
|
||||||
for i := 0; i < cnt; i++ {
|
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()
|
at := allocAuthToken()
|
||||||
id, err := NewAuthTokenId(ctx)
|
id, err := NewAuthTokenId(ctx)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|||||||
Reference in new issue
Block a user