Merge commit from fork

* fix: respect lockout policy on password change (with old password)

* add tarpitting

* cleanup
This commit is contained in:
Livio Spring
2025-10-29 10:07:35 +01:00
committed by GitHub
parent 72a5c33e6a
commit b8db8cdf9c
17 changed files with 619 additions and 49 deletions
+10
View File
@@ -1091,6 +1091,7 @@ func TestCheckTOTP(t *testing.T) {
type fields struct {
sessionWriteModel *SessionWriteModel
eventstore func(*testing.T) *eventstore.Eventstore
tarpit Tarpit
}
tests := []struct {
@@ -1109,6 +1110,7 @@ func TestCheckTOTP(t *testing.T) {
aggregate: sessAgg,
},
eventstore: expectEventstore(),
tarpit: expectTarpit(0),
},
wantErr: zerrors.ThrowInvalidArgument(nil, "COMMAND-8N9ds", "Errors.User.UserIDMissing"),
},
@@ -1124,6 +1126,7 @@ func TestCheckTOTP(t *testing.T) {
eventstore: expectEventstore(
expectFilterError(io.ErrClosedPipe),
),
tarpit: expectTarpit(0),
},
wantErr: io.ErrClosedPipe,
},
@@ -1143,6 +1146,7 @@ func TestCheckTOTP(t *testing.T) {
),
),
),
tarpit: expectTarpit(0),
},
wantErr: zerrors.ThrowPreconditionFailed(nil, "COMMAND-3Mif9s", "Errors.User.MFA.OTP.NotReady"),
},
@@ -1169,6 +1173,7 @@ func TestCheckTOTP(t *testing.T) {
eventFromEventPusher(org.NewLockoutPolicyAddedEvent(ctx, orgAgg, 0, 0, false)),
),
),
tarpit: expectTarpit(1),
},
wantErrorCommands: []eventstore.Command{
user.NewHumanOTPCheckFailedEvent(ctx, userAgg, nil),
@@ -1198,6 +1203,7 @@ func TestCheckTOTP(t *testing.T) {
eventFromEventPusher(org.NewLockoutPolicyAddedEvent(ctx, orgAgg, 1, 1, false)),
),
),
tarpit: expectTarpit(1),
},
wantErrorCommands: []eventstore.Command{
user.NewHumanOTPCheckFailedEvent(ctx, userAgg, nil),
@@ -1225,6 +1231,7 @@ func TestCheckTOTP(t *testing.T) {
),
expectFilter(), // recheck
),
tarpit: expectTarpit(0),
},
wantEventCommands: []eventstore.Command{
user.NewHumanOTPCheckSucceededEvent(ctx, userAgg, nil),
@@ -1253,6 +1260,7 @@ func TestCheckTOTP(t *testing.T) {
user.NewUserLockedEvent(ctx, userAgg),
),
),
tarpit: expectTarpit(0),
},
wantErr: zerrors.ThrowPreconditionFailed(nil, "COMMAND-SF3fg", "Errors.User.Locked"),
},
@@ -1264,11 +1272,13 @@ func TestCheckTOTP(t *testing.T) {
eventstore: tt.fields.eventstore(t),
totpAlg: cryptoAlg,
now: func() time.Time { return testNow },
tarpit: tt.fields.tarpit.tarpit,
}
gotCmds, err := CheckTOTP(tt.code)(ctx, cmd)
require.ErrorIs(t, err, tt.wantErr)
assert.Equal(t, tt.wantErrorCommands, gotCmds)
assert.Equal(t, tt.wantEventCommands, cmd.eventCommands)
tt.fields.tarpit.metExpectedCalls(t)
})
}
}