diff --git a/spec/unit/crypto/backup.spec.js b/spec/unit/crypto/backup.spec.js index 6d6b59ea6..53102daed 100644 --- a/spec/unit/crypto/backup.spec.js +++ b/spec/unit/crypto/backup.spec.js @@ -576,5 +576,21 @@ describe("MegolmBackup", function() { const cachedKey = await client._crypto.getSessionBackupPrivateKey(); expect(cachedKey).not.toBeNull(); }); + + it("fails if an known algorithm is used", async function() { + const BAD_BACKUP_INFO = Object.assign({}, BACKUP_INFO, { + algorithm: "this.algorithm.does.not.exist", + }); + client._http.authedRequest = function() { + return Promise.resolve(KEY_BACKUP_DATA); + }; + + await expect(client.restoreKeyBackupWithRecoveryKey( + "EsTc LW2K PGiF wKEA 3As5 g5c4 BXwk qeeJ ZJV8 Q9fu gUMN UE4d", + ROOM_ID, + SESSION_ID, + BAD_BACKUP_INFO, + )).rejects.toThrow(); + }); }); }); diff --git a/src/crypto/backup.ts b/src/crypto/backup.ts index fbd06db25..f470e3c9e 100644 --- a/src/crypto/backup.ts +++ b/src/crypto/backup.ts @@ -238,6 +238,8 @@ export class BackupManager { } /** + * Check if the given backup info is trusted. + * * @param {object} backupInfo key backup info dict from /room_keys/version * @return {object} { * usable: [bool], // is the backup trusted, true iff there is a sig that is valid & from a trusted device @@ -351,7 +353,7 @@ export class BackupManager { ) ); }); - ret.usable ||= ret.trusted_locally; + ret.usable = ret.usable || ret.trusted_locally; return ret; }