Replace MatrixClient.userHasCrossSigningKeys by MatrixClient.getCrypto.userHasCrossSigningKeys (#148)

This commit is contained in:
Florian Duros 2024-10-15 09:50:26 +02:00 committed by GitHub
parent 07506253f9
commit 503d9004d1
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 9 additions and 9 deletions

View file

@ -426,7 +426,7 @@ export default class MatrixChat extends React.PureComponent<IProps, IState> {
// from another device. // from another device.
promisesList.push( promisesList.push(
(async (): Promise<void> => { (async (): Promise<void> => {
crossSigningIsSetUp = await cli.userHasCrossSigningKeys(); crossSigningIsSetUp = Boolean(await cli.getCrypto()?.userHasCrossSigningKeys());
})(), })(),
); );
} }

View file

@ -126,7 +126,6 @@ describe("<MatrixChat />", () => {
}), }),
getVisibleRooms: jest.fn().mockReturnValue([]), getVisibleRooms: jest.fn().mockReturnValue([]),
getRooms: jest.fn().mockReturnValue([]), getRooms: jest.fn().mockReturnValue([]),
userHasCrossSigningKeys: jest.fn(),
setGlobalBlacklistUnverifiedDevices: jest.fn(), setGlobalBlacklistUnverifiedDevices: jest.fn(),
setGlobalErrorOnUnknownDevices: jest.fn(), setGlobalErrorOnUnknownDevices: jest.fn(),
getCrypto: jest.fn().mockReturnValue({ getCrypto: jest.fn().mockReturnValue({
@ -136,6 +135,7 @@ describe("<MatrixChat />", () => {
getUserVerificationStatus: jest.fn().mockResolvedValue(new UserVerificationStatus(false, false, false)), getUserVerificationStatus: jest.fn().mockResolvedValue(new UserVerificationStatus(false, false, false)),
getVersion: jest.fn().mockReturnValue("1"), getVersion: jest.fn().mockReturnValue("1"),
setDeviceIsolationMode: jest.fn(), setDeviceIsolationMode: jest.fn(),
userHasCrossSigningKeys: jest.fn(),
}), }),
// This needs to not finish immediately because we need to test the screen appears // This needs to not finish immediately because we need to test the screen appears
bootstrapCrossSigning: jest.fn().mockImplementation(() => bootstrapDeferred.promise), bootstrapCrossSigning: jest.fn().mockImplementation(() => bootstrapDeferred.promise),
@ -1010,10 +1010,10 @@ describe("<MatrixChat />", () => {
.fn() .fn()
.mockResolvedValue(new UserVerificationStatus(false, false, false)), .mockResolvedValue(new UserVerificationStatus(false, false, false)),
setDeviceIsolationMode: jest.fn(), setDeviceIsolationMode: jest.fn(),
userHasCrossSigningKeys: jest.fn().mockResolvedValue(false),
}; };
loginClient.isCryptoEnabled.mockReturnValue(true); loginClient.isCryptoEnabled.mockReturnValue(true);
loginClient.getCrypto.mockReturnValue(mockCrypto as any); 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 () => { it("should go straight to logged in view when crypto is not enabled", async () => {
@ -1021,7 +1021,7 @@ describe("<MatrixChat />", () => {
await getComponentAndLogin(true); 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 () => { 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("<MatrixChat />", () => {
describe("when server supports cross signing and user does not have cross signing setup", () => { describe("when server supports cross signing and user does not have cross signing setup", () => {
beforeEach(() => { beforeEach(() => {
loginClient.doesServerSupportUnstableFeature.mockResolvedValue(true); loginClient.doesServerSupportUnstableFeature.mockResolvedValue(true);
loginClient.userHasCrossSigningKeys.mockResolvedValue(false); jest.spyOn(loginClient.getCrypto()!, "userHasCrossSigningKeys").mockResolvedValue(false);
}); });
describe("when encryption is force disabled", () => { describe("when encryption is force disabled", () => {
@ -1088,7 +1088,7 @@ describe("<MatrixChat />", () => {
await getComponentAndLogin(); await getComponentAndLogin();
expect(loginClient.userHasCrossSigningKeys).toHaveBeenCalled(); expect(loginClient.getCrypto()!.userHasCrossSigningKeys).toHaveBeenCalled();
// set up keys screen is rendered // set up keys screen is rendered
await expect(await screen.findByText("Setting up keys")).toBeInTheDocument(); await expect(await screen.findByText("Setting up keys")).toBeInTheDocument();
@ -1096,11 +1096,11 @@ describe("<MatrixChat />", () => {
}); });
it("should show complete security screen when user has cross signing setup", async () => { 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(); await getComponentAndLogin();
expect(loginClient.userHasCrossSigningKeys).toHaveBeenCalled(); expect(loginClient.getCrypto()!.userHasCrossSigningKeys).toHaveBeenCalled();
await flushPromises(); await flushPromises();
@ -1113,7 +1113,7 @@ describe("<MatrixChat />", () => {
await getComponentAndLogin(); await getComponentAndLogin();
expect(loginClient.userHasCrossSigningKeys).toHaveBeenCalled(); expect(loginClient.getCrypto()!.userHasCrossSigningKeys).toHaveBeenCalled();
await flushPromises(); await flushPromises();