Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

Commit

Permalink
Call the AsJson forms of import and exportRoomKeys
Browse files Browse the repository at this point in the history
  • Loading branch information
andybalaam committed Feb 9, 2024
1 parent f1fbff9 commit 4a09235
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,10 @@ export default class ExportE2eKeysDialog extends React.Component<IProps, IState>
// 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], {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};

Expand All @@ -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),
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};

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

Check warning on line 93 in test/components/views/dialogs/security/ImportE2eKeysDialog-test.tsx

View workflow job for this annotation

GitHub Actions / Jest (1)

RETRY 1: ImportE2eKeysDialog › should import exported keys on submit

expect(jest.fn()).toHaveBeenCalled() Expected number of calls: >= 1 Received number of calls: 0 Ignored nodes: comments, script, style <html> <head /> <body> <div> <div data-focus-guard="true" style="width: 1px; height: 0px; padding: 0px; overflow: hidden; position: fixed; top: 1px; left: 1px;" tabindex="0" /> <div aria-labelledby="mx_BaseDialog_title" class="mx_importE2eKeysDialog mx_Dialog_fixedWidth" data-focus-lock-disabled="false" role="dialog" > <div class="mx_Dialog_header mx_Dialog_headerWithCancel" > <h2 class="mx_Heading_h3 mx_Dialog_title" id="mx_BaseDialog_title" > Import room keys </h2> <div aria-label="Close dialog" class="mx_AccessibleButton mx_Dialog_cancelButton" role="button" tabindex="0" /> </div> <form> <div class="mx_Dialog_content" > <p> This process allows you to import encryption keys that you had previously exported from another Matrix client. You will then be able to decrypt any messages that the other client could decrypt. </p> <p> The export file will be protected with a passphrase. You should enter the passphrase here, to decrypt the file. </p> <div class="error" > Unknown error </div> <div class="mx_E2eKeysDialog_inputTable" > <div class="mx_E2eKeysDialog_inputRow" > <div class="mx_E2eKeysDialog_inputLabel" > <label for="importFile" > File to import </label> </div> <div class="mx_E2eKeysDialog_inputCell" > <input id="importFile" type="file" /> </div> </div> <div class="mx_E2eKeysDialog_inputRow" > <div class="mx_Field mx_Field_input" > <input id="mx_Field_5" label="Enter passphrase" placeholder="Enter passphrase" size="64" type="password" value="passphrase" /> <label for="mx_Field_5" > Enter passphrase </label> </div> </div> </div> </div> <div class="mx_Dialog_buttons" > <input class="mx_Dialog_primary" type="submit" value="Import" /> <button> Cancel </button> </div> </form> </div> <div data-focus-guard="true" style="width: 1px; height: 0px; padding: 0px; overflow: hidden; position: fixed; top: 1px; left: 1px;" tabindex="0" /> </div> </body> </html> at toHaveBeenCalled (test/components/views/dialogs/security/ImportE2eKeysDialog-test.tsx:93:58) at runWithExpensiveErrorDiagnosticsDisabled (node_modules/@testing-library/react/node_modules/@testing-library/dom/dist/config.js:47:12) at checkCallback (node_modules/@testing-library/react/node_modules/@testing-library/dom/dist/wait-for.js:127:77) at checkRealTimersCallback (node_modules/@testing-library/react/node_modules/@testing-library/dom/dist/wait-for.js:121:16) at Timeout.task [as _onTimeout] (node_modules/jsdom/lib/jsdom/browser/Window.js:520:19)

Check warning on line 93 in test/components/views/dialogs/security/ImportE2eKeysDialog-test.tsx

View workflow job for this annotation

GitHub Actions / Jest (1)

RETRY 2: ImportE2eKeysDialog › should import exported keys on submit

