Skip to content

test : added unit tests for crypto utility functions - #2621

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

test : added unit tests for crypto utility functions#2621
tmdeveloper007 wants to merge 1 commit into
Priyanshu-byte-coder:mainfrom
tmdeveloper007:#2616

Conversation

@tmdeveloper007

Copy link
Copy Markdown

Closes #2616.

Summary of What Has Been Done: Added unit tests for src/lib/crypto.ts covering encryptToken, decryptToken, safeCompare, getExpectedSignature, and verifyGitHubSignature. ENCRYPTION_KEY is set in beforeAll and cleaned up in afterAll.

Changes Made:

  • Created test/crypto.test.ts with 29 test cases
  • encryptToken: produces encrypted+iv object, both non-empty hex strings, different ciphertext each time due to random IV, handles empty string and unicode
  • decryptToken: correctly roundtrips encryptToken output, returns null for tampered ciphertext, invalid IV length, non-hex ciphertext, too-short ciphertext, correctly handles unicode roundtrip
  • safeCompare: true for equal strings, false for different-length strings, false for same-length different strings, empty strings, unicode strings
  • getExpectedSignature: prefixed with 'sha256=', 71-char output (64 hex chars), different for different bodies/secrets
  • verifyGitHubSignature: true for correctly signed body, false for tampered body, wrong prefix, no sha256=, null/undefined signature, empty body

Impact it Made: Validates AES-256-GCM token encryption/decryption roundtrip. Guards GitHub webhook signature verification used across API webhook routes.

@github-actions github-actions Bot added type:testing GSSoC type bonus: tests (+10 pts) gssoc26 GSSoC 2026 contribution labels Jun 20, 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 crypto utility functions

2 participants