From b2509316cda65c0c1ec51cea5558794b3e597947 Mon Sep 17 00:00:00 2001 From: Kerry Archibald Date: Fri, 16 Sep 2022 11:33:12 +0200 Subject: [PATCH 1/9] renamed: spec/unit/crypto/verification/sas.spec.js -> spec/unit/crypto/verification/sas.spec.ts --- spec/unit/crypto/verification/{sas.spec.js => sas.spec.ts} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename spec/unit/crypto/verification/{sas.spec.js => sas.spec.ts} (100%) diff --git a/spec/unit/crypto/verification/sas.spec.js b/spec/unit/crypto/verification/sas.spec.ts similarity index 100% rename from spec/unit/crypto/verification/sas.spec.js rename to spec/unit/crypto/verification/sas.spec.ts From 2c9963b37e25290d9e674453e07fe8988dd630fc Mon Sep 17 00:00:00 2001 From: Kerry Archibald Date: Fri, 16 Sep 2022 11:37:40 +0200 Subject: [PATCH 2/9] ts issues in sas.spec --- spec/unit/crypto/verification/sas.spec.ts | 29 ++++++++++++----------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/spec/unit/crypto/verification/sas.spec.ts b/spec/unit/crypto/verification/sas.spec.ts index 7344c037968..5866e06f054 100644 --- a/spec/unit/crypto/verification/sas.spec.ts +++ b/spec/unit/crypto/verification/sas.spec.ts @@ -19,10 +19,14 @@ import { makeTestClients, setupWebcrypto, teardownWebcrypto } from './util'; import { MatrixEvent } from "../../../../src/models/event"; import { SAS } from "../../../../src/crypto/verification/SAS"; import { DeviceInfo } from "../../../../src/crypto/deviceinfo"; -import { verificationMethods } from "../../../../src/crypto"; +import { CryptoEvent, verificationMethods } from "../../../../src/crypto"; import * as olmlib from "../../../../src/crypto/olmlib"; import { logger } from "../../../../src/logger"; import { resetCrossSigningKeys } from "../crypto-utils"; +import { VerificationBase } from "../../../../src/crypto/verification/Base"; +import { IVerificationChannel } from "../../../../src/crypto/verification/request/Channel"; +import { MatrixClient } from "../../../../src"; +import { VerificationRequest } from "../../../../src/crypto/verification/request/VerificationRequest"; const Olm = global.Olm; @@ -48,13 +52,14 @@ describe("SAS verification", function() { //channel, baseApis, userId, deviceId, startEvent, request const request = { onVerifierCancelled: function() {}, - }; + } as VerificationRequest; const channel = { send: function() { return Promise.resolve(); }, - }; - const sas = new SAS(channel, {}, "@alice:example.com", "ABCDEFG", null, request); + } as unknown as IVerificationChannel; + const mockClient = {} as unknown as MatrixClient; + const sas = new SAS(channel, mockClient, "@alice:example.com", "ABCDEFG", null, request); sas.handleEvent(new MatrixEvent({ sender: "@alice:example.com", type: "es.inquisition", @@ -65,7 +70,7 @@ describe("SAS verification", function() { expect(spy).toHaveBeenCalled(); // Cancel the SAS for cleanup (we started a verification, so abort) - sas.cancel(); + sas.cancel(new Error('error')); }); describe("verification", () => { @@ -403,16 +408,12 @@ describe("SAS verification", function() { }, ); alice.client.setDeviceVerified = jest.fn(); - alice.client.downloadKeys = () => { - return Promise.resolve(); - }; + alice.client.downloadKeys = jest.fn().mockResolvedValue({}); bob.client.setDeviceVerified = jest.fn(); - bob.client.downloadKeys = () => { - return Promise.resolve(); - }; + bob.client.downloadKeys = jest.fn().mockResolvedValue({}); - const bobPromise = new Promise((resolve, reject) => { - bob.client.on("crypto.verification.request", request => { + const bobPromise = new Promise>((resolve, reject) => { + bob.client.on(CryptoEvent.VerificationRequest, request => { request.verifier.on("show_sas", (e) => { e.mismatch(); }); @@ -501,7 +502,7 @@ describe("SAS verification", function() { aliceSasEvent = null; bobSasEvent = null; - bobPromise = new Promise((resolve, reject) => { + bobPromise = new Promise((resolve, reject) => { bob.client.on("crypto.verification.request", async (request) => { const verifier = request.beginKeyVerification(SAS.NAME); verifier.on("show_sas", (e) => { From 291897ec45384a27bfd21ba239c8e1e87256b172 Mon Sep 17 00:00:00 2001 From: Kerry Archibald Date: Fri, 16 Sep 2022 11:38:01 +0200 Subject: [PATCH 3/9] renamed: spec/unit/crypto/verification/secret_request.spec.js -> spec/unit/crypto/verification/secret_request.spec.ts --- .../{secret_request.spec.js => secret_request.spec.ts} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename spec/unit/crypto/verification/{secret_request.spec.js => secret_request.spec.ts} (100%) diff --git a/spec/unit/crypto/verification/secret_request.spec.js b/spec/unit/crypto/verification/secret_request.spec.ts similarity index 100% rename from spec/unit/crypto/verification/secret_request.spec.js rename to spec/unit/crypto/verification/secret_request.spec.ts From 82573e26936121e51630050889e46150678fd66d Mon Sep 17 00:00:00 2001 From: Kerry Archibald Date: Fri, 16 Sep 2022 11:41:50 +0200 Subject: [PATCH 4/9] ts issues in secret_request.spec --- .../verification/secret_request.spec.ts | 26 +++++++++++++++---- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/spec/unit/crypto/verification/secret_request.spec.ts b/spec/unit/crypto/verification/secret_request.spec.ts index 398edc10a60..e3f784771e5 100644 --- a/spec/unit/crypto/verification/secret_request.spec.ts +++ b/spec/unit/crypto/verification/secret_request.spec.ts @@ -18,6 +18,8 @@ import { CrossSigningInfo } from '../../../../src/crypto/CrossSigning'; import { encodeBase64 } from "../../../../src/crypto/olmlib"; import { setupWebcrypto, teardownWebcrypto } from './util'; import { VerificationBase } from '../../../../src/crypto/verification/Base'; +import { MatrixClient } from '../../../../src'; +import { VerificationRequest } from '../../../../src/crypto/verification/request/VerificationRequest'; jest.useFakeTimers(); @@ -54,9 +56,21 @@ describe("self-verifications", () => { cacheCallbacks, ); crossSigningInfo.keys = { - master: { keys: { X: testKeyPub } }, - self_signing: { keys: { X: testKeyPub } }, - user_signing: { keys: { X: testKeyPub } }, + master: { + keys: { X: testKeyPub }, + usage: [], + user_id: 'user-id', + }, + self_signing: { + keys: { X: testKeyPub }, + usage: [], + user_id: 'user-id', + }, + user_signing: { + keys: { X: testKeyPub }, + usage: [], + user_id: 'user-id', + }, }; const secretStorage = { @@ -79,11 +93,11 @@ describe("self-verifications", () => { getUserId: () => userId, getKeyBackupVersion: () => Promise.resolve({}), restoreKeyBackupWithCache, - }; + } as unknown as MatrixClient; const request = { onVerifierFinished: () => undefined, - }; + } as unknown as VerificationRequest; const verification = new VerificationBase( undefined, // channel @@ -93,6 +107,8 @@ describe("self-verifications", () => { undefined, // startEvent request, ); + + // @ts-ignore set private property verification.resolve = () => undefined; const result = await verification.done(); From 45dd170df687fbbe330d15482b66d3793862cc1f Mon Sep 17 00:00:00 2001 From: Kerry Archibald Date: Fri, 16 Sep 2022 11:42:06 +0200 Subject: [PATCH 5/9] renamed: spec/unit/crypto/verification/verification_request.spec.js -> spec/unit/crypto/verification/verification_request.spec.ts --- ...{verification_request.spec.js => verification_request.spec.ts} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename spec/unit/crypto/verification/{verification_request.spec.js => verification_request.spec.ts} (100%) diff --git a/spec/unit/crypto/verification/verification_request.spec.js b/spec/unit/crypto/verification/verification_request.spec.ts similarity index 100% rename from spec/unit/crypto/verification/verification_request.spec.js rename to spec/unit/crypto/verification/verification_request.spec.ts From ff0b8dc9511b7f984bce41d78ae1fead9feca4b7 Mon Sep 17 00:00:00 2001 From: Kerry Archibald Date: Fri, 16 Sep 2022 12:05:05 +0200 Subject: [PATCH 6/9] ts fix verification_req.spec --- .../verification/verification_request.spec.ts | 72 +++++++++++++------ 1 file changed, 50 insertions(+), 22 deletions(-) diff --git a/spec/unit/crypto/verification/verification_request.spec.ts b/spec/unit/crypto/verification/verification_request.spec.ts index f8de29cee66..d16b9a4e8c8 100644 --- a/spec/unit/crypto/verification/verification_request.spec.ts +++ b/spec/unit/crypto/verification/verification_request.spec.ts @@ -19,9 +19,16 @@ import { InRoomChannel } from "../../../../src/crypto/verification/request/InRoo import { ToDeviceChannel } from "../../../../src/crypto/verification/request/ToDeviceChannel"; import { MatrixEvent } from "../../../../src/models/event"; +import { MatrixClient } from "../../../../src/client"; import { setupWebcrypto, teardownWebcrypto } from "./util"; - -function makeMockClient(userId, deviceId) { +import { IVerificationChannel } from "../../../../src/crypto/verification/request/Channel"; +import { VerificationBase } from "../../../../src/crypto/verification/Base"; + +type MockClient = MatrixClient & { + popEvents: () => MatrixEvent[]; + popDeviceEvents: (userId: string, deviceId: string) => MatrixEvent[]; +}; +function makeMockClient(userId: string, deviceId: string): MockClient { let counter = 1; let events = []; const deviceEvents = {}; @@ -54,16 +61,18 @@ function makeMockClient(userId, deviceId) { deviceEvents[userId][deviceId].push(event); } } - return Promise.resolve(); + return Promise.resolve({}); }, - popEvents() { + // @ts-ignore special testing fn + popEvents(): MatrixEvent[] { const e = events; events = []; return e; }, - popDeviceEvents(userId, deviceId) { + // @ts-ignore special testing fn + popDeviceEvents(userId: string, deviceId: string): MatrixEvent[] { const forDevice = deviceEvents[userId]; const events = forDevice && forDevice[deviceId]; const result = events || []; @@ -72,12 +81,21 @@ function makeMockClient(userId, deviceId) { } return result; }, - }; + } as unknown as MockClient; } const MOCK_METHOD = "mock-verify"; -class MockVerifier { - constructor(channel, client, userId, deviceId, startEvent) { +class MockVerifier extends VerificationBase<'', any> { + public _channel; + public _startEvent; + constructor( + channel: IVerificationChannel, + client: MatrixClient, + userId: string, + deviceId: string, + startEvent: MatrixEvent, + ) { + super(channel, client, userId, deviceId, startEvent, {} as unknown as VerificationRequest); this._channel = channel; this._startEvent = startEvent; } @@ -115,7 +133,7 @@ function makeRemoteEcho(event) { async function distributeEvent(ownRequest, theirRequest, event) { await ownRequest.channel.handleEvent( - makeRemoteEcho(event), ownRequest, true); + makeRemoteEcho(event), ownRequest, true); await theirRequest.channel.handleEvent(event, theirRequest, true); } @@ -133,12 +151,15 @@ describe("verification request unit tests", function() { it("transition from UNSENT to DONE through happy path", async function() { const alice = makeMockClient("@alice:matrix.tld", "device1"); const bob = makeMockClient("@bob:matrix.tld", "device1"); + const verificationMethods = new Map( + [[MOCK_METHOD, MockVerifier]], + ) as unknown as Map; const aliceRequest = new VerificationRequest( new InRoomChannel(alice, "!room", bob.getUserId()), - new Map([[MOCK_METHOD, MockVerifier]]), alice); + verificationMethods, alice); const bobRequest = new VerificationRequest( new InRoomChannel(bob, "!room"), - new Map([[MOCK_METHOD, MockVerifier]]), bob); + verificationMethods, bob); expect(aliceRequest.invalid).toBe(true); expect(bobRequest.invalid).toBe(true); @@ -157,7 +178,7 @@ describe("verification request unit tests", function() { expect(aliceRequest.ready).toBe(true); const verifier = aliceRequest.beginKeyVerification(MOCK_METHOD); - await verifier.start(); + await (verifier as MockVerifier).start(); const [startEvent] = alice.popEvents(); expect(startEvent.getType()).toBe(START_TYPE); await distributeEvent(aliceRequest, bobRequest, startEvent); @@ -165,8 +186,7 @@ describe("verification request unit tests", function() { expect(aliceRequest.verifier).toBeInstanceOf(MockVerifier); expect(bobRequest.started).toBe(true); expect(bobRequest.verifier).toBeInstanceOf(MockVerifier); - - await bobRequest.verifier.start(); + await (bobRequest.verifier as MockVerifier).start(); const [bobDoneEvent] = bob.popEvents(); expect(bobDoneEvent.getType()).toBe(DONE_TYPE); await distributeEvent(bobRequest, aliceRequest, bobDoneEvent); @@ -180,12 +200,18 @@ describe("verification request unit tests", function() { it("methods only contains common methods", async function() { const alice = makeMockClient("@alice:matrix.tld", "device1"); const bob = makeMockClient("@bob:matrix.tld", "device1"); + const aliceVerificationMethods = new Map( + [["c", function() {}], ["a", function() {}]], + ) as unknown as Map; + const bobVerificationMethods = new Map( + [["c", function() {}], ["b", function() {}]] + ) as unknown as Map; const aliceRequest = new VerificationRequest( new InRoomChannel(alice, "!room", bob.getUserId()), - new Map([["c", function() {}], ["a", function() {}]]), alice); + aliceVerificationMethods, alice); const bobRequest = new VerificationRequest( new InRoomChannel(bob, "!room"), - new Map([["c", function() {}], ["b", function() {}]]), bob); + bobVerificationMethods, bob); await aliceRequest.sendRequest(); const [requestEvent] = alice.popEvents(); await distributeEvent(aliceRequest, bobRequest, requestEvent); @@ -222,22 +248,25 @@ describe("verification request unit tests", function() { it("verify own device with to_device messages", async function() { const bob1 = makeMockClient("@bob:matrix.tld", "device1"); const bob2 = makeMockClient("@bob:matrix.tld", "device2"); + const verificationMethods = new Map( + [[MOCK_METHOD, MockVerifier]], + ) as unknown as Map; const bob1Request = new VerificationRequest( new ToDeviceChannel(bob1, bob1.getUserId(), ["device1", "device2"], ToDeviceChannel.makeTransactionId(), "device2"), - new Map([[MOCK_METHOD, MockVerifier]]), bob1); + verificationMethods, bob1); const to = { userId: "@bob:matrix.tld", deviceId: "device2" }; const verifier = bob1Request.beginKeyVerification(MOCK_METHOD, to); expect(verifier).toBeInstanceOf(MockVerifier); - await verifier.start(); + await (verifier as MockVerifier).start(); const [startEvent] = bob1.popDeviceEvents(to.userId, to.deviceId); expect(startEvent.getType()).toBe(START_TYPE); const bob2Request = new VerificationRequest( new ToDeviceChannel(bob2, bob2.getUserId(), ["device1"]), - new Map([[MOCK_METHOD, MockVerifier]]), bob2); + verificationMethods, bob2); await bob2Request.channel.handleEvent(startEvent, bob2Request, true); - await bob2Request.verifier.start(); + await (bob2Request.verifier as MockVerifier).start(); const [doneEvent1] = bob2.popDeviceEvents("@bob:matrix.tld", "device1"); expect(doneEvent1.getType()).toBe(DONE_TYPE); await bob1Request.channel.handleEvent(doneEvent1, bob1Request, true); @@ -256,8 +285,7 @@ describe("verification request unit tests", function() { new InRoomChannel(alice, "!room", bob.getUserId()), new Map(), alice); await aliceRequest.sendRequest(); const [requestEvent] = alice.popEvents(); - await aliceRequest.channel.handleEvent(requestEvent, aliceRequest, true, - true, true); + await aliceRequest.channel.handleEvent(requestEvent, aliceRequest, true); expect(aliceRequest.cancelled).toBe(false); expect(aliceRequest._cancellingUserId).toBe(undefined); From e9e457bb496ff82a2b777cd43219e77103db1f1d Mon Sep 17 00:00:00 2001 From: Kerry Archibald Date: Fri, 16 Sep 2022 12:05:50 +0200 Subject: [PATCH 7/9] renamed: spec/browserify/sync-browserify.spec.js -> spec/browserify/sync-browserify.spec.ts --- .../{sync-browserify.spec.js => sync-browserify.spec.ts} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename spec/browserify/{sync-browserify.spec.js => sync-browserify.spec.ts} (100%) diff --git a/spec/browserify/sync-browserify.spec.js b/spec/browserify/sync-browserify.spec.ts similarity index 100% rename from spec/browserify/sync-browserify.spec.js rename to spec/browserify/sync-browserify.spec.ts From b488a600d0c3ee4f35de1bc5de470bbb90b8e27c Mon Sep 17 00:00:00 2001 From: Kerry Archibald Date: Fri, 16 Sep 2022 12:12:45 +0200 Subject: [PATCH 8/9] fix strict --- spec/unit/crypto/verification/sas.spec.ts | 5 +++-- .../crypto/verification/secret_request.spec.ts | 13 +++++++------ .../verification/verification_request.spec.ts | 18 +++++++++--------- 3 files changed, 19 insertions(+), 17 deletions(-) diff --git a/spec/unit/crypto/verification/sas.spec.ts b/spec/unit/crypto/verification/sas.spec.ts index 5866e06f054..f82b313fbc7 100644 --- a/spec/unit/crypto/verification/sas.spec.ts +++ b/spec/unit/crypto/verification/sas.spec.ts @@ -59,7 +59,8 @@ describe("SAS verification", function() { }, } as unknown as IVerificationChannel; const mockClient = {} as unknown as MatrixClient; - const sas = new SAS(channel, mockClient, "@alice:example.com", "ABCDEFG", null, request); + const event = new MatrixEvent({ type: 'test' }); + const sas = new SAS(channel, mockClient, "@alice:example.com", "ABCDEFG", event, request); sas.handleEvent(new MatrixEvent({ sender: "@alice:example.com", type: "es.inquisition", @@ -422,7 +423,7 @@ describe("SAS verification", function() { }); const aliceVerifier = alice.client.beginKeyVerification( - verificationMethods.SAS, bob.client.getUserId(), bob.client.deviceId, + verificationMethods.SAS, bob.client.getUserId()!, bob.client.deviceId!, ); const aliceSpy = jest.fn(); diff --git a/spec/unit/crypto/verification/secret_request.spec.ts b/spec/unit/crypto/verification/secret_request.spec.ts index e3f784771e5..1c0a7410a4d 100644 --- a/spec/unit/crypto/verification/secret_request.spec.ts +++ b/spec/unit/crypto/verification/secret_request.spec.ts @@ -18,8 +18,9 @@ import { CrossSigningInfo } from '../../../../src/crypto/CrossSigning'; import { encodeBase64 } from "../../../../src/crypto/olmlib"; import { setupWebcrypto, teardownWebcrypto } from './util'; import { VerificationBase } from '../../../../src/crypto/verification/Base'; -import { MatrixClient } from '../../../../src'; +import { MatrixClient, MatrixEvent } from '../../../../src'; import { VerificationRequest } from '../../../../src/crypto/verification/request/VerificationRequest'; +import { IVerificationChannel } from '../../../../src/crypto/verification/request/Channel'; jest.useFakeTimers(); @@ -100,11 +101,11 @@ describe("self-verifications", () => { } as unknown as VerificationRequest; const verification = new VerificationBase( - undefined, // channel + undefined as unknown as IVerificationChannel, // channel client, // baseApis userId, "ABC", // deviceId - undefined, // startEvent + undefined as unknown as MatrixEvent, // startEvent request, ); @@ -118,12 +119,12 @@ describe("self-verifications", () => { expect(secretStorage.request.mock.calls.length).toBe(4); expect(cacheCallbacks.storeCrossSigningKeyCache.mock.calls[0][1]) - .toEqual(testKey); + .toEqual(testKey); expect(cacheCallbacks.storeCrossSigningKeyCache.mock.calls[1][1]) - .toEqual(testKey); + .toEqual(testKey); expect(storeSessionBackupPrivateKey.mock.calls[0][0]) - .toEqual(testKey); + .toEqual(testKey); expect(restoreKeyBackupWithCache).toHaveBeenCalled(); diff --git a/spec/unit/crypto/verification/verification_request.spec.ts b/spec/unit/crypto/verification/verification_request.spec.ts index d16b9a4e8c8..92b350f047b 100644 --- a/spec/unit/crypto/verification/verification_request.spec.ts +++ b/spec/unit/crypto/verification/verification_request.spec.ts @@ -30,7 +30,7 @@ type MockClient = MatrixClient & { }; function makeMockClient(userId: string, deviceId: string): MockClient { let counter = 1; - let events = []; + let events: MatrixEvent[] = []; const deviceEvents = {}; return { getUserId() { return userId; }, @@ -155,7 +155,7 @@ describe("verification request unit tests", function() { [[MOCK_METHOD, MockVerifier]], ) as unknown as Map; const aliceRequest = new VerificationRequest( - new InRoomChannel(alice, "!room", bob.getUserId()), + new InRoomChannel(alice, "!room", bob.getUserId()!), verificationMethods, alice); const bobRequest = new VerificationRequest( new InRoomChannel(bob, "!room"), @@ -204,10 +204,10 @@ describe("verification request unit tests", function() { [["c", function() {}], ["a", function() {}]], ) as unknown as Map; const bobVerificationMethods = new Map( - [["c", function() {}], ["b", function() {}]] + [["c", function() {}], ["b", function() {}]], ) as unknown as Map; const aliceRequest = new VerificationRequest( - new InRoomChannel(alice, "!room", bob.getUserId()), + new InRoomChannel(alice, "!room", bob.getUserId()!), aliceVerificationMethods, alice); const bobRequest = new VerificationRequest( new InRoomChannel(bob, "!room"), @@ -227,7 +227,7 @@ describe("verification request unit tests", function() { const bob1 = makeMockClient("@bob:matrix.tld", "device1"); const bob2 = makeMockClient("@bob:matrix.tld", "device2"); const aliceRequest = new VerificationRequest( - new InRoomChannel(alice, "!room", bob1.getUserId()), new Map(), alice); + new InRoomChannel(alice, "!room", bob1.getUserId()!), new Map(), alice); await aliceRequest.sendRequest(); const [requestEvent] = alice.popEvents(); const bob1Request = new VerificationRequest( @@ -252,7 +252,7 @@ describe("verification request unit tests", function() { [[MOCK_METHOD, MockVerifier]], ) as unknown as Map; const bob1Request = new VerificationRequest( - new ToDeviceChannel(bob1, bob1.getUserId(), ["device1", "device2"], + new ToDeviceChannel(bob1, bob1.getUserId()!, ["device1", "device2"], ToDeviceChannel.makeTransactionId(), "device2"), verificationMethods, bob1); const to = { userId: "@bob:matrix.tld", deviceId: "device2" }; @@ -262,7 +262,7 @@ describe("verification request unit tests", function() { const [startEvent] = bob1.popDeviceEvents(to.userId, to.deviceId); expect(startEvent.getType()).toBe(START_TYPE); const bob2Request = new VerificationRequest( - new ToDeviceChannel(bob2, bob2.getUserId(), ["device1"]), + new ToDeviceChannel(bob2, bob2.getUserId()!, ["device1"]), verificationMethods, bob2); await bob2Request.channel.handleEvent(startEvent, bob2Request, true); @@ -282,7 +282,7 @@ describe("verification request unit tests", function() { const alice = makeMockClient("@alice:matrix.tld", "device1"); const bob = makeMockClient("@bob:matrix.tld", "device1"); const aliceRequest = new VerificationRequest( - new InRoomChannel(alice, "!room", bob.getUserId()), new Map(), alice); + new InRoomChannel(alice, "!room", bob.getUserId()!), new Map(), alice); await aliceRequest.sendRequest(); const [requestEvent] = alice.popEvents(); await aliceRequest.channel.handleEvent(requestEvent, aliceRequest, true); @@ -297,7 +297,7 @@ describe("verification request unit tests", function() { const alice = makeMockClient("@alice:matrix.tld", "device1"); const bob = makeMockClient("@bob:matrix.tld", "device1"); const aliceRequest = new VerificationRequest( - new InRoomChannel(alice, "!room", bob.getUserId()), new Map(), alice); + new InRoomChannel(alice, "!room", bob.getUserId()!), new Map(), alice); await aliceRequest.sendRequest(); const [requestEvent] = alice.popEvents(); const bobRequest = new VerificationRequest( From 6b62cc8a2f507b4564207f584a34ff5bf70b1107 Mon Sep 17 00:00:00 2001 From: Kerry Archibald Date: Fri, 16 Sep 2022 16:53:06 +0200 Subject: [PATCH 9/9] formatting --- .../verification/verification_request.spec.ts | 64 +++++++++++++++---- 1 file changed, 50 insertions(+), 14 deletions(-) diff --git a/spec/unit/crypto/verification/verification_request.spec.ts b/spec/unit/crypto/verification/verification_request.spec.ts index 92b350f047b..0b759efb993 100644 --- a/spec/unit/crypto/verification/verification_request.spec.ts +++ b/spec/unit/crypto/verification/verification_request.spec.ts @@ -133,7 +133,10 @@ function makeRemoteEcho(event) { async function distributeEvent(ownRequest, theirRequest, event) { await ownRequest.channel.handleEvent( - makeRemoteEcho(event), ownRequest, true); + makeRemoteEcho(event), + ownRequest, + true, + ); await theirRequest.channel.handleEvent(event, theirRequest, true); } @@ -156,10 +159,14 @@ describe("verification request unit tests", function() { ) as unknown as Map; const aliceRequest = new VerificationRequest( new InRoomChannel(alice, "!room", bob.getUserId()!), - verificationMethods, alice); + verificationMethods, + alice, + ); const bobRequest = new VerificationRequest( new InRoomChannel(bob, "!room"), - verificationMethods, bob); + verificationMethods, + bob, + ); expect(aliceRequest.invalid).toBe(true); expect(bobRequest.invalid).toBe(true); @@ -211,7 +218,9 @@ describe("verification request unit tests", function() { aliceVerificationMethods, alice); const bobRequest = new VerificationRequest( new InRoomChannel(bob, "!room"), - bobVerificationMethods, bob); + bobVerificationMethods, + bob, + ); await aliceRequest.sendRequest(); const [requestEvent] = alice.popEvents(); await distributeEvent(aliceRequest, bobRequest, requestEvent); @@ -227,13 +236,22 @@ describe("verification request unit tests", function() { const bob1 = makeMockClient("@bob:matrix.tld", "device1"); const bob2 = makeMockClient("@bob:matrix.tld", "device2"); const aliceRequest = new VerificationRequest( - new InRoomChannel(alice, "!room", bob1.getUserId()!), new Map(), alice); + new InRoomChannel(alice, "!room", bob1.getUserId()!), + new Map(), + alice, + ); await aliceRequest.sendRequest(); const [requestEvent] = alice.popEvents(); const bob1Request = new VerificationRequest( - new InRoomChannel(bob1, "!room"), new Map(), bob1); + new InRoomChannel(bob1, "!room"), + new Map(), + bob1, + ); const bob2Request = new VerificationRequest( - new InRoomChannel(bob2, "!room"), new Map(), bob2); + new InRoomChannel(bob2, "!room"), + new Map(), + bob2, + ); await bob1Request.channel.handleEvent(requestEvent, bob1Request, true); await bob2Request.channel.handleEvent(requestEvent, bob2Request, true); @@ -252,9 +270,16 @@ describe("verification request unit tests", function() { [[MOCK_METHOD, MockVerifier]], ) as unknown as Map; const bob1Request = new VerificationRequest( - new ToDeviceChannel(bob1, bob1.getUserId()!, ["device1", "device2"], - ToDeviceChannel.makeTransactionId(), "device2"), - verificationMethods, bob1); + new ToDeviceChannel( + bob1, + bob1.getUserId()!, + ["device1", "device2"], + ToDeviceChannel.makeTransactionId(), + "device2", + ), + verificationMethods, + bob1, + ); const to = { userId: "@bob:matrix.tld", deviceId: "device2" }; const verifier = bob1Request.beginKeyVerification(MOCK_METHOD, to); expect(verifier).toBeInstanceOf(MockVerifier); @@ -263,7 +288,9 @@ describe("verification request unit tests", function() { expect(startEvent.getType()).toBe(START_TYPE); const bob2Request = new VerificationRequest( new ToDeviceChannel(bob2, bob2.getUserId()!, ["device1"]), - verificationMethods, bob2); + verificationMethods, + bob2, + ); await bob2Request.channel.handleEvent(startEvent, bob2Request, true); await (bob2Request.verifier as MockVerifier).start(); @@ -282,7 +309,10 @@ describe("verification request unit tests", function() { const alice = makeMockClient("@alice:matrix.tld", "device1"); const bob = makeMockClient("@bob:matrix.tld", "device1"); const aliceRequest = new VerificationRequest( - new InRoomChannel(alice, "!room", bob.getUserId()!), new Map(), alice); + new InRoomChannel(alice, "!room", bob.getUserId()!), + new Map(), + alice, + ); await aliceRequest.sendRequest(); const [requestEvent] = alice.popEvents(); await aliceRequest.channel.handleEvent(requestEvent, aliceRequest, true); @@ -297,11 +327,17 @@ describe("verification request unit tests", function() { const alice = makeMockClient("@alice:matrix.tld", "device1"); const bob = makeMockClient("@bob:matrix.tld", "device1"); const aliceRequest = new VerificationRequest( - new InRoomChannel(alice, "!room", bob.getUserId()!), new Map(), alice); + new InRoomChannel(alice, "!room", bob.getUserId()!), + new Map(), + alice, + ); await aliceRequest.sendRequest(); const [requestEvent] = alice.popEvents(); const bobRequest = new VerificationRequest( - new InRoomChannel(bob, "!room"), new Map(), bob); + new InRoomChannel(bob, "!room"), + new Map(), + bob, + ); await bobRequest.channel.handleEvent(requestEvent, bobRequest, true);