First batch: remove deprecated calls on MatrixClient (#28207)

* Remove `initCrypto` mocking

* Remove `MatrixClient.downloadKeys` mocking

* Remove `MatrixClient.getStoredDevice` mocking

* Replace `MatrixClient.setGlobalBlacklistUnverifiedDevices` by `MatrixClient.CryptoApi.globalBlacklistUnverifiedDevices`

* Remove `MatrixClient.getStoredCrossSigningForUser` mocking

* Replace `MatrixClient.legacyDeviceVerification` by `MatrixClient.CryptoApi.requestDeviceVerification`

* Remove `MatrixClient.isCrossSigningReady` mock

* Replace `MatrixClient.bootstrapCrossSigning` by `MatrixClient.getCrypto.bootstrapCrossSigning`

* Replace `MatrixClient.getCryptoTrustCrossSignedDevices` by `MatrixClient.getCrypto.getTrustCrossSignedDevices`

* Replace `MatrixClient.hasSecretStorageKey` by `MatrixClient.SecretStorage.hasKey`

* Replace `MatrixClient.getDefaultSecretStorageKeyId` by `MatrixClient.SecretStorage.getDefaultKeyId`

* Remove `MatrixClient.encryptAndSendToDevices` call
This commit is contained in:
Florian Duros 2024-10-21 13:53:39 +02:00 committed by GitHub
parent 26a98e5e30
commit 46d13921d0
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
17 changed files with 22 additions and 55 deletions

View file

@ -76,7 +76,7 @@ async function getSecretStorageKey({
keys: Record<string, SecretStorage.SecretStorageKeyDescription>; keys: Record<string, SecretStorage.SecretStorageKeyDescription>;
}): Promise<[string, Uint8Array]> { }): Promise<[string, Uint8Array]> {
const cli = MatrixClientPeg.safeGet(); const cli = MatrixClientPeg.safeGet();
let keyId = await cli.getDefaultSecretStorageKeyId(); let keyId = await cli.secretStorage.getDefaultKeyId();
let keyInfo!: SecretStorage.SecretStorageKeyDescription; let keyInfo!: SecretStorage.SecretStorageKeyDescription;
if (keyId) { if (keyId) {
// use the default SSSS key if set // use the default SSSS key if set

View file

@ -69,7 +69,7 @@ export default class CreateKeyBackupDialog extends React.PureComponent<IProps, I
const cli = MatrixClientPeg.safeGet(); const cli = MatrixClientPeg.safeGet();
try { try {
// Check if 4S already set up // Check if 4S already set up
const secretStorageAlreadySetup = await cli.hasSecretStorageKey(); const secretStorageAlreadySetup = await cli.secretStorage.hasKey();
if (!secretStorageAlreadySetup) { if (!secretStorageAlreadySetup) {
// bootstrap secret storage; that will also create a backup version // bootstrap secret storage; that will also create a backup version

View file

@ -1709,9 +1709,10 @@ export default class MatrixChat extends React.PureComponent<IProps, IState> {
} }
} }
if (cli.getCrypto()) { const crypto = cli.getCrypto();
if (crypto) {
const blacklistEnabled = SettingsStore.getValueAt(SettingLevel.DEVICE, "blacklistUnverifiedDevices"); const blacklistEnabled = SettingsStore.getValueAt(SettingLevel.DEVICE, "blacklistUnverifiedDevices");
cli.setGlobalBlacklistUnverifiedDevices(blacklistEnabled); crypto.globalBlacklistUnverifiedDevices = blacklistEnabled;
// With cross-signing enabled, we send to unknown devices // With cross-signing enabled, we send to unknown devices
// without prompting. Any bad-device status the user should // without prompting. Any bad-device status the user should

View file

@ -229,7 +229,7 @@ export default class AccessSecretStorageDialog extends React.PureComponent<IProp
await accessSecretStorage(async (): Promise<void> => { await accessSecretStorage(async (): Promise<void> => {
// Now reset cross-signing so everything Just Works™ again. // Now reset cross-signing so everything Just Works™ again.
const cli = MatrixClientPeg.safeGet(); const cli = MatrixClientPeg.safeGet();
await cli.bootstrapCrossSigning({ await cli.getCrypto()?.bootstrapCrossSigning({
authUploadDeviceSigningKeys: async (makeRequest): Promise<void> => { authUploadDeviceSigningKeys: async (makeRequest): Promise<void> => {
const { finished } = Modal.createDialog(InteractiveAuthDialog, { const { finished } = Modal.createDialog(InteractiveAuthDialog, {
title: _t("encryption|bootstrap_title"), title: _t("encryption|bootstrap_title"),

View file

@ -137,7 +137,7 @@ export default class CreateCrossSigningDialog extends React.PureComponent<IProps
try { try {
const cli = MatrixClientPeg.safeGet(); const cli = MatrixClientPeg.safeGet();
await cli.bootstrapCrossSigning({ await cli.getCrypto()?.bootstrapCrossSigning({
authUploadDeviceSigningKeys: this.doBootstrapUIAuth, authUploadDeviceSigningKeys: this.doBootstrapUIAuth,
}); });
this.props.onFinished(true); this.props.onFinished(true);

View file

@ -266,7 +266,7 @@ export default class RestoreKeyBackupDialog extends React.PureComponent<IProps,
try { try {
const cli = MatrixClientPeg.safeGet(); const cli = MatrixClientPeg.safeGet();
const backupInfo = await cli.getKeyBackupVersion(); const backupInfo = await cli.getKeyBackupVersion();
const has4S = await cli.hasSecretStorageKey(); const has4S = await cli.secretStorage.hasKey();
const backupKeyStored = has4S ? await cli.isKeyBackupKeyStored() : null; const backupKeyStored = has4S ? await cli.isKeyBackupKeyStored() : null;
this.setState({ this.setState({
backupInfo, backupInfo,

View file

@ -140,6 +140,7 @@ export default class CryptographyPanel extends React.Component<IProps, IState> {
}; };
private updateBlacklistDevicesFlag = (checked: boolean): void => { private updateBlacklistDevicesFlag = (checked: boolean): void => {
MatrixClientPeg.safeGet().setGlobalBlacklistUnverifiedDevices(checked); const crypto = MatrixClientPeg.safeGet().getCrypto();
if (crypto) crypto.globalBlacklistUnverifiedDevices = checked;
}; };
} }

View file

@ -7,7 +7,6 @@ Please see LICENSE files in the repository root for full details.
*/ */
import { User, MatrixClient, RoomMember } from "matrix-js-sdk/src/matrix"; import { User, MatrixClient, RoomMember } from "matrix-js-sdk/src/matrix";
import { VerificationMethod } from "matrix-js-sdk/src/types";
import { CrossSigningKey, VerificationRequest } from "matrix-js-sdk/src/crypto-api"; import { CrossSigningKey, VerificationRequest } from "matrix-js-sdk/src/crypto-api";
import dis from "./dispatcher/dispatcher"; import dis from "./dispatcher/dispatcher";
@ -39,7 +38,7 @@ export async function verifyDevice(matrixClient: MatrixClient, user: User, devic
return; return;
} }
// if cross-signing is not explicitly disabled, check if it should be enabled first. // if cross-signing is not explicitly disabled, check if it should be enabled first.
if (matrixClient.getCryptoTrustCrossSignedDevices()) { if (matrixClient.getCrypto()?.getTrustCrossSignedDevices()) {
if (!(await enable4SIfNeeded(matrixClient))) { if (!(await enable4SIfNeeded(matrixClient))) {
return; return;
} }
@ -50,11 +49,9 @@ export async function verifyDevice(matrixClient: MatrixClient, user: User, devic
device, device,
onFinished: async (action): Promise<void> => { onFinished: async (action): Promise<void> => {
if (action === "sas") { if (action === "sas") {
const verificationRequestPromise = matrixClient.legacyDeviceVerification( const verificationRequestPromise = matrixClient
user.userId, .getCrypto()
device.deviceId, ?.requestDeviceVerification(user.userId, device.deviceId);
VerificationMethod.Sas,
);
setRightPanel({ member: user, verificationRequestPromise }); setRightPanel({ member: user, verificationRequestPromise });
} else if (action === "legacy") { } else if (action === "legacy") {
Modal.createDialog(ManualDeviceKeyVerificationDialog, { Modal.createDialog(ManualDeviceKeyVerificationDialog, {

View file

@ -141,10 +141,8 @@ export const mockClientMethodsDevice = (
export const mockClientMethodsCrypto = (): Partial< export const mockClientMethodsCrypto = (): Partial<
Record<MethodLikeKeys<MatrixClient> & PropertyLikeKeys<MatrixClient>, unknown> Record<MethodLikeKeys<MatrixClient> & PropertyLikeKeys<MatrixClient>, unknown>
> => ({ > => ({
isCrossSigningReady: jest.fn(),
isKeyBackupKeyStored: jest.fn(), isKeyBackupKeyStored: jest.fn(),
getCrossSigningCacheCallbacks: jest.fn().mockReturnValue({ getCrossSigningKeyCache: jest.fn() }), getCrossSigningCacheCallbacks: jest.fn().mockReturnValue({ getCrossSigningKeyCache: jest.fn() }),
getStoredCrossSigningForUser: jest.fn(),
getKeyBackupVersion: jest.fn().mockResolvedValue(null), getKeyBackupVersion: jest.fn().mockResolvedValue(null),
secretStorage: { hasKey: jest.fn() }, secretStorage: { hasKey: jest.fn() },
getCrypto: jest.fn().mockReturnValue({ getCrypto: jest.fn().mockReturnValue({

View file

@ -95,20 +95,17 @@ export function createTestClient(): MatrixClient {
getUser: jest.fn().mockReturnValue({ on: jest.fn(), off: jest.fn() }), getUser: jest.fn().mockReturnValue({ on: jest.fn(), off: jest.fn() }),
getDevice: jest.fn(), getDevice: jest.fn(),
getDeviceId: jest.fn().mockReturnValue("ABCDEFGHI"), getDeviceId: jest.fn().mockReturnValue("ABCDEFGHI"),
getStoredCrossSigningForUser: jest.fn(),
getStoredDevice: jest.fn(),
deviceId: "ABCDEFGHI", deviceId: "ABCDEFGHI",
getDevices: jest.fn().mockResolvedValue({ devices: [{ device_id: "ABCDEFGHI" }] }), getDevices: jest.fn().mockResolvedValue({ devices: [{ device_id: "ABCDEFGHI" }] }),
getSessionId: jest.fn().mockReturnValue("iaszphgvfku"), getSessionId: jest.fn().mockReturnValue("iaszphgvfku"),
credentials: { userId: "@userId:matrix.org" }, credentials: { userId: "@userId:matrix.org" },
bootstrapCrossSigning: jest.fn(),
hasSecretStorageKey: jest.fn(),
getKeyBackupVersion: jest.fn(), getKeyBackupVersion: jest.fn(),
secretStorage: { secretStorage: {
get: jest.fn(), get: jest.fn(),
isStored: jest.fn().mockReturnValue(false), isStored: jest.fn().mockReturnValue(false),
checkKey: jest.fn().mockResolvedValue(false), checkKey: jest.fn().mockResolvedValue(false),
hasKey: jest.fn().mockReturnValue(false),
}, },
store: { store: {
@ -208,12 +205,10 @@ export function createTestClient(): MatrixClient {
}), }),
hasLazyLoadMembersEnabled: jest.fn().mockReturnValue(false), hasLazyLoadMembersEnabled: jest.fn().mockReturnValue(false),
isInitialSyncComplete: jest.fn().mockReturnValue(true), isInitialSyncComplete: jest.fn().mockReturnValue(true),
downloadKeys: jest.fn(),
fetchRoomEvent: jest.fn().mockRejectedValue({}), fetchRoomEvent: jest.fn().mockRejectedValue({}),
makeTxnId: jest.fn().mockImplementation(() => `t${txnId++}`), makeTxnId: jest.fn().mockImplementation(() => `t${txnId++}`),
sendToDevice: jest.fn().mockResolvedValue(undefined), sendToDevice: jest.fn().mockResolvedValue(undefined),
queueToDevice: jest.fn().mockResolvedValue(undefined), queueToDevice: jest.fn().mockResolvedValue(undefined),
encryptAndSendToDevices: jest.fn().mockResolvedValue(undefined),
cancelPendingEvent: jest.fn(), cancelPendingEvent: jest.fn(),
getMediaHandler: jest.fn().mockReturnValue({ getMediaHandler: jest.fn().mockReturnValue({

View file

@ -83,12 +83,10 @@ describe("MatrixClientPeg", () => {
it("should initialise the rust crypto library by default", async () => { it("should initialise the rust crypto library by default", async () => {
const mockSetValue = jest.spyOn(SettingsStore, "setValue").mockResolvedValue(undefined); const mockSetValue = jest.spyOn(SettingsStore, "setValue").mockResolvedValue(undefined);
const mockInitCrypto = jest.spyOn(testPeg.safeGet(), "initCrypto").mockResolvedValue(undefined);
const mockInitRustCrypto = jest.spyOn(testPeg.safeGet(), "initRustCrypto").mockResolvedValue(undefined); const mockInitRustCrypto = jest.spyOn(testPeg.safeGet(), "initRustCrypto").mockResolvedValue(undefined);
const cryptoStoreKey = new Uint8Array([1, 2, 3, 4]); const cryptoStoreKey = new Uint8Array([1, 2, 3, 4]);
await testPeg.start({ rustCryptoStoreKey: cryptoStoreKey }); await testPeg.start({ rustCryptoStoreKey: cryptoStoreKey });
expect(mockInitCrypto).not.toHaveBeenCalled();
expect(mockInitRustCrypto).toHaveBeenCalledWith({ storageKey: cryptoStoreKey }); expect(mockInitRustCrypto).toHaveBeenCalledWith({ storageKey: cryptoStoreKey });
// we should have stashed the setting in the settings store // we should have stashed the setting in the settings store

View file

@ -125,7 +125,6 @@ describe("<MatrixChat />", () => {
}), }),
getVisibleRooms: jest.fn().mockReturnValue([]), getVisibleRooms: jest.fn().mockReturnValue([]),
getRooms: jest.fn().mockReturnValue([]), getRooms: jest.fn().mockReturnValue([]),
setGlobalBlacklistUnverifiedDevices: jest.fn(),
setGlobalErrorOnUnknownDevices: jest.fn(), setGlobalErrorOnUnknownDevices: jest.fn(),
getCrypto: jest.fn().mockReturnValue({ getCrypto: jest.fn().mockReturnValue({
getVerificationRequestsToDeviceInProgress: jest.fn().mockReturnValue([]), getVerificationRequestsToDeviceInProgress: jest.fn().mockReturnValue([]),
@ -136,9 +135,10 @@ describe("<MatrixChat />", () => {
setDeviceIsolationMode: jest.fn(), setDeviceIsolationMode: jest.fn(),
userHasCrossSigningKeys: jest.fn(), userHasCrossSigningKeys: jest.fn(),
getActiveSessionBackupVersion: jest.fn().mockResolvedValue(null), getActiveSessionBackupVersion: jest.fn().mockResolvedValue(null),
globalBlacklistUnverifiedDevices: false,
// This needs to not finish immediately because we need to test the screen appears
bootstrapCrossSigning: jest.fn().mockImplementation(() => bootstrapDeferred.promise),
}), }),
// This needs to not finish immediately because we need to test the screen appears
bootstrapCrossSigning: jest.fn().mockImplementation(() => bootstrapDeferred.promise),
secretStorage: { secretStorage: {
isStored: jest.fn().mockReturnValue(null), isStored: jest.fn().mockReturnValue(null),
}, },
@ -1011,6 +1011,8 @@ describe("<MatrixChat />", () => {
.mockResolvedValue(new UserVerificationStatus(false, false, false)), .mockResolvedValue(new UserVerificationStatus(false, false, false)),
setDeviceIsolationMode: jest.fn(), setDeviceIsolationMode: jest.fn(),
userHasCrossSigningKeys: jest.fn().mockResolvedValue(false), userHasCrossSigningKeys: jest.fn().mockResolvedValue(false),
// This needs to not finish immediately because we need to test the screen appears
bootstrapCrossSigning: jest.fn().mockImplementation(() => bootstrapDeferred.promise),
}; };
loginClient.getCrypto.mockReturnValue(mockCrypto as any); loginClient.getCrypto.mockReturnValue(mockCrypto as any);
}); });

View file

@ -34,7 +34,7 @@ describe("CreateKeyBackupDialog", () => {
it("should display an error message when backup creation failed", async () => { it("should display an error message when backup creation failed", async () => {
const matrixClient = createTestClient(); const matrixClient = createTestClient();
mocked(matrixClient.hasSecretStorageKey).mockResolvedValue(true); jest.spyOn(matrixClient.secretStorage, "hasKey").mockResolvedValue(true);
mocked(matrixClient.getCrypto()!.resetKeyBackup).mockImplementation(() => { mocked(matrixClient.getCrypto()!.resetKeyBackup).mockImplementation(() => {
throw new Error("failed"); throw new Error("failed");
}); });
@ -49,7 +49,7 @@ describe("CreateKeyBackupDialog", () => {
it("should display an error message when there is no Crypto available", async () => { it("should display an error message when there is no Crypto available", async () => {
const matrixClient = createTestClient(); const matrixClient = createTestClient();
mocked(matrixClient.hasSecretStorageKey).mockResolvedValue(true); jest.spyOn(matrixClient.secretStorage, "hasKey").mockResolvedValue(true);
mocked(matrixClient.getCrypto).mockReturnValue(undefined); mocked(matrixClient.getCrypto).mockReturnValue(undefined);
MatrixClientPeg.safeGet = MatrixClientPeg.get = () => matrixClient; MatrixClientPeg.safeGet = MatrixClientPeg.get = () => matrixClient;

View file

@ -160,7 +160,6 @@ beforeEach(() => {
getRoom: jest.fn(), getRoom: jest.fn(),
credentials: {}, credentials: {},
setPowerLevel: jest.fn(), setPowerLevel: jest.fn(),
downloadKeys: jest.fn(),
getCrypto: jest.fn().mockReturnValue(mockCrypto), getCrypto: jest.fn().mockReturnValue(mockCrypto),
} as unknown as MatrixClient); } as unknown as MatrixClient);

View file

@ -34,7 +34,6 @@ describe("<CrossSigningPanel />", () => {
}); });
mockClient.doesServerSupportUnstableFeature.mockResolvedValue(true); mockClient.doesServerSupportUnstableFeature.mockResolvedValue(true);
mockClient.isCrossSigningReady.mockResolvedValue(false);
}); });
afterEach(() => { afterEach(() => {

View file

@ -17,7 +17,6 @@ import {
waitForElementToBeRemoved, waitForElementToBeRemoved,
within, within,
} from "jest-matrix-react"; } from "jest-matrix-react";
import { DeviceInfo } from "matrix-js-sdk/src/crypto/deviceinfo";
import { logger } from "matrix-js-sdk/src/logger"; import { logger } from "matrix-js-sdk/src/logger";
import { CryptoApi, DeviceVerificationStatus, VerificationRequest } from "matrix-js-sdk/src/crypto-api"; import { CryptoApi, DeviceVerificationStatus, VerificationRequest } from "matrix-js-sdk/src/crypto-api";
import { defer, sleep } from "matrix-js-sdk/src/utils"; import { defer, sleep } from "matrix-js-sdk/src/utils";
@ -205,7 +204,6 @@ describe("<SessionManagerTab />", () => {
...mockClientMethodsServer(), ...mockClientMethodsServer(),
getCrypto: jest.fn().mockReturnValue(mockCrypto), getCrypto: jest.fn().mockReturnValue(mockCrypto),
getDevices: jest.fn(), getDevices: jest.fn(),
getStoredDevice: jest.fn(),
getDeviceId: jest.fn().mockReturnValue(deviceId), getDeviceId: jest.fn().mockReturnValue(deviceId),
deleteMultipleDevices: jest.fn(), deleteMultipleDevices: jest.fn(),
generateClientSecret: jest.fn(), generateClientSecret: jest.fn(),
@ -220,10 +218,6 @@ describe("<SessionManagerTab />", () => {
}); });
jest.clearAllMocks(); jest.clearAllMocks();
jest.spyOn(logger, "error").mockRestore(); jest.spyOn(logger, "error").mockRestore();
mockClient.getStoredDevice.mockImplementation((_userId, id) => {
const device = [alicesDevice, alicesMobileDevice].find((device) => device.device_id === id);
return device ? new DeviceInfo(device.device_id) : null;
});
mockCrypto.getDeviceVerificationStatus.mockReset().mockResolvedValue(new DeviceVerificationStatus({})); mockCrypto.getDeviceVerificationStatus.mockReset().mockResolvedValue(new DeviceVerificationStatus({}));
mockClient.getDevices.mockReset().mockResolvedValue({ devices: [alicesDevice, alicesMobileDevice] }); mockClient.getDevices.mockReset().mockResolvedValue({ devices: [alicesDevice, alicesMobileDevice] });
@ -292,7 +286,6 @@ describe("<SessionManagerTab />", () => {
mockClient.getDevices.mockResolvedValue({ mockClient.getDevices.mockResolvedValue({
devices: [alicesDevice, alicesMobileDevice, alicesOlderMobileDevice], devices: [alicesDevice, alicesMobileDevice, alicesOlderMobileDevice],
}); });
mockClient.getStoredDevice.mockImplementation((_userId, deviceId) => new DeviceInfo(deviceId));
mockCrypto.getDeviceVerificationStatus.mockImplementation(async (_userId, deviceId) => { mockCrypto.getDeviceVerificationStatus.mockImplementation(async (_userId, deviceId) => {
// alices device is trusted // alices device is trusted
if (deviceId === alicesDevice.device_id) { if (deviceId === alicesDevice.device_id) {
@ -464,7 +457,6 @@ describe("<SessionManagerTab />", () => {
mockClient.getDevices.mockResolvedValue({ mockClient.getDevices.mockResolvedValue({
devices: [alicesDevice, alicesMobileDevice], devices: [alicesDevice, alicesMobileDevice],
}); });
mockClient.getStoredDevice.mockImplementation(() => new DeviceInfo(alicesDevice.device_id));
mockCrypto.getDeviceVerificationStatus.mockResolvedValue( mockCrypto.getDeviceVerificationStatus.mockResolvedValue(
new DeviceVerificationStatus({ crossSigningVerified: true, localVerified: true }), new DeviceVerificationStatus({ crossSigningVerified: true, localVerified: true }),
); );
@ -568,7 +560,6 @@ describe("<SessionManagerTab />", () => {
mockClient.getDevices.mockResolvedValue({ mockClient.getDevices.mockResolvedValue({
devices: [alicesDevice, alicesMobileDevice], devices: [alicesDevice, alicesMobileDevice],
}); });
mockClient.getStoredDevice.mockImplementation((_userId, deviceId) => new DeviceInfo(deviceId));
mockCrypto.getDeviceVerificationStatus.mockImplementation(async (_userId, deviceId) => { mockCrypto.getDeviceVerificationStatus.mockImplementation(async (_userId, deviceId) => {
if (deviceId === alicesDevice.device_id) { if (deviceId === alicesDevice.device_id) {
return new DeviceVerificationStatus({ crossSigningVerified: true, localVerified: true }); return new DeviceVerificationStatus({ crossSigningVerified: true, localVerified: true });
@ -595,7 +586,6 @@ describe("<SessionManagerTab />", () => {
mockClient.getDevices.mockResolvedValue({ mockClient.getDevices.mockResolvedValue({
devices: [alicesDevice, alicesMobileDevice], devices: [alicesDevice, alicesMobileDevice],
}); });
mockClient.getStoredDevice.mockImplementation((_userId, deviceId) => new DeviceInfo(deviceId));
mockCrypto.getDeviceVerificationStatus.mockImplementation(async (_userId, deviceId) => { mockCrypto.getDeviceVerificationStatus.mockImplementation(async (_userId, deviceId) => {
// current session verified = able to verify other sessions // current session verified = able to verify other sessions
if (deviceId === alicesDevice.device_id) { if (deviceId === alicesDevice.device_id) {
@ -629,7 +619,6 @@ describe("<SessionManagerTab />", () => {
mockClient.getDevices.mockResolvedValue({ mockClient.getDevices.mockResolvedValue({
devices: [alicesDevice, alicesMobileDevice], devices: [alicesDevice, alicesMobileDevice],
}); });
mockClient.getStoredDevice.mockImplementation((_userId, deviceId) => new DeviceInfo(deviceId));
mockCrypto.getDeviceVerificationStatus.mockImplementation(async (_userId, deviceId) => { mockCrypto.getDeviceVerificationStatus.mockImplementation(async (_userId, deviceId) => {
if (deviceId === alicesDevice.device_id) { if (deviceId === alicesDevice.device_id) {
return new DeviceVerificationStatus({ crossSigningVerified: true, localVerified: true }); return new DeviceVerificationStatus({ crossSigningVerified: true, localVerified: true });
@ -667,7 +656,6 @@ describe("<SessionManagerTab />", () => {
mockClient.getDevices.mockResolvedValue({ mockClient.getDevices.mockResolvedValue({
devices: [alicesDevice, alicesMobileDevice, alicesDehydratedDevice], devices: [alicesDevice, alicesMobileDevice, alicesDehydratedDevice],
}); });
mockClient.getStoredDevice.mockImplementation((_userId, deviceId) => new DeviceInfo(deviceId));
const devicesMap = new Map<string, Device>([ const devicesMap = new Map<string, Device>([
[alicesDeviceObj.deviceId, alicesDeviceObj], [alicesDeviceObj.deviceId, alicesDeviceObj],
@ -708,7 +696,6 @@ describe("<SessionManagerTab />", () => {
mockClient.getDevices.mockResolvedValue({ mockClient.getDevices.mockResolvedValue({
devices: [alicesDevice, alicesMobileDevice, alicesDehydratedDevice], devices: [alicesDevice, alicesMobileDevice, alicesDehydratedDevice],
}); });
mockClient.getStoredDevice.mockImplementation((_userId, deviceId) => new DeviceInfo(deviceId));
const devicesMap = new Map<string, Device>([ const devicesMap = new Map<string, Device>([
[alicesDeviceObj.deviceId, alicesDeviceObj], [alicesDeviceObj.deviceId, alicesDeviceObj],
@ -749,7 +736,6 @@ describe("<SessionManagerTab />", () => {
mockClient.getDevices.mockResolvedValue({ mockClient.getDevices.mockResolvedValue({
devices: [alicesDevice, alicesMobileDevice, alicesDehydratedDevice, alicesOtherDehydratedDevice], devices: [alicesDevice, alicesMobileDevice, alicesDehydratedDevice, alicesOtherDehydratedDevice],
}); });
mockClient.getStoredDevice.mockImplementation((_userId, deviceId) => new DeviceInfo(deviceId));
const devicesMap = new Map<string, Device>([ const devicesMap = new Map<string, Device>([
[alicesDeviceObj.deviceId, alicesDeviceObj], [alicesDeviceObj.deviceId, alicesDeviceObj],

View file

@ -11,7 +11,6 @@ import { render, RenderResult, screen } from "jest-matrix-react";
import userEvent from "@testing-library/user-event"; import userEvent from "@testing-library/user-event";
import { mocked, Mocked } from "jest-mock"; import { mocked, Mocked } from "jest-mock";
import { IMyDevice, MatrixClient } from "matrix-js-sdk/src/matrix"; import { IMyDevice, MatrixClient } from "matrix-js-sdk/src/matrix";
import { DeviceInfo } from "matrix-js-sdk/src/crypto/deviceinfo";
import { CryptoApi, DeviceVerificationStatus } from "matrix-js-sdk/src/crypto-api"; import { CryptoApi, DeviceVerificationStatus } from "matrix-js-sdk/src/crypto-api";
import dis from "../../../src/dispatcher/dispatcher"; import dis from "../../../src/dispatcher/dispatcher";
@ -25,7 +24,6 @@ describe("UnverifiedSessionToast", () => {
const otherDevice: IMyDevice = { const otherDevice: IMyDevice = {
device_id: "ABC123", device_id: "ABC123",
}; };
const otherDeviceInfo = new DeviceInfo(otherDevice.device_id);
let client: Mocked<MatrixClient>; let client: Mocked<MatrixClient>;
let renderResult: RenderResult; let renderResult: RenderResult;
@ -40,13 +38,6 @@ describe("UnverifiedSessionToast", () => {
throw new Error(`Unknown device ${deviceId}`); throw new Error(`Unknown device ${deviceId}`);
}); });
client.getStoredDevice.mockImplementation((userId: string, deviceId: string) => {
if (deviceId === otherDevice.device_id) {
return otherDeviceInfo;
}
return null;
});
client.getCrypto.mockReturnValue({ client.getCrypto.mockReturnValue({
getDeviceVerificationStatus: jest getDeviceVerificationStatus: jest
.fn() .fn()