@@ -174,7 +174,7 @@ describe("RendezvousV1", function () {
174
174
aliceTransport . otherParty = bobTransport ;
175
175
bobTransport . otherParty = aliceTransport ;
176
176
177
- // alice is already signs in and generates a code
177
+ // alice is already signed in and generates a code
178
178
const aliceOnFailure = jest . fn ( ) ;
179
179
const alice = makeMockClient ( {
180
180
userId : "alice" ,
@@ -192,7 +192,7 @@ describe("RendezvousV1", function () {
192
192
193
193
const aliceStartProm = aliceRz . startAfterShowingCode ( ) ;
194
194
195
- // bob is try to sign in and scans the code
195
+ // bob wants to sign in and scans the code
196
196
const bobOnFailure = jest . fn ( ) ;
197
197
const bobEcdh = new MSC3903ECDHRendezvousChannel (
198
198
bobTransport ,
@@ -221,14 +221,135 @@ describe("RendezvousV1", function () {
221
221
await bobStartPromise ;
222
222
} ) ;
223
223
224
+ it ( "other device already signed in" , async function ( ) {
225
+ const aliceTransport = makeTransport ( "Alice" , "https://test.rz/123456" ) ;
226
+ const bobTransport = makeTransport ( "Bob" , "https://test.rz/999999" ) ;
227
+ transports . push ( aliceTransport , bobTransport ) ;
228
+ aliceTransport . otherParty = bobTransport ;
229
+ bobTransport . otherParty = aliceTransport ;
230
+
231
+ // alice is already signed in and generates a code
232
+ const aliceOnFailure = jest . fn ( ) ;
233
+ const alice = makeMockClient ( {
234
+ userId : "alice" ,
235
+ deviceId : "ALICE" ,
236
+ msc3882Enabled : true ,
237
+ msc3886Enabled : false ,
238
+ } ) ;
239
+ const aliceEcdh = new MSC3903ECDHRendezvousChannel ( aliceTransport , undefined , aliceOnFailure ) ;
240
+ const aliceRz = new MSC3906Rendezvous ( aliceEcdh , alice , undefined , true ) ;
241
+ aliceTransport . onCancelled = aliceOnFailure ;
242
+ await aliceRz . generateCode ( ) ;
243
+ const code = JSON . parse ( aliceRz . code ! ) as ECDHRendezvousCode ;
244
+
245
+ expect ( code . rendezvous . key ) . toBeDefined ( ) ;
246
+
247
+ const aliceStartProm = aliceRz . startAfterShowingCode ( ) ;
248
+
249
+ // bob wants to sign in and scans the code
250
+ const bobOnFailure = jest . fn ( ) ;
251
+ const bobEcdh = new MSC3903ECDHRendezvousChannel (
252
+ bobTransport ,
253
+ decodeBase64 ( code . rendezvous . key ) , // alice's public key
254
+ bobOnFailure ,
255
+ ) ;
256
+
257
+ const bobStartPromise = ( async ( ) => {
258
+ const bobChecksum = await bobEcdh . connect ( ) ;
259
+ logger . info ( `Bob checksums is ${ bobChecksum } now sending intent` ) ;
260
+ // await bobEcdh.send({ type: 'm.login.progress', intent: RendezvousIntent.LOGIN_ON_NEW_DEVICE });
261
+
262
+ // wait for protocols
263
+ logger . info ( "Bob waiting for protocols" ) ;
264
+ const protocols = await bobEcdh . receive ( ) ;
265
+
266
+ logger . info ( `Bob protocols: ${ JSON . stringify ( protocols ) } ` ) ;
267
+
268
+ expect ( protocols ) . toEqual ( {
269
+ type : "m.login.progress" ,
270
+ protocols : [ "org.matrix.msc3906.login_token" ] ,
271
+ } ) ;
272
+
273
+ await bobEcdh . send ( {
274
+ type : "m.login.finish" ,
275
+ intent : RendezvousIntent . RECIPROCATE_LOGIN_ON_EXISTING_DEVICE ,
276
+ } ) ;
277
+ } ) ( ) ;
278
+
279
+ await aliceStartProm ;
280
+ await bobStartPromise ;
281
+
282
+ expect ( aliceOnFailure ) . toHaveBeenCalledWith ( RendezvousFailureReason . OtherDeviceAlreadySignedIn ) ;
283
+ } ) ;
284
+
285
+ it ( "invalid payload after protocols" , async function ( ) {
286
+ const aliceTransport = makeTransport ( "Alice" , "https://test.rz/123456" ) ;
287
+ const bobTransport = makeTransport ( "Bob" , "https://test.rz/999999" ) ;
288
+ transports . push ( aliceTransport , bobTransport ) ;
289
+ aliceTransport . otherParty = bobTransport ;
290
+ bobTransport . otherParty = aliceTransport ;
291
+
292
+ // alice is already signed in and generates a code
293
+ const aliceOnFailure = jest . fn ( ) ;
294
+ const alice = makeMockClient ( {
295
+ userId : "alice" ,
296
+ deviceId : "ALICE" ,
297
+ msc3882Enabled : true ,
298
+ msc3886Enabled : false ,
299
+ } ) ;
300
+ const aliceEcdh = new MSC3903ECDHRendezvousChannel ( aliceTransport , undefined , aliceOnFailure ) ;
301
+ const aliceRz = new MSC3906Rendezvous ( aliceEcdh , alice , undefined , true ) ;
302
+ aliceTransport . onCancelled = aliceOnFailure ;
303
+ await aliceRz . generateCode ( ) ;
304
+ const code = JSON . parse ( aliceRz . code ! ) as ECDHRendezvousCode ;
305
+
306
+ expect ( code . rendezvous . key ) . toBeDefined ( ) ;
307
+
308
+ const aliceStartProm = aliceRz . startAfterShowingCode ( ) ;
309
+
310
+ // bob wants to sign in and scans the code
311
+ const bobOnFailure = jest . fn ( ) ;
312
+ const bobEcdh = new MSC3903ECDHRendezvousChannel (
313
+ bobTransport ,
314
+ decodeBase64 ( code . rendezvous . key ) , // alice's public key
315
+ bobOnFailure ,
316
+ ) ;
317
+
318
+ const bobStartPromise = ( async ( ) => {
319
+ const bobChecksum = await bobEcdh . connect ( ) ;
320
+ logger . info ( `Bob checksums is ${ bobChecksum } now sending intent` ) ;
321
+ // await bobEcdh.send({ type: 'm.login.progress', intent: RendezvousIntent.LOGIN_ON_NEW_DEVICE });
322
+
323
+ // wait for protocols
324
+ logger . info ( "Bob waiting for protocols" ) ;
325
+ const protocols = await bobEcdh . receive ( ) ;
326
+
327
+ logger . info ( `Bob protocols: ${ JSON . stringify ( protocols ) } ` ) ;
328
+
329
+ expect ( protocols ) . toEqual ( {
330
+ type : "m.login.progress" ,
331
+ protocols : [ "org.matrix.msc3906.login_token" ] ,
332
+ } ) ;
333
+
334
+ await bobEcdh . send ( {
335
+ type : "invalid" ,
336
+ } ) ;
337
+ } ) ( ) ;
338
+
339
+ await aliceStartProm ;
340
+ await bobStartPromise ;
341
+
342
+ expect ( aliceOnFailure ) . toHaveBeenCalledWith ( RendezvousFailureReason . Unknown ) ;
343
+ } ) ;
344
+
224
345
it ( "new device declines protocol with outcome unsupported" , async function ( ) {
225
346
const aliceTransport = makeTransport ( "Alice" , "https://test.rz/123456" ) ;
226
347
const bobTransport = makeTransport ( "Bob" , "https://test.rz/999999" ) ;
227
348
transports . push ( aliceTransport , bobTransport ) ;
228
349
aliceTransport . otherParty = bobTransport ;
229
350
bobTransport . otherParty = aliceTransport ;
230
351
231
- // alice is already signs in and generates a code
352
+ // alice is already signed in and generates a code
232
353
const aliceOnFailure = jest . fn ( ) ;
233
354
const alice = makeMockClient ( {
234
355
userId : "alice" ,
@@ -246,7 +367,7 @@ describe("RendezvousV1", function () {
246
367
247
368
const aliceStartProm = aliceRz . startAfterShowingCode ( ) ;
248
369
249
- // bob is try to sign in and scans the code
370
+ // bob wants to sign in and scans the code
250
371
const bobOnFailure = jest . fn ( ) ;
251
372
const bobEcdh = new MSC3903ECDHRendezvousChannel (
252
373
bobTransport ,
@@ -286,7 +407,7 @@ describe("RendezvousV1", function () {
286
407
aliceTransport . otherParty = bobTransport ;
287
408
bobTransport . otherParty = aliceTransport ;
288
409
289
- // alice is already signs in and generates a code
410
+ // alice is already signed in and generates a code
290
411
const aliceOnFailure = jest . fn ( ) ;
291
412
const alice = makeMockClient ( {
292
413
userId : "alice" ,
@@ -304,7 +425,7 @@ describe("RendezvousV1", function () {
304
425
305
426
const aliceStartProm = aliceRz . startAfterShowingCode ( ) ;
306
427
307
- // bob is try to sign in and scans the code
428
+ // bob wants to sign in and scans the code
308
429
const bobOnFailure = jest . fn ( ) ;
309
430
const bobEcdh = new MSC3903ECDHRendezvousChannel (
310
431
bobTransport ,
@@ -344,7 +465,7 @@ describe("RendezvousV1", function () {
344
465
aliceTransport . otherParty = bobTransport ;
345
466
bobTransport . otherParty = aliceTransport ;
346
467
347
- // alice is already signs in and generates a code
468
+ // alice is already signed in and generates a code
348
469
const aliceOnFailure = jest . fn ( ) ;
349
470
const alice = makeMockClient ( {
350
471
userId : "alice" ,
@@ -362,7 +483,7 @@ describe("RendezvousV1", function () {
362
483
363
484
const aliceStartProm = aliceRz . startAfterShowingCode ( ) ;
364
485
365
- // bob is try to sign in and scans the code
486
+ // bob wants to sign in and scans the code
366
487
const bobOnFailure = jest . fn ( ) ;
367
488
const bobEcdh = new MSC3903ECDHRendezvousChannel (
368
489
bobTransport ,
@@ -404,7 +525,7 @@ describe("RendezvousV1", function () {
404
525
aliceTransport . otherParty = bobTransport ;
405
526
bobTransport . otherParty = aliceTransport ;
406
527
407
- // alice is already signs in and generates a code
528
+ // alice is already signed in and generates a code
408
529
const aliceOnFailure = jest . fn ( ) ;
409
530
const alice = makeMockClient ( {
410
531
userId : "alice" ,
@@ -422,7 +543,7 @@ describe("RendezvousV1", function () {
422
543
423
544
const aliceStartProm = aliceRz . startAfterShowingCode ( ) ;
424
545
425
- // bob is try to sign in and scans the code
546
+ // bob wants to sign in and scans the code
426
547
const bobOnFailure = jest . fn ( ) ;
427
548
const bobEcdh = new MSC3903ECDHRendezvousChannel (
428
549
bobTransport ,
@@ -471,7 +592,7 @@ describe("RendezvousV1", function () {
471
592
aliceTransport . otherParty = bobTransport ;
472
593
bobTransport . otherParty = aliceTransport ;
473
594
474
- // alice is already signs in and generates a code
595
+ // alice is already signed in and generates a code
475
596
const aliceOnFailure = jest . fn ( ) ;
476
597
const aliceVerification = jest . fn ( ) ;
477
598
const alice = makeMockClient ( {
@@ -496,7 +617,7 @@ describe("RendezvousV1", function () {
496
617
497
618
const aliceStartProm = aliceRz . startAfterShowingCode ( ) ;
498
619
499
- // bob is try to sign in and scans the code
620
+ // bob wants to sign in and scans the code
500
621
const bobOnFailure = jest . fn ( ) ;
501
622
const bobEcdh = new MSC3903ECDHRendezvousChannel (
502
623
bobTransport ,
0 commit comments