From 35ad92bf540a909b4f398862f1fd7997a8374469 Mon Sep 17 00:00:00 2001 From: Andy Balaam Date: Wed, 14 Feb 2024 10:33:39 +0000 Subject: [PATCH] Call the AsJson forms of import and exportRoomKeys (#12233) --- .../views/dialogs/security/ExportE2eKeysDialog.tsx | 4 ++-- .../views/dialogs/security/ImportE2eKeysDialog.tsx | 2 +- .../views/dialogs/security/ExportE2eKeysDialog-test.tsx | 6 +++--- .../views/dialogs/security/ImportE2eKeysDialog-test.tsx | 6 +++--- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/async-components/views/dialogs/security/ExportE2eKeysDialog.tsx b/src/async-components/views/dialogs/security/ExportE2eKeysDialog.tsx index 5b50a0ed54..0223d1beef 100644 --- a/src/async-components/views/dialogs/security/ExportE2eKeysDialog.tsx +++ b/src/async-components/views/dialogs/security/ExportE2eKeysDialog.tsx @@ -109,10 +109,10 @@ export default class ExportE2eKeysDialog extends React.Component // asynchronous ones. Promise.resolve() .then(() => { - return this.props.matrixClient.getCrypto()!.exportRoomKeys(); + return this.props.matrixClient.getCrypto()!.exportRoomKeysAsJson(); }) .then((k) => { - return MegolmExportEncryption.encryptMegolmKeyFile(JSON.stringify(k), passphrase); + return MegolmExportEncryption.encryptMegolmKeyFile(k, passphrase); }) .then((f) => { const blob = new Blob([f], { diff --git a/src/async-components/views/dialogs/security/ImportE2eKeysDialog.tsx b/src/async-components/views/dialogs/security/ImportE2eKeysDialog.tsx index f10974ee04..498de104af 100644 --- a/src/async-components/views/dialogs/security/ImportE2eKeysDialog.tsx +++ b/src/async-components/views/dialogs/security/ImportE2eKeysDialog.tsx @@ -108,7 +108,7 @@ export default class ImportE2eKeysDialog extends React.Component return MegolmExportEncryption.decryptMegolmKeyFile(arrayBuffer, passphrase); }) .then((keys) => { - return this.props.matrixClient.getCrypto()!.importRoomKeys(JSON.parse(keys)); + return this.props.matrixClient.getCrypto()!.importRoomKeysAsJson(keys); }) .then(() => { // TODO: it would probably be nice to give some feedback about what we've imported here. diff --git a/test/components/views/dialogs/security/ExportE2eKeysDialog-test.tsx b/test/components/views/dialogs/security/ExportE2eKeysDialog-test.tsx index 5f29bc1192..0436fb2bf2 100644 --- a/test/components/views/dialogs/security/ExportE2eKeysDialog-test.tsx +++ b/test/components/views/dialogs/security/ExportE2eKeysDialog-test.tsx @@ -66,10 +66,10 @@ describe("ExportE2eKeysDialog", () => { const cli = createTestClient(); const keys: IMegolmSessionData[] = []; const passphrase = "ThisIsAMoreSecurePW123$$"; - const exportRoomKeys = jest.fn().mockResolvedValue(keys); + const exportRoomKeysAsJson = jest.fn().mockResolvedValue(JSON.stringify(keys)); cli.getCrypto = () => { return { - exportRoomKeys, + exportRoomKeysAsJson, } as unknown as CryptoApi; }; @@ -85,7 +85,7 @@ describe("ExportE2eKeysDialog", () => { fireEvent.click(container.querySelector("[type=submit]")!); // Then it exports keys and encrypts them - await waitFor(() => expect(exportRoomKeys).toHaveBeenCalled()); + await waitFor(() => expect(exportRoomKeysAsJson).toHaveBeenCalled()); await waitFor(() => expect(MegolmExportEncryption.encryptMegolmKeyFile).toHaveBeenCalledWith(JSON.stringify(keys), passphrase), ); diff --git a/test/components/views/dialogs/security/ImportE2eKeysDialog-test.tsx b/test/components/views/dialogs/security/ImportE2eKeysDialog-test.tsx index 99e61abf61..af7b85b0c2 100644 --- a/test/components/views/dialogs/security/ImportE2eKeysDialog-test.tsx +++ b/test/components/views/dialogs/security/ImportE2eKeysDialog-test.tsx @@ -71,10 +71,10 @@ describe("ImportE2eKeysDialog", () => { const cli = createTestClient(); const onFinished = jest.fn(); const file = new File(["test"], "file.txt", { type: "text/plain" }); - const importRoomKeys = jest.fn(); + const importRoomKeysAsJson = jest.fn(); cli.getCrypto = () => { return { - importRoomKeys, + importRoomKeysAsJson, } as unknown as CryptoApi; }; @@ -90,6 +90,6 @@ describe("ImportE2eKeysDialog", () => { await userEvent.paste("passphrase"); fireEvent.click(container.querySelector("[type=submit]")!); - await waitFor(() => expect(importRoomKeys).toHaveBeenCalled()); + await waitFor(() => expect(importRoomKeysAsJson).toHaveBeenCalled()); }); });