[Test Improver] Add unit tests for crypto/encryption utilities - #89
Draft
github-actions[bot] wants to merge 1 commit into
Draft
[Test Improver] Add unit tests for crypto/encryption utilities#89github-actions[bot] wants to merge 1 commit into
github-actions[bot] wants to merge 1 commit into
Conversation
Add tests for the deriveKey, encrypt, and decrypt functions in shell/utils/crypto/encryption.ts. These cryptographic utilities are used by the notifications store for persisting encrypted notifications in local storage and had no existing test coverage. Tests cover: - deriveKey: algorithm, non-extractability, key usages, and key uniqueness per password - encrypt: output shape, base64 encoding of cipher and iv fields, and random IV generation per call - decrypt: round-trip fidelity for plain, unicode, long, JSON, and special-character strings; rejection on wrong key and tampered cipher Wire up Node.js webcrypto to the global scope so the Web Crypto API is available in the JSDOM test environment. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
26 tasks
21 tasks
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.
🤖 This PR was created by Test Improver, an automated AI assistant focused on improving test coverage.
Goal and Rationale
shell/utils/crypto/encryption.tsprovides thederiveKey,encrypt, anddecryptfunctions that are the cryptographic backbone of the notification store — it encrypts sensitive notification data before persisting it tolocalStorage. Despite being security-critical code, it had zero test coverage.Approach
Wrote 15 unit tests across three describe blocks:
deriveKeyAES-GCM), non-extractability, correct key usages, per-password uniqueness (verified by cross-key decryption failure)encryptcipher+iv), base64 format, random IV per calldecryptThe JSDOM test environment doesn't ship the Web Crypto API, so the test file wires up Node.js's built-in
webcryptoviaObject.defineProperty(global, 'crypto', { value: webcrypto })— a pattern limited to this single test file.Coverage Impact
shell/utils/crypto/encryption.tsTest Status
All 15 tests pass:
Lint: no errors or warnings (
eslint --max-warnings 0).Trade-offs
deriveKeytake ~100–200 ms each. This is acceptable for 15 tests and reflects the real cost of the function.Reproducibility
Warning
Firewall blocked 1 domain
The following domain was blocked by the firewall during workflow execution:
download.cypress.ioSee Network Configuration for more information.