Skip to content

test : added unit tests for rate-limit utility functions - #2632

Closed
tmdeveloper007 wants to merge 1 commit into
Priyanshu-byte-coder:mainfrom
tmdeveloper007:#2627
Closed

test : added unit tests for rate-limit utility functions#2632
tmdeveloper007 wants to merge 1 commit into
Priyanshu-byte-coder:mainfrom
tmdeveloper007:#2627

Conversation

@tmdeveloper007

Copy link
Copy Markdown

Closes #2627.

Summary of What Has Been Done:
Added test/rate-limit.test.ts covering the exported utility functions from src/lib/rate-limit.ts: getClientIp and createMemoryFixedWindowRateLimiter. All 14 tests pass under vitest.

Changes Made:

  • New file: test/rate-limit.test.ts (14 tests).
  • getClientIp: cf-connecting-ip priority, x-real-ip fallback, x-forwarded-for first-IP extraction, no-headers returns unknown, empty-header returns unknown, whitespace trimming.
  • createMemoryFixedWindowRateLimiter: allows within limit, denies at limit, per-key isolation, window expiry resets the counter, returns correct reset unix timestamp.

Impact it Made:
Locks the contract for the in-memory rate limiter used by auth and metrics API routes. The limiter prevents abuse of /api/auth/* and /api/metrics/* endpoints. Future changes to window timing or bucket management will surface a test failure rather than silently allowing rate-limit bypass.

@github-actions github-actions Bot added gssoc26 GSSoC 2026 contribution type:testing GSSoC type bonus: tests (+10 pts) labels Jun 21, 2026
@github-actions

Copy link
Copy Markdown

GSSoC Label Checklist 🏷️

@Umbrella-io — please apply the appropriate labels before merging:

Difficulty (pick one):

  • level:beginner — 20 pts
  • level:intermediate — 35 pts
  • level:advanced — 55 pts
  • level:critical — 80 pts

Quality (optional):

  • quality:clean — ×1.2 multiplier
  • quality:exceptional — ×1.5 multiplier

Validation (required to score):

  • gssoc:approved — counts for points
  • gssoc:invalid / gssoc:spam / gssoc:ai-slop — does not score

Type labels (type:*) are auto-detected from files and title. Review and adjust if needed.
Points formula: (difficulty × quality_multiplier) + type_bonus

@Priyanshu-byte-coder

Copy link
Copy Markdown
Owner

CI is failing on this PR. Please fix the TypeScript/test errors before we can merge. Run npm run typecheck and npm test locally to reproduce.

@tmdeveloper007

Copy link
Copy Markdown
Author

This PR has been closed as it has been stale for more than 2 days without recent activity or merging. If this work is still relevant, please reopen a fresh PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gssoc26 GSSoC 2026 contribution type:testing GSSoC type bonus: tests (+10 pts)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

test : add unit tests for goals-sync-utils repository extraction

2 participants