fix: expire abandoned auth attempts

This commit is contained in:
Josh Creek
2026-08-31 22:22:33 +01:00
parent 9fe6c57b5d
commit ae164e625a
3 changed files with 39 additions and 1 deletions
+18
View File
@@ -109,3 +109,21 @@ func TestAuthCoordinatorRejectsExpiredCompletion(t *testing.T) {
t.Fatalf("expired attempt completed: %v", err)
}
}
func TestAuthCoordinatorExpiresAbandonedPendingAttemptsAtBoundary(t *testing.T) {
now := time.Unix(1000, 0)
coordinator := NewAuthCoordinator()
ticket := SteamTicket{TicketID: "ticket-1", ExpiresAt: now.Add(time.Second)}
if err := coordinator.Begin("attempt-1", ticket, now); err != nil {
t.Fatal(err)
}
if expired := coordinator.Expire(now.Add(time.Second)); len(expired) != 1 || expired[0].State != AuthRejected {
t.Fatalf("expired attempts = %+v", expired)
}
if _, err := coordinator.Get("attempt-1"); !errors.Is(err, ErrAuthAttemptPending) {
t.Fatalf("expired attempt was exposed: %v", err)
}
if expired := coordinator.Expire(now.Add(2 * time.Second)); len(expired) != 0 {
t.Fatalf("expired attempt repeated: %+v", expired)
}
}