Add Certificates page and Traefik API frontend client
This commit is contained in:
parent
9e4c612dcb
commit
7fc90524b5
40 changed files with 6585 additions and 359 deletions
40
backend/internal/auth/ratelimit_test.go
Normal file
40
backend/internal/auth/ratelimit_test.go
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
package auth
|
||||
|
||||
import (
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func TestLoginRateLimiter_Allow(t *testing.T) {
|
||||
lim := NewLoginRateLimiter(3, time.Minute, 10*time.Second)
|
||||
key := "127.0.0.1"
|
||||
for i := 0; i < 3; i++ {
|
||||
if !lim.Allow(key) {
|
||||
t.Fatalf("should allow attempt %d", i)
|
||||
}
|
||||
lim.RecordFailure(key)
|
||||
}
|
||||
if lim.Allow(key) {
|
||||
t.Fatalf("should block after 3 failures")
|
||||
}
|
||||
// After block duration with 0 block, should allow immediately (no block)
|
||||
lim2 := NewLoginRateLimiter(5, time.Minute, 0)
|
||||
for i := 0; i < 5; i++ {
|
||||
lim2.RecordFailure(key)
|
||||
}
|
||||
// With block 0, Allow should reset after reaching max and not block
|
||||
if !lim2.Allow(key) {
|
||||
t.Fatalf("with 0 block duration, should allow after max")
|
||||
}
|
||||
}
|
||||
|
||||
func TestLoginRateLimiter_SuccessClears(t *testing.T) {
|
||||
lim := NewLoginRateLimiter(3, time.Minute, 10*time.Second)
|
||||
key := "1.2.3.4"
|
||||
lim.RecordFailure(key)
|
||||
lim.RecordFailure(key)
|
||||
lim.RecordSuccess(key)
|
||||
if !lim.Allow(key) {
|
||||
t.Fatalf("success should clear")
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue