mirror of
https://github.com/andwati/zitadel.git
synced 2026-10-18 05:52:51 +00:00
fix(authorizations): flaky integration tests (#11215)
# Which Problems Are Solved Flaky integration tests related to authorizations RT. # How the Problems Are Solved By setting the `created_at` and `updated_at` timestamps based on event timestamps while creating an authorization. # Additional Changes N/A # Additional Context https://cloud.nx.app/runs/ICj84SxEf0/task/%40zitadel%2Fapi%3Atest-integration
This commit is contained in:
@@ -43,7 +43,6 @@ func TestServer_AuthorizationReduces(t *testing.T) {
|
||||
role1, role2 := "role1", "role2"
|
||||
projectID := prepareProjectAndProjectRoles(t, orgID, []string{role1, role2})
|
||||
|
||||
//beforeCreate := time.Now()
|
||||
// create authorization
|
||||
createdAuthorization, err := AuthorizationClient.CreateAuthorization(CTX, &authorization_v2.CreateAuthorizationRequest{
|
||||
UserId: user.UserId,
|
||||
@@ -52,7 +51,6 @@ func TestServer_AuthorizationReduces(t *testing.T) {
|
||||
RoleKeys: []string{role1, role2},
|
||||
})
|
||||
require.NoError(t, err)
|
||||
//afterCreate := time.Now().Add(500 * time.Millisecond)
|
||||
|
||||
// add a new role to the project
|
||||
role3 := "role3"
|
||||
@@ -64,14 +62,12 @@ func TestServer_AuthorizationReduces(t *testing.T) {
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
||||
//beforeUpdate := time.Now()
|
||||
// update roles to [role1, role2, role3]
|
||||
_, err = AuthorizationClient.UpdateAuthorization(CTX, &authorization_v2.UpdateAuthorizationRequest{
|
||||
updated, err := AuthorizationClient.UpdateAuthorization(CTX, &authorization_v2.UpdateAuthorizationRequest{
|
||||
Id: createdAuthorization.Id,
|
||||
RoleKeys: []string{role1, role2, role3},
|
||||
})
|
||||
require.NoError(t, err)
|
||||
//afterUpdate := time.Now().Add(500 * time.Millisecond)
|
||||
|
||||
require.EventuallyWithT(t, func(collect *assert.CollectT) {
|
||||
az, err := authorizationRepo.Get(CTX, pool, database.WithCondition(
|
||||
@@ -80,8 +76,8 @@ func TestServer_AuthorizationReduces(t *testing.T) {
|
||||
require.NoError(collect, err)
|
||||
require.Len(collect, az.Roles, 3)
|
||||
assert.Equal(collect, []string{role1, role2, role3}, az.Roles)
|
||||
//assert.WithinRange(collect, az.UpdatedAt, beforeUpdate, afterUpdate)
|
||||
//assert.WithinRange(collect, az.CreatedAt, beforeCreate, afterCreate)
|
||||
assert.Equal(collect, createdAuthorization.GetCreationDate().AsTime(), az.CreatedAt.UTC())
|
||||
assert.Equal(collect, updated.GetChangeDate().AsTime(), az.UpdatedAt.UTC())
|
||||
}, retryDuration, tick, "authorization not updated within %v: %v", retryDuration, err)
|
||||
})
|
||||
|
||||
@@ -91,22 +87,18 @@ func TestServer_AuthorizationReduces(t *testing.T) {
|
||||
// prepare project and project roles
|
||||
projectID := prepareProjectAndProjectRoles(t, orgID, nil)
|
||||
// create authorization
|
||||
//beforeCreate := time.Now()
|
||||
createdAuthorization, err := AuthorizationClient.CreateAuthorization(CTX, &authorization_v2.CreateAuthorizationRequest{
|
||||
UserId: user.UserId,
|
||||
ProjectId: projectID,
|
||||
OrganizationId: orgID,
|
||||
})
|
||||
require.NoError(t, err)
|
||||
//afterCreate := time.Now().Add(500 * time.Millisecond)
|
||||
|
||||
//before := time.Now()
|
||||
// deactivate authorization
|
||||
_, err = AuthorizationClient.DeactivateAuthorization(CTX, &authorization_v2.DeactivateAuthorizationRequest{
|
||||
deactivated, err := AuthorizationClient.DeactivateAuthorization(CTX, &authorization_v2.DeactivateAuthorizationRequest{
|
||||
Id: createdAuthorization.Id,
|
||||
})
|
||||
require.NoError(t, err)
|
||||
//after := time.Now().Add(500 * time.Millisecond)
|
||||
|
||||
require.EventuallyWithT(t, func(collect *assert.CollectT) {
|
||||
az, err := authorizationRepo.Get(CTX, pool, database.WithCondition(
|
||||
@@ -114,8 +106,8 @@ func TestServer_AuthorizationReduces(t *testing.T) {
|
||||
))
|
||||
require.NoError(collect, err)
|
||||
assert.Equal(collect, domain.AuthorizationStateInactive, az.State)
|
||||
//assert.WithinRange(collect, az.UpdatedAt, before, after)
|
||||
//assert.WithinRange(collect, az.CreatedAt, beforeCreate, afterCreate)
|
||||
assert.Equal(collect, createdAuthorization.GetCreationDate().AsTime(), az.CreatedAt.UTC())
|
||||
assert.Equal(collect, deactivated.GetChangeDate().AsTime(), az.UpdatedAt.UTC())
|
||||
}, retryDuration, tick, "authorization not deactivated within %v: %v", retryDuration, err)
|
||||
})
|
||||
|
||||
@@ -125,14 +117,12 @@ func TestServer_AuthorizationReduces(t *testing.T) {
|
||||
// prepare project
|
||||
projectID := prepareProjectAndProjectRoles(t, orgID, nil)
|
||||
// create authorization
|
||||
//beforeCreate := time.Now()
|
||||
createdAuthorization, err := AuthorizationClient.CreateAuthorization(CTX, &authorization_v2.CreateAuthorizationRequest{
|
||||
UserId: user.UserId,
|
||||
ProjectId: projectID,
|
||||
OrganizationId: orgID,
|
||||
})
|
||||
require.NoError(t, err)
|
||||
//afterCreate := time.Now().Add(500 * time.Millisecond)
|
||||
|
||||
// deactivate authorization
|
||||
_, err = AuthorizationClient.DeactivateAuthorization(CTX, &authorization_v2.DeactivateAuthorizationRequest{
|
||||
@@ -140,13 +130,11 @@ func TestServer_AuthorizationReduces(t *testing.T) {
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
||||
//before := time.Now()
|
||||
// re-activate authorization
|
||||
_, err = AuthorizationClient.ActivateAuthorization(CTX, &authorization_v2.ActivateAuthorizationRequest{
|
||||
reactivated, err := AuthorizationClient.ActivateAuthorization(CTX, &authorization_v2.ActivateAuthorizationRequest{
|
||||
Id: createdAuthorization.Id,
|
||||
})
|
||||
require.NoError(t, err)
|
||||
//after := time.Now().Add(500 * time.Millisecond)
|
||||
|
||||
require.EventuallyWithT(t, func(collect *assert.CollectT) {
|
||||
az, err := authorizationRepo.Get(CTX, pool, database.WithCondition(
|
||||
@@ -154,8 +142,8 @@ func TestServer_AuthorizationReduces(t *testing.T) {
|
||||
))
|
||||
require.NoError(collect, err)
|
||||
assert.Equal(collect, domain.AuthorizationStateActive, az.State)
|
||||
//assert.WithinRange(collect, az.UpdatedAt, before, after)
|
||||
//assert.WithinRange(collect, az.CreatedAt, beforeCreate, afterCreate)
|
||||
assert.Equal(collect, createdAuthorization.GetCreationDate().AsTime(), az.CreatedAt.UTC())
|
||||
assert.Equal(collect, reactivated.GetChangeDate().AsTime(), az.UpdatedAt.UTC())
|
||||
}, retryDuration, tick, "authorization not activated within %v: %v", retryDuration, err)
|
||||
})
|
||||
|
||||
@@ -247,13 +235,11 @@ func TestServer_AuthorizationReduces(t *testing.T) {
|
||||
// create authorization with roles
|
||||
createdAuthorization := createAndEnsureAuthorization(t, instanceID, orgID, user.UserId, projectID, []string{role1, role2}, retryDuration, tick)
|
||||
// delete a project role
|
||||
//before := time.Now()
|
||||
_, err := ProjectClient.RemoveProjectRole(CTX, &project_v2beta.RemoveProjectRoleRequest{
|
||||
roleRemoved, err := ProjectClient.RemoveProjectRole(CTX, &project_v2beta.RemoveProjectRoleRequest{
|
||||
ProjectId: projectID,
|
||||
RoleKey: role2,
|
||||
})
|
||||
require.NoError(t, err)
|
||||
//after := time.Now()
|
||||
|
||||
// ensure authorization is updated
|
||||
require.EventuallyWithT(t, func(collect *assert.CollectT) {
|
||||
@@ -263,7 +249,10 @@ func TestServer_AuthorizationReduces(t *testing.T) {
|
||||
require.NoError(collect, err)
|
||||
assert.Equal(collect, []string{role1}, az.Roles)
|
||||
assert.Equal(collect, domain.AuthorizationStateActive, az.State)
|
||||
//assert.WithinRange(collect, az.UpdatedAt, before, after)
|
||||
assert.Equal(collect, createdAuthorization.GetCreationDate().AsTime(), az.CreatedAt.UTC())
|
||||
// project role removal triggers a UserGrantCascadeChangedEvent,
|
||||
// so the RT UpdatedAt should match the role removal time
|
||||
assert.Equal(collect, roleRemoved.GetRemovalDate().AsTime(), az.UpdatedAt.UTC())
|
||||
}, retryDuration, tick, "authorization not updated within %v: %v", retryDuration, err)
|
||||
})
|
||||
|
||||
@@ -346,14 +335,12 @@ func TestServer_AuthorizationReduces(t *testing.T) {
|
||||
// create authorization with roles
|
||||
createdAuthorization := createAndEnsureAuthorization(t, instanceID, grantedOrganization.OrganizationId, user.UserId, projectID, []string{role1, role2}, retryDuration, tick)
|
||||
// update project grant
|
||||
//beforeUpdate := time.Now()
|
||||
_, err = ProjectClient.UpdateProjectGrant(CTX, &project_v2beta.UpdateProjectGrantRequest{
|
||||
ProjectId: projectID,
|
||||
GrantedOrganizationId: grantedOrganization.OrganizationId,
|
||||
RoleKeys: []string{role1},
|
||||
})
|
||||
require.NoError(t, err)
|
||||
//afterUpdate := time.Now().Add(500 * time.Millisecond) // add some buffer for eventual consistency of cascading changes
|
||||
|
||||
// ensure authorization is updated
|
||||
require.EventuallyWithT(t, func(collect *assert.CollectT) {
|
||||
@@ -362,7 +349,10 @@ func TestServer_AuthorizationReduces(t *testing.T) {
|
||||
))
|
||||
require.NoError(collect, err)
|
||||
assert.Equal(collect, []string{role1}, az.Roles)
|
||||
//assert.WithinRange(collect, az.UpdatedAt, beforeUpdate, afterUpdate)
|
||||
assert.Equal(collect, createdAuthorization.GetCreationDate().AsTime(), az.CreatedAt.UTC())
|
||||
// (@grvijayan) todo: should we check the timestamp here?
|
||||
// the authorization/authorization_roles RT is updated based on cascade deletions in the project_grant_roles table,
|
||||
// so the project grant update time cannot be used here
|
||||
}, retryDuration, tick, "authorization not updated within %v: %v", retryDuration, err)
|
||||
})
|
||||
|
||||
@@ -407,7 +397,6 @@ func TestServer_AuthorizationReduces(t *testing.T) {
|
||||
_ = instance.AddProjectRole(CTX, t, projectResp.Id, role2, "display", "")
|
||||
|
||||
// create authorization with roles
|
||||
//beforeCreate := time.Now()
|
||||
createdAuthorization, err := instance.Client.AuthorizationV2.CreateAuthorization(CTX, &authorization_v2.CreateAuthorizationRequest{
|
||||
UserId: user.UserId,
|
||||
ProjectId: projectResp.Id,
|
||||
@@ -415,7 +404,6 @@ func TestServer_AuthorizationReduces(t *testing.T) {
|
||||
OrganizationId: orgResp.OrganizationId,
|
||||
})
|
||||
require.NoError(t, err)
|
||||
//afterCreate := time.Now().Add(500 * time.Millisecond)
|
||||
|
||||
// ensure authorization exists
|
||||
require.EventuallyWithT(t, func(collect *assert.CollectT) {
|
||||
@@ -425,8 +413,8 @@ func TestServer_AuthorizationReduces(t *testing.T) {
|
||||
require.NoError(collect, err)
|
||||
assert.Equal(collect, []string{role1, role2}, az.Roles)
|
||||
assert.Equal(collect, domain.AuthorizationStateActive, az.State)
|
||||
//assert.WithinRange(collect, az.CreatedAt, beforeCreate, afterCreate)
|
||||
//assert.WithinRange(collect, az.UpdatedAt, beforeCreate, afterCreate)
|
||||
assert.Equal(collect, createdAuthorization.GetCreationDate().AsTime(), az.CreatedAt.UTC())
|
||||
assert.Equal(collect, createdAuthorization.GetCreationDate().AsTime(), az.UpdatedAt.UTC())
|
||||
}, retryDuration, tick, "authorization not found within %v: %v", retryDuration, err)
|
||||
|
||||
// delete the instance
|
||||
@@ -448,7 +436,6 @@ func TestServer_AuthorizationReduces(t *testing.T) {
|
||||
|
||||
func createAndEnsureAuthorization(t *testing.T, instanceID, orgID, userID, projectID string, roles []string, retryDuration time.Duration, tick time.Duration) *authorization_v2.CreateAuthorizationResponse {
|
||||
// create authorization
|
||||
//beforeCreate := time.Now()
|
||||
createdAuthorization, err := AuthorizationClient.CreateAuthorization(CTX, &authorization_v2.CreateAuthorizationRequest{
|
||||
UserId: userID,
|
||||
ProjectId: projectID,
|
||||
@@ -456,7 +443,6 @@ func createAndEnsureAuthorization(t *testing.T, instanceID, orgID, userID, proje
|
||||
OrganizationId: orgID,
|
||||
})
|
||||
require.NoError(t, err)
|
||||
//afterCreate := time.Now().Add(500 * time.Millisecond)
|
||||
// ensure authorization exists
|
||||
authzRepo := repository.AuthorizationRepository()
|
||||
require.EventuallyWithT(t, func(collect *assert.CollectT) {
|
||||
@@ -466,8 +452,8 @@ func createAndEnsureAuthorization(t *testing.T, instanceID, orgID, userID, proje
|
||||
require.NoError(collect, err)
|
||||
assert.Equal(collect, roles, az.Roles)
|
||||
assert.Equal(collect, domain.AuthorizationStateActive, az.State)
|
||||
//assert.WithinRange(collect, az.CreatedAt, beforeCreate, afterCreate)
|
||||
//assert.WithinRange(collect, az.UpdatedAt, beforeCreate, afterCreate)
|
||||
assert.Equal(collect, createdAuthorization.GetCreationDate().AsTime().UTC(), az.CreatedAt.UTC())
|
||||
assert.Equal(collect, createdAuthorization.GetCreationDate().AsTime().UTC(), az.UpdatedAt.UTC())
|
||||
}, retryDuration, tick, "authorization not found within %v: %v", retryDuration, err)
|
||||
return createdAuthorization
|
||||
}
|
||||
|
||||
@@ -37,18 +37,28 @@ func (a authorization) qualifiedAuthorizationRolesTableName() string {
|
||||
// -------------------------------------------------------------
|
||||
|
||||
const insertAuthorizationStmt = `INSERT INTO zitadel.authorizations (
|
||||
instance_id, id, user_id, grant_id, project_id, state
|
||||
instance_id, id, user_id, grant_id, project_id, state, created_at, updated_at
|
||||
)
|
||||
VALUES ($1, $2, $3, $4, $5, $6)
|
||||
VALUES ($1, $2, $3, $4, $5, $6, $7, $8)
|
||||
RETURNING created_at, updated_at`
|
||||
|
||||
const insertAuthorizationWithRolesStmt = `WITH roles AS (
|
||||
INSERT INTO zitadel.authorization_roles
|
||||
(instance_id, authorization_id, grant_id, project_id, role_key)
|
||||
VALUES ($1, $2, $4, $5, unnest($7::text[])))` + insertAuthorizationStmt
|
||||
VALUES ($1, $2, $4, $5, unnest($9::text[])))` + insertAuthorizationStmt
|
||||
|
||||
// Create implements [domain.AuthorizationRepository].
|
||||
func (a authorization) Create(ctx context.Context, client database.QueryExecutor, authorization *domain.Authorization) error {
|
||||
var (
|
||||
createdAt, updatedAt any = database.DefaultInstruction, database.DefaultInstruction
|
||||
)
|
||||
if !authorization.CreatedAt.IsZero() {
|
||||
createdAt = authorization.CreatedAt
|
||||
}
|
||||
if !authorization.UpdatedAt.IsZero() {
|
||||
updatedAt = authorization.UpdatedAt
|
||||
}
|
||||
|
||||
builder := database.NewStatementBuilder(insertAuthorizationWithRolesStmt,
|
||||
authorization.InstanceID,
|
||||
authorization.ID,
|
||||
@@ -56,6 +66,8 @@ func (a authorization) Create(ctx context.Context, client database.QueryExecutor
|
||||
authorization.GrantID,
|
||||
authorization.ProjectID,
|
||||
authorization.State,
|
||||
createdAt,
|
||||
updatedAt,
|
||||
authorization.Roles,
|
||||
)
|
||||
|
||||
|
||||
@@ -44,6 +44,8 @@ func TestCreateAuthorization(t *testing.T) {
|
||||
InstanceID: instanceID,
|
||||
State: domain.AuthorizationStateActive,
|
||||
Roles: []string{role1},
|
||||
CreatedAt: time.Now(),
|
||||
UpdatedAt: time.Now(),
|
||||
}
|
||||
err := authorizationRepo.Create(t.Context(), tx, existingAuthorization)
|
||||
require.NoError(t, err)
|
||||
@@ -66,6 +68,8 @@ func TestCreateAuthorization(t *testing.T) {
|
||||
InstanceID: "random-id",
|
||||
State: domain.AuthorizationStateActive,
|
||||
Roles: nil,
|
||||
CreatedAt: time.Now(),
|
||||
UpdatedAt: time.Now(),
|
||||
},
|
||||
wantErr: new(database.ForeignKeyError),
|
||||
},
|
||||
@@ -78,6 +82,8 @@ func TestCreateAuthorization(t *testing.T) {
|
||||
InstanceID: instanceID,
|
||||
State: domain.AuthorizationStateActive,
|
||||
Roles: nil,
|
||||
CreatedAt: time.Now(),
|
||||
UpdatedAt: time.Now(),
|
||||
},
|
||||
wantErr: new(database.ForeignKeyError),
|
||||
},
|
||||
@@ -90,6 +96,8 @@ func TestCreateAuthorization(t *testing.T) {
|
||||
InstanceID: instanceID,
|
||||
State: domain.AuthorizationStateActive,
|
||||
Roles: []string{"role3"},
|
||||
CreatedAt: time.Now(),
|
||||
UpdatedAt: time.Now(),
|
||||
},
|
||||
wantErr: new(database.ForeignKeyError),
|
||||
},
|
||||
@@ -103,6 +111,8 @@ func TestCreateAuthorization(t *testing.T) {
|
||||
InstanceID: instanceID,
|
||||
State: domain.AuthorizationStateActive,
|
||||
Roles: nil,
|
||||
CreatedAt: time.Now(),
|
||||
UpdatedAt: time.Now(),
|
||||
},
|
||||
wantErr: new(database.ForeignKeyError),
|
||||
},
|
||||
@@ -129,6 +139,8 @@ func TestCreateAuthorization(t *testing.T) {
|
||||
InstanceID: existingAuthorization.InstanceID,
|
||||
State: domain.AuthorizationStateActive,
|
||||
Roles: nil,
|
||||
CreatedAt: time.Now(),
|
||||
UpdatedAt: time.Now(),
|
||||
},
|
||||
wantErr: database.NewUniqueError("authorizations", "uq_authorizations_instance_id_id", nil),
|
||||
},
|
||||
@@ -140,6 +152,8 @@ func TestCreateAuthorization(t *testing.T) {
|
||||
InstanceID: instanceID,
|
||||
State: domain.AuthorizationStateActive,
|
||||
Roles: nil,
|
||||
CreatedAt: time.Now(),
|
||||
UpdatedAt: time.Now(),
|
||||
},
|
||||
wantErr: database.NewCheckError("authorizations", "", nil),
|
||||
},
|
||||
@@ -152,6 +166,8 @@ func TestCreateAuthorization(t *testing.T) {
|
||||
InstanceID: instanceID,
|
||||
State: domain.AuthorizationStateActive,
|
||||
Roles: nil,
|
||||
CreatedAt: time.Now(),
|
||||
UpdatedAt: time.Now(),
|
||||
},
|
||||
},
|
||||
{
|
||||
@@ -163,6 +179,8 @@ func TestCreateAuthorization(t *testing.T) {
|
||||
InstanceID: instanceID,
|
||||
State: domain.AuthorizationStateActive,
|
||||
Roles: []string{role1, role2},
|
||||
CreatedAt: time.Now(),
|
||||
UpdatedAt: time.Now(),
|
||||
},
|
||||
},
|
||||
{
|
||||
@@ -175,6 +193,8 @@ func TestCreateAuthorization(t *testing.T) {
|
||||
InstanceID: instanceID,
|
||||
State: domain.AuthorizationStateActive,
|
||||
Roles: []string{role1},
|
||||
CreatedAt: time.Now(),
|
||||
UpdatedAt: time.Now(),
|
||||
},
|
||||
},
|
||||
{
|
||||
@@ -187,6 +207,8 @@ func TestCreateAuthorization(t *testing.T) {
|
||||
InstanceID: instanceID,
|
||||
State: domain.AuthorizationStateActive,
|
||||
Roles: []string{role2},
|
||||
CreatedAt: time.Now(),
|
||||
UpdatedAt: time.Now(),
|
||||
},
|
||||
wantErr: new(database.ForeignKeyError),
|
||||
},
|
||||
@@ -200,6 +222,8 @@ func TestCreateAuthorization(t *testing.T) {
|
||||
InstanceID: instanceID,
|
||||
State: domain.AuthorizationStateActive,
|
||||
Roles: nil,
|
||||
CreatedAt: time.Now(),
|
||||
UpdatedAt: time.Now(),
|
||||
},
|
||||
},
|
||||
}
|
||||
@@ -255,6 +279,8 @@ func TestGetAuthorization(t *testing.T) {
|
||||
InstanceID: instanceID,
|
||||
State: domain.AuthorizationStateActive,
|
||||
Roles: []string{role1, role2},
|
||||
CreatedAt: time.Now(),
|
||||
UpdatedAt: time.Now(),
|
||||
}
|
||||
err := authorizationRepo.Create(t.Context(), tx, authorizationWithRolesUser)
|
||||
require.NoError(t, err)
|
||||
@@ -267,6 +293,8 @@ func TestGetAuthorization(t *testing.T) {
|
||||
InstanceID: instanceID,
|
||||
State: domain.AuthorizationStateActive,
|
||||
Roles: nil,
|
||||
CreatedAt: time.Now(),
|
||||
UpdatedAt: time.Now(),
|
||||
}
|
||||
err = authorizationRepo.Create(t.Context(), tx, authorizationWithoutRolesUser)
|
||||
require.NoError(t, err)
|
||||
@@ -283,6 +311,8 @@ func TestGetAuthorization(t *testing.T) {
|
||||
InstanceID: instanceID,
|
||||
State: domain.AuthorizationStateActive,
|
||||
Roles: []string{role1},
|
||||
CreatedAt: time.Now(),
|
||||
UpdatedAt: time.Now(),
|
||||
}
|
||||
err = authorizationRepo.Create(t.Context(), tx, authorizationProjectGrantWithRoles)
|
||||
require.NoError(t, err)
|
||||
@@ -294,6 +324,8 @@ func TestGetAuthorization(t *testing.T) {
|
||||
GrantID: gu.Ptr(grantID),
|
||||
InstanceID: instanceID,
|
||||
State: domain.AuthorizationStateActive,
|
||||
CreatedAt: time.Now(),
|
||||
UpdatedAt: time.Now(),
|
||||
}
|
||||
err = authorizationRepo.Create(t.Context(), tx, authorizationProjectGrantWithoutRoles)
|
||||
require.NoError(t, err)
|
||||
@@ -443,6 +475,8 @@ func TestListAuthorization(t *testing.T) {
|
||||
InstanceID: instanceID,
|
||||
State: domain.AuthorizationStateActive,
|
||||
Roles: []string{project1Role1, project1Role2},
|
||||
CreatedAt: time.Now(),
|
||||
UpdatedAt: time.Now(),
|
||||
}
|
||||
err := authorizationRepo.Create(t.Context(), tx, authorizationWithRolesUser1Project1)
|
||||
require.NoError(t, err)
|
||||
@@ -455,6 +489,8 @@ func TestListAuthorization(t *testing.T) {
|
||||
InstanceID: instanceID,
|
||||
State: domain.AuthorizationStateActive,
|
||||
Roles: nil,
|
||||
CreatedAt: time.Now(),
|
||||
UpdatedAt: time.Now(),
|
||||
}
|
||||
err = authorizationRepo.Create(t.Context(), tx, authorizationWithoutRolesUser1Project1)
|
||||
require.NoError(t, err)
|
||||
@@ -467,6 +503,8 @@ func TestListAuthorization(t *testing.T) {
|
||||
InstanceID: instanceID,
|
||||
State: domain.AuthorizationStateActive,
|
||||
Roles: []string{project2Role1, project2Role2},
|
||||
CreatedAt: time.Now(),
|
||||
UpdatedAt: time.Now(),
|
||||
}
|
||||
err = authorizationRepo.Create(t.Context(), tx, authorizationWithRolesUser1Project2)
|
||||
require.NoError(t, err)
|
||||
@@ -480,6 +518,8 @@ func TestListAuthorization(t *testing.T) {
|
||||
InstanceID: instanceID,
|
||||
State: domain.AuthorizationStateInactive,
|
||||
Roles: nil,
|
||||
CreatedAt: time.Now(),
|
||||
UpdatedAt: time.Now(),
|
||||
}
|
||||
err = authorizationRepo.Create(t.Context(), tx, authorizationWithoutRolesUser1Project2)
|
||||
require.NoError(t, err)
|
||||
@@ -493,6 +533,8 @@ func TestListAuthorization(t *testing.T) {
|
||||
InstanceID: instanceID,
|
||||
State: domain.AuthorizationStateActive,
|
||||
Roles: []string{project1Role1, project1Role2},
|
||||
CreatedAt: time.Now(),
|
||||
UpdatedAt: time.Now(),
|
||||
}
|
||||
err = authorizationRepo.Create(t.Context(), tx, authorizationWithRolesUser2Project1)
|
||||
require.NoError(t, err)
|
||||
@@ -505,6 +547,8 @@ func TestListAuthorization(t *testing.T) {
|
||||
InstanceID: instanceID,
|
||||
State: domain.AuthorizationStateInactive,
|
||||
Roles: nil,
|
||||
CreatedAt: time.Now(),
|
||||
UpdatedAt: time.Now(),
|
||||
}
|
||||
err = authorizationRepo.Create(t.Context(), tx, authorizationWithoutRolesUser2Project1)
|
||||
require.NoError(t, err)
|
||||
@@ -517,6 +561,8 @@ func TestListAuthorization(t *testing.T) {
|
||||
InstanceID: instanceID,
|
||||
State: domain.AuthorizationStateActive,
|
||||
Roles: []string{project2Role1, project2Role2},
|
||||
CreatedAt: time.Now(),
|
||||
UpdatedAt: time.Now(),
|
||||
}
|
||||
err = authorizationRepo.Create(t.Context(), tx, authorizationWithRolesUser2Project2)
|
||||
require.NoError(t, err)
|
||||
@@ -529,6 +575,8 @@ func TestListAuthorization(t *testing.T) {
|
||||
InstanceID: instanceID,
|
||||
State: domain.AuthorizationStateActive,
|
||||
Roles: nil,
|
||||
CreatedAt: time.Now(),
|
||||
UpdatedAt: time.Now(),
|
||||
}
|
||||
err = authorizationRepo.Create(t.Context(), tx, authorizationWithoutRolesUser2Project2)
|
||||
require.NoError(t, err)
|
||||
@@ -545,6 +593,8 @@ func TestListAuthorization(t *testing.T) {
|
||||
InstanceID: instanceID,
|
||||
State: domain.AuthorizationStateActive,
|
||||
Roles: []string{project1Role1},
|
||||
CreatedAt: time.Now(),
|
||||
UpdatedAt: time.Now(),
|
||||
}
|
||||
err = authorizationRepo.Create(t.Context(), tx, authorizationProjectGrantWithRoles)
|
||||
require.NoError(t, err)
|
||||
@@ -556,6 +606,8 @@ func TestListAuthorization(t *testing.T) {
|
||||
GrantID: gu.Ptr(grantID),
|
||||
InstanceID: instanceID,
|
||||
State: domain.AuthorizationStateActive,
|
||||
CreatedAt: time.Now(),
|
||||
UpdatedAt: time.Now(),
|
||||
}
|
||||
err = authorizationRepo.Create(t.Context(), tx, authorizationProjectGrantWithoutRoles)
|
||||
require.NoError(t, err)
|
||||
@@ -847,6 +899,8 @@ func TestUpdateAuthorization(t *testing.T) {
|
||||
InstanceID: instanceID,
|
||||
State: domain.AuthorizationStateActive,
|
||||
Roles: nil,
|
||||
CreatedAt: time.Now(),
|
||||
UpdatedAt: time.Now(),
|
||||
}
|
||||
err := authorizationRepo.Create(t.Context(), tx, activeAuthorization)
|
||||
require.NoError(t, err)
|
||||
@@ -858,6 +912,8 @@ func TestUpdateAuthorization(t *testing.T) {
|
||||
InstanceID: instanceID,
|
||||
State: domain.AuthorizationStateInactive,
|
||||
Roles: nil,
|
||||
CreatedAt: time.Now(),
|
||||
UpdatedAt: time.Now(),
|
||||
}
|
||||
err = authorizationRepo.Create(t.Context(), tx, inactiveAuthorization)
|
||||
require.NoError(t, err)
|
||||
@@ -964,6 +1020,8 @@ func TestAuthorizationUpdate_setRoles(t *testing.T) {
|
||||
InstanceID: instanceID,
|
||||
State: domain.AuthorizationStateActive,
|
||||
Roles: nil,
|
||||
CreatedAt: time.Now(),
|
||||
UpdatedAt: time.Now(),
|
||||
}
|
||||
err := authorizationRepo.Create(t.Context(), tx, authorization1)
|
||||
require.NoError(t, err)
|
||||
@@ -975,6 +1033,8 @@ func TestAuthorizationUpdate_setRoles(t *testing.T) {
|
||||
InstanceID: instanceID,
|
||||
State: domain.AuthorizationStateActive,
|
||||
Roles: []string{role5, role6},
|
||||
CreatedAt: time.Now(),
|
||||
UpdatedAt: time.Now(),
|
||||
}
|
||||
err = authorizationRepo.Create(t.Context(), tx, authorization2)
|
||||
require.NoError(t, err)
|
||||
@@ -1081,6 +1141,8 @@ func TestDeleteAuthorization(t *testing.T) {
|
||||
InstanceID: instanceID,
|
||||
State: domain.AuthorizationStateActive,
|
||||
Roles: []string{role1, role2},
|
||||
CreatedAt: time.Now(),
|
||||
UpdatedAt: time.Now(),
|
||||
}
|
||||
err := authorizationRepo.Create(t.Context(), tx, authorizationWithRoles)
|
||||
require.NoError(t, err)
|
||||
@@ -1092,6 +1154,8 @@ func TestDeleteAuthorization(t *testing.T) {
|
||||
InstanceID: instanceID,
|
||||
State: domain.AuthorizationStateActive,
|
||||
Roles: nil,
|
||||
CreatedAt: time.Now(),
|
||||
UpdatedAt: time.Now(),
|
||||
}
|
||||
err = authorizationRepo.Create(t.Context(), tx, authorizationWithoutRoles)
|
||||
require.NoError(t, err)
|
||||
@@ -1103,6 +1167,8 @@ func TestDeleteAuthorization(t *testing.T) {
|
||||
InstanceID: instanceID,
|
||||
State: domain.AuthorizationStateActive,
|
||||
Roles: nil,
|
||||
CreatedAt: time.Now(),
|
||||
UpdatedAt: time.Now(),
|
||||
}
|
||||
err = authorizationRepo.Create(t.Context(), tx, deletedAuthorization)
|
||||
require.NoError(t, err)
|
||||
@@ -1122,6 +1188,8 @@ func TestDeleteAuthorization(t *testing.T) {
|
||||
InstanceID: instanceID,
|
||||
State: domain.AuthorizationStateActive,
|
||||
Roles: []string{role1},
|
||||
CreatedAt: time.Now(),
|
||||
UpdatedAt: time.Now(),
|
||||
}
|
||||
err = authorizationRepo.Create(t.Context(), tx, authorizationProjectGrant)
|
||||
require.NoError(t, err)
|
||||
|
||||
Reference in New Issue
Block a user