Don't start key backups when opening settings (#11640)
* SecureBackupPanel: stop calling `checkKeyBackup` `checkKeyBackup` will start key backups if they aren't already running. In my not-so-humble opinion, the mere act of opening a settings panel shouldn't change anything. * fix SecurityUserSettingsTab test
This commit is contained in:
parent
c6fec9b95b
commit
c879882558
5 changed files with 95 additions and 53 deletions
|
@ -67,7 +67,7 @@ export default class SecureBackupPanel extends React.PureComponent<{}, IState> {
|
||||||
}
|
}
|
||||||
|
|
||||||
public componentDidMount(): void {
|
public componentDidMount(): void {
|
||||||
this.checkKeyBackupStatus();
|
this.loadBackupStatus();
|
||||||
|
|
||||||
MatrixClientPeg.safeGet().on(CryptoEvent.KeyBackupStatus, this.onKeyBackupStatus);
|
MatrixClientPeg.safeGet().on(CryptoEvent.KeyBackupStatus, this.onKeyBackupStatus);
|
||||||
MatrixClientPeg.safeGet().on(CryptoEvent.KeyBackupSessionsRemaining, this.onKeyBackupSessionsRemaining);
|
MatrixClientPeg.safeGet().on(CryptoEvent.KeyBackupSessionsRemaining, this.onKeyBackupSessionsRemaining);
|
||||||
|
@ -97,28 +97,6 @@ export default class SecureBackupPanel extends React.PureComponent<{}, IState> {
|
||||||
this.loadBackupStatus();
|
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> {
|
private async loadBackupStatus(): Promise<void> {
|
||||||
this.setState({ loading: true });
|
this.setState({ loading: true });
|
||||||
this.getUpdatedDiagnostics();
|
this.getUpdatedDiagnostics();
|
||||||
|
|
|
@ -46,19 +46,17 @@ describe("<SecureBackupPanel />", () => {
|
||||||
const getComponent = () => render(<SecureBackupPanel />);
|
const getComponent = () => render(<SecureBackupPanel />);
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
client.checkKeyBackup.mockResolvedValue({
|
client.getKeyBackupVersion.mockResolvedValue({
|
||||||
backupInfo: {
|
version: "1",
|
||||||
version: "1",
|
algorithm: "test",
|
||||||
algorithm: "test",
|
auth_data: {
|
||||||
auth_data: {
|
public_key: "1234",
|
||||||
public_key: "1234",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
trustInfo: {
|
|
||||||
usable: false,
|
|
||||||
sigs: [],
|
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
client.isKeyBackupTrusted.mockResolvedValue({
|
||||||
|
usable: false,
|
||||||
|
sigs: [],
|
||||||
|
});
|
||||||
|
|
||||||
mocked(client.secretStorage.hasKey).mockClear().mockResolvedValue(false);
|
mocked(client.secretStorage.hasKey).mockClear().mockResolvedValue(false);
|
||||||
client.deleteKeyBackupVersion.mockClear().mockResolvedValue();
|
client.deleteKeyBackupVersion.mockClear().mockResolvedValue();
|
||||||
|
@ -75,14 +73,21 @@ describe("<SecureBackupPanel />", () => {
|
||||||
expect(screen.queryByRole("progressbar")).not.toBeInTheDocument();
|
expect(screen.queryByRole("progressbar")).not.toBeInTheDocument();
|
||||||
});
|
});
|
||||||
|
|
||||||
it("handles null backup info", async () => {
|
it("handles error fetching backup", async () => {
|
||||||
// checkKeyBackup can fail and return null for various reasons
|
// getKeyBackupVersion can fail for various reasons
|
||||||
client.checkKeyBackup.mockResolvedValue(null);
|
client.getKeyBackupVersion.mockImplementation(async () => {
|
||||||
getComponent();
|
throw new Error("beep beep");
|
||||||
// flush checkKeyBackup promise
|
});
|
||||||
await flushPromises();
|
const renderResult = getComponent();
|
||||||
|
await renderResult.findByText("Unable to load key backup status");
|
||||||
|
expect(renderResult.container).toMatchSnapshot();
|
||||||
|
});
|
||||||
|
|
||||||
// no backup info
|
it("handles absence of backup", async () => {
|
||||||
|
client.getKeyBackupVersion.mockResolvedValue(null);
|
||||||
|
getComponent();
|
||||||
|
// flush getKeyBackupVersion promise
|
||||||
|
await flushPromises();
|
||||||
expect(screen.getByText("Back up your keys before signing out to avoid losing them.")).toBeInTheDocument();
|
expect(screen.getByText("Back up your keys before signing out to avoid losing them.")).toBeInTheDocument();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -124,18 +129,12 @@ describe("<SecureBackupPanel />", () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it("deletes backup after confirmation", async () => {
|
it("deletes backup after confirmation", async () => {
|
||||||
client.checkKeyBackup
|
client.getKeyBackupVersion
|
||||||
.mockResolvedValueOnce({
|
.mockResolvedValueOnce({
|
||||||
backupInfo: {
|
version: "1",
|
||||||
version: "1",
|
algorithm: "test",
|
||||||
algorithm: "test",
|
auth_data: {
|
||||||
auth_data: {
|
public_key: "1234",
|
||||||
public_key: "1234",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
trustInfo: {
|
|
||||||
usable: false,
|
|
||||||
sigs: [],
|
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
.mockResolvedValue(null);
|
.mockResolvedValue(null);
|
||||||
|
|
|
@ -1,5 +1,70 @@
|
||||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
// 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`] = `
|
exports[`<SecureBackupPanel /> suggests connecting session to key backup when backup exists 1`] = `
|
||||||
<div>
|
<div>
|
||||||
<div
|
<div
|
||||||
|
|
|
@ -41,6 +41,7 @@ describe("<SecurityUserSettingsTab />", () => {
|
||||||
...mockClientMethodsCrypto(),
|
...mockClientMethodsCrypto(),
|
||||||
getRooms: jest.fn().mockReturnValue([]),
|
getRooms: jest.fn().mockReturnValue([]),
|
||||||
getIgnoredUsers: jest.fn(),
|
getIgnoredUsers: jest.fn(),
|
||||||
|
getKeyBackupVersion: jest.fn(),
|
||||||
});
|
});
|
||||||
|
|
||||||
const getComponent = () => (
|
const getComponent = () => (
|
||||||
|
|
|
@ -152,7 +152,6 @@ export const mockClientMethodsCrypto = (): Partial<
|
||||||
isKeyBackupKeyStored: jest.fn(),
|
isKeyBackupKeyStored: jest.fn(),
|
||||||
getCrossSigningCacheCallbacks: jest.fn().mockReturnValue({ getCrossSigningKeyCache: jest.fn() }),
|
getCrossSigningCacheCallbacks: jest.fn().mockReturnValue({ getCrossSigningKeyCache: jest.fn() }),
|
||||||
getStoredCrossSigningForUser: jest.fn(),
|
getStoredCrossSigningForUser: jest.fn(),
|
||||||
checkKeyBackup: jest.fn().mockReturnValue({}),
|
|
||||||
secretStorage: { hasKey: jest.fn() },
|
secretStorage: { hasKey: jest.fn() },
|
||||||
getCrypto: jest.fn().mockReturnValue({
|
getCrypto: jest.fn().mockReturnValue({
|
||||||
getUserDeviceInfo: jest.fn(),
|
getUserDeviceInfo: jest.fn(),
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue