fixed verificaiton error
This commit is contained in:
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user