Files
upstream-rocketchat/apps/meteor/client/lib/e2ee/content.spec.ts
upstream-mirror 30810eecd7
Some checks failed
Create issues from TODOs / todos (push) Failing after 3s
Close inactive issues / close-issues (push) Has been cancelled
Deploy GitHub Pages / deploy-preview (push) Has been cancelled
CI / ⚙️ Variables Setup (push) Has been cancelled
CI / ⚙️ Test Guard (push) Has been cancelled
CI / 🚀 Notify external services - draft (push) Has been cancelled
CI / 📦 Build Packages (push) Has been cancelled
CI / 📦 Meteor Build (coverage) (push) Has been cancelled
CI / 📦 Meteor Build (production) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [account-service presence-service omnichannel-transcript-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [account-service presence-service omnichannel-transcript-service], fips) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [authorization-service queue-worker-service ddp-streamer-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [authorization-service queue-worker-service ddp-streamer-service], fips) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [rocketchat], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [rocketchat], coverage) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [rocketchat], fips) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [account-service presence-service omnichannel-transcript-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [authorization-service queue-worker-service ddp-streamer-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [rocketchat], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [rocketchat], coverage) (push) Has been cancelled
CI / 🚢 Publish Docker Images (ghcr.io) (push) Has been cancelled
CI / 📦 Track Image Sizes (push) Has been cancelled
CI / 🔎 Code Check - Action Lint (push) Has been cancelled
CI / 🔎 Code Check (push) Has been cancelled
CI / 🔨 Test Storybook (push) Has been cancelled
CI / 🔨 Test Unit (push) Has been cancelled
CI / 🔨 Test API (CE) (push) Has been cancelled
CI / 🔨 Test API Livechat (CE) (push) Has been cancelled
CI / 🔨 Test UI (CE) (push) Has been cancelled
CI / 🔨 Test API (EE) (push) Has been cancelled
CI / 🔨 Test API Livechat (EE) (push) Has been cancelled
CI / 🔨 Test API Apps (deno-runtime - EE) (push) Has been cancelled
CI / 🔨 Test UI (EE) (push) Has been cancelled
CI / 🔨 Test API (FIPS) (push) Has been cancelled
CI / 🔨 Test API Livechat (FIPS) (push) Has been cancelled
CI / 🔨 Test UI (FIPS) (push) Has been cancelled
CI / 🔨 Test Federation Matrix (push) Has been cancelled
CI / 📊 Report Coverage (push) Has been cancelled
CI / ✅ Tests Done (push) Has been cancelled
CI / 🚀 Publish build assets (push) Has been cancelled
CI / 🚀 Publish Docker Images (DockerHub) (push) Has been cancelled
CI / 🚀 Notify external services (push) Has been cancelled
CI / Update Version Durability (push) Has been cancelled
Release / Release (push) Has been cancelled
Auto-close duplicate issues / auto-close-duplicates (push) Failing after 1s
Code scanning - action / CodeQL-Build (push) Failing after 2s
snapshot of https://github.com/RocketChat/Rocket.Chat.git (develop, 2026-09-16; blobs > 131072B omitted)
2026-09-16 01:21:02 +05:00

145 lines
3.7 KiB
TypeScript

import { decodeEncryptedContent } from './content';
import { importKey, decrypt, type Key } from './crypto/aes';
describe('content', () => {
const msgv1web = Object.freeze({
_id: 'JfAxN6Ncsw2XS9eiY',
rid: '68dad82a10815056615446aa',
e2eMentions: {
e2eUserMentions: [],
e2eChannelMentions: [],
},
content: Object.freeze({
algorithm: 'rc.v1.aes-sha2',
ciphertext: '32c9e7917b78LHjHfqLMeDn+2UK1PhD/soFe8CVwvFdLkslcfxNHby4=',
}),
t: 'e2e',
ts: {
$date: '2025-09-29T19:07:07.908Z',
},
u: {
_id: 'bm4cAAcN92jgXe2jN',
username: 'alice',
name: 'alice',
},
msg: '',
_updatedAt: {
$date: '2025-09-29T19:07:07.929Z',
},
urls: [],
mentions: [],
channels: [],
});
const msgv1mob = Object.freeze({
_id: 'AZF8Myj605B3f7ZPL',
rid: '68dad82a10815056615446aa',
msg: '32c9e7917b783JpM8aOVludqIRzx+DOqjEU9Mj3NUWb+/GLRl7sdkvTtCMChH1LBjMjJJvVJ6Rlw4dI8BYFftZWiCOiR7TPwriCoSPiZ7dY5C4H2q8MVSdR95ZiyG7eWQ5j5/rxzAYsSWDA9LkumW8JBb+WQ1hD9JMfQd4IXtlFMnaDgEhZhe/s=',
t: 'e2e',
e2e: 'pending',
e2eMentions: {
e2eUserMentions: [],
e2eChannelMentions: [],
},
content: Object.freeze({
algorithm: 'rc.v1.aes-sha2',
ciphertext:
'32c9e7917b783JpM8aOVludqIRzx+DOqjEU9Mj3NUWb+/GLRl7sdkvTtCMChH1LBjMjJJvVJ6Rlw4dI8BYFftZWiCOiR7TPwriCoSPiZ7dY5C4H2q8MVSdR95ZiyG7eWQ5j5/rxzAYsSWDA9LkumW8JBb+WQ1hD9JMfQd4IXtlFMnaDgEhZhe/s=',
}),
ts: {
$date: '2025-09-29T19:28:35.261Z',
},
u: {
_id: 'RQTYT5RJoDKZFwDhk',
username: 'bob',
name: 'bob',
},
_updatedAt: {
$date: '2025-09-29T19:28:35.274Z',
},
urls: [],
mentions: [],
channels: [],
});
describe('v1 messages', () => {
let key: Key<{ name: 'AES-CBC'; length: 128 }>;
beforeAll(async () => {
key = await importKey({
alg: 'A128CBC',
ext: true,
k: 'qb8In0Rpa9nwSusvxxDcbQ',
key_ops: ['encrypt', 'decrypt'],
kty: 'oct',
});
});
test('parse v1 web message', async () => {
const parsed = decodeEncryptedContent(msgv1web.content);
const decrypted = await decrypt(key, parsed);
expect(decrypted).toMatchInlineSnapshot(`"{"msg":"hello"}"`);
});
test('parse v1 mobile message', async () => {
const parsed = decodeEncryptedContent(msgv1mob.content);
const decrypted = await decrypt(key, parsed);
expect(decrypted).toMatchInlineSnapshot(
`"{"_id":"AZF8Myj605B3f7ZPL","text":"world","userId":"RQTYT5RJoDKZFwDhk","ts":{"$date":1759174115076}}"`,
);
});
test('parse v1 mobile message from msg field', async () => {
const parsed = decodeEncryptedContent(msgv1mob.msg);
const decrypted = await decrypt(key, parsed);
expect(decrypted).toMatchInlineSnapshot(
`"{"_id":"AZF8Myj605B3f7ZPL","text":"world","userId":"RQTYT5RJoDKZFwDhk","ts":{"$date":1759174115076}}"`,
);
});
});
const msgv2web = Object.freeze({
_id: 'h6sXWTiKcWfcgkhgo',
rid: '68c9da1b0427bc33b429207e',
e2eMentions: {
e2eUserMentions: [],
e2eChannelMentions: [],
},
content: Object.freeze({
algorithm: 'rc.v2.aes-sha2',
kid: 'f46d2864-0384-4a87-8815-51fba2cad216',
iv: 'wXbYQ8q9sYRCHtNp',
ciphertext: 'cIDO9mXzCCrrl/wORP0Jf6oWeusqzSCXVGGvY7CHrA==',
}),
t: 'e2e',
ts: {
$date: '2025-09-30T18:05:30.876Z',
},
u: {
_id: 'Ctk47kkuzJihnmvZE',
username: 'alice',
name: 'Alice',
},
msg: '',
_updatedAt: {
$date: '2025-09-30T18:05:30.887Z',
},
urls: [],
mentions: [],
channels: [],
});
test('parse v2 web message', async () => {
const parsed = decodeEncryptedContent(msgv2web.content);
const key = await importKey({
alg: 'A256GCM',
ext: true,
k: '9o1xoHt4OamRJvnaLna-5akUb5L98S_iWYGGaXPZ1Yg',
key_ops: ['encrypt', 'decrypt'],
kty: 'oct',
});
const decrypted = await decrypt(key, parsed);
expect(decrypted).toMatchInlineSnapshot(`"{"msg":"hello"}"`);
});
});