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

Don't start key backups when opening settings #11640

Merged
merged 3 commits into from
Sep 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 1 addition & 23 deletions src/components/views/settings/SecureBackupPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export default class SecureBackupPanel extends React.PureComponent<{}, IState> {
}

public componentDidMount(): void {
this.checkKeyBackupStatus();
this.loadBackupStatus();

MatrixClientPeg.safeGet().on(CryptoEvent.KeyBackupStatus, this.onKeyBackupStatus);
MatrixClientPeg.safeGet().on(CryptoEvent.KeyBackupSessionsRemaining, this.onKeyBackupSessionsRemaining);
Expand Down Expand Up @@ -97,28 +97,6 @@ export default class SecureBackupPanel extends React.PureComponent<{}, IState> {
this.loadBackupStatus();
};

private async checkKeyBackupStatus(): Promise<void> {
this.getUpdatedDiagnostics();
try {
const keyBackupResult = await MatrixClientPeg.safeGet().checkKeyBackup();
this.setState({
loading: false,
error: false,
backupInfo: keyBackupResult?.backupInfo ?? null,
backupSigStatus: keyBackupResult?.trustInfo ?? null,
});
} catch (e) {
logger.log("Unable to fetch check backup status", e);
if (this.unmounted) return;
this.setState({
loading: false,
error: true,
backupInfo: null,
backupSigStatus: null,
});
}
}

private async loadBackupStatus(): Promise<void> {
this.setState({ loading: true });
this.getUpdatedDiagnostics();
Expand Down
55 changes: 27 additions & 28 deletions test/components/views/settings/SecureBackupPanel-test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,19 +46,17 @@ describe("<SecureBackupPanel />", () => {
const getComponent = () => render(<SecureBackupPanel />);

beforeEach(() => {
client.checkKeyBackup.mockResolvedValue({
backupInfo: {
version: "1",
algorithm: "test",
auth_data: {
public_key: "1234",
},
},
trustInfo: {
usable: false,
sigs: [],
client.getKeyBackupVersion.mockResolvedValue({
version: "1",
algorithm: "test",
auth_data: {
public_key: "1234",
},
});
client.isKeyBackupTrusted.mockResolvedValue({
usable: false,
sigs: [],
});

mocked(client.secretStorage.hasKey).mockClear().mockResolvedValue(false);
client.deleteKeyBackupVersion.mockClear().mockResolvedValue();
Expand All @@ -75,14 +73,21 @@ describe("<SecureBackupPanel />", () => {
expect(screen.queryByRole("progressbar")).not.toBeInTheDocument();
});

it("handles null backup info", async () => {
// checkKeyBackup can fail and return null for various reasons
client.checkKeyBackup.mockResolvedValue(null);
it("handles error fetching backup", async () => {
// getKeyBackupVersion can fail for various reasons
client.getKeyBackupVersion.mockImplementation(async () => {
throw new Error("beep beep");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖

});
const renderResult = getComponent();
await renderResult.findByText("Unable to load key backup status");
expect(renderResult.container).toMatchSnapshot();
});

it("handles absence of backup", async () => {
client.getKeyBackupVersion.mockResolvedValue(null);
getComponent();
// flush checkKeyBackup promise
// flush getKeyBackupVersion promise
await flushPromises();

// no backup info
expect(screen.getByText("Back up your keys before signing out to avoid losing them.")).toBeInTheDocument();
});

Expand Down Expand Up @@ -124,18 +129,12 @@ describe("<SecureBackupPanel />", () => {
});

it("deletes backup after confirmation", async () => {
client.checkKeyBackup
client.getKeyBackupVersion
.mockResolvedValueOnce({
backupInfo: {
version: "1",
algorithm: "test",
auth_data: {
public_key: "1234",
},
},
trustInfo: {
usable: false,
sigs: [],
version: "1",
algorithm: "test",
auth_data: {
public_key: "1234",
},
})
.mockResolvedValue(null);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,70 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`<SecureBackupPanel /> handles error fetching backup 1`] = `
<div>
<div
class="mx_SettingsSubsection_text"
>
Back up your encryption keys with your account data in case you lose access to your sessions. Your keys will be secured with a unique Security Key.
</div>
<div
class="mx_SettingsSubsection_text"
>
Unable to load key backup status
</div>
<details>
<summary>
Advanced
</summary>
<table
class="mx_SecureBackupPanel_statusList"
>
<tr>
<th
scope="row"
>
Backup key stored:
</th>
<td>
not stored
</td>
</tr>
<tr>
<th
scope="row"
>
Backup key cached:
</th>
<td>
not found locally

</td>
</tr>
<tr>
<th
scope="row"
>
Secret storage public key:
</th>
<td>
not found
</td>
</tr>
<tr>
<th
scope="row"
>
Secret storage:
</th>
<td>
not ready
</td>
</tr>
</table>
</details>
</div>
`;

exports[`<SecureBackupPanel /> suggests connecting session to key backup when backup exists 1`] = `
<div>
<div
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ describe("<SecurityUserSettingsTab />", () => {
...mockClientMethodsCrypto(),
getRooms: jest.fn().mockReturnValue([]),
getIgnoredUsers: jest.fn(),
getKeyBackupVersion: jest.fn(),
});

const getComponent = () => (
Expand Down
1 change: 0 additions & 1 deletion test/test-utils/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,6 @@ export const mockClientMethodsCrypto = (): Partial<
isKeyBackupKeyStored: jest.fn(),
getCrossSigningCacheCallbacks: jest.fn().mockReturnValue({ getCrossSigningKeyCache: jest.fn() }),
getStoredCrossSigningForUser: jest.fn(),
checkKeyBackup: jest.fn().mockReturnValue({}),
secretStorage: { hasKey: jest.fn() },
getCrypto: jest.fn().mockReturnValue({
getUserDeviceInfo: jest.fn(),
Expand Down
Loading