diff --git a/src/components/structures/MatrixChat.tsx b/src/components/structures/MatrixChat.tsx index 7689017856..fae289114b 100644 --- a/src/components/structures/MatrixChat.tsx +++ b/src/components/structures/MatrixChat.tsx @@ -412,7 +412,7 @@ export default class MatrixChat extends React.PureComponent { private async postLoginSetup(): Promise { const cli = MatrixClientPeg.safeGet(); - const cryptoEnabled = cli.isCryptoEnabled(); + const cryptoEnabled = cli.getCrypto(); if (!cryptoEnabled) { this.onLoggedIn(); } @@ -1618,7 +1618,7 @@ export default class MatrixChat extends React.PureComponent { .catch((e) => logger.error("Unable to start DecryptionFailureTracker", e)); cli.on(ClientEvent.Room, (room) => { - if (cli.isCryptoEnabled()) { + if (cli.getCrypto()) { const blacklistEnabled = SettingsStore.getValueAt( SettingLevel.ROOM_DEVICE, "blacklistUnverifiedDevices", @@ -1706,7 +1706,7 @@ export default class MatrixChat extends React.PureComponent { } } - if (cli.isCryptoEnabled()) { + if (cli.getCrypto()) { const blacklistEnabled = SettingsStore.getValueAt(SettingLevel.DEVICE, "blacklistUnverifiedDevices"); cli.setGlobalBlacklistUnverifiedDevices(blacklistEnabled); diff --git a/src/components/structures/RoomView.tsx b/src/components/structures/RoomView.tsx index 1b191f5d8e..9a75c62481 100644 --- a/src/components/structures/RoomView.tsx +++ b/src/components/structures/RoomView.tsx @@ -1461,7 +1461,7 @@ export class RoomView extends React.Component { // set the state immediately then update, so we don't scare the user into thinking the room is unencrypted this.setState({ e2eStatus }); - if (this.context.client.isCryptoEnabled()) { + if (this.context.client.getCrypto()) { /* At this point, the user has encryption on and cross-signing on */ e2eStatus = await shieldStatusForRoom(this.context.client, room); RoomView.e2eStatusCache.set(room.roomId, e2eStatus); diff --git a/src/components/views/rooms/SendMessageComposer.tsx b/src/components/views/rooms/SendMessageComposer.tsx index 1b3fb47163..03825a25f9 100644 --- a/src/components/views/rooms/SendMessageComposer.tsx +++ b/src/components/views/rooms/SendMessageComposer.tsx @@ -265,7 +265,7 @@ export class SendMessageComposer extends React.Component) { super(props, context); - if (this.props.mxClient.isCryptoEnabled() && this.props.mxClient.isRoomEncrypted(this.props.room.roomId)) { + if (this.props.mxClient.getCrypto() && this.props.mxClient.isRoomEncrypted(this.props.room.roomId)) { this.prepareToEncrypt = throttle( () => { this.props.mxClient.prepareToEncrypt(this.props.room); diff --git a/src/hooks/useEncryptionStatus.ts b/src/hooks/useEncryptionStatus.ts index e3e44fca77..30417f7821 100644 --- a/src/hooks/useEncryptionStatus.ts +++ b/src/hooks/useEncryptionStatus.ts @@ -15,7 +15,7 @@ export function useEncryptionStatus(client: MatrixClient, room: Room): E2EStatus const [e2eStatus, setE2eStatus] = useState(null); useEffect(() => { - if (client.isCryptoEnabled()) { + if (client.getCrypto()) { shieldStatusForRoom(client, room).then((e2eStatus) => { setE2eStatus(e2eStatus); }); diff --git a/test/components/structures/MatrixChat-test.tsx b/test/components/structures/MatrixChat-test.tsx index 8876fdc802..1d6eca83a5 100644 --- a/test/components/structures/MatrixChat-test.tsx +++ b/test/components/structures/MatrixChat-test.tsx @@ -98,7 +98,6 @@ describe("", () => { getThirdpartyProtocols: jest.fn().mockResolvedValue({}), getClientWellKnown: jest.fn().mockReturnValue({}), isVersionSupported: jest.fn().mockResolvedValue(false), - isCryptoEnabled: jest.fn().mockReturnValue(false), initRustCrypto: jest.fn(), getRoom: jest.fn(), getMediaHandler: jest.fn().mockReturnValue({ @@ -1011,13 +1010,12 @@ describe("", () => { .mockResolvedValue(new UserVerificationStatus(false, false, false)), setDeviceIsolationMode: jest.fn(), }; - loginClient.isCryptoEnabled.mockReturnValue(true); loginClient.getCrypto.mockReturnValue(mockCrypto as any); loginClient.userHasCrossSigningKeys.mockClear().mockResolvedValue(false); }); it("should go straight to logged in view when crypto is not enabled", async () => { - loginClient.isCryptoEnabled.mockReturnValue(false); + loginClient.getCrypto.mockReturnValue(undefined); await getComponentAndLogin(true); diff --git a/test/components/structures/RoomView-test.tsx b/test/components/structures/RoomView-test.tsx index 1e11272c56..ff294ba7f0 100644 --- a/test/components/structures/RoomView-test.tsx +++ b/test/components/structures/RoomView-test.tsx @@ -97,6 +97,7 @@ describe("RoomView", () => { stores.rightPanelStore.useUnitTestClient(cli); jest.spyOn(VoipUserMapper.sharedInstance(), "getVirtualRoomForRoom").mockResolvedValue(undefined); + jest.spyOn(cli, "getCrypto").mockReturnValue(undefined); }); afterEach(() => { @@ -230,7 +231,6 @@ describe("RoomView", () => { it("updates url preview visibility on encryption state change", async () => { room.getMyMembership = jest.fn().mockReturnValue(KnownMembership.Join); // we should be starting unencrypted - expect(cli.isCryptoEnabled()).toEqual(false); expect(cli.isRoomEncrypted(room.roomId)).toEqual(false); const roomViewInstance = await getRoomViewInstance(); @@ -246,7 +246,6 @@ describe("RoomView", () => { expect(roomViewInstance.state.showUrlPreview).toBe(true); // now enable encryption - cli.isCryptoEnabled.mockReturnValue(true); cli.isRoomEncrypted.mockReturnValue(true); // and fake an encryption event into the room to prompt it to re-check diff --git a/test/components/views/dialogs/security/CreateSecretStorageDialog-test.tsx b/test/components/views/dialogs/security/CreateSecretStorageDialog-test.tsx index 52db753258..0ee7c00fc5 100644 --- a/test/components/views/dialogs/security/CreateSecretStorageDialog-test.tsx +++ b/test/components/views/dialogs/security/CreateSecretStorageDialog-test.tsx @@ -134,8 +134,6 @@ describe("CreateSecretStorageDialog", () => { }); it("calls bootstrapSecretStorage once keys are restored if the backup is now trusted", async () => { - mockClient.isCryptoEnabled.mockReturnValue(true); - const result = renderComponent(); await result.findByText(/Enter your account password to confirm the upgrade/); expect(result.container).toMatchSnapshot(); diff --git a/test/components/views/right_panel/UserInfo-test.tsx b/test/components/views/right_panel/UserInfo-test.tsx index 8c21246fa5..a0e2bfcdfc 100644 --- a/test/components/views/right_panel/UserInfo-test.tsx +++ b/test/components/views/right_panel/UserInfo-test.tsx @@ -142,7 +142,6 @@ beforeEach(() => { isUserIgnored: jest.fn(), getIgnoredUsers: jest.fn(), setIgnoredUsers: jest.fn(), - isCryptoEnabled: jest.fn(), getUserId: jest.fn(), getSafeUserId: jest.fn(), getDomain: jest.fn(), @@ -424,7 +423,6 @@ describe("", () => { describe("with crypto enabled", () => { beforeEach(() => { - mockClient.isCryptoEnabled.mockReturnValue(true); mockClient.doesServerSupportUnstableFeature.mockResolvedValue(true); mockCrypto.getUserVerificationStatus.mockResolvedValue(new UserVerificationStatus(false, false, false)); @@ -663,7 +661,6 @@ describe("", () => { describe("with an encrypted room", () => { beforeEach(() => { - mockClient.isCryptoEnabled.mockReturnValue(true); mockClient.isRoomEncrypted.mockReturnValue(true); }); diff --git a/test/components/views/rooms/RoomHeader-test.tsx b/test/components/views/rooms/RoomHeader-test.tsx index 6981906392..b5d054a9f5 100644 --- a/test/components/views/rooms/RoomHeader-test.tsx +++ b/test/components/views/rooms/RoomHeader-test.tsx @@ -8,15 +8,7 @@ Please see LICENSE files in the repository root for full details. import React from "react"; import { CallType, MatrixCall } from "matrix-js-sdk/src/webrtc/call"; -import { - EventType, - JoinRule, - MatrixClient, - MatrixEvent, - PendingEventOrdering, - Room, - RoomMember, -} from "matrix-js-sdk/src/matrix"; +import { EventType, JoinRule, MatrixEvent, PendingEventOrdering, Room, RoomMember } from "matrix-js-sdk/src/matrix"; import { KnownMembership } from "matrix-js-sdk/src/types"; import { createEvent, @@ -86,6 +78,7 @@ describe("RoomHeader", () => { } as unknown as DMRoomMap); setCardSpy = jest.spyOn(RightPanelStore.instance, "setCard"); + jest.spyOn(ShieldUtils, "shieldStatusForRoom").mockResolvedValue(ShieldUtils.E2EStatus.Normal); }); afterEach(() => { @@ -579,10 +572,7 @@ describe("RoomHeader", () => { }); describe("dm", () => { - let client: MatrixClient; beforeEach(() => { - client = MatrixClientPeg.get()!; - // Make the mocked room a DM mocked(DMRoomMap.shared().getUserIdForRoomId).mockImplementation((roomId) => { if (roomId === room.roomId) return "@user:example.com"; @@ -608,8 +598,6 @@ describe("RoomHeader", () => { getMxcAvatarUrl: () => "mxc://avatar.url/image.png", }, ]); - jest.spyOn(client, "isCryptoEnabled").mockReturnValue(true); - jest.spyOn(ShieldUtils, "shieldStatusForRoom").mockResolvedValue(ShieldUtils.E2EStatus.Normal); }); it.each([ diff --git a/test/components/views/rooms/SendMessageComposer-test.tsx b/test/components/views/rooms/SendMessageComposer-test.tsx index 562f8b26d8..a1364e6743 100644 --- a/test/components/views/rooms/SendMessageComposer-test.tsx +++ b/test/components/views/rooms/SendMessageComposer-test.tsx @@ -571,7 +571,6 @@ describe("", () => { it("should call prepareToEncrypt when the user is typing", async () => { const cli = stubClient(); - cli.isCryptoEnabled = jest.fn().mockReturnValue(true); cli.isRoomEncrypted = jest.fn().mockReturnValue(true); cli.prepareToEncrypt = jest.fn(); const room = mkStubRoom("!roomId:server", "Room", cli); diff --git a/test/components/views/settings/devices/LoginWithQR-test.tsx b/test/components/views/settings/devices/LoginWithQR-test.tsx index 0bb0a951c6..82ea0b0828 100644 --- a/test/components/views/settings/devices/LoginWithQR-test.tsx +++ b/test/components/views/settings/devices/LoginWithQR-test.tsx @@ -38,7 +38,6 @@ function makeClient() { getUser: jest.fn(), isGuest: jest.fn().mockReturnValue(false), isUserIgnored: jest.fn(), - isCryptoEnabled: jest.fn(), getUserId: jest.fn(), on: jest.fn(), isSynapseAdministrator: jest.fn().mockResolvedValue(false), diff --git a/test/components/views/settings/devices/LoginWithQRSection-test.tsx b/test/components/views/settings/devices/LoginWithQRSection-test.tsx index c71e419395..0b9a371241 100644 --- a/test/components/views/settings/devices/LoginWithQRSection-test.tsx +++ b/test/components/views/settings/devices/LoginWithQRSection-test.tsx @@ -25,7 +25,6 @@ function makeClient(wellKnown: IClientWellKnown) { getUser: jest.fn(), isGuest: jest.fn().mockReturnValue(false), isUserIgnored: jest.fn(), - isCryptoEnabled: jest.fn(), getUserId: jest.fn(), on: jest.fn(), isSynapseAdministrator: jest.fn().mockResolvedValue(false), diff --git a/test/test-utils/client.ts b/test/test-utils/client.ts index 19625043e1..7b0e22e70e 100644 --- a/test/test-utils/client.ts +++ b/test/test-utils/client.ts @@ -141,7 +141,6 @@ export const mockClientMethodsDevice = ( export const mockClientMethodsCrypto = (): Partial< Record & PropertyLikeKeys, unknown> > => ({ - isCryptoEnabled: jest.fn(), isCrossSigningReady: jest.fn(), isKeyBackupKeyStored: jest.fn(), getCrossSigningCacheCallbacks: jest.fn().mockReturnValue({ getCrossSigningKeyCache: jest.fn() }), diff --git a/test/test-utils/test-utils.ts b/test/test-utils/test-utils.ts index fe9d078f3a..3a427b34a2 100644 --- a/test/test-utils/test-utils.ts +++ b/test/test-utils/test-utils.ts @@ -214,7 +214,6 @@ export function createTestClient(): MatrixClient { relations: jest.fn().mockResolvedValue({ events: [], }), - isCryptoEnabled: jest.fn().mockReturnValue(false), hasLazyLoadMembersEnabled: jest.fn().mockReturnValue(false), isInitialSyncComplete: jest.fn().mockReturnValue(true), downloadKeys: jest.fn(),