From 1250bb883348ee4c76af85fb371cd4a6f779f007 Mon Sep 17 00:00:00 2001 From: Andy Balaam Date: Wed, 6 Dec 2023 15:09:31 +0000 Subject: [PATCH] Call scheduleAllGroupSessionsForBackup during resetKeyBackup (#3935) since its equivalent is done automatically in Rust crypto when we call resetKeyBackup. --- spec/integ/crypto/crypto.spec.ts | 14 ++++++++++++++ src/client.ts | 7 +++++++ src/crypto/index.ts | 1 + 3 files changed, 22 insertions(+) diff --git a/spec/integ/crypto/crypto.spec.ts b/spec/integ/crypto/crypto.spec.ts index 5992cc8ef..4120b5f53 100644 --- a/spec/integ/crypto/crypto.spec.ts +++ b/spec/integ/crypto/crypto.spec.ts @@ -2832,6 +2832,19 @@ describe.each(Object.entries(CRYPTO_BACKENDS))("crypto (%s)", (backend: string, const newBackupUploadPromise = awaitMegolmBackupKeyUpload(); + // Track calls to scheduleAllGroupSessionsForBackup. This is + // only relevant on legacy encryption. + const scheduleAllGroupSessionsForBackup = jest.fn(); + if (backend === "libolm") { + aliceClient.crypto!.backupManager.scheduleAllGroupSessionsForBackup = + scheduleAllGroupSessionsForBackup; + } else { + // With Rust crypto, we don't need to call this function, so + // we call the dummy value here so we pass our later + // expectation. + scheduleAllGroupSessionsForBackup(); + } + await aliceClient.getCrypto()!.resetKeyBackup(); await awaitDeleteCalled; await newBackupStatusUpdate; @@ -2843,6 +2856,7 @@ describe.each(Object.entries(CRYPTO_BACKENDS))("crypto (%s)", (backend: string, expect(nextVersion).toBeDefined(); expect(nextVersion).not.toEqual(currentVersion); expect(nextKey).not.toEqual(currentBackupKey); + expect(scheduleAllGroupSessionsForBackup).toHaveBeenCalled(); // The `deleteKeyBackupVersion` API is deprecated but has been modified to work with both crypto backend // ensure that it works anyhow diff --git a/src/client.ts b/src/client.ts index 99862b55d..a9531fcff 100644 --- a/src/client.ts +++ b/src/client.ts @@ -3646,6 +3646,9 @@ export class MatrixClient extends TypedEventEmitter { if (!this.crypto) { @@ -3658,6 +3661,10 @@ export class MatrixClient extends TypedEventEmitter { diff --git a/src/crypto/index.ts b/src/crypto/index.ts index 99aa0bd84..2f67dc1ba 100644 --- a/src/crypto/index.ts +++ b/src/crypto/index.ts @@ -1211,6 +1211,7 @@ export class Crypto extends TypedEventEmitter