mirror of
https://github.com/jcreek/CosmicClash.git
synced 2026-09-13 12:52:05 +00:00
feat(multiplayer): enforce account and IP rate limits
This commit is contained in:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user