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 1s
82 lines
2.5 KiB
TypeScript
82 lines
2.5 KiB
TypeScript
import * as Aes from './crypto/aes';
|
|
import { E2ERoom } from './rocketchat.e2e.room';
|
|
import { sdk } from '../SDKClient';
|
|
|
|
jest.mock('./crypto/aes');
|
|
jest.mock('../../../client/lib/SDKClient', () => ({
|
|
sdk: { rest: { post: jest.fn() } },
|
|
}));
|
|
jest.mock('../../../app/utils/rocketchat.info', () => ({
|
|
Info: { version: '8.7.0' },
|
|
}));
|
|
|
|
class FakeResponse {
|
|
constructor(
|
|
private readonly body: unknown,
|
|
public readonly status = 400,
|
|
) {}
|
|
|
|
clone() {
|
|
return this;
|
|
}
|
|
|
|
async json() {
|
|
return this.body;
|
|
}
|
|
}
|
|
(global as any).Response = FakeResponse;
|
|
|
|
const makeRoom = () => new E2ERoom('user-1', { _id: 'room-1', t: 'p', encrypted: true } as any);
|
|
|
|
describe('E2ERoom.createGroupKey', () => {
|
|
beforeEach(() => {
|
|
jest.clearAllMocks();
|
|
(Aes.generate as jest.Mock).mockResolvedValue('group-key');
|
|
(Aes.exportJwk as jest.Mock).mockResolvedValue({ k: 'jwk' });
|
|
});
|
|
|
|
afterEach(() => {
|
|
jest.restoreAllMocks();
|
|
});
|
|
|
|
it('should discard the local key and not distribute it when it loses the race', async () => {
|
|
(sdk.rest.post as jest.Mock).mockRejectedValueOnce(
|
|
new (global as any).Response({ success: false, errorType: 'error-room-e2e-key-already-exists' }),
|
|
);
|
|
|
|
const e2eRoom = makeRoom();
|
|
const result = await e2eRoom.createGroupKey();
|
|
|
|
expect(result).toBe(false);
|
|
expect(e2eRoom.groupSessionKey).toBeNull();
|
|
expect(e2eRoom.keyID).toBeUndefined();
|
|
expect(sdk.rest.post).toHaveBeenCalledTimes(1); // only setRoomKeyID was called
|
|
expect(sdk.rest.post).toHaveBeenCalledWith('/v1/e2e.setRoomKeyID', { rid: e2eRoom.roomId, keyID: expect.any(String) });
|
|
});
|
|
|
|
it('should return true and distribute the key when it wins the race', async () => {
|
|
(sdk.rest.post as jest.Mock).mockResolvedValue({});
|
|
jest.spyOn(E2ERoom.prototype as any, 'encryptGroupKeyForParticipant').mockResolvedValue('mykey');
|
|
const encryptForOthersSpy = jest.spyOn(E2ERoom.prototype as any, 'encryptKeyForOtherParticipants').mockResolvedValue(undefined);
|
|
|
|
const e2eRoom = makeRoom();
|
|
const result = await e2eRoom.createGroupKey();
|
|
|
|
expect(result).toBe(true);
|
|
expect(e2eRoom.groupSessionKey).not.toBeNull();
|
|
|
|
expect(sdk.rest.post).toHaveBeenCalledWith('/v1/e2e.setRoomKeyID', {
|
|
rid: e2eRoom.roomId,
|
|
keyID: expect.any(String),
|
|
});
|
|
expect(sdk.rest.post).toHaveBeenCalledWith('/v1/e2e.updateGroupKey', {
|
|
rid: e2eRoom.roomId,
|
|
uid: e2eRoom.userId,
|
|
key: 'mykey',
|
|
});
|
|
|
|
expect(encryptForOthersSpy).toHaveBeenCalledTimes(1);
|
|
expect(sdk.rest.post).toHaveBeenCalledTimes(2); // both setRoomKeyID and updateGroupKey are called
|
|
});
|
|
});
|