mirror of
https://github.com/andwati/zitadel.git
synced 2026-11-10 16:15:12 +00:00
chore: fix some eventual consistent integration testing (#10752)
# Which Problems Are Solved Flakiness in integration tests because of eventual consistentcy. # How the Problems Are Solved Split tests related to feature flags and other eventual consistent resources. # Additional Changes None # Additional Context None Co-authored-by: Marco A. <[email protected]>
This commit is contained in:
@@ -8,6 +8,8 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
"github.com/zitadel/logging"
|
||||
|
||||
"github.com/zitadel/zitadel/internal/integration"
|
||||
@@ -16,15 +18,13 @@ import (
|
||||
)
|
||||
|
||||
var (
|
||||
CTX context.Context
|
||||
IAMOwnerCTX context.Context
|
||||
UserCTX context.Context
|
||||
LoginCTX context.Context
|
||||
Instance *integration.Instance
|
||||
Client session.SessionServiceClient
|
||||
User *user.AddHumanUserResponse
|
||||
DeactivatedUser *user.AddHumanUserResponse
|
||||
LockedUser *user.AddHumanUserResponse
|
||||
CTX context.Context
|
||||
IAMOwnerCTX context.Context
|
||||
UserCTX context.Context
|
||||
LoginCTX context.Context
|
||||
Instance *integration.Instance
|
||||
Client session.SessionServiceClient
|
||||
User *user.AddHumanUserResponse
|
||||
)
|
||||
|
||||
func TestMain(m *testing.M) {
|
||||
@@ -40,8 +40,6 @@ func TestMain(m *testing.M) {
|
||||
UserCTX = Instance.WithAuthorization(ctx, integration.UserTypeNoPermission)
|
||||
LoginCTX = Instance.WithAuthorization(ctx, integration.UserTypeLogin)
|
||||
User = createFullUser(CTX)
|
||||
DeactivatedUser = createDeactivatedUser(CTX)
|
||||
LockedUser = createLockedUser(CTX)
|
||||
return m.Run()
|
||||
}())
|
||||
}
|
||||
@@ -61,16 +59,36 @@ func createFullUser(ctx context.Context) *user.AddHumanUserResponse {
|
||||
return userResp
|
||||
}
|
||||
|
||||
func createDeactivatedUser(ctx context.Context) *user.AddHumanUserResponse {
|
||||
func createDeactivatedUser(ctx context.Context, t *testing.T) *user.AddHumanUserResponse {
|
||||
userResp := Instance.CreateHumanUser(ctx)
|
||||
_, err := Instance.Client.UserV2.DeactivateUser(ctx, &user.DeactivateUserRequest{UserId: userResp.GetUserId()})
|
||||
logging.OnError(err).Fatal("deactivate human user")
|
||||
|
||||
retryDuration, tick := integration.WaitForAndTickWithMaxDuration(ctx, time.Minute)
|
||||
require.EventuallyWithT(t, func(collect *assert.CollectT) {
|
||||
result, err := Instance.Client.UserV2.GetUserByID(ctx, &user.GetUserByIDRequest{
|
||||
UserId: userResp.GetUserId(),
|
||||
})
|
||||
assert.NoError(collect, err)
|
||||
assert.Equal(t, user.UserState_USER_STATE_INACTIVE, result.GetUser().GetState())
|
||||
}, retryDuration, tick, "user not locked in time")
|
||||
|
||||
return userResp
|
||||
}
|
||||
|
||||
func createLockedUser(ctx context.Context) *user.AddHumanUserResponse {
|
||||
func createLockedUser(ctx context.Context, t *testing.T) *user.AddHumanUserResponse {
|
||||
userResp := Instance.CreateHumanUser(ctx)
|
||||
_, err := Instance.Client.UserV2.LockUser(ctx, &user.LockUserRequest{UserId: userResp.GetUserId()})
|
||||
logging.OnError(err).Fatal("lock human user")
|
||||
|
||||
retryDuration, tick := integration.WaitForAndTickWithMaxDuration(ctx, time.Minute)
|
||||
require.EventuallyWithT(t, func(collect *assert.CollectT) {
|
||||
result, err := Instance.Client.UserV2.GetUserByID(ctx, &user.GetUserByIDRequest{
|
||||
UserId: userResp.GetUserId(),
|
||||
})
|
||||
assert.NoError(collect, err)
|
||||
assert.Equal(t, user.UserState_USER_STATE_LOCKED, result.GetUser().GetState())
|
||||
}, retryDuration, tick, "user not locked in time")
|
||||
|
||||
return userResp
|
||||
}
|
||||
|
||||
@@ -127,6 +127,9 @@ func verifyFactors(t assert.TestingT, factors *session.Factors, creationDate, ch
|
||||
}
|
||||
|
||||
func TestServer_CreateSession(t *testing.T) {
|
||||
lockedUser := createLockedUser(CTX, t)
|
||||
deactivatedUser := createDeactivatedUser(CTX, t)
|
||||
|
||||
tests := []struct {
|
||||
name string
|
||||
req *session.CreateSessionRequest
|
||||
@@ -190,7 +193,7 @@ func TestServer_CreateSession(t *testing.T) {
|
||||
Checks: &session.Checks{
|
||||
User: &session.CheckUser{
|
||||
Search: &session.CheckUser_UserId{
|
||||
UserId: DeactivatedUser.GetUserId(),
|
||||
UserId: deactivatedUser.GetUserId(),
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -203,7 +206,7 @@ func TestServer_CreateSession(t *testing.T) {
|
||||
Checks: &session.Checks{
|
||||
User: &session.CheckUser{
|
||||
Search: &session.CheckUser_UserId{
|
||||
UserId: LockedUser.GetUserId(),
|
||||
UserId: lockedUser.GetUserId(),
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user