fix(domain): Fix session checks failing tests (#11881)

# Which Problems Are Solved

2 tests were failing on the new session checks:

  - Password check (events) fails due to a race condition
- IDP intent check (events) (also password test) fails due to a flaky
time comparison

# How the Problems Are Solved

- Race condition: remove setting the password hasher in the test. It's
already globally set in `domain_test.go`
- Time comparison: use `assert.WithinRange` instead of `assert.InDelta`
and use 2 second range to make sure you don't get resolution issues

# Additional Context

- Closes #11878
This commit is contained in:
Marco A.
2026-03-20 06:57:36 +01:00
committed by GitHub
parent a592fd7293
commit 8d1a099deb
3 changed files with 134 additions and 21 deletions
@@ -17,7 +17,6 @@ import (
"github.com/zitadel/zitadel/backend/v3/storage/database/dbmock"
noopdb "github.com/zitadel/zitadel/backend/v3/storage/database/dialect/noop"
"github.com/zitadel/zitadel/internal/api/authz"
"github.com/zitadel/zitadel/internal/crypto"
"github.com/zitadel/zitadel/internal/eventstore"
"github.com/zitadel/zitadel/internal/repository/session"
"github.com/zitadel/zitadel/internal/repository/user"
@@ -1049,7 +1048,7 @@ func TestPasswordCheckCommand_Execute(t *testing.T) {
}
if tc.humanRepo != nil {
humanRepo := tc.humanRepo(ctrl)
userRepo := domainmock.NewMockUserRepository(ctrl)
userRepo := domainmock.NewUserRepo(ctrl)
userRepo.EXPECT().Human().Times(1).Return(humanRepo)
domain.WithUserRepo(userRepo)(opts)
}
@@ -1071,7 +1070,6 @@ func TestPasswordCheckCommand_Execute(t *testing.T) {
func TestPasswordCheckCommand_Events(t *testing.T) {
t.Parallel()
domain.SetPasswordHasher(&crypto.Hasher{})
userAgg := user.NewAggregate("user-1", "org-1").Aggregate
sessAgg := session.NewAggregate("session-1", "instance-1").Aggregate
@@ -1206,7 +1204,7 @@ func TestPasswordCheckCommand_Events(t *testing.T) {
case *session.PasswordCheckedEvent:
actualAssertedType, ok := events[i].(*session.PasswordCheckedEvent)
require.True(t, ok)
assert.InDelta(t, expectedAssertedType.CheckedAt.UnixMilli(), actualAssertedType.CheckedAt.UnixMilli(), 10)
assert.Equal(t, tc.cmd.CheckTime, actualAssertedType.CheckedAt)
}
}
})