feat(multiplayer): enforce account and IP rate limits

This commit is contained in:
Josh Creek
2026-09-01 19:18:40 +01:00
parent aa97259165
commit e1abac1271
4 changed files with 76 additions and 19 deletions
+20
View File
@@ -28,6 +28,26 @@ func TestRateLimiterEnforcesWindowAndBoundsKeyMemory(t *testing.T) {
}
}
func TestRateLimiterChargesCredentialAndIPDimensionsAtomically(t *testing.T) {
limiter, err := NewRateLimiter(1, time.Minute, 8)
if err != nil {
t.Fatal(err)
}
start := time.Unix(1000, 0)
if !limiter.AllowKeys([]string{"auth:player", "ip:one"}, start) {
t.Fatal("first request was rejected")
}
if limiter.AllowKeys([]string{"auth:player", "ip:two"}, start) {
t.Fatal("same credential bypassed the account dimension by changing IP")
}
if limiter.AllowKeys([]string{"auth:other", "ip:one"}, start) {
t.Fatal("same IP bypassed the IP dimension by changing credential")
}
if !limiter.AllowKeys([]string{"auth:other", "ip:two"}, start) {
t.Fatal("unrelated credential/IP pair was charged by a rejected request")
}
}
func TestRateLimitedHTTPBoundaryReturnsGeneric429(t *testing.T) {
limiter, err := NewRateLimiter(1, time.Minute, 8)
if err != nil {