-
-
Notifications
You must be signed in to change notification settings - Fork 64
chore(docs): add PR ↔ bug report mapping #196
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
morningstarxcdcode
wants to merge
11
commits into
Darshan3690:main
Choose a base branch
from
morningstarxcdcode:chore/bug-pr-mapping
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 10 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
0023f32
fix: Critical security and performance improvements
29c6a6a
fix: syntax, improve rate limiter, add rate-limit response headers, a…
072a463
docs: add BUG-018 rate limiting bug report
6b0167d
docs: improve test examples (add Content-Type), add Prisma testing gu…
27673c2
feat(rate-limit): add Upstash adapter scaffold, env-based selection, …
c37b5e4
feat(rate-limit): implement Upstash mapping and add mocked tests; ena…
a041930
test: add jest config for TypeScript tests
116e469
test: mock Upstash Ratelimit and add tests
4475919
feat(rate-limit): improve Upstash adapter (client caching, robust res…
2d50ba3
chore(docs): add PR ↔ bug report mapping (PR_MAPPING.md)
56a352f
Merge branch 'main' into chore/bug-pr-mapping
morningstarxcdcode File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| import { upstashLimit } from '@/lib/rate-limit-upstash'; | ||
|
|
||
| const originalUrl = process.env.UPSTASH_REDIS_REST_URL; | ||
| const originalToken = process.env.UPSTASH_REDIS_REST_TOKEN; | ||
| // Ensure env vars are set for the adapter to initialize (mocked services will be used) | ||
| process.env.UPSTASH_REDIS_REST_URL = process.env.UPSTASH_REDIS_REST_URL || 'http://localhost'; | ||
| process.env.UPSTASH_REDIS_REST_TOKEN = process.env.UPSTASH_REDIS_REST_TOKEN || 'test-token'; | ||
|
|
||
| jest.mock('@upstash/redis', () => ({ | ||
| Redis: jest.fn().mockImplementation(() => ({})), | ||
| }), { virtual: true }); | ||
|
|
||
| jest.mock('@upstash/ratelimit', () => { | ||
| const slidingWindow = jest.fn().mockImplementation((_max: number, _win: string) => ({})); | ||
| const Ratelimit = jest.fn().mockImplementation(() => ({ | ||
| limit: async (_id: string) => ({ success: true, remaining: 2, resetAfter: 10000 }), | ||
| })); | ||
| // Attach static helper | ||
| (Ratelimit as any).slidingWindow = slidingWindow; | ||
| return { Ratelimit }; | ||
| }, { virtual: true }); | ||
|
|
||
| describe('Upstash adapter (mocked)', () => { | ||
| afterAll(() => { | ||
| if (originalUrl === undefined) { | ||
| delete process.env.UPSTASH_REDIS_REST_URL; | ||
| } else { | ||
| process.env.UPSTASH_REDIS_REST_URL = originalUrl; | ||
| } | ||
|
|
||
| if (originalToken === undefined) { | ||
| delete process.env.UPSTASH_REDIS_REST_TOKEN; | ||
| } else { | ||
| process.env.UPSTASH_REDIS_REST_TOKEN = originalToken; | ||
| } | ||
| }); | ||
|
|
||
| it('returns mapped rate limit result', async () => { | ||
| const res = await upstashLimit('test-id', { maxRequests: 5, windowMs: 60 * 60 * 1000 }); | ||
| expect(res.success).toBe(true); | ||
| expect(typeof res.remaining).toBe('number'); | ||
| expect(typeof res.reset).toBe('number'); | ||
| }); | ||
| }); |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| import { checkRateLimit as checkLimitInmem, RateLimitConfig } from '@/lib/rate-limit'; | ||
|
|
||
| describe('In-memory rate limiter (sanity checks)', () => { | ||
| const originalRateLimitMode = process.env.RATE_LIMIT_MODE; | ||
|
|
||
| afterAll(() => { | ||
| if (originalRateLimitMode === undefined) { | ||
| delete process.env.RATE_LIMIT_MODE; | ||
| } else { | ||
| process.env.RATE_LIMIT_MODE = originalRateLimitMode; | ||
| } | ||
| }); | ||
|
|
||
| it('should allow requests up to the limit and then block', async () => { | ||
| process.env.RATE_LIMIT_MODE = 'INMEM'; | ||
|
|
||
| const key = `test:${Date.now()}:${Math.random()}`; | ||
| const config: RateLimitConfig = { maxRequests: 3, windowMs: 1000 * 60 }; | ||
|
|
||
| const r1 = await checkLimitInmem(key, config); | ||
| expect(r1.success).toBe(true); | ||
|
|
||
| const r2 = await checkLimitInmem(key, config); | ||
| expect(r2.success).toBe(true); | ||
|
|
||
| const r3 = await checkLimitInmem(key, config); | ||
| expect(r3.success).toBe(true); | ||
|
|
||
| const r4 = await checkLimitInmem(key, config); | ||
| expect(r4.success).toBe(false); | ||
| }); | ||
| }); |
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
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
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
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
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.