Use the non-deprecated exportRoomKeys method on CryptoApi (#12231)
* Expand the export test to check encryptMegolmKeyFile was called * Use the non-deprecated exportRoomKeys method on CryptoApi
This commit is contained in:
parent
cdfcd37b94
commit
a664172a22
2 changed files with 27 additions and 6 deletions
|
@ -109,7 +109,7 @@ export default class ExportE2eKeysDialog extends React.Component<IProps, IState>
|
||||||
// asynchronous ones.
|
// asynchronous ones.
|
||||||
Promise.resolve()
|
Promise.resolve()
|
||||||
.then(() => {
|
.then(() => {
|
||||||
return this.props.matrixClient.exportRoomKeys();
|
return this.props.matrixClient.getCrypto()!.exportRoomKeys();
|
||||||
})
|
})
|
||||||
.then((k) => {
|
.then((k) => {
|
||||||
return MegolmExportEncryption.encryptMegolmKeyFile(JSON.stringify(k), passphrase);
|
return MegolmExportEncryption.encryptMegolmKeyFile(JSON.stringify(k), passphrase);
|
||||||
|
|
|
@ -17,7 +17,9 @@ limitations under the License.
|
||||||
import React from "react";
|
import React from "react";
|
||||||
import { screen, fireEvent, render, waitFor } from "@testing-library/react";
|
import { screen, fireEvent, render, waitFor } from "@testing-library/react";
|
||||||
import userEvent from "@testing-library/user-event";
|
import userEvent from "@testing-library/user-event";
|
||||||
|
import { CryptoApi, IMegolmSessionData } from "matrix-js-sdk/src/matrix";
|
||||||
|
|
||||||
|
import * as MegolmExportEncryption from "../../../../../src/utils/MegolmExportEncryption";
|
||||||
import ExportE2eKeysDialog from "../../../../../src/async-components/views/dialogs/security/ExportE2eKeysDialog";
|
import ExportE2eKeysDialog from "../../../../../src/async-components/views/dialogs/security/ExportE2eKeysDialog";
|
||||||
import { createTestClient } from "../../../../test-utils";
|
import { createTestClient } from "../../../../test-utils";
|
||||||
|
|
||||||
|
@ -60,13 +62,32 @@ describe("ExportE2eKeysDialog", () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should export if everything is fine", async () => {
|
it("should export if everything is fine", async () => {
|
||||||
|
// Given a client able to export keys
|
||||||
const cli = createTestClient();
|
const cli = createTestClient();
|
||||||
const onFinished = jest.fn();
|
const keys: IMegolmSessionData[] = [];
|
||||||
|
const passphrase = "ThisIsAMoreSecurePW123$$";
|
||||||
|
const exportRoomKeys = jest.fn().mockResolvedValue(keys);
|
||||||
|
cli.getCrypto = () => {
|
||||||
|
return {
|
||||||
|
exportRoomKeys,
|
||||||
|
} as unknown as CryptoApi;
|
||||||
|
};
|
||||||
|
|
||||||
const { container } = render(<ExportE2eKeysDialog matrixClient={cli} onFinished={onFinished} />);
|
// Mock the result of encrypting the sessions. If we don't do this, the
|
||||||
await userEvent.type(screen.getByLabelText("Enter passphrase"), "ThisIsAMoreSecurePW123$$");
|
// encryption process fails, possibly because we didn't initialise
|
||||||
await userEvent.type(screen.getByLabelText("Confirm passphrase"), "ThisIsAMoreSecurePW123$$");
|
// something.
|
||||||
|
jest.spyOn(MegolmExportEncryption, "encryptMegolmKeyFile").mockResolvedValue(new ArrayBuffer(3));
|
||||||
|
|
||||||
|
// When we tell the dialog to export
|
||||||
|
const { container } = render(<ExportE2eKeysDialog matrixClient={cli} onFinished={jest.fn()} />);
|
||||||
|
await userEvent.type(screen.getByLabelText("Enter passphrase"), passphrase);
|
||||||
|
await userEvent.type(screen.getByLabelText("Confirm passphrase"), passphrase);
|
||||||
fireEvent.click(container.querySelector("[type=submit]")!);
|
fireEvent.click(container.querySelector("[type=submit]")!);
|
||||||
await waitFor(() => expect(cli.exportRoomKeys).toHaveBeenCalled());
|
|
||||||
|
// Then it exports keys and encrypts them
|
||||||
|
await waitFor(() => expect(exportRoomKeys).toHaveBeenCalled());
|
||||||
|
await waitFor(() =>
|
||||||
|
expect(MegolmExportEncryption.encryptMegolmKeyFile).toHaveBeenCalledWith(JSON.stringify(keys), passphrase),
|
||||||
|
);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue