Repository navigation
test(middleware): cover rate limiter distributed counters, key isolation, and reset headers - #2221
Open
ranjan1969x wants to merge 1 commit into
Open
ranjan1969x wants to merge 1 commit into
ranjan1969x wants to merge 1 commit into
Conversation
…ion, and reset headers
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR adds comprehensive unit and regression test coverage for
rateLimitermiddleware inbackend/src/middleware/__tests__/rateLimiter.test.ts, addressing Redis outages / fail-open resilience, key isolation across identity dimensions, and reset header contracts.Closes #2091
Details of Changes
loginRateLimiter: Tests compound key generator (${ip}:${publicKey}) ensuring distinct public keys on the same client IP do not share rate limit budgets.ipLoginRateLimiter: Tests aggregate IP-based limiting enforcing max attempts across all public keys from a single IP.challengeRateLimiter: Validates standardRateLimit-*headers on accepted requests and verifies that exhausting the budget returns HTTP 429 with compliantRetry-After: 60header and error JSON.verifyRateLimiter: Validates 429 response structure andRetry-Afterreset header when verification limit is exceeded.sendCommandtimes out or rejects withETIMEDOUT, the middleware fails open gracefully (passOnStoreError: true), allowing incoming requests through tonext()rather than returning 500 errors.Verification & CI Proof
npm run lint: Passed (0 errors)npm run build: Passed (0 errors)npm test -- src/middleware/__tests__/rateLimiter.test.ts: 8/8 tests passing (100% green)