@@ -174,7 +174,7 @@ describe("RendezvousV1", function () {
174174 aliceTransport . otherParty = bobTransport ;
175175 bobTransport . otherParty = aliceTransport ;
176176
177- // alice is already signs in and generates a code
177+ // alice is already signed in and generates a code
178178 const aliceOnFailure = jest . fn ( ) ;
179179 const alice = makeMockClient ( {
180180 userId : "alice" ,
@@ -192,7 +192,7 @@ describe("RendezvousV1", function () {
192192
193193 const aliceStartProm = aliceRz . startAfterShowingCode ( ) ;
194194
195- // bob is try to sign in and scans the code
195+ // bob wants to sign in and scans the code
196196 const bobOnFailure = jest . fn ( ) ;
197197 const bobEcdh = new MSC3903ECDHRendezvousChannel (
198198 bobTransport ,
@@ -221,14 +221,135 @@ describe("RendezvousV1", function () {
221221 await bobStartPromise ;
222222 } ) ;
223223
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+
224345 it ( "new device declines protocol with outcome unsupported" , async function ( ) {
225346 const aliceTransport = makeTransport ( "Alice" , "https://test.rz/123456" ) ;
226347 const bobTransport = makeTransport ( "Bob" , "https://test.rz/999999" ) ;
227348 transports . push ( aliceTransport , bobTransport ) ;
228349 aliceTransport . otherParty = bobTransport ;
229350 bobTransport . otherParty = aliceTransport ;
230351
231- // alice is already signs in and generates a code
352+ // alice is already signed in and generates a code
232353 const aliceOnFailure = jest . fn ( ) ;
233354 const alice = makeMockClient ( {
234355 userId : "alice" ,
@@ -246,7 +367,7 @@ describe("RendezvousV1", function () {
246367
247368 const aliceStartProm = aliceRz . startAfterShowingCode ( ) ;
248369
249- // bob is try to sign in and scans the code
370+ // bob wants to sign in and scans the code
250371 const bobOnFailure = jest . fn ( ) ;
251372 const bobEcdh = new MSC3903ECDHRendezvousChannel (
252373 bobTransport ,
@@ -286,7 +407,7 @@ describe("RendezvousV1", function () {
286407 aliceTransport . otherParty = bobTransport ;
287408 bobTransport . otherParty = aliceTransport ;
288409
289- // alice is already signs in and generates a code
410+ // alice is already signed in and generates a code
290411 const aliceOnFailure = jest . fn ( ) ;
291412 const alice = makeMockClient ( {
292413 userId : "alice" ,
@@ -304,7 +425,7 @@ describe("RendezvousV1", function () {
304425
305426 const aliceStartProm = aliceRz . startAfterShowingCode ( ) ;
306427
307- // bob is try to sign in and scans the code
428+ // bob wants to sign in and scans the code
308429 const bobOnFailure = jest . fn ( ) ;
309430 const bobEcdh = new MSC3903ECDHRendezvousChannel (
310431 bobTransport ,
@@ -344,7 +465,7 @@ describe("RendezvousV1", function () {
344465 aliceTransport . otherParty = bobTransport ;
345466 bobTransport . otherParty = aliceTransport ;
346467
347- // alice is already signs in and generates a code
468+ // alice is already signed in and generates a code
348469 const aliceOnFailure = jest . fn ( ) ;
349470 const alice = makeMockClient ( {
350471 userId : "alice" ,
@@ -362,7 +483,7 @@ describe("RendezvousV1", function () {
362483
363484 const aliceStartProm = aliceRz . startAfterShowingCode ( ) ;
364485
365- // bob is try to sign in and scans the code
486+ // bob wants to sign in and scans the code
366487 const bobOnFailure = jest . fn ( ) ;
367488 const bobEcdh = new MSC3903ECDHRendezvousChannel (
368489 bobTransport ,
@@ -404,7 +525,7 @@ describe("RendezvousV1", function () {
404525 aliceTransport . otherParty = bobTransport ;
405526 bobTransport . otherParty = aliceTransport ;
406527
407- // alice is already signs in and generates a code
528+ // alice is already signed in and generates a code
408529 const aliceOnFailure = jest . fn ( ) ;
409530 const alice = makeMockClient ( {
410531 userId : "alice" ,
@@ -422,7 +543,7 @@ describe("RendezvousV1", function () {
422543
423544 const aliceStartProm = aliceRz . startAfterShowingCode ( ) ;
424545
425- // bob is try to sign in and scans the code
546+ // bob wants to sign in and scans the code
426547 const bobOnFailure = jest . fn ( ) ;
427548 const bobEcdh = new MSC3903ECDHRendezvousChannel (
428549 bobTransport ,
@@ -471,7 +592,7 @@ describe("RendezvousV1", function () {
471592 aliceTransport . otherParty = bobTransport ;
472593 bobTransport . otherParty = aliceTransport ;
473594
474- // alice is already signs in and generates a code
595+ // alice is already signed in and generates a code
475596 const aliceOnFailure = jest . fn ( ) ;
476597 const aliceVerification = jest . fn ( ) ;
477598 const alice = makeMockClient ( {
@@ -496,7 +617,7 @@ describe("RendezvousV1", function () {
496617
497618 const aliceStartProm = aliceRz . startAfterShowingCode ( ) ;
498619
499- // bob is try to sign in and scans the code
620+ // bob wants to sign in and scans the code
500621 const bobOnFailure = jest . fn ( ) ;
501622 const bobEcdh = new MSC3903ECDHRendezvousChannel (
502623 bobTransport ,
0 commit comments