Skip to content

Commit

Permalink
backup spec | Test when roomId is specified
Browse files Browse the repository at this point in the history
  • Loading branch information
BillCarsonFr committed May 31, 2024
1 parent 7dcce0f commit 9b6b4c7
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions spec/integ/crypto/megolm-backup.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -590,6 +590,46 @@ describe.each(Object.entries(CRYPTO_BACKENDS))("megolm-keys backup (%s)", (backe
expect(result.imported).toStrictEqual(20);
});

it("Should report failures when decryption works but import fails - per room variant", async function () {
// @ts-ignore - mock a private method for testing purpose
aliceCrypto.importBackedUpRoomKeys = jest
.fn()
.mockImplementationOnce((keys: IMegolmSessionData[], version: String, opts?: ImportRoomKeysOpts) => {
// report 10 failures to import
opts!.progressCallback!({
stage: "load_keys",
successes: 20,
failures: 10,
total: 30,
});
return Promise.resolve();
})
// Ok for other chunks
.mockResolvedValue(importMockImpl);

const { response, expectedTotal } = createBackupDownloadResponse([30]);
const roomId = Object.keys(response.rooms)[0];

fetchMock.get(`express:/_matrix/client/v3/room_keys/keys/${roomId}`, response.rooms[roomId]);

const check = await aliceCrypto.checkKeyBackupAndEnable();

const progressCallback = jest.fn();
const result = await aliceClient.restoreKeyBackupWithRecoveryKey(
testData.BACKUP_DECRYPTION_KEY_BASE58,
roomId,
undefined,
check!.backupInfo!,
{
progressCallback,
},
);

expect(result.total).toStrictEqual(expectedTotal);
// A chunk failed to import
expect(result.imported).toStrictEqual(20);
});

it("recover specific session from backup", async function () {
fetchMock.get(
"express:/_matrix/client/v3/room_keys/keys/:room_id/:session_id",
Expand Down

0 comments on commit 9b6b4c7

Please sign in to comment.