Skip to content
This repository has been archived by the owner on Oct 16, 2024. It is now read-only.

Commit

Permalink
Replace MatrixClient.userHasCrossSigningKeys by `MatrixClient.getCr…
Browse files Browse the repository at this point in the history
…ypto.userHasCrossSigningKeys` (#148)
  • Loading branch information
florianduros authored Oct 15, 2024
1 parent 0750625 commit 503d900
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/components/structures/MatrixChat.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,7 @@ export default class MatrixChat extends React.PureComponent<IProps, IState> {
// from another device.
promisesList.push(
(async (): Promise<void> => {
crossSigningIsSetUp = await cli.userHasCrossSigningKeys();
crossSigningIsSetUp = Boolean(await cli.getCrypto()?.userHasCrossSigningKeys());
})(),
);
}
Expand Down
16 changes: 8 additions & 8 deletions test/components/structures/MatrixChat-test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,6 @@ describe("<MatrixChat />", () => {
}),
getVisibleRooms: jest.fn().mockReturnValue([]),
getRooms: jest.fn().mockReturnValue([]),
userHasCrossSigningKeys: jest.fn(),
setGlobalBlacklistUnverifiedDevices: jest.fn(),
setGlobalErrorOnUnknownDevices: jest.fn(),
getCrypto: jest.fn().mockReturnValue({
Expand All @@ -136,6 +135,7 @@ describe("<MatrixChat />", () => {
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),
Expand Down Expand Up @@ -1010,18 +1010,18 @@ describe("<MatrixChat />", () => {
.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 () => {
loginClient.isCryptoEnabled.mockReturnValue(false);

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 () => {
Expand All @@ -1042,7 +1042,7 @@ describe("<MatrixChat />", () => {
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", () => {
Expand Down Expand Up @@ -1088,19 +1088,19 @@ describe("<MatrixChat />", () => {

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();
});
});

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();

Expand All @@ -1113,7 +1113,7 @@ describe("<MatrixChat />", () => {

await getComponentAndLogin();

expect(loginClient.userHasCrossSigningKeys).toHaveBeenCalled();
expect(loginClient.getCrypto()!.userHasCrossSigningKeys).toHaveBeenCalled();

await flushPromises();

Expand Down

0 comments on commit 503d900

Please sign in to comment.