You've already forked matrix-js-sdk
mirror of
https://github.com/matrix-org/matrix-js-sdk.git
synced 2025-11-25 05:23:13 +03:00
test typescriptification - last few unit test files (#2675)
* renamed: spec/unit/crypto/verification/sas.spec.js -> spec/unit/crypto/verification/sas.spec.ts * ts issues in sas.spec * renamed: spec/unit/crypto/verification/secret_request.spec.js -> spec/unit/crypto/verification/secret_request.spec.ts * ts issues in secret_request.spec * renamed: spec/unit/crypto/verification/verification_request.spec.js -> spec/unit/crypto/verification/verification_request.spec.ts * ts fix verification_req.spec * renamed: spec/browserify/sync-browserify.spec.js -> spec/browserify/sync-browserify.spec.ts * fix strict * formatting
This commit is contained in:
@@ -19,10 +19,14 @@ import { makeTestClients, setupWebcrypto, teardownWebcrypto } from './util';
|
|||||||
import { MatrixEvent } from "../../../../src/models/event";
|
import { MatrixEvent } from "../../../../src/models/event";
|
||||||
import { SAS } from "../../../../src/crypto/verification/SAS";
|
import { SAS } from "../../../../src/crypto/verification/SAS";
|
||||||
import { DeviceInfo } from "../../../../src/crypto/deviceinfo";
|
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 * as olmlib from "../../../../src/crypto/olmlib";
|
||||||
import { logger } from "../../../../src/logger";
|
import { logger } from "../../../../src/logger";
|
||||||
import { resetCrossSigningKeys } from "../crypto-utils";
|
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;
|
const Olm = global.Olm;
|
||||||
|
|
||||||
@@ -48,13 +52,15 @@ describe("SAS verification", function() {
|
|||||||
//channel, baseApis, userId, deviceId, startEvent, request
|
//channel, baseApis, userId, deviceId, startEvent, request
|
||||||
const request = {
|
const request = {
|
||||||
onVerifierCancelled: function() {},
|
onVerifierCancelled: function() {},
|
||||||
};
|
} as VerificationRequest;
|
||||||
const channel = {
|
const channel = {
|
||||||
send: function() {
|
send: function() {
|
||||||
return Promise.resolve();
|
return Promise.resolve();
|
||||||
},
|
},
|
||||||
};
|
} as unknown as IVerificationChannel;
|
||||||
const sas = new SAS(channel, {}, "@alice:example.com", "ABCDEFG", null, request);
|
const mockClient = {} as unknown as MatrixClient;
|
||||||
|
const event = new MatrixEvent({ type: 'test' });
|
||||||
|
const sas = new SAS(channel, mockClient, "@alice:example.com", "ABCDEFG", event, request);
|
||||||
sas.handleEvent(new MatrixEvent({
|
sas.handleEvent(new MatrixEvent({
|
||||||
sender: "@alice:example.com",
|
sender: "@alice:example.com",
|
||||||
type: "es.inquisition",
|
type: "es.inquisition",
|
||||||
@@ -65,7 +71,7 @@ describe("SAS verification", function() {
|
|||||||
expect(spy).toHaveBeenCalled();
|
expect(spy).toHaveBeenCalled();
|
||||||
|
|
||||||
// Cancel the SAS for cleanup (we started a verification, so abort)
|
// Cancel the SAS for cleanup (we started a verification, so abort)
|
||||||
sas.cancel();
|
sas.cancel(new Error('error'));
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("verification", () => {
|
describe("verification", () => {
|
||||||
@@ -403,16 +409,12 @@ describe("SAS verification", function() {
|
|||||||
},
|
},
|
||||||
);
|
);
|
||||||
alice.client.setDeviceVerified = jest.fn();
|
alice.client.setDeviceVerified = jest.fn();
|
||||||
alice.client.downloadKeys = () => {
|
alice.client.downloadKeys = jest.fn().mockResolvedValue({});
|
||||||
return Promise.resolve();
|
|
||||||
};
|
|
||||||
bob.client.setDeviceVerified = jest.fn();
|
bob.client.setDeviceVerified = jest.fn();
|
||||||
bob.client.downloadKeys = () => {
|
bob.client.downloadKeys = jest.fn().mockResolvedValue({});
|
||||||
return Promise.resolve();
|
|
||||||
};
|
|
||||||
|
|
||||||
const bobPromise = new Promise((resolve, reject) => {
|
const bobPromise = new Promise<VerificationBase<any, any>>((resolve, reject) => {
|
||||||
bob.client.on("crypto.verification.request", request => {
|
bob.client.on(CryptoEvent.VerificationRequest, request => {
|
||||||
request.verifier.on("show_sas", (e) => {
|
request.verifier.on("show_sas", (e) => {
|
||||||
e.mismatch();
|
e.mismatch();
|
||||||
});
|
});
|
||||||
@@ -421,7 +423,7 @@ describe("SAS verification", function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
const aliceVerifier = alice.client.beginKeyVerification(
|
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();
|
const aliceSpy = jest.fn();
|
||||||
@@ -501,7 +503,7 @@ describe("SAS verification", function() {
|
|||||||
aliceSasEvent = null;
|
aliceSasEvent = null;
|
||||||
bobSasEvent = null;
|
bobSasEvent = null;
|
||||||
|
|
||||||
bobPromise = new Promise((resolve, reject) => {
|
bobPromise = new Promise<void>((resolve, reject) => {
|
||||||
bob.client.on("crypto.verification.request", async (request) => {
|
bob.client.on("crypto.verification.request", async (request) => {
|
||||||
const verifier = request.beginKeyVerification(SAS.NAME);
|
const verifier = request.beginKeyVerification(SAS.NAME);
|
||||||
verifier.on("show_sas", (e) => {
|
verifier.on("show_sas", (e) => {
|
||||||
@@ -18,6 +18,9 @@ import { CrossSigningInfo } from '../../../../src/crypto/CrossSigning';
|
|||||||
import { encodeBase64 } from "../../../../src/crypto/olmlib";
|
import { encodeBase64 } from "../../../../src/crypto/olmlib";
|
||||||
import { setupWebcrypto, teardownWebcrypto } from './util';
|
import { setupWebcrypto, teardownWebcrypto } from './util';
|
||||||
import { VerificationBase } from '../../../../src/crypto/verification/Base';
|
import { VerificationBase } from '../../../../src/crypto/verification/Base';
|
||||||
|
import { MatrixClient, MatrixEvent } from '../../../../src';
|
||||||
|
import { VerificationRequest } from '../../../../src/crypto/verification/request/VerificationRequest';
|
||||||
|
import { IVerificationChannel } from '../../../../src/crypto/verification/request/Channel';
|
||||||
|
|
||||||
jest.useFakeTimers();
|
jest.useFakeTimers();
|
||||||
|
|
||||||
@@ -54,9 +57,21 @@ describe("self-verifications", () => {
|
|||||||
cacheCallbacks,
|
cacheCallbacks,
|
||||||
);
|
);
|
||||||
crossSigningInfo.keys = {
|
crossSigningInfo.keys = {
|
||||||
master: { keys: { X: testKeyPub } },
|
master: {
|
||||||
self_signing: { keys: { X: testKeyPub } },
|
keys: { X: testKeyPub },
|
||||||
user_signing: { 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 = {
|
const secretStorage = {
|
||||||
@@ -79,20 +94,22 @@ describe("self-verifications", () => {
|
|||||||
getUserId: () => userId,
|
getUserId: () => userId,
|
||||||
getKeyBackupVersion: () => Promise.resolve({}),
|
getKeyBackupVersion: () => Promise.resolve({}),
|
||||||
restoreKeyBackupWithCache,
|
restoreKeyBackupWithCache,
|
||||||
};
|
} as unknown as MatrixClient;
|
||||||
|
|
||||||
const request = {
|
const request = {
|
||||||
onVerifierFinished: () => undefined,
|
onVerifierFinished: () => undefined,
|
||||||
};
|
} as unknown as VerificationRequest;
|
||||||
|
|
||||||
const verification = new VerificationBase(
|
const verification = new VerificationBase(
|
||||||
undefined, // channel
|
undefined as unknown as IVerificationChannel, // channel
|
||||||
client, // baseApis
|
client, // baseApis
|
||||||
userId,
|
userId,
|
||||||
"ABC", // deviceId
|
"ABC", // deviceId
|
||||||
undefined, // startEvent
|
undefined as unknown as MatrixEvent, // startEvent
|
||||||
request,
|
request,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// @ts-ignore set private property
|
||||||
verification.resolve = () => undefined;
|
verification.resolve = () => undefined;
|
||||||
|
|
||||||
const result = await verification.done();
|
const result = await verification.done();
|
||||||
@@ -102,12 +119,12 @@ describe("self-verifications", () => {
|
|||||||
expect(secretStorage.request.mock.calls.length).toBe(4);
|
expect(secretStorage.request.mock.calls.length).toBe(4);
|
||||||
|
|
||||||
expect(cacheCallbacks.storeCrossSigningKeyCache.mock.calls[0][1])
|
expect(cacheCallbacks.storeCrossSigningKeyCache.mock.calls[0][1])
|
||||||
.toEqual(testKey);
|
.toEqual(testKey);
|
||||||
expect(cacheCallbacks.storeCrossSigningKeyCache.mock.calls[1][1])
|
expect(cacheCallbacks.storeCrossSigningKeyCache.mock.calls[1][1])
|
||||||
.toEqual(testKey);
|
.toEqual(testKey);
|
||||||
|
|
||||||
expect(storeSessionBackupPrivateKey.mock.calls[0][0])
|
expect(storeSessionBackupPrivateKey.mock.calls[0][0])
|
||||||
.toEqual(testKey);
|
.toEqual(testKey);
|
||||||
|
|
||||||
expect(restoreKeyBackupWithCache).toHaveBeenCalled();
|
expect(restoreKeyBackupWithCache).toHaveBeenCalled();
|
||||||
|
|
||||||
@@ -19,11 +19,18 @@ import { InRoomChannel } from "../../../../src/crypto/verification/request/InRoo
|
|||||||
import { ToDeviceChannel } from
|
import { ToDeviceChannel } from
|
||||||
"../../../../src/crypto/verification/request/ToDeviceChannel";
|
"../../../../src/crypto/verification/request/ToDeviceChannel";
|
||||||
import { MatrixEvent } from "../../../../src/models/event";
|
import { MatrixEvent } from "../../../../src/models/event";
|
||||||
|
import { MatrixClient } from "../../../../src/client";
|
||||||
import { setupWebcrypto, teardownWebcrypto } from "./util";
|
import { setupWebcrypto, teardownWebcrypto } from "./util";
|
||||||
|
import { IVerificationChannel } from "../../../../src/crypto/verification/request/Channel";
|
||||||
|
import { VerificationBase } from "../../../../src/crypto/verification/Base";
|
||||||
|
|
||||||
function makeMockClient(userId, deviceId) {
|
type MockClient = MatrixClient & {
|
||||||
|
popEvents: () => MatrixEvent[];
|
||||||
|
popDeviceEvents: (userId: string, deviceId: string) => MatrixEvent[];
|
||||||
|
};
|
||||||
|
function makeMockClient(userId: string, deviceId: string): MockClient {
|
||||||
let counter = 1;
|
let counter = 1;
|
||||||
let events = [];
|
let events: MatrixEvent[] = [];
|
||||||
const deviceEvents = {};
|
const deviceEvents = {};
|
||||||
return {
|
return {
|
||||||
getUserId() { return userId; },
|
getUserId() { return userId; },
|
||||||
@@ -54,16 +61,18 @@ function makeMockClient(userId, deviceId) {
|
|||||||
deviceEvents[userId][deviceId].push(event);
|
deviceEvents[userId][deviceId].push(event);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return Promise.resolve();
|
return Promise.resolve({});
|
||||||
},
|
},
|
||||||
|
|
||||||
popEvents() {
|
// @ts-ignore special testing fn
|
||||||
|
popEvents(): MatrixEvent[] {
|
||||||
const e = events;
|
const e = events;
|
||||||
events = [];
|
events = [];
|
||||||
return e;
|
return e;
|
||||||
},
|
},
|
||||||
|
|
||||||
popDeviceEvents(userId, deviceId) {
|
// @ts-ignore special testing fn
|
||||||
|
popDeviceEvents(userId: string, deviceId: string): MatrixEvent[] {
|
||||||
const forDevice = deviceEvents[userId];
|
const forDevice = deviceEvents[userId];
|
||||||
const events = forDevice && forDevice[deviceId];
|
const events = forDevice && forDevice[deviceId];
|
||||||
const result = events || [];
|
const result = events || [];
|
||||||
@@ -72,12 +81,21 @@ function makeMockClient(userId, deviceId) {
|
|||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
},
|
},
|
||||||
};
|
} as unknown as MockClient;
|
||||||
}
|
}
|
||||||
|
|
||||||
const MOCK_METHOD = "mock-verify";
|
const MOCK_METHOD = "mock-verify";
|
||||||
class MockVerifier {
|
class MockVerifier extends VerificationBase<'', any> {
|
||||||
constructor(channel, client, userId, deviceId, startEvent) {
|
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._channel = channel;
|
||||||
this._startEvent = startEvent;
|
this._startEvent = startEvent;
|
||||||
}
|
}
|
||||||
@@ -115,7 +133,10 @@ function makeRemoteEcho(event) {
|
|||||||
|
|
||||||
async function distributeEvent(ownRequest, theirRequest, event) {
|
async function distributeEvent(ownRequest, theirRequest, event) {
|
||||||
await ownRequest.channel.handleEvent(
|
await ownRequest.channel.handleEvent(
|
||||||
makeRemoteEcho(event), ownRequest, true);
|
makeRemoteEcho(event),
|
||||||
|
ownRequest,
|
||||||
|
true,
|
||||||
|
);
|
||||||
await theirRequest.channel.handleEvent(event, theirRequest, true);
|
await theirRequest.channel.handleEvent(event, theirRequest, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -133,12 +154,19 @@ describe("verification request unit tests", function() {
|
|||||||
it("transition from UNSENT to DONE through happy path", async function() {
|
it("transition from UNSENT to DONE through happy path", async function() {
|
||||||
const alice = makeMockClient("@alice:matrix.tld", "device1");
|
const alice = makeMockClient("@alice:matrix.tld", "device1");
|
||||||
const bob = makeMockClient("@bob:matrix.tld", "device1");
|
const bob = makeMockClient("@bob:matrix.tld", "device1");
|
||||||
|
const verificationMethods = new Map(
|
||||||
|
[[MOCK_METHOD, MockVerifier]],
|
||||||
|
) as unknown as Map<string, typeof VerificationBase>;
|
||||||
const aliceRequest = new VerificationRequest(
|
const aliceRequest = new VerificationRequest(
|
||||||
new InRoomChannel(alice, "!room", bob.getUserId()),
|
new InRoomChannel(alice, "!room", bob.getUserId()!),
|
||||||
new Map([[MOCK_METHOD, MockVerifier]]), alice);
|
verificationMethods,
|
||||||
|
alice,
|
||||||
|
);
|
||||||
const bobRequest = new VerificationRequest(
|
const bobRequest = new VerificationRequest(
|
||||||
new InRoomChannel(bob, "!room"),
|
new InRoomChannel(bob, "!room"),
|
||||||
new Map([[MOCK_METHOD, MockVerifier]]), bob);
|
verificationMethods,
|
||||||
|
bob,
|
||||||
|
);
|
||||||
expect(aliceRequest.invalid).toBe(true);
|
expect(aliceRequest.invalid).toBe(true);
|
||||||
expect(bobRequest.invalid).toBe(true);
|
expect(bobRequest.invalid).toBe(true);
|
||||||
|
|
||||||
@@ -157,7 +185,7 @@ describe("verification request unit tests", function() {
|
|||||||
expect(aliceRequest.ready).toBe(true);
|
expect(aliceRequest.ready).toBe(true);
|
||||||
|
|
||||||
const verifier = aliceRequest.beginKeyVerification(MOCK_METHOD);
|
const verifier = aliceRequest.beginKeyVerification(MOCK_METHOD);
|
||||||
await verifier.start();
|
await (verifier as MockVerifier).start();
|
||||||
const [startEvent] = alice.popEvents();
|
const [startEvent] = alice.popEvents();
|
||||||
expect(startEvent.getType()).toBe(START_TYPE);
|
expect(startEvent.getType()).toBe(START_TYPE);
|
||||||
await distributeEvent(aliceRequest, bobRequest, startEvent);
|
await distributeEvent(aliceRequest, bobRequest, startEvent);
|
||||||
@@ -165,8 +193,7 @@ describe("verification request unit tests", function() {
|
|||||||
expect(aliceRequest.verifier).toBeInstanceOf(MockVerifier);
|
expect(aliceRequest.verifier).toBeInstanceOf(MockVerifier);
|
||||||
expect(bobRequest.started).toBe(true);
|
expect(bobRequest.started).toBe(true);
|
||||||
expect(bobRequest.verifier).toBeInstanceOf(MockVerifier);
|
expect(bobRequest.verifier).toBeInstanceOf(MockVerifier);
|
||||||
|
await (bobRequest.verifier as MockVerifier).start();
|
||||||
await bobRequest.verifier.start();
|
|
||||||
const [bobDoneEvent] = bob.popEvents();
|
const [bobDoneEvent] = bob.popEvents();
|
||||||
expect(bobDoneEvent.getType()).toBe(DONE_TYPE);
|
expect(bobDoneEvent.getType()).toBe(DONE_TYPE);
|
||||||
await distributeEvent(bobRequest, aliceRequest, bobDoneEvent);
|
await distributeEvent(bobRequest, aliceRequest, bobDoneEvent);
|
||||||
@@ -180,12 +207,20 @@ describe("verification request unit tests", function() {
|
|||||||
it("methods only contains common methods", async function() {
|
it("methods only contains common methods", async function() {
|
||||||
const alice = makeMockClient("@alice:matrix.tld", "device1");
|
const alice = makeMockClient("@alice:matrix.tld", "device1");
|
||||||
const bob = makeMockClient("@bob:matrix.tld", "device1");
|
const bob = makeMockClient("@bob:matrix.tld", "device1");
|
||||||
|
const aliceVerificationMethods = new Map(
|
||||||
|
[["c", function() {}], ["a", function() {}]],
|
||||||
|
) as unknown as Map<string, typeof VerificationBase>;
|
||||||
|
const bobVerificationMethods = new Map(
|
||||||
|
[["c", function() {}], ["b", function() {}]],
|
||||||
|
) as unknown as Map<string, typeof VerificationBase>;
|
||||||
const aliceRequest = new VerificationRequest(
|
const aliceRequest = new VerificationRequest(
|
||||||
new InRoomChannel(alice, "!room", bob.getUserId()),
|
new InRoomChannel(alice, "!room", bob.getUserId()!),
|
||||||
new Map([["c", function() {}], ["a", function() {}]]), alice);
|
aliceVerificationMethods, alice);
|
||||||
const bobRequest = new VerificationRequest(
|
const bobRequest = new VerificationRequest(
|
||||||
new InRoomChannel(bob, "!room"),
|
new InRoomChannel(bob, "!room"),
|
||||||
new Map([["c", function() {}], ["b", function() {}]]), bob);
|
bobVerificationMethods,
|
||||||
|
bob,
|
||||||
|
);
|
||||||
await aliceRequest.sendRequest();
|
await aliceRequest.sendRequest();
|
||||||
const [requestEvent] = alice.popEvents();
|
const [requestEvent] = alice.popEvents();
|
||||||
await distributeEvent(aliceRequest, bobRequest, requestEvent);
|
await distributeEvent(aliceRequest, bobRequest, requestEvent);
|
||||||
@@ -201,13 +236,22 @@ describe("verification request unit tests", function() {
|
|||||||
const bob1 = makeMockClient("@bob:matrix.tld", "device1");
|
const bob1 = makeMockClient("@bob:matrix.tld", "device1");
|
||||||
const bob2 = makeMockClient("@bob:matrix.tld", "device2");
|
const bob2 = makeMockClient("@bob:matrix.tld", "device2");
|
||||||
const aliceRequest = new VerificationRequest(
|
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();
|
await aliceRequest.sendRequest();
|
||||||
const [requestEvent] = alice.popEvents();
|
const [requestEvent] = alice.popEvents();
|
||||||
const bob1Request = new VerificationRequest(
|
const bob1Request = new VerificationRequest(
|
||||||
new InRoomChannel(bob1, "!room"), new Map(), bob1);
|
new InRoomChannel(bob1, "!room"),
|
||||||
|
new Map(),
|
||||||
|
bob1,
|
||||||
|
);
|
||||||
const bob2Request = new VerificationRequest(
|
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 bob1Request.channel.handleEvent(requestEvent, bob1Request, true);
|
||||||
await bob2Request.channel.handleEvent(requestEvent, bob2Request, true);
|
await bob2Request.channel.handleEvent(requestEvent, bob2Request, true);
|
||||||
@@ -222,22 +266,34 @@ describe("verification request unit tests", function() {
|
|||||||
it("verify own device with to_device messages", async function() {
|
it("verify own device with to_device messages", async function() {
|
||||||
const bob1 = makeMockClient("@bob:matrix.tld", "device1");
|
const bob1 = makeMockClient("@bob:matrix.tld", "device1");
|
||||||
const bob2 = makeMockClient("@bob:matrix.tld", "device2");
|
const bob2 = makeMockClient("@bob:matrix.tld", "device2");
|
||||||
|
const verificationMethods = new Map(
|
||||||
|
[[MOCK_METHOD, MockVerifier]],
|
||||||
|
) as unknown as Map<string, typeof VerificationBase>;
|
||||||
const bob1Request = new VerificationRequest(
|
const bob1Request = new VerificationRequest(
|
||||||
new ToDeviceChannel(bob1, bob1.getUserId(), ["device1", "device2"],
|
new ToDeviceChannel(
|
||||||
ToDeviceChannel.makeTransactionId(), "device2"),
|
bob1,
|
||||||
new Map([[MOCK_METHOD, MockVerifier]]), bob1);
|
bob1.getUserId()!,
|
||||||
|
["device1", "device2"],
|
||||||
|
ToDeviceChannel.makeTransactionId(),
|
||||||
|
"device2",
|
||||||
|
),
|
||||||
|
verificationMethods,
|
||||||
|
bob1,
|
||||||
|
);
|
||||||
const to = { userId: "@bob:matrix.tld", deviceId: "device2" };
|
const to = { userId: "@bob:matrix.tld", deviceId: "device2" };
|
||||||
const verifier = bob1Request.beginKeyVerification(MOCK_METHOD, to);
|
const verifier = bob1Request.beginKeyVerification(MOCK_METHOD, to);
|
||||||
expect(verifier).toBeInstanceOf(MockVerifier);
|
expect(verifier).toBeInstanceOf(MockVerifier);
|
||||||
await verifier.start();
|
await (verifier as MockVerifier).start();
|
||||||
const [startEvent] = bob1.popDeviceEvents(to.userId, to.deviceId);
|
const [startEvent] = bob1.popDeviceEvents(to.userId, to.deviceId);
|
||||||
expect(startEvent.getType()).toBe(START_TYPE);
|
expect(startEvent.getType()).toBe(START_TYPE);
|
||||||
const bob2Request = new VerificationRequest(
|
const bob2Request = new VerificationRequest(
|
||||||
new ToDeviceChannel(bob2, bob2.getUserId(), ["device1"]),
|
new ToDeviceChannel(bob2, bob2.getUserId()!, ["device1"]),
|
||||||
new Map([[MOCK_METHOD, MockVerifier]]), bob2);
|
verificationMethods,
|
||||||
|
bob2,
|
||||||
|
);
|
||||||
|
|
||||||
await bob2Request.channel.handleEvent(startEvent, bob2Request, true);
|
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");
|
const [doneEvent1] = bob2.popDeviceEvents("@bob:matrix.tld", "device1");
|
||||||
expect(doneEvent1.getType()).toBe(DONE_TYPE);
|
expect(doneEvent1.getType()).toBe(DONE_TYPE);
|
||||||
await bob1Request.channel.handleEvent(doneEvent1, bob1Request, true);
|
await bob1Request.channel.handleEvent(doneEvent1, bob1Request, true);
|
||||||
@@ -253,11 +309,13 @@ describe("verification request unit tests", function() {
|
|||||||
const alice = makeMockClient("@alice:matrix.tld", "device1");
|
const alice = makeMockClient("@alice:matrix.tld", "device1");
|
||||||
const bob = makeMockClient("@bob:matrix.tld", "device1");
|
const bob = makeMockClient("@bob:matrix.tld", "device1");
|
||||||
const aliceRequest = new VerificationRequest(
|
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();
|
await aliceRequest.sendRequest();
|
||||||
const [requestEvent] = alice.popEvents();
|
const [requestEvent] = alice.popEvents();
|
||||||
await aliceRequest.channel.handleEvent(requestEvent, aliceRequest, true,
|
await aliceRequest.channel.handleEvent(requestEvent, aliceRequest, true);
|
||||||
true, true);
|
|
||||||
|
|
||||||
expect(aliceRequest.cancelled).toBe(false);
|
expect(aliceRequest.cancelled).toBe(false);
|
||||||
expect(aliceRequest._cancellingUserId).toBe(undefined);
|
expect(aliceRequest._cancellingUserId).toBe(undefined);
|
||||||
@@ -269,11 +327,17 @@ describe("verification request unit tests", function() {
|
|||||||
const alice = makeMockClient("@alice:matrix.tld", "device1");
|
const alice = makeMockClient("@alice:matrix.tld", "device1");
|
||||||
const bob = makeMockClient("@bob:matrix.tld", "device1");
|
const bob = makeMockClient("@bob:matrix.tld", "device1");
|
||||||
const aliceRequest = new VerificationRequest(
|
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();
|
await aliceRequest.sendRequest();
|
||||||
const [requestEvent] = alice.popEvents();
|
const [requestEvent] = alice.popEvents();
|
||||||
const bobRequest = new VerificationRequest(
|
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);
|
await bobRequest.channel.handleEvent(requestEvent, bobRequest, true);
|
||||||
|
|
||||||
Reference in New Issue
Block a user