Repository navigation
test: cover E2EE with the real client and a WebCrypto implementation - #7866
diegolmello wants to merge 13 commits into
Conversation
…ependent and anchor E2EE flow in sniffler map
…plicate encrypt cases
stop() never cleared the key distribution interval, and the interval was only stored after the first run, so a stop during that run left it alive. The next sign-in then skipped its first distribution because a timer already existed. NATIVE-1870
generatePassphrase loads its word list with import(), which Jest's CommonJS runtime rejects without --experimental-vm-modules.
Runs Encryption against an in-memory WatermelonDB and the WebCrypto fake: initialize, stop, persistKeys, createKeys, changePassword and its force gate, provideRoomKeyToUser, getSample and key distribution, pending and last-message decryption, decryptMessages, decryptFiles and the file decryption queue. NATIVE-1856
…d the password policy NATIVE-1856
…l client NATIVE-1856
sendMessage and resendMessage passed an undefined encryption result to chat.sendMessage, which threw into a catch that only logged, so the message stayed TEMP with no retry. They now post nothing and leave it in ERROR. NATIVE-1869
… key requests, suggested keys and search
|
No actionable comments were generated in the recent review.
|
| Layer / File(s) | Summary |
|---|---|
Cryptographic test support and fixtures __mocks__/@rocket.chat/mobile-crypto.ts, app/lib/encryption/__tests__/fixtures/*, app/lib/testUtils/*, babel.config.js, package.json, .sniffler/test-map.json, app/containers/NewMediaCall/VoipCallLifecycle.integration.test.tsx, app/lib/encryption/encryption.test.ts, app/views/RoomView/hooks/__tests__/useE2EEStatus.test.ts |
Adds a Node.js-backed crypto mock, Web Crypto helpers, V1 and V2 fixtures, an in-memory database factory, and test-environment configuration. Removes mobile-crypto Jest mocks and a test comment. |
Room, key, and message cryptography app/lib/encryption/room.test.ts, app/lib/encryption/__tests__/{message,privateKey,roomKey,suggestedGroupKey,utils}.test.ts |
Tests real cryptographic room-key, message, and file operations, including V1 and V2 formats, key sharing, fallback behavior, and handshake cases. |
Encryption lifecycle and key distribution app/lib/encryption/encryption.ts, app/lib/encryption/__tests__/{decryption,keyDistribution,lifecycle}.test.ts, app/sagas/__tests__/encryption.*.test.ts, app/reducers/encryption.test.ts |
Clears the key-distribution interval on stop and starts it before the initial distribution run. Adds coverage for lifecycle, key sharing, decryption, saga flows, and reducer state. |
Encrypted application workflows app/lib/methods/sendMessage.ts, app/lib/methods/__tests__/*e2ee.test.ts, app/lib/methods/sendFileMessage/__tests__/*e2ee.test.ts, app/lib/methods/subscriptions/__tests__/rooms.e2ekeyRequest.test.ts, app/lib/encryption/__tests__/file.test.ts, app/views/CreateChannelView/RoomSettings/SwitchItemEncrypted.test.tsx, app/views/E2EEncryptionSecurityView/__tests__/utils.test.ts |
Adds tests for encrypted message and file flows, room search, key requests, file decryption, and E2E settings. Message sends now use an error status and skip the send call when encryption returns no message. |
Priority:
Estimated code review effort: 4 (Complex) | ~45 minutes
Change: Bug fix
Suggested labels: type: bug
Suggested reviewers: rohit3523, otaviostasiak, dnlsilva
Merge Risk: 
Minimal · up to 054e2
-
This change mostly adds encryption test coverage. It also stops room key distribution on client stop and keeps encrypted messages in an error state when no session key is available, rather than leaving them stuck as sending. No merge-blocking risk was identified.
Pre-merge checks: 
4 · 
1
-
Failed checks: 1 warning Passed checks: 4 passedFull details: Docstring Coverage
-
Explanation
Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 2 functions across 26 files. (6 skipped: 6 unsupported.)
Resolution
Write docstrings for the functions missing them to satisfy the coverage threshold.
-
- Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Warning
Errors were encountered while retrieving linked issues.
Errors: 1
-
- JIRA integration encountered authorization issues. Please disconnect and reconnect the integration in the CodeRabbit UI.
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
Comment @coderabbitai help to get the list of available commands.
… test/e2ee-coverage-plan
Proposed changes
This adds unit coverage for end-to-end encryption. The tests run the real
Encryptionclient against a WebCrypto-backed fake of@rocket.chat/mobile-crypto, notjest.fncrypto stubs. The fixtures are produced the way the Rocket.Chat web client produces them, so the tests also check that mobile and web stay compatible.Test infrastructure
__mocks__/@rocket.chat/mobile-crypto.ts: a Node WebCrypto implementation of the native module (AES-CBC/GCM/CTR, RSA-OAEP, PBKDF2, HMAC, SHA, and file encrypt/decrypt).app/lib/encryption/__tests__/fixtures/: golden fixtures for the user key pair, v1 and v2 room keys, messages and a file.generate.mjsregenerates them, following the web client's algorithms.app/lib/testUtils/inMemoryDatabase.ts(in-memory WatermelonDB) andapp/lib/testUtils/e2eeWebClient.ts.Coverage
sendMessage,resendMessageandeditMessagesendt: 'e2e'withcontentand no plaintextmsg.sendFileMessageV2sends ciphertext in both the form content and themediaConfirmpayload.e2ekeyRequestonly for a matching key ID.room.test.ts, the encryption reducer test and theSwitchItemEncryptedtests are rewritten so they don't depend on test order.I checked each new test by breaking the code it guards: every test failed on the broken code and passed once the code was restored.
Issue(s)
https://rocketchat.atlassian.net/browse/NATIVE-1878
How to test or reproduce
Unit tests:
TZ=UTC pnpm test app/lib/encryption app/lib/methods app/sagas/__tests__ app/reducers/encryption.test.tsTZ=UTC, some unrelated suites fail locally.Screenshots
Types of changes
Checklist
Further comments
Summary by CodeRabbit