Files
Luminary/internal/auth/loginlimit/limit_test.go
T
renjue 76ba500417
CI / docker (push) Successful in 2m4s
Initial commit: Luminary AI Gateway
OpenAI-compatible AI gateway with Vue admin UI, multi-provider egress,
ingress key governance, monitoring, and security controls.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-06-23 21:46:16 +08:00

37 lines
654 B
Go

package loginlimit
import (
"testing"
"time"
)
func TestLimiterLockout(t *testing.T) {
l := New(3, time.Minute)
ip := "192.168.1.1"
for i := 0; i < 2; i++ {
if locked, _ := l.Check(ip); locked {
t.Fatalf("unexpected lock at attempt %d", i)
}
l.RecordFailure(ip)
}
if locked, _ := l.Check(ip); locked {
t.Fatal("should not lock before max attempts")
}
l.RecordFailure(ip)
locked, retry := l.Check(ip)
if !locked {
t.Fatal("expected lock after max failures")
}
if retry <= 0 {
t.Fatal("expected positive retry duration")
}
l.Reset(ip)
if locked, _ := l.Check(ip); locked {
t.Fatal("expected unlock after reset")
}
}