Skip to content

test: add mocked crypto.subtle coverage for decryptTokenEdge (#2990)#3196

Open
aaniya22 wants to merge 1 commit into
Priyanshu-byte-coder:mainfrom
aaniya22:test/2990-crypto-edge-unit-tests
Open

test: add mocked crypto.subtle coverage for decryptTokenEdge (#2990)#3196
aaniya22 wants to merge 1 commit into
Priyanshu-byte-coder:mainfrom
aaniya22:test/2990-crypto-edge-unit-tests

Conversation

@aaniya22

Copy link
Copy Markdown

Summary

Adds two missing test cases to test/crypto-edge.test.ts: mocking globalThis.crypto.subtle via vi.stubGlobal to verify decryptTokenEdge returns null when crypto.subtle.decrypt throws, and to assert the exact parameters passed to crypto.subtle.importKey and crypto.subtle.decrypt, per issue #2990.

Closes #2990


Type of Change

  • 🐛 Bug fix (non-breaking change that fixes an issue)
  • ✨ New feature (non-breaking change that adds functionality)
  • 💥 Breaking change (fix or feature that changes existing behavior)
  • 📝 Documentation update
  • ♻️ Refactor / code cleanup (no functional change)
  • ⚡ Performance improvement
  • 🔒 Security fix
  • 🧪 Tests only

What Changed

  • test/crypto-edge.test.ts — added two tests to the decryptTokenEdge describe block:
    • "returns null when crypto.subtle.decrypt throws" — stubs globalThis.crypto.subtle with vi.stubGlobal so decrypt rejects, and asserts the function catches it and returns null.
    • "calls crypto.subtle.importKey and crypto.subtle.decrypt with the correct parameters" — stubs crypto.subtle with spies and asserts importKey is called with "raw", a 32-byte key, { name: "AES-GCM" }, false, ["decrypt"], and decrypt is called with { name: "AES-GCM", iv: <12-byte Uint8Array>, tagLength: 128 } and the correctly-sized encrypted byte array.

How to Test

  1. Pull this branch.
  2. Run pnpm install (use --ignore-scripts if the optional tree-sitter native build fails locally — unrelated to this change).
  3. Run npx vitest run test/crypto-edge.test.ts.

Expected result: All 15 tests in the file pass, including the two new mocked-crypto.subtle tests.


Screenshots / Recordings

Not applicable — test-only change, no UI impact.


Checklist

  • Linked the related issue above
  • Self-reviewed my own diff
  • No unnecessary console.log, debug code, or commented-out blocks
  • npm run lint passes locally
  • No TypeScript errors (npm run type-check)
  • Added or updated tests where applicable
  • Updated documentation / comments if behavior changed

Accessibility (UI changes only)

Not applicable — no UI changes.


Additional Context

Most of the coverage requested in #2990 (missing/invalid key, invalid hex/odd-length ciphertext, invalid IV length, successful decryption) already existed in test/crypto-edge.test.ts on main, using the real Web Crypto API end-to-end. This PR adds the two pieces the issue specifically asked for that weren't covered: mocking globalThis.crypto.subtle with vi.stubGlobal, and verifying the exact call parameters to importKey/decrypt. Flagging this so the diff's scope relative to the issue is clear.

@github-actions github-actions Bot added type:testing GSSoC type bonus: tests (+10 pts) gssoc26 GSSoC 2026 contribution type:feature GSSoC type bonus: new feature labels Jul 13, 2026
@github-actions

Copy link
Copy Markdown

GSSoC Label Checklist 🏷️

@Priyanshu-byte-coder — 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

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

Labels

gssoc26 GSSoC 2026 contribution type:feature GSSoC type bonus: new feature 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-edge.ts

1 participant