From 1cf9e546fd917978b77538bcacc6a9f9dd81200e Mon Sep 17 00:00:00 2001 From: ElementRobot Date: Wed, 10 Dec 2025 19:14:32 +0100 Subject: [PATCH] Don't show the key storage out of sync toast when backup disabled (#31506) (#31507) (cherry picked from commit 4bd8eeb17ac7af8f1957522c9b14f7f9d5bad038) Co-authored-by: Hubert Chathi --- src/DeviceListener.ts | 5 ++++- test/unit-tests/DeviceListener-test.ts | 26 +++++++++++++++++++++++++- 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/src/DeviceListener.ts b/src/DeviceListener.ts index ff58517cd2..3591db8d82 100644 --- a/src/DeviceListener.ts +++ b/src/DeviceListener.ts @@ -438,7 +438,10 @@ export default class DeviceListener { // said we are OK with that. const keyBackupIsOk = keyBackupUploadActive || backupDisabled; - const backupKeyCached = (await crypto.getSessionBackupPrivateKey()) !== null; + // If key backup is active and not disabled: do we have the backup key + // cached locally? + const backupKeyCached = + !keyBackupUploadActive || backupDisabled || (await crypto.getSessionBackupPrivateKey()) !== null; const allSystemsReady = isCurrentDeviceTrusted && allCrossSigningSecretsCached && keyBackupIsOk && recoveryIsOk && backupKeyCached; diff --git a/test/unit-tests/DeviceListener-test.ts b/test/unit-tests/DeviceListener-test.ts index e167e9964a..ef3b01b68c 100644 --- a/test/unit-tests/DeviceListener-test.ts +++ b/test/unit-tests/DeviceListener-test.ts @@ -367,7 +367,7 @@ describe("DeviceListener", () => { expect(SetupEncryptionToast.hideToast).toHaveBeenCalled(); }); - it("shows an out-of-sync toast when one of the secrets is missing locally", async () => { + it("shows an out-of-sync toast when one of the cross-signing secrets is missing locally", async () => { mockCrypto!.getCrossSigningStatus.mockResolvedValue({ publicKeysOnDevice: true, privateKeysInSecretStorage: true, @@ -385,6 +385,30 @@ describe("DeviceListener", () => { ); }); + it("shows an out-of-sync toast when the backup key is missing locally", async () => { + mockCrypto!.getSecretStorageStatus.mockResolvedValue(readySecretStorageStatus); + mockCrypto!.getActiveSessionBackupVersion.mockResolvedValue("1"); + mockCrypto!.getSessionBackupPrivateKey.mockResolvedValue(null); + + await createAndStart(); + + expect(SetupEncryptionToast.showToast).toHaveBeenCalledWith( + SetupEncryptionToast.Kind.KEY_STORAGE_OUT_OF_SYNC, + ); + }); + + it("does not show an out-of-sync toast when the backup key is missing locally but backup is purposely disabled", async () => { + mockCrypto!.getSecretStorageStatus.mockResolvedValue(readySecretStorageStatus); + mockCrypto!.getSessionBackupPrivateKey.mockResolvedValue(null); + mockClient.getAccountDataFromServer.mockImplementation((eventType) => + eventType === BACKUP_DISABLED_ACCOUNT_DATA_KEY ? ({ disabled: true } as any) : null, + ); + + await createAndStart(); + + expect(SetupEncryptionToast.hideToast).toHaveBeenCalled(); + }); + it("hides the out-of-sync toast after we receive the missing secrets", async () => { mockCrypto!.getSecretStorageStatus.mockResolvedValue(readySecretStorageStatus); mockCrypto!.getActiveSessionBackupVersion.mockResolvedValue("1");