From 503d9004d15df4fb50fba2605265e32ff5b837af Mon Sep 17 00:00:00 2001 From: Florian Duros Date: Tue, 15 Oct 2024 09:50:26 +0200 Subject: [PATCH] Replace `MatrixClient.userHasCrossSigningKeys` by `MatrixClient.getCrypto.userHasCrossSigningKeys` (#148) --- src/components/structures/MatrixChat.tsx | 2 +- test/components/structures/MatrixChat-test.tsx | 16 ++++++++-------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/components/structures/MatrixChat.tsx b/src/components/structures/MatrixChat.tsx index cc0357a8f1..0e5ec04d33 100644 --- a/src/components/structures/MatrixChat.tsx +++ b/src/components/structures/MatrixChat.tsx @@ -426,7 +426,7 @@ export default class MatrixChat extends React.PureComponent { // from another device. promisesList.push( (async (): Promise => { - crossSigningIsSetUp = await cli.userHasCrossSigningKeys(); + crossSigningIsSetUp = Boolean(await cli.getCrypto()?.userHasCrossSigningKeys()); })(), ); } diff --git a/test/components/structures/MatrixChat-test.tsx b/test/components/structures/MatrixChat-test.tsx index 3e8c164260..1202dc0481 100644 --- a/test/components/structures/MatrixChat-test.tsx +++ b/test/components/structures/MatrixChat-test.tsx @@ -126,7 +126,6 @@ describe("", () => { }), getVisibleRooms: jest.fn().mockReturnValue([]), getRooms: jest.fn().mockReturnValue([]), - userHasCrossSigningKeys: jest.fn(), setGlobalBlacklistUnverifiedDevices: jest.fn(), setGlobalErrorOnUnknownDevices: jest.fn(), getCrypto: jest.fn().mockReturnValue({ @@ -136,6 +135,7 @@ describe("", () => { getUserVerificationStatus: jest.fn().mockResolvedValue(new UserVerificationStatus(false, false, false)), getVersion: jest.fn().mockReturnValue("1"), setDeviceIsolationMode: jest.fn(), + userHasCrossSigningKeys: jest.fn(), }), // This needs to not finish immediately because we need to test the screen appears bootstrapCrossSigning: jest.fn().mockImplementation(() => bootstrapDeferred.promise), @@ -1010,10 +1010,10 @@ describe("", () => { .fn() .mockResolvedValue(new UserVerificationStatus(false, false, false)), setDeviceIsolationMode: jest.fn(), + userHasCrossSigningKeys: jest.fn().mockResolvedValue(false), }; 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 () => { @@ -1021,7 +1021,7 @@ describe("", () => { await getComponentAndLogin(true); - expect(loginClient.userHasCrossSigningKeys).not.toHaveBeenCalled(); + expect(loginClient.getCrypto()!.userHasCrossSigningKeys).not.toHaveBeenCalled(); }); it("should go straight to logged in view when user does not have cross signing keys and server does not support cross signing", async () => { @@ -1042,7 +1042,7 @@ describe("", () => { describe("when server supports cross signing and user does not have cross signing setup", () => { beforeEach(() => { loginClient.doesServerSupportUnstableFeature.mockResolvedValue(true); - loginClient.userHasCrossSigningKeys.mockResolvedValue(false); + jest.spyOn(loginClient.getCrypto()!, "userHasCrossSigningKeys").mockResolvedValue(false); }); describe("when encryption is force disabled", () => { @@ -1088,7 +1088,7 @@ describe("", () => { await getComponentAndLogin(); - expect(loginClient.userHasCrossSigningKeys).toHaveBeenCalled(); + expect(loginClient.getCrypto()!.userHasCrossSigningKeys).toHaveBeenCalled(); // set up keys screen is rendered await expect(await screen.findByText("Setting up keys")).toBeInTheDocument(); @@ -1096,11 +1096,11 @@ describe("", () => { }); it("should show complete security screen when user has cross signing setup", async () => { - loginClient.userHasCrossSigningKeys.mockResolvedValue(true); + jest.spyOn(loginClient.getCrypto()!, "userHasCrossSigningKeys").mockResolvedValue(true); await getComponentAndLogin(); - expect(loginClient.userHasCrossSigningKeys).toHaveBeenCalled(); + expect(loginClient.getCrypto()!.userHasCrossSigningKeys).toHaveBeenCalled(); await flushPromises(); @@ -1113,7 +1113,7 @@ describe("", () => { await getComponentAndLogin(); - expect(loginClient.userHasCrossSigningKeys).toHaveBeenCalled(); + expect(loginClient.getCrypto()!.userHasCrossSigningKeys).toHaveBeenCalled(); await flushPromises();