1
0
mirror of https://github.com/matrix-org/matrix-js-sdk.git synced 2025-08-09 10:22:46 +03:00

add unit test and minor fixes

This commit is contained in:
Hubert Chathi
2021-05-31 21:52:20 -04:00
parent 07bfa5532e
commit c543358826
2 changed files with 19 additions and 1 deletions

View File

@@ -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();
});
});
});

View File

@@ -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;
}