fixed verificaiton error

This commit is contained in:
Stephan D
2026-02-12 20:46:11 +01:00
parent 55624aa8b5
commit e605c734ad
2 changed files with 45 additions and 15 deletions

View File

@@ -849,15 +849,26 @@ func TestCreate_CooldownExpiresAllowsCreation(t *testing.T) {
accountRef := bson.NewObjectID()
// First creation without cooldown.
_, err := db.Create(ctx, req(accountRef, model.PurposePasswordReset, "", time.Hour))
firstRaw, err := db.Create(ctx, req(accountRef, model.PurposePasswordReset, "", time.Hour))
require.NoError(t, err)
time.Sleep(2 * time.Millisecond)
// Re-create with short cooldown — the prior token is old enough to be invalidated.
r2 := req(accountRef, model.PurposePasswordReset, "", time.Hour).WithCooldown(time.Millisecond)
_, err = db.Create(ctx, r2)
secondRaw, err := db.Create(ctx, r2)
require.NoError(t, err)
assert.NotEqual(t, firstRaw, secondRaw)
// Old token should be rotated out after successful re-issue.
_, err = db.Consume(ctx, accountRef, model.PurposePasswordReset, firstRaw)
require.Error(t, err)
assert.True(t, errors.Is(err, verification.ErrTokenAlreadyUsed))
// New token remains valid.
tok, err := db.Consume(ctx, accountRef, model.PurposePasswordReset, secondRaw)
require.NoError(t, err)
assert.Equal(t, accountRef, tok.AccountRef)
}
func TestCreate_CooldownNilIgnored(t *testing.T) {