expect(jest.fn()).toHaveBeenCalled() Expected number of calls: >= 1 Received number of calls: 0 Ignored nodes: comments, script, style <html> <head /> <body> <div> <div data-focus-guard="true" style="width: 1px; height: 0px; padding: 0px; overflow: hidden; position: fixed; top: 1px; left: 1px;" tabindex="0" /> <div aria-labelledby="mx_BaseDialog_title" class="mx_importE2eKeysDialog mx_Dialog_fixedWidth" data-focus-lock-disabled="false" role="dialog" > <div class="mx_Dialog_header mx_Dialog_headerWithCancel" > <h2 class="mx_Heading_h3 mx_Dialog_title" id="mx_BaseDialog_title" > Import room keys </h2> <div aria-label="Close dialog" class="mx_AccessibleButton mx_Dialog_cancelButton" role="button" tabindex="0" /> </div> <form> <div class="mx_Dialog_content" > <p> This process allows you to import encryption keys that you had previously exported from another Matrix client. You will then be able to decrypt any messages that the other client could decrypt. </p> <p> The export file will be protected with a passphrase. You should enter the passphrase here, to decrypt the file. </p> <div class="error" > Unknown error </div> <div class="mx_E2eKeysDialog_inputTable" > <div class="mx_E2eKeysDialog_inputRow" > <div class="mx_E2eKeysDialog_inputLabel" > <label for="importFile" > File to import </label> </div> <div class="mx_E2eKeysDialog_inputCell" > <input id="importFile" type="file" /> </div> </div> <div class="mx_E2eKeysDialog_inputRow" > <div class="mx_Field mx_Field_input" > <input id="mx_Field_6" label="Enter passphrase" placeholder="Enter passphrase" size="64" type="password" value="passphrase" /> <label for="mx_Field_6" > Enter passphrase </label> </div> </div> </div> </div> <div class="mx_Dialog_buttons" > <input class="mx_Dialog_primary" type="submit" value="Import" /> <button> Cancel </button> </div> </form> </div> <div data-focus-guard="true" style="width: 1px; height: 0px; padding: 0px; overflow: hidden; position: fixed; top: 1px; left: 1px;" tabindex="0" /> </div> </body> </html> at toHaveBeenCalled (test/components/views/dialogs/security/ImportE2eKeysDialog-test.tsx:93:58) at runWithExpensiveErrorDiagnosticsDisabled (node_modules/@testing-library/react/node_modules/@testing-library/dom/dist/config.js:47:12) at checkCallback (node_modules/@testing-library/react/node_modules/@testing-library/dom/dist/wait-for.js:127:77) at checkRealTimersCallback (node_modules/@testing-library/react/node_modules/@testing-library/dom/dist/wait-for.js:121:16) at Timeout.task [as _onTimeout] (node_modules/jsdom/lib/jsdom/browser/Window.js:520:19)

Check failure on line 93 in test/components/views/dialogs/security/ImportE2eKeysDialog-test.tsx

View workflow job for this annotation

GitHub Actions / Jest (1)

ImportE2eKeysDialog › should import exported keys on submit

expect(jest.fn()).toHaveBeenCalled() Expected number of calls: >= 1 Received number of calls: 0 Ignored nodes: comments, script, style <html> <head /> <body> <div> <div data-focus-guard="true" style="width: 1px; height: 0px; padding: 0px; overflow: hidden; position: fixed; top: 1px; left: 1px;" tabindex="0" /> <div aria-labelledby="mx_BaseDialog_title" class="mx_importE2eKeysDialog mx_Dialog_fixedWidth" data-focus-lock-disabled="false" role="dialog" > <div class="mx_Dialog_header mx_Dialog_headerWithCancel" > <h2 class="mx_Heading_h3 mx_Dialog_title" id="mx_BaseDialog_title" > Import room keys </h2> <div aria-label="Close dialog" class="mx_AccessibleButton mx_Dialog_cancelButton" role="button" tabindex="0" /> </div> <form> <div class="mx_Dialog_content" > <p> This process allows you to import encryption keys that you had previously exported from another Matrix client. You will then be able to decrypt any messages that the other client could decrypt. </p> <p> The export file will be protected with a passphrase. You should enter the passphrase here, to decrypt the file. </p> <div class="error" > Unknown error </div> <div class="mx_E2eKeysDialog_inputTable" > <div class="mx_E2eKeysDialog_inputRow" > <div class="mx_E2eKeysDialog_inputLabel" > <label for="importFile" > File to import </label> </div> <div class="mx_E2eKeysDialog_inputCell" > <input id="importFile" type="file" /> </div> </div> <div class="mx_E2eKeysDialog_inputRow" > <div class="mx_Field mx_Field_input" > <input id="mx_Field_7" label="Enter passphrase" placeholder="Enter passphrase" size="64" type="password" value="passphrase" /> <label for="mx_Field_7" > Enter passphrase </label> </div> </div> </div> </div> <div class="mx_Dialog_buttons" > <input class="mx_Dialog_primary" type="submit" value="Import" /> <button> Cancel </button> </div> </form> </div> <div data-focus-guard="true" style="width: 1px; height: 0px; padding: 0px; overflow: hidden; position: fixed; top: 1px; left: 1px;" tabindex="0" /> </div> </body> </html> at toHaveBeenCalled (test/components/views/dialogs/security/ImportE2eKeysDialog-test.tsx:93:58) at runWithExpensiveErrorDiagnosticsDisabled (node_modules/@testing-library/react/node_modules/@testing-library/dom/dist/config.js:47:12) at checkCallback (node_modules/@testing-library/react/node_modules/@testing-library/dom/dist/wait-for.js:127:77) at checkRealTimersCallback (node_modules/@testing-library/react/node_modules/@testing-library/dom/dist/wait-for.js:121:16) at Timeout.task [as _onTimeout] (node_modules/jsdom/lib/jsdom/browser/Window.js:520:19)
});
});

0 comments on commit 4a09235

Please sign in to comment.