Skip to content

Commit

Permalink
test(crypto api): update resetEncryption tests
Browse files Browse the repository at this point in the history
  • Loading branch information
florianduros committed Jan 23, 2025
1 parent 431bfe5 commit 8770b56
Showing 1 changed file with 7 additions and 23 deletions.
30 changes: 7 additions & 23 deletions spec/unit/rust-crypto/rust-crypto.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1896,22 +1896,6 @@ describe("RustCrypto", () => {
});

it("reset should reset 4S, backup and cross-signing", async () => {
// We don't have a key backup
fetchMock.get("path:/_matrix/client/v3/room_keys/version", {});

const rustCrypto = await makeTestRustCrypto(makeMatrixHttpApi(), undefined, undefined, secretStorage);

const authUploadDeviceSigningKeys = jest.fn();
await rustCrypto.resetEncryption(authUploadDeviceSigningKeys);

// The default key id should be deleted
expect(secretStorage.setDefaultKeyId).toHaveBeenCalledWith(null);
expect(await rustCrypto.getActiveSessionBackupVersion()).toBeNull();
// The new cross signing keys should be uploaded
expect(authUploadDeviceSigningKeys).toHaveBeenCalledWith(expect.any(Function));
});

it("key backup should be re-enabled after reset", async () => {
// When we will delete the key backup
let backupIsDeleted = false;
fetchMock.delete("path:/_matrix/client/v3/room_keys/version/1", () => {
Expand All @@ -1923,6 +1907,13 @@ describe("RustCrypto", () => {
return backupIsDeleted ? {} : testData.SIGNED_BACKUP_DATA;
});

// A new key backup should be created after the reset
let newKeyBackupInfo!: KeyBackupInfo;
fetchMock.post("path:/_matrix/client/v3/room_keys/version", (res, options) => {
newKeyBackupInfo = JSON.parse(options.body as string);
return { version: "2" };
});

// We consider the key backup as trusted
jest.spyOn(RustBackupManager.prototype, "isKeyBackupTrusted").mockResolvedValue({
trusted: true,
Expand All @@ -1933,13 +1924,6 @@ describe("RustCrypto", () => {
// We have a key backup
expect(await rustCrypto.getActiveSessionBackupVersion()).not.toBeNull();

// A new key backup should be created after the reset
let newKeyBackupInfo!: KeyBackupInfo;
fetchMock.post("path:/_matrix/client/v3/room_keys/version", (res, options) => {
newKeyBackupInfo = JSON.parse(options.body as string);
return { version: "2" };
});

const authUploadDeviceSigningKeys = jest.fn();
await rustCrypto.resetEncryption(authUploadDeviceSigningKeys);

Expand Down

0 comments on commit 8770b56

Please sign in to comment.