mirror of
https://github.com/element-hq/element-web
synced 2024-11-27 03:36:07 +03:00
Use new api CryptoApi.getCrossSigningStatus
in CrossSigningPanel
(#11052)
* Use new api `CryptoApi.getCrossSigningStatus` in `CrossSigningPanel` * Update `CrossSigningPanel-test.tsx` * Update `publicKeysOnDevice` * Fix `CryptoApi` import * Fix strict type * Fix tests * Remove `crossSigningInfo` in `mockClientMethodsCrypto` * Move matrix client initialization in `beforeEach`
This commit is contained in:
parent
a40d1ec670
commit
d5d1ec775c
3 changed files with 45 additions and 28 deletions
|
@ -90,17 +90,15 @@ export default class CrossSigningPanel extends React.PureComponent<{}, IState> {
|
||||||
|
|
||||||
private async getUpdatedStatus(): Promise<void> {
|
private async getUpdatedStatus(): Promise<void> {
|
||||||
const cli = MatrixClientPeg.get();
|
const cli = MatrixClientPeg.get();
|
||||||
const crypto = cli.crypto;
|
const crypto = cli.getCrypto();
|
||||||
if (!crypto) return;
|
if (!crypto) return;
|
||||||
|
|
||||||
const pkCache = cli.getCrossSigningCacheCallbacks();
|
const crossSigningStatus = await crypto.getCrossSigningStatus();
|
||||||
const crossSigning = crypto.crossSigningInfo;
|
const crossSigningPublicKeysOnDevice = crossSigningStatus.publicKeysOnDevice;
|
||||||
const secretStorage = cli.secretStorage;
|
const crossSigningPrivateKeysInStorage = crossSigningStatus.privateKeysInSecretStorage;
|
||||||
const crossSigningPublicKeysOnDevice = Boolean(crossSigning.getId());
|
const masterPrivateKeyCached = crossSigningStatus.privateKeysCachedLocally.masterKey;
|
||||||
const crossSigningPrivateKeysInStorage = Boolean(await crossSigning.isStoredInSecretStorage(secretStorage));
|
const selfSigningPrivateKeyCached = crossSigningStatus.privateKeysCachedLocally.selfSigningKey;
|
||||||
const masterPrivateKeyCached = !!(await pkCache?.getCrossSigningKeyCache?.("master"));
|
const userSigningPrivateKeyCached = crossSigningStatus.privateKeysCachedLocally.userSigningKey;
|
||||||
const selfSigningPrivateKeyCached = !!(await pkCache?.getCrossSigningKeyCache?.("self_signing"));
|
|
||||||
const userSigningPrivateKeyCached = !!(await pkCache?.getCrossSigningKeyCache?.("user_signing"));
|
|
||||||
const homeserverSupportsCrossSigning = await cli.doesServerSupportUnstableFeature(
|
const homeserverSupportsCrossSigning = await cli.doesServerSupportUnstableFeature(
|
||||||
"org.matrix.e2e_cross_signing",
|
"org.matrix.e2e_cross_signing",
|
||||||
);
|
);
|
||||||
|
|
|
@ -16,7 +16,8 @@ limitations under the License.
|
||||||
|
|
||||||
import React from "react";
|
import React from "react";
|
||||||
import { render, screen } from "@testing-library/react";
|
import { render, screen } from "@testing-library/react";
|
||||||
import { mocked } from "jest-mock";
|
import { Mocked, mocked } from "jest-mock";
|
||||||
|
import { MatrixClient } from "matrix-js-sdk/src/matrix";
|
||||||
|
|
||||||
import CrossSigningPanel from "../../../../src/components/views/settings/CrossSigningPanel";
|
import CrossSigningPanel from "../../../../src/components/views/settings/CrossSigningPanel";
|
||||||
import {
|
import {
|
||||||
|
@ -28,17 +29,18 @@ import {
|
||||||
|
|
||||||
describe("<CrossSigningPanel />", () => {
|
describe("<CrossSigningPanel />", () => {
|
||||||
const userId = "@alice:server.org";
|
const userId = "@alice:server.org";
|
||||||
const mockClient = getMockClientWithEventEmitter({
|
let mockClient: Mocked<MatrixClient>;
|
||||||
...mockClientMethodsUser(userId),
|
|
||||||
...mockClientMethodsCrypto(),
|
|
||||||
doesServerSupportUnstableFeature: jest.fn(),
|
|
||||||
});
|
|
||||||
const getComponent = () => render(<CrossSigningPanel />);
|
const getComponent = () => render(<CrossSigningPanel />);
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
|
mockClient = getMockClientWithEventEmitter({
|
||||||
|
...mockClientMethodsUser(userId),
|
||||||
|
...mockClientMethodsCrypto(),
|
||||||
|
doesServerSupportUnstableFeature: jest.fn(),
|
||||||
|
});
|
||||||
|
|
||||||
mockClient.doesServerSupportUnstableFeature.mockResolvedValue(true);
|
mockClient.doesServerSupportUnstableFeature.mockResolvedValue(true);
|
||||||
mockClient.isCrossSigningReady.mockResolvedValue(false);
|
mockClient.isCrossSigningReady.mockResolvedValue(false);
|
||||||
mocked(mockClient.crypto!.crossSigningInfo).isStoredInSecretStorage.mockClear().mockResolvedValue(null);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should render a spinner while loading", () => {
|
it("should render a spinner while loading", () => {
|
||||||
|
@ -72,15 +74,20 @@ describe("<CrossSigningPanel />", () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should render when keys are backed up", async () => {
|
it("should render when keys are backed up", async () => {
|
||||||
mocked(mockClient.crypto!.crossSigningInfo).isStoredInSecretStorage.mockResolvedValue({ test: {} });
|
mocked(mockClient.getCrypto()!.getCrossSigningStatus).mockResolvedValue({
|
||||||
|
publicKeysOnDevice: true,
|
||||||
|
privateKeysInSecretStorage: true,
|
||||||
|
privateKeysCachedLocally: {
|
||||||
|
masterKey: true,
|
||||||
|
selfSigningKey: true,
|
||||||
|
userSigningKey: true,
|
||||||
|
},
|
||||||
|
});
|
||||||
getComponent();
|
getComponent();
|
||||||
await flushPromises();
|
await flushPromises();
|
||||||
|
|
||||||
expect(screen.getByTestId("summarised-status").innerHTML).toEqual("✅ Cross-signing is ready for use.");
|
expect(screen.getByTestId("summarised-status").innerHTML).toEqual("✅ Cross-signing is ready for use.");
|
||||||
expect(screen.getByText("Cross-signing private keys:").parentElement!).toMatchSnapshot();
|
expect(screen.getByText("Cross-signing private keys:").parentElement!).toMatchSnapshot();
|
||||||
expect(mockClient.crypto!.crossSigningInfo.isStoredInSecretStorage).toHaveBeenCalledWith(
|
|
||||||
mockClient.secretStorage,
|
|
||||||
);
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -97,7 +104,15 @@ describe("<CrossSigningPanel />", () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should render when keys are backed up", async () => {
|
it("should render when keys are backed up", async () => {
|
||||||
mocked(mockClient.crypto!.crossSigningInfo).isStoredInSecretStorage.mockResolvedValue({ test: {} });
|
mocked(mockClient.getCrypto()!.getCrossSigningStatus).mockResolvedValue({
|
||||||
|
publicKeysOnDevice: true,
|
||||||
|
privateKeysInSecretStorage: true,
|
||||||
|
privateKeysCachedLocally: {
|
||||||
|
masterKey: true,
|
||||||
|
selfSigningKey: true,
|
||||||
|
userSigningKey: true,
|
||||||
|
},
|
||||||
|
});
|
||||||
getComponent();
|
getComponent();
|
||||||
await flushPromises();
|
await flushPromises();
|
||||||
|
|
||||||
|
@ -105,9 +120,6 @@ describe("<CrossSigningPanel />", () => {
|
||||||
"Your account has a cross-signing identity in secret storage, but it is not yet trusted by this session.",
|
"Your account has a cross-signing identity in secret storage, but it is not yet trusted by this session.",
|
||||||
);
|
);
|
||||||
expect(screen.getByText("Cross-signing private keys:").parentElement!).toMatchSnapshot();
|
expect(screen.getByText("Cross-signing private keys:").parentElement!).toMatchSnapshot();
|
||||||
expect(mockClient.crypto!.crossSigningInfo.isStoredInSecretStorage).toHaveBeenCalledWith(
|
|
||||||
mockClient.secretStorage,
|
|
||||||
);
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -156,9 +156,16 @@ export const mockClientMethodsCrypto = (): Partial<
|
||||||
crypto: {
|
crypto: {
|
||||||
isSecretStorageReady: jest.fn(),
|
isSecretStorageReady: jest.fn(),
|
||||||
getSessionBackupPrivateKey: jest.fn(),
|
getSessionBackupPrivateKey: jest.fn(),
|
||||||
crossSigningInfo: {
|
|
||||||
getId: jest.fn(),
|
|
||||||
isStoredInSecretStorage: jest.fn(),
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
|
getCrypto: jest.fn().mockReturnValue({
|
||||||
|
getCrossSigningStatus: jest.fn().mockResolvedValue({
|
||||||
|
publicKeysOnDevice: true,
|
||||||
|
privateKeysInSecretStorage: false,
|
||||||
|
privateKeysCachedLocally: {
|
||||||
|
masterKey: true,
|
||||||
|
selfSigningKey: true,
|
||||||
|
userSigningKey: true,
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
}),
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue