@webex/plugin-meetings 3.13.0-next.1 → 3.13.0-next.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/babel.config.js +17 -1
- package/dist/aiEnableRequest/index.js +1 -1
- package/dist/breakouts/breakout.js +1 -1
- package/dist/breakouts/index.js +1 -1
- package/dist/common/wasm-loader.js +174 -0
- package/dist/common/wasm-loader.js.map +1 -0
- package/dist/config.js +2 -1
- package/dist/config.js.map +1 -1
- package/dist/constants.js +1 -1
- package/dist/constants.js.map +1 -1
- package/dist/e2ee/E2eeManager.js +91 -0
- package/dist/e2ee/E2eeManager.js.map +1 -0
- package/dist/e2ee/E2eeSignaling.js +200 -0
- package/dist/e2ee/E2eeSignaling.js.map +1 -0
- package/dist/e2ee/MediaEncryptionService.js +75 -0
- package/dist/e2ee/MediaEncryptionService.js.map +1 -0
- package/dist/e2ee/mls.js +558 -0
- package/dist/e2ee/mls.js.map +1 -0
- package/dist/e2ee/types.js +59 -0
- package/dist/e2ee/types.js.map +1 -0
- package/dist/e2ee/wasm.d.js +7 -0
- package/dist/e2ee/wasm.d.js.map +1 -0
- package/dist/interpretation/index.js +1 -1
- package/dist/interpretation/siLanguage.js +1 -1
- package/dist/meetings/index.js +20 -0
- package/dist/meetings/index.js.map +1 -1
- package/dist/types/common/wasm-loader.d.ts +55 -0
- package/dist/types/config.d.ts +1 -0
- package/dist/types/constants.d.ts +1 -1
- package/dist/types/e2ee/E2eeManager.d.ts +23 -0
- package/dist/types/e2ee/E2eeSignaling.d.ts +94 -0
- package/dist/types/e2ee/MediaEncryptionService.d.ts +27 -0
- package/dist/types/e2ee/mls.d.ts +191 -0
- package/dist/types/e2ee/types.d.ts +104 -0
- package/dist/types/meetings/index.d.ts +4 -0
- package/dist/webinar/index.js +1 -1
- package/package.json +14 -14
- package/src/common/wasm-loader.ts +124 -0
- package/src/config.ts +1 -0
- package/src/constants.ts +1 -1
- package/src/e2ee/E2eeManager.ts +58 -0
- package/src/e2ee/E2eeSignaling.ts +215 -0
- package/src/e2ee/MediaEncryptionService.ts +41 -0
- package/src/e2ee/mls.ts +548 -0
- package/src/e2ee/types.ts +114 -0
- package/src/e2ee/wasm.d.ts +153 -0
- package/src/meetings/ai-docs/meetings-spec.md +2 -0
- package/src/meetings/index.ts +18 -0
- package/test/unit/spec/common/wasm-loader.ts +171 -0
- package/test/unit/spec/e2ee/E2eeManager.ts +82 -0
- package/test/unit/spec/e2ee/E2eeSignaling.ts +172 -0
- package/test/unit/spec/e2ee/MediaEncryptionService.ts +43 -0
- package/test/unit/spec/e2ee/mls.ts +765 -0
- package/test/unit/spec/meeting-info/index.js +2 -3
- package/test/unit/spec/meetings/index.js +20 -0
|
@@ -0,0 +1,765 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright (c) 2015-2026 Cisco Systems, Inc. See LICENSE file.
|
|
3
|
+
*/
|
|
4
|
+
import 'jsdom-global/register';
|
|
5
|
+
import {assert} from '@webex/test-helper-chai';
|
|
6
|
+
import sinon from 'sinon';
|
|
7
|
+
import MLS from '@webex/plugin-meetings/src/e2ee/mls';
|
|
8
|
+
import LoggerProxy from '@webex/plugin-meetings/src/common/logs/logger-proxy';
|
|
9
|
+
import testUtils from '../../../utils/testUtils';
|
|
10
|
+
|
|
11
|
+
describe('plugin-meetings', () => {
|
|
12
|
+
describe('MLS', () => {
|
|
13
|
+
let fakeE2ee;
|
|
14
|
+
let callbacks;
|
|
15
|
+
let loadModule;
|
|
16
|
+
let webE2eeConstructor;
|
|
17
|
+
let httpClient;
|
|
18
|
+
let session;
|
|
19
|
+
|
|
20
|
+
// Replaces the whole logger: other specs install loggers whose methods are already sinon stubs,
|
|
21
|
+
// so stubbing individual methods of LoggerProxy.logger fails depending on test order.
|
|
22
|
+
const stubLogger = () => {
|
|
23
|
+
const logger = {
|
|
24
|
+
info: sinon.stub(),
|
|
25
|
+
log: sinon.stub(),
|
|
26
|
+
warn: sinon.stub(),
|
|
27
|
+
error: sinon.stub(),
|
|
28
|
+
trace: sinon.stub(),
|
|
29
|
+
debug: sinon.stub(),
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
sinon.stub(LoggerProxy, 'logger').value(logger);
|
|
33
|
+
|
|
34
|
+
return logger;
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
const config = {
|
|
38
|
+
participantId: 'user-1',
|
|
39
|
+
deviceUrl: 'https://wdm.webex.com/device-1',
|
|
40
|
+
correlationId: 'corr-1',
|
|
41
|
+
displayName: 'Alice',
|
|
42
|
+
serviceUrl: 'https://mes.webex.com/group-1',
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
const buildFakeE2ee = () => {
|
|
46
|
+
callbacks = {};
|
|
47
|
+
const record = (name) =>
|
|
48
|
+
sinon.stub().callsFake((cb) => {
|
|
49
|
+
callbacks[name] = cb;
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
return {
|
|
53
|
+
initialize: sinon.stub(),
|
|
54
|
+
addX509Credential: sinon.stub(),
|
|
55
|
+
setTrustAnchors: sinon.stub(),
|
|
56
|
+
setJoinTimeout: sinon.stub(),
|
|
57
|
+
setCoalesceWindow: sinon.stub(),
|
|
58
|
+
join: sinon.stub(),
|
|
59
|
+
leave: sinon.stub(),
|
|
60
|
+
handle: sinon.stub(),
|
|
61
|
+
llmConnected: sinon.stub(),
|
|
62
|
+
setLlmConnectedBeforeJoin: sinon.stub(),
|
|
63
|
+
securityCode: sinon.stub().returns('CODE-1'),
|
|
64
|
+
roster: sinon.stub().returns([]),
|
|
65
|
+
isLeader: sinon.stub().returns(false),
|
|
66
|
+
completeHttpRequest: sinon.stub(),
|
|
67
|
+
completeWait: sinon.stub(),
|
|
68
|
+
setOnNewTransaction: record('newTransaction'),
|
|
69
|
+
setOnCompleteTransaction: record('completeTransaction'),
|
|
70
|
+
setOnHttpRequest: record('httpRequest'),
|
|
71
|
+
setOnWait: record('wait'),
|
|
72
|
+
setOnGotKey: record('gotKey'),
|
|
73
|
+
setOnUseKey: record('useKey'),
|
|
74
|
+
setOnLeader: record('leader'),
|
|
75
|
+
setOnPurgeBefore: record('purgeBefore'),
|
|
76
|
+
setOnEvicted: record('evicted'),
|
|
77
|
+
setOnAddRoster: record('addRoster'),
|
|
78
|
+
setOnRemoveRoster: record('removeRoster'),
|
|
79
|
+
setOnE2eeVersion: record('e2eeVersion'),
|
|
80
|
+
setOnMissingCommit: record('missingCommit'),
|
|
81
|
+
setOnLog: record('log'),
|
|
82
|
+
};
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
beforeEach(() => {
|
|
86
|
+
fakeE2ee = buildFakeE2ee();
|
|
87
|
+
webE2eeConstructor = sinon.stub().returns(fakeE2ee);
|
|
88
|
+
const module = {WebE2EE: webE2eeConstructor};
|
|
89
|
+
|
|
90
|
+
loadModule = sinon.stub().resolves(module);
|
|
91
|
+
httpClient = {request: sinon.stub().resolves({result: 'ok', n: 1})};
|
|
92
|
+
session = new MLS({httpClient, loadModule});
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
afterEach(() => {
|
|
96
|
+
sinon.restore();
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
describe('initialize', () => {
|
|
100
|
+
it('loads the module, wires callbacks and initializes with defaults', async () => {
|
|
101
|
+
await session.initialize(config);
|
|
102
|
+
|
|
103
|
+
assert.calledOnce(loadModule);
|
|
104
|
+
assert.calledOnceWithExactly(
|
|
105
|
+
fakeE2ee.initialize,
|
|
106
|
+
'user-1',
|
|
107
|
+
'https://wdm.webex.com/device-1',
|
|
108
|
+
'WEB',
|
|
109
|
+
'corr-1',
|
|
110
|
+
'Alice',
|
|
111
|
+
'https://mes.webex.com/group-1'
|
|
112
|
+
);
|
|
113
|
+
assert.calledOnceWithExactly(fakeE2ee.setJoinTimeout, 180000);
|
|
114
|
+
assert.calledOnceWithExactly(fakeE2ee.setCoalesceWindow, 500);
|
|
115
|
+
assert.notCalled(fakeE2ee.addX509Credential);
|
|
116
|
+
assert.notCalled(fakeE2ee.setTrustAnchors);
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
it('does not initialize a second engine when called again', async () => {
|
|
120
|
+
await session.initialize(config);
|
|
121
|
+
await session.initialize({...config, participantId: 'user-2'});
|
|
122
|
+
|
|
123
|
+
// The loader may be called again, but returns the cached WASM module.
|
|
124
|
+
assert.calledTwice(loadModule);
|
|
125
|
+
assert.calledOnce(webE2eeConstructor);
|
|
126
|
+
assert.calledOnceWithExactly(
|
|
127
|
+
fakeE2ee.initialize,
|
|
128
|
+
'user-1',
|
|
129
|
+
'https://wdm.webex.com/device-1',
|
|
130
|
+
'WEB',
|
|
131
|
+
'corr-1',
|
|
132
|
+
'Alice',
|
|
133
|
+
'https://mes.webex.com/group-1'
|
|
134
|
+
);
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
it('applies credentials, trust anchors, device type and custom timeouts', async () => {
|
|
138
|
+
const privateKey = new Uint8Array([9]);
|
|
139
|
+
const certChain = [new Uint8Array([1]), new Uint8Array([2])];
|
|
140
|
+
|
|
141
|
+
await session.initialize({
|
|
142
|
+
...config,
|
|
143
|
+
deviceType: 'MAC',
|
|
144
|
+
credentials: {privateKey, certChain},
|
|
145
|
+
trustAnchors: {webexCaRoots: 'ca-roots'},
|
|
146
|
+
joinTimeout: 5000,
|
|
147
|
+
coalesceWindow: 100,
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
assert.calledWith(fakeE2ee.initialize, 'user-1', 'https://wdm.webex.com/device-1', 'MAC');
|
|
151
|
+
|
|
152
|
+
const [passedKey, passedChain] = fakeE2ee.addX509Credential.firstCall.args;
|
|
153
|
+
|
|
154
|
+
assert.equal(passedKey, privateKey);
|
|
155
|
+
assert.instanceOf(passedChain[0], Uint8Array);
|
|
156
|
+
assert.calledOnceWithExactly(
|
|
157
|
+
fakeE2ee.setTrustAnchors,
|
|
158
|
+
'ca-roots',
|
|
159
|
+
'',
|
|
160
|
+
'',
|
|
161
|
+
new Uint8Array()
|
|
162
|
+
);
|
|
163
|
+
assert.calledOnceWithExactly(fakeE2ee.setJoinTimeout, 5000);
|
|
164
|
+
assert.calledOnceWithExactly(fakeE2ee.setCoalesceWindow, 100);
|
|
165
|
+
});
|
|
166
|
+
});
|
|
167
|
+
|
|
168
|
+
describe('engine events', () => {
|
|
169
|
+
beforeEach(async () => {
|
|
170
|
+
await session.initialize(config);
|
|
171
|
+
});
|
|
172
|
+
|
|
173
|
+
it('emits joinSuccess on a successful join transaction', () => {
|
|
174
|
+
const spy = sinon.stub();
|
|
175
|
+
const baseKey = new Uint8Array([1, 2]);
|
|
176
|
+
|
|
177
|
+
session.on('joinSuccess', spy);
|
|
178
|
+
callbacks.newTransaction({id: 'tx-1', type: 'join'});
|
|
179
|
+
callbacks.completeTransaction('tx-1', {
|
|
180
|
+
status: 'join_success',
|
|
181
|
+
epoch: 3,
|
|
182
|
+
base_key: baseKey,
|
|
183
|
+
index: 5,
|
|
184
|
+
index_bits: 8,
|
|
185
|
+
sec_code: 'SEC-CODE',
|
|
186
|
+
sframe_cipher_suite: 1,
|
|
187
|
+
sframe_epoch_bits: 4,
|
|
188
|
+
});
|
|
189
|
+
// Mutate the key to verify that we emit a copy.
|
|
190
|
+
baseKey.fill(0);
|
|
191
|
+
|
|
192
|
+
assert.calledOnce(spy);
|
|
193
|
+
const payload = spy.firstCall.args[0];
|
|
194
|
+
|
|
195
|
+
assert.equal(payload.epoch, 3);
|
|
196
|
+
assert.equal(payload.securityCode, 'SEC-CODE');
|
|
197
|
+
assert.deepEqual(payload.sframe, {cipherSuite: 1, epochBits: 4});
|
|
198
|
+
assert.deepEqual(Array.from(payload.key.baseKey), [1, 2]);
|
|
199
|
+
assert.equal(payload.key.index, 5);
|
|
200
|
+
assert.equal(payload.key.indexBits, 8);
|
|
201
|
+
assert.isFalse(payload.key.canEncrypt);
|
|
202
|
+
});
|
|
203
|
+
|
|
204
|
+
it('emits joinFailure when the join transaction fails', () => {
|
|
205
|
+
const spy = sinon.stub();
|
|
206
|
+
|
|
207
|
+
session.on('joinFailure', spy);
|
|
208
|
+
callbacks.newTransaction({id: 'tx-1', type: 'join'});
|
|
209
|
+
callbacks.completeTransaction('tx-1', {status: 'failure', reason: 'join_failure'});
|
|
210
|
+
|
|
211
|
+
assert.calledOnceWithExactly(spy, {reason: 'join_failure'});
|
|
212
|
+
});
|
|
213
|
+
|
|
214
|
+
it('logs an update transaction failure without emitting joinFailure', () => {
|
|
215
|
+
const errorLog = stubLogger().error;
|
|
216
|
+
const joinFailureSpy = sinon.stub();
|
|
217
|
+
|
|
218
|
+
session.on('joinFailure', joinFailureSpy);
|
|
219
|
+
callbacks.newTransaction({id: 'update-1', type: 'update'});
|
|
220
|
+
callbacks.completeTransaction('update-1', {status: 'failure', reason: 'update_override'});
|
|
221
|
+
// A repeated completion is ignored after the transaction has been removed.
|
|
222
|
+
callbacks.completeTransaction('update-1', {status: 'failure', reason: 'update_override'});
|
|
223
|
+
|
|
224
|
+
assert.calledOnceWithExactly(
|
|
225
|
+
errorLog,
|
|
226
|
+
'e2ee: MLS --> update transaction failed (id=update-1, reason=update_override)'
|
|
227
|
+
);
|
|
228
|
+
assert.notCalled(joinFailureSpy);
|
|
229
|
+
});
|
|
230
|
+
|
|
231
|
+
it('does not emit joinFailure when an update succeeds', () => {
|
|
232
|
+
const joinFailureSpy = sinon.stub();
|
|
233
|
+
|
|
234
|
+
session.on('joinFailure', joinFailureSpy);
|
|
235
|
+
callbacks.newTransaction({id: 'update-1', type: 'update'});
|
|
236
|
+
callbacks.completeTransaction('update-1', {status: 'update_success'});
|
|
237
|
+
|
|
238
|
+
assert.notCalled(joinFailureSpy);
|
|
239
|
+
});
|
|
240
|
+
|
|
241
|
+
it('ignores a join success result for an update transaction', () => {
|
|
242
|
+
const joinSuccessSpy = sinon.stub();
|
|
243
|
+
|
|
244
|
+
session.on('joinSuccess', joinSuccessSpy);
|
|
245
|
+
callbacks.newTransaction({id: 'update-1', type: 'update'});
|
|
246
|
+
callbacks.completeTransaction('update-1', {
|
|
247
|
+
status: 'join_success',
|
|
248
|
+
epoch: 3,
|
|
249
|
+
base_key: new Uint8Array([1]),
|
|
250
|
+
index: 0,
|
|
251
|
+
index_bits: 0,
|
|
252
|
+
sec_code: 'SEC-CODE',
|
|
253
|
+
sframe_cipher_suite: 1,
|
|
254
|
+
sframe_epoch_bits: 4,
|
|
255
|
+
});
|
|
256
|
+
|
|
257
|
+
assert.notCalled(joinSuccessSpy);
|
|
258
|
+
});
|
|
259
|
+
|
|
260
|
+
it('ignores completion for a transaction that was not registered', () => {
|
|
261
|
+
const joinFailureSpy = sinon.stub();
|
|
262
|
+
|
|
263
|
+
session.on('joinFailure', joinFailureSpy);
|
|
264
|
+
callbacks.completeTransaction('unknown', {status: 'failure', reason: 'update_override'});
|
|
265
|
+
|
|
266
|
+
assert.notCalled(joinFailureSpy);
|
|
267
|
+
});
|
|
268
|
+
|
|
269
|
+
it('ignores outstanding transaction completions after leave', () => {
|
|
270
|
+
const joinFailureSpy = sinon.stub();
|
|
271
|
+
|
|
272
|
+
session.on('joinFailure', joinFailureSpy);
|
|
273
|
+
callbacks.newTransaction({id: 'join-1', type: 'join'});
|
|
274
|
+
session.leave();
|
|
275
|
+
callbacks.completeTransaction('join-1', {status: 'failure', reason: 'timeout'});
|
|
276
|
+
|
|
277
|
+
assert.notCalled(joinFailureSpy);
|
|
278
|
+
});
|
|
279
|
+
|
|
280
|
+
it('does not emit events to a listener after it is removed', () => {
|
|
281
|
+
const spy = sinon.stub();
|
|
282
|
+
|
|
283
|
+
session.on('evicted', spy);
|
|
284
|
+
callbacks.evicted();
|
|
285
|
+
session.off('evicted', spy);
|
|
286
|
+
callbacks.evicted();
|
|
287
|
+
|
|
288
|
+
assert.calledOnceWithExactly(spy, undefined);
|
|
289
|
+
});
|
|
290
|
+
|
|
291
|
+
it('emits newKey when the engine reports a key', () => {
|
|
292
|
+
const spy = sinon.stub();
|
|
293
|
+
|
|
294
|
+
session.on('newKey', spy);
|
|
295
|
+
callbacks.gotKey({
|
|
296
|
+
epoch: 7,
|
|
297
|
+
base_key: new Uint8Array([4, 5]),
|
|
298
|
+
index: 1,
|
|
299
|
+
index_bits: 2,
|
|
300
|
+
sec_code: 'x',
|
|
301
|
+
});
|
|
302
|
+
|
|
303
|
+
assert.calledOnce(spy);
|
|
304
|
+
const key = spy.firstCall.args[0];
|
|
305
|
+
|
|
306
|
+
assert.equal(key.epoch, 7);
|
|
307
|
+
assert.deepEqual(Array.from(key.baseKey), [4, 5]);
|
|
308
|
+
assert.isFalse(key.canEncrypt);
|
|
309
|
+
});
|
|
310
|
+
|
|
311
|
+
it('emits useKey and purgeKeys', () => {
|
|
312
|
+
const useKeySpy = sinon.stub();
|
|
313
|
+
const purgeSpy = sinon.stub();
|
|
314
|
+
|
|
315
|
+
session.on('useKey', useKeySpy);
|
|
316
|
+
session.on('purgeKeys', purgeSpy);
|
|
317
|
+
callbacks.useKey(9);
|
|
318
|
+
callbacks.purgeBefore(4);
|
|
319
|
+
|
|
320
|
+
assert.calledOnceWithExactly(useKeySpy, {epoch: 9});
|
|
321
|
+
assert.calledOnceWithExactly(purgeSpy, {epoch: 4});
|
|
322
|
+
});
|
|
323
|
+
|
|
324
|
+
it('emits rosterAdded with mapped members and rosterRemoved with urls', () => {
|
|
325
|
+
const addedSpy = sinon.stub();
|
|
326
|
+
const removedSpy = sinon.stub();
|
|
327
|
+
|
|
328
|
+
session.on('rosterAdded', addedSpy);
|
|
329
|
+
session.on('rosterRemoved', removedSpy);
|
|
330
|
+
callbacks.addRoster([
|
|
331
|
+
{
|
|
332
|
+
url: 'd1',
|
|
333
|
+
display_name: 'Bob',
|
|
334
|
+
device_type: 'WEB',
|
|
335
|
+
validation_result: 0,
|
|
336
|
+
x509: [
|
|
337
|
+
{
|
|
338
|
+
result: 0,
|
|
339
|
+
member_certs: [
|
|
340
|
+
{
|
|
341
|
+
primary_name: 'bob@example.com',
|
|
342
|
+
common_name: 'Bob',
|
|
343
|
+
organization_name: 'Example',
|
|
344
|
+
email_addresses: ['bob@example.com'],
|
|
345
|
+
domain_names: ['example.com'],
|
|
346
|
+
not_before: 1000,
|
|
347
|
+
not_after: 2000,
|
|
348
|
+
signature_algorithm: 'rsa-sha256',
|
|
349
|
+
public_key_algorithm: 'rsaEncryption',
|
|
350
|
+
identity_type: 2,
|
|
351
|
+
der: new Uint8Array([1, 2, 3]),
|
|
352
|
+
},
|
|
353
|
+
],
|
|
354
|
+
},
|
|
355
|
+
],
|
|
356
|
+
},
|
|
357
|
+
]);
|
|
358
|
+
callbacks.removeRoster(['d2']);
|
|
359
|
+
|
|
360
|
+
assert.calledOnceWithExactly(addedSpy, [
|
|
361
|
+
{
|
|
362
|
+
url: 'd1',
|
|
363
|
+
displayName: 'Bob',
|
|
364
|
+
deviceType: 'WEB',
|
|
365
|
+
validationResult: 0,
|
|
366
|
+
identityResults: [
|
|
367
|
+
{
|
|
368
|
+
result: 0,
|
|
369
|
+
certificateChain: [
|
|
370
|
+
{
|
|
371
|
+
primaryName: 'bob@example.com',
|
|
372
|
+
commonName: 'Bob',
|
|
373
|
+
organizationName: 'Example',
|
|
374
|
+
emailAddresses: ['bob@example.com'],
|
|
375
|
+
domainNames: ['example.com'],
|
|
376
|
+
notBefore: 1000,
|
|
377
|
+
notAfter: 2000,
|
|
378
|
+
signatureAlgorithm: 'rsa-sha256',
|
|
379
|
+
publicKeyAlgorithm: 'rsaEncryption',
|
|
380
|
+
identityType: 2,
|
|
381
|
+
der: new Uint8Array([1, 2, 3]),
|
|
382
|
+
},
|
|
383
|
+
],
|
|
384
|
+
},
|
|
385
|
+
],
|
|
386
|
+
},
|
|
387
|
+
]);
|
|
388
|
+
assert.calledOnceWithExactly(removedSpy, {urls: ['d2']});
|
|
389
|
+
});
|
|
390
|
+
|
|
391
|
+
it('emits leaderChanged, evicted and versionNegotiated', () => {
|
|
392
|
+
const leaderSpy = sinon.stub();
|
|
393
|
+
const evictedSpy = sinon.stub();
|
|
394
|
+
const versionSpy = sinon.stub();
|
|
395
|
+
|
|
396
|
+
session.on('leaderChanged', leaderSpy);
|
|
397
|
+
session.on('evicted', evictedSpy);
|
|
398
|
+
session.on('versionNegotiated', versionSpy);
|
|
399
|
+
callbacks.leader();
|
|
400
|
+
callbacks.evicted();
|
|
401
|
+
callbacks.e2eeVersion(2);
|
|
402
|
+
|
|
403
|
+
assert.calledOnceWithExactly(leaderSpy, {isLeader: true});
|
|
404
|
+
assert.calledOnce(evictedSpy);
|
|
405
|
+
assert.calledOnceWithExactly(versionSpy, {version: 2});
|
|
406
|
+
});
|
|
407
|
+
|
|
408
|
+
it('emits securityCodeChanged only when the code actually changes', () => {
|
|
409
|
+
const spy = sinon.stub();
|
|
410
|
+
|
|
411
|
+
session.on('securityCodeChanged', spy);
|
|
412
|
+
|
|
413
|
+
// Establish the baseline security code via a successful join.
|
|
414
|
+
fakeE2ee.securityCode.returns('CODE-1');
|
|
415
|
+
callbacks.newTransaction({id: 'tx', type: 'join'});
|
|
416
|
+
callbacks.completeTransaction('tx', {
|
|
417
|
+
status: 'join_success',
|
|
418
|
+
epoch: 1,
|
|
419
|
+
base_key: new Uint8Array(),
|
|
420
|
+
index: 0,
|
|
421
|
+
index_bits: 0,
|
|
422
|
+
sec_code: 'CODE-1',
|
|
423
|
+
sframe_cipher_suite: 0,
|
|
424
|
+
sframe_epoch_bits: 0,
|
|
425
|
+
});
|
|
426
|
+
|
|
427
|
+
// Same as the baseline code -> no emit.
|
|
428
|
+
callbacks.addRoster([]);
|
|
429
|
+
assert.notCalled(spy);
|
|
430
|
+
|
|
431
|
+
// Changed -> emit once.
|
|
432
|
+
fakeE2ee.securityCode.returns('CODE-2');
|
|
433
|
+
callbacks.addRoster([]);
|
|
434
|
+
callbacks.addRoster([]);
|
|
435
|
+
callbacks.removeRoster(['d1']);
|
|
436
|
+
callbacks.removeRoster(['d1']);
|
|
437
|
+
assert.calledOnceWithExactly(spy, {code: 'CODE-2'});
|
|
438
|
+
});
|
|
439
|
+
});
|
|
440
|
+
|
|
441
|
+
describe('http and wait routing', () => {
|
|
442
|
+
beforeEach(async () => {
|
|
443
|
+
await session.initialize(config);
|
|
444
|
+
});
|
|
445
|
+
|
|
446
|
+
const encodeJson = (value) => new TextEncoder().encode(JSON.stringify(value));
|
|
447
|
+
const decodeJson = (bytes) => JSON.parse(new TextDecoder().decode(bytes));
|
|
448
|
+
|
|
449
|
+
it('copies the request body before the callback returns, since the engine reuses that memory', async () => {
|
|
450
|
+
const body = encodeJson({op: 'llmConnected'});
|
|
451
|
+
|
|
452
|
+
callbacks.httpRequest({url: 'https://mes.webex.com/op', body, handlerId: 43});
|
|
453
|
+
body.fill(0x7b);
|
|
454
|
+
|
|
455
|
+
await testUtils.flushPromises();
|
|
456
|
+
|
|
457
|
+
assert.calledOnceWithExactly(httpClient.request, 'https://mes.webex.com/op', {
|
|
458
|
+
op: 'llmConnected',
|
|
459
|
+
});
|
|
460
|
+
assert.calledOnce(fakeE2ee.completeHttpRequest);
|
|
461
|
+
assert.isTrue(fakeE2ee.completeHttpRequest.firstCall.args[1]);
|
|
462
|
+
});
|
|
463
|
+
|
|
464
|
+
it('decodes the request bytes, routes the object to the client and completes with encoded response bytes', async () => {
|
|
465
|
+
callbacks.httpRequest({
|
|
466
|
+
url: 'https://mes.webex.com/op',
|
|
467
|
+
body: encodeJson({op: 'join', epoch: 2}),
|
|
468
|
+
handlerId: 42,
|
|
469
|
+
});
|
|
470
|
+
|
|
471
|
+
assert.notCalled(httpClient.request);
|
|
472
|
+
|
|
473
|
+
await testUtils.flushPromises();
|
|
474
|
+
|
|
475
|
+
assert.calledOnceWithExactly(httpClient.request, 'https://mes.webex.com/op', {
|
|
476
|
+
op: 'join',
|
|
477
|
+
epoch: 2,
|
|
478
|
+
});
|
|
479
|
+
assert.calledOnce(fakeE2ee.completeHttpRequest);
|
|
480
|
+
|
|
481
|
+
const [handlerId, success, body, code, message] =
|
|
482
|
+
fakeE2ee.completeHttpRequest.firstCall.args;
|
|
483
|
+
|
|
484
|
+
assert.equal(handlerId, 42);
|
|
485
|
+
assert.isTrue(success);
|
|
486
|
+
assert.instanceOf(body, Uint8Array);
|
|
487
|
+
assert.deepEqual(decodeJson(body), {result: 'ok', n: 1});
|
|
488
|
+
assert.equal(code, 0);
|
|
489
|
+
assert.equal(message, '');
|
|
490
|
+
});
|
|
491
|
+
|
|
492
|
+
it('completes an undefined HTTP response as successful empty bytes', async () => {
|
|
493
|
+
httpClient.request.resolves(undefined);
|
|
494
|
+
|
|
495
|
+
callbacks.httpRequest({
|
|
496
|
+
url: 'https://mes.webex.com/op',
|
|
497
|
+
body: encodeJson({op: 'join'}),
|
|
498
|
+
handlerId: 44,
|
|
499
|
+
});
|
|
500
|
+
|
|
501
|
+
await testUtils.flushPromises();
|
|
502
|
+
|
|
503
|
+
assert.calledOnce(httpClient.request);
|
|
504
|
+
assert.calledOnce(fakeE2ee.completeHttpRequest);
|
|
505
|
+
|
|
506
|
+
const [handlerId, success, body, code, message] =
|
|
507
|
+
fakeE2ee.completeHttpRequest.firstCall.args;
|
|
508
|
+
|
|
509
|
+
assert.equal(handlerId, 44);
|
|
510
|
+
assert.isTrue(success);
|
|
511
|
+
assert.deepEqual(Array.from(body), []);
|
|
512
|
+
assert.equal(code, 0);
|
|
513
|
+
assert.equal(message, '');
|
|
514
|
+
});
|
|
515
|
+
|
|
516
|
+
[
|
|
517
|
+
{
|
|
518
|
+
description: 'passes the media-encryption error code from the response body',
|
|
519
|
+
error: Object.assign(new Error('nope'), {code: 503, body: {errorCode: 78400011}}),
|
|
520
|
+
expectedCode: 78400011,
|
|
521
|
+
expectedMessage: 'nope',
|
|
522
|
+
},
|
|
523
|
+
{
|
|
524
|
+
description: 'passes 0 when the rejection has no response body',
|
|
525
|
+
error: Object.assign(new Error('network down'), {code: 503}),
|
|
526
|
+
expectedCode: 0,
|
|
527
|
+
expectedMessage: 'network down',
|
|
528
|
+
},
|
|
529
|
+
{
|
|
530
|
+
description: 'passes 0 when the response body error code is not an integer',
|
|
531
|
+
error: Object.assign(new Error('odd'), {body: {errorCode: '78400011'}}),
|
|
532
|
+
expectedCode: 0,
|
|
533
|
+
expectedMessage: 'odd',
|
|
534
|
+
},
|
|
535
|
+
{
|
|
536
|
+
description: 'uses a default message when the rejection has none',
|
|
537
|
+
error: {body: {errorCode: 78400003}},
|
|
538
|
+
expectedCode: 78400003,
|
|
539
|
+
expectedMessage: 'Request failed',
|
|
540
|
+
},
|
|
541
|
+
].forEach(({description, error, expectedCode, expectedMessage}) => {
|
|
542
|
+
it(`completes an http request as failed when the client rejects and ${description}`, async () => {
|
|
543
|
+
const warnLog = stubLogger().warn;
|
|
544
|
+
|
|
545
|
+
httpClient.request.rejects(error);
|
|
546
|
+
|
|
547
|
+
callbacks.httpRequest({url: 'https://mes.webex.com/op', body: encodeJson({}), handlerId: 7});
|
|
548
|
+
|
|
549
|
+
await testUtils.flushPromises();
|
|
550
|
+
|
|
551
|
+
assert.calledOnceWithExactly(
|
|
552
|
+
warnLog,
|
|
553
|
+
`e2ee: MLS --> HTTP request failed (url=https://mes.webex.com/op, errorCode=${expectedCode}): ${expectedMessage}`
|
|
554
|
+
);
|
|
555
|
+
assert.calledOnce(fakeE2ee.completeHttpRequest);
|
|
556
|
+
|
|
557
|
+
const [handlerId, success, body, code, message] =
|
|
558
|
+
fakeE2ee.completeHttpRequest.firstCall.args;
|
|
559
|
+
|
|
560
|
+
assert.equal(handlerId, 7);
|
|
561
|
+
assert.isFalse(success);
|
|
562
|
+
assert.equal(body.length, 0);
|
|
563
|
+
assert.equal(code, expectedCode);
|
|
564
|
+
assert.equal(message, expectedMessage);
|
|
565
|
+
});
|
|
566
|
+
});
|
|
567
|
+
|
|
568
|
+
it('emits mediaEncryptionRequestFailure instead of rejecting when the engine throws on a failed completion', async () => {
|
|
569
|
+
const errorLog = stubLogger().error;
|
|
570
|
+
const mediaEncryptionRequestFailure = sinon.stub();
|
|
571
|
+
const unhandledRejection = sinon.stub();
|
|
572
|
+
|
|
573
|
+
process.on('unhandledRejection', unhandledRejection);
|
|
574
|
+
session.on('mediaEncryptionRequestFailure', mediaEncryptionRequestFailure);
|
|
575
|
+
httpClient.request.rejects(Object.assign(new Error('not leader'), {body: {errorCode: 78400011}}));
|
|
576
|
+
// Emscripten surfaces a thrown C++ exception as its numeric pointer.
|
|
577
|
+
fakeE2ee.completeHttpRequest.throws(12345);
|
|
578
|
+
|
|
579
|
+
try {
|
|
580
|
+
callbacks.httpRequest({url: 'https://mes.webex.com/op', body: encodeJson({}), handlerId: 7});
|
|
581
|
+
|
|
582
|
+
await testUtils.flushPromises();
|
|
583
|
+
await testUtils.flushPromises();
|
|
584
|
+
} finally {
|
|
585
|
+
process.off('unhandledRejection', unhandledRejection);
|
|
586
|
+
}
|
|
587
|
+
|
|
588
|
+
assert.calledOnce(fakeE2ee.completeHttpRequest);
|
|
589
|
+
assert.calledOnce(errorLog);
|
|
590
|
+
assert.match(
|
|
591
|
+
errorLog.firstCall.args[0],
|
|
592
|
+
/^e2ee: MLS --> engine threw while completing HTTP request \(success=false, errorCode=78400011\): /
|
|
593
|
+
);
|
|
594
|
+
assert.calledOnceWithExactly(mediaEncryptionRequestFailure, {errorCode: 78400011, message: 'not leader'});
|
|
595
|
+
assert.notCalled(unhandledRejection);
|
|
596
|
+
});
|
|
597
|
+
|
|
598
|
+
it('emits mediaEncryptionRequestFailure without retrying completion when the engine throws on a successful completion', async () => {
|
|
599
|
+
const errorLog = stubLogger().error;
|
|
600
|
+
const mediaEncryptionRequestFailure = sinon.stub();
|
|
601
|
+
|
|
602
|
+
session.on('mediaEncryptionRequestFailure', mediaEncryptionRequestFailure);
|
|
603
|
+
fakeE2ee.completeHttpRequest.throws(new Error('json parse'));
|
|
604
|
+
|
|
605
|
+
callbacks.httpRequest({url: 'https://mes.webex.com/op', body: encodeJson({}), handlerId: 7});
|
|
606
|
+
|
|
607
|
+
await testUtils.flushPromises();
|
|
608
|
+
|
|
609
|
+
assert.calledOnce(fakeE2ee.completeHttpRequest);
|
|
610
|
+
assert.isTrue(fakeE2ee.completeHttpRequest.firstCall.args[1]);
|
|
611
|
+
assert.calledOnceWithExactly(
|
|
612
|
+
errorLog,
|
|
613
|
+
'e2ee: MLS --> engine threw while completing HTTP request (success=true, errorCode=0): Error: json parse'
|
|
614
|
+
);
|
|
615
|
+
assert.calledOnceWithExactly(mediaEncryptionRequestFailure, {
|
|
616
|
+
errorCode: 0,
|
|
617
|
+
message: 'Engine failed to process HTTP response',
|
|
618
|
+
});
|
|
619
|
+
});
|
|
620
|
+
|
|
621
|
+
it('logs and completes an http request as failed when the request body is not valid JSON', async () => {
|
|
622
|
+
const errorLog = stubLogger().error;
|
|
623
|
+
|
|
624
|
+
callbacks.httpRequest({
|
|
625
|
+
url: 'https://mes.webex.com/op',
|
|
626
|
+
body: new TextEncoder().encode('{not json'),
|
|
627
|
+
handlerId: 8,
|
|
628
|
+
});
|
|
629
|
+
|
|
630
|
+
assert.notCalled(fakeE2ee.completeHttpRequest);
|
|
631
|
+
|
|
632
|
+
await testUtils.flushPromises();
|
|
633
|
+
|
|
634
|
+
assert.notCalled(httpClient.request);
|
|
635
|
+
assert.calledOnce(errorLog);
|
|
636
|
+
assert.match(
|
|
637
|
+
errorLog.firstCall.args[0],
|
|
638
|
+
/^e2ee: MLS --> failed to parse engine HTTP request body as JSON \(url=https:\/\/mes\.webex\.com\/op\): /
|
|
639
|
+
);
|
|
640
|
+
assert.calledOnce(fakeE2ee.completeHttpRequest);
|
|
641
|
+
|
|
642
|
+
const [handlerId, success, body, code, message] =
|
|
643
|
+
fakeE2ee.completeHttpRequest.firstCall.args;
|
|
644
|
+
|
|
645
|
+
assert.equal(handlerId, 8);
|
|
646
|
+
assert.isFalse(success);
|
|
647
|
+
assert.equal(body.length, 0);
|
|
648
|
+
assert.equal(code, 0);
|
|
649
|
+
assert.match(message, /^Invalid JSON in HTTP request body: /);
|
|
650
|
+
});
|
|
651
|
+
|
|
652
|
+
it('logs and completes an http request as failed when the response cannot be serialized to JSON', async () => {
|
|
653
|
+
const errorLog = stubLogger().error;
|
|
654
|
+
|
|
655
|
+
httpClient.request.resolves({big: BigInt(1)});
|
|
656
|
+
|
|
657
|
+
callbacks.httpRequest({url: 'https://mes.webex.com/op', body: encodeJson({}), handlerId: 9});
|
|
658
|
+
|
|
659
|
+
await testUtils.flushPromises();
|
|
660
|
+
|
|
661
|
+
assert.calledOnceWithExactly(httpClient.request, 'https://mes.webex.com/op', {});
|
|
662
|
+
assert.calledOnce(errorLog);
|
|
663
|
+
assert.match(
|
|
664
|
+
errorLog.firstCall.args[0],
|
|
665
|
+
/^e2ee: MLS --> failed to serialize HTTP response body as JSON \(url=https:\/\/mes\.webex\.com\/op\): /
|
|
666
|
+
);
|
|
667
|
+
assert.calledOnce(fakeE2ee.completeHttpRequest);
|
|
668
|
+
|
|
669
|
+
const [handlerId, success, body, code, message] =
|
|
670
|
+
fakeE2ee.completeHttpRequest.firstCall.args;
|
|
671
|
+
|
|
672
|
+
assert.equal(handlerId, 9);
|
|
673
|
+
assert.isFalse(success);
|
|
674
|
+
assert.equal(body.length, 0);
|
|
675
|
+
assert.equal(code, 0);
|
|
676
|
+
assert.match(message, /^Unserializable HTTP response body: /);
|
|
677
|
+
});
|
|
678
|
+
|
|
679
|
+
it('schedules a wait and completes it', () => {
|
|
680
|
+
const setTimeoutStub = sinon.stub(global, 'setTimeout');
|
|
681
|
+
|
|
682
|
+
callbacks.wait(1500, 11);
|
|
683
|
+
|
|
684
|
+
assert.calledOnce(setTimeoutStub);
|
|
685
|
+
assert.equal(setTimeoutStub.firstCall.args[1], 1500);
|
|
686
|
+
assert.notCalled(fakeE2ee.completeWait);
|
|
687
|
+
|
|
688
|
+
setTimeoutStub.firstCall.args[0]();
|
|
689
|
+
|
|
690
|
+
assert.calledOnceWithExactly(fakeE2ee.completeWait, 11);
|
|
691
|
+
});
|
|
692
|
+
});
|
|
693
|
+
|
|
694
|
+
describe('log routing', () => {
|
|
695
|
+
beforeEach(async () => {
|
|
696
|
+
await session.initialize(config);
|
|
697
|
+
});
|
|
698
|
+
|
|
699
|
+
it('maps WASM log levels to the plugin logger', () => {
|
|
700
|
+
const logger = stubLogger();
|
|
701
|
+
|
|
702
|
+
// Engine LogLevel: fatal=1, error=2, warn=3, info=4, debug=5.
|
|
703
|
+
callbacks.log(1, 'a fatal');
|
|
704
|
+
callbacks.log(2, 'an error');
|
|
705
|
+
callbacks.log(3, 'a warning');
|
|
706
|
+
callbacks.log(4, 'an info');
|
|
707
|
+
callbacks.log(5, 'a debug');
|
|
708
|
+
|
|
709
|
+
assert.calledWithMatch(logger.error, 'a fatal');
|
|
710
|
+
assert.calledWithMatch(logger.error, 'an error');
|
|
711
|
+
assert.calledWithMatch(logger.warn, 'a warning');
|
|
712
|
+
assert.calledWithMatch(logger.info, 'an info');
|
|
713
|
+
assert.calledWithMatch(logger.debug, 'a debug');
|
|
714
|
+
});
|
|
715
|
+
});
|
|
716
|
+
|
|
717
|
+
describe('delegating methods', () => {
|
|
718
|
+
beforeEach(async () => {
|
|
719
|
+
await session.initialize(config);
|
|
720
|
+
});
|
|
721
|
+
|
|
722
|
+
it('forwards lifecycle calls to the engine', () => {
|
|
723
|
+
const event = new Uint8Array([1, 2, 3]);
|
|
724
|
+
|
|
725
|
+
session.join();
|
|
726
|
+
session.leave();
|
|
727
|
+
session.handleEvent(event, 'llm');
|
|
728
|
+
session.setLlmConnectedBeforeJoin(true);
|
|
729
|
+
session.llmConnected();
|
|
730
|
+
|
|
731
|
+
assert.calledOnce(fakeE2ee.join);
|
|
732
|
+
assert.calledOnce(fakeE2ee.leave);
|
|
733
|
+
assert.calledOnce(fakeE2ee.handle);
|
|
734
|
+
assert.deepEqual(Array.from(fakeE2ee.handle.firstCall.args[0]), [1, 2, 3]);
|
|
735
|
+
assert.calledOnceWithExactly(fakeE2ee.setLlmConnectedBeforeJoin, true);
|
|
736
|
+
assert.calledOnce(fakeE2ee.llmConnected);
|
|
737
|
+
});
|
|
738
|
+
|
|
739
|
+
it('exposes security code, roster and leader state', () => {
|
|
740
|
+
fakeE2ee.securityCode.returns('SEC');
|
|
741
|
+
fakeE2ee.isLeader.returns(true);
|
|
742
|
+
fakeE2ee.roster.returns([
|
|
743
|
+
{url: 'd1', display_name: 'Bob', device_type: 'WEB', validation_result: 1},
|
|
744
|
+
]);
|
|
745
|
+
|
|
746
|
+
assert.equal(session.getSecurityCode(), 'SEC');
|
|
747
|
+
assert.isTrue(session.isLeader());
|
|
748
|
+
assert.deepEqual(session.getRoster(), [
|
|
749
|
+
{url: 'd1', displayName: 'Bob', deviceType: 'WEB', validationResult: 1},
|
|
750
|
+
]);
|
|
751
|
+
});
|
|
752
|
+
});
|
|
753
|
+
|
|
754
|
+
describe('before initialization', () => {
|
|
755
|
+
it('returns empty defaults and throws on lifecycle calls', () => {
|
|
756
|
+
assert.equal(session.getSecurityCode(), '');
|
|
757
|
+
assert.deepEqual(session.getRoster(), []);
|
|
758
|
+
assert.isFalse(session.isLeader());
|
|
759
|
+
assert.throws(() => session.join(), /not initialized/);
|
|
760
|
+
assert.throws(() => session.leave(), /not initialized/);
|
|
761
|
+
assert.throws(() => session.handleEvent(new Uint8Array(), 'llm'), /not initialized/);
|
|
762
|
+
});
|
|
763
|
+
});
|
|
764
|
+
});
|
|
765
|
+
});
|