mirror of
https://github.com/element-hq/element-web
synced 2024-11-22 09:15:41 +03:00
Call the AsJson forms of import and exportRoomKeys (#12233)
This commit is contained in:
parent
44e18b188c
commit
35ad92bf54
4 changed files with 9 additions and 9 deletions
|
@ -109,10 +109,10 @@ export default class ExportE2eKeysDialog extends React.Component<IProps, IState>
|
||||||
// asynchronous ones.
|
// asynchronous ones.
|
||||||
Promise.resolve()
|
Promise.resolve()
|
||||||
.then(() => {
|
.then(() => {
|
||||||
return this.props.matrixClient.getCrypto()!.exportRoomKeys();
|
return this.props.matrixClient.getCrypto()!.exportRoomKeysAsJson();
|
||||||
})
|
})
|
||||||
.then((k) => {
|
.then((k) => {
|
||||||
return MegolmExportEncryption.encryptMegolmKeyFile(JSON.stringify(k), passphrase);
|
return MegolmExportEncryption.encryptMegolmKeyFile(k, passphrase);
|
||||||
})
|
})
|
||||||
.then((f) => {
|
.then((f) => {
|
||||||
const blob = new Blob([f], {
|
const blob = new Blob([f], {
|
||||||
|
|
|
@ -108,7 +108,7 @@ export default class ImportE2eKeysDialog extends React.Component<IProps, IState>
|
||||||
return MegolmExportEncryption.decryptMegolmKeyFile(arrayBuffer, passphrase);
|
return MegolmExportEncryption.decryptMegolmKeyFile(arrayBuffer, passphrase);
|
||||||
})
|
})
|
||||||
.then((keys) => {
|
.then((keys) => {
|
||||||
return this.props.matrixClient.getCrypto()!.importRoomKeys(JSON.parse(keys));
|
return this.props.matrixClient.getCrypto()!.importRoomKeysAsJson(keys);
|
||||||
})
|
})
|
||||||
.then(() => {
|
.then(() => {
|
||||||
// TODO: it would probably be nice to give some feedback about what we've imported here.
|
// TODO: it would probably be nice to give some feedback about what we've imported here.
|
||||||
|
|
|
@ -66,10 +66,10 @@ describe("ExportE2eKeysDialog", () => {
|
||||||
const cli = createTestClient();
|
const cli = createTestClient();
|
||||||
const keys: IMegolmSessionData[] = [];
|
const keys: IMegolmSessionData[] = [];
|
||||||
const passphrase = "ThisIsAMoreSecurePW123$$";
|
const passphrase = "ThisIsAMoreSecurePW123$$";
|
||||||
const exportRoomKeys = jest.fn().mockResolvedValue(keys);
|
const exportRoomKeysAsJson = jest.fn().mockResolvedValue(JSON.stringify(keys));
|
||||||
cli.getCrypto = () => {
|
cli.getCrypto = () => {
|
||||||
return {
|
return {
|
||||||
exportRoomKeys,
|
exportRoomKeysAsJson,
|
||||||
} as unknown as CryptoApi;
|
} as unknown as CryptoApi;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -85,7 +85,7 @@ describe("ExportE2eKeysDialog", () => {
|
||||||
fireEvent.click(container.querySelector("[type=submit]")!);
|
fireEvent.click(container.querySelector("[type=submit]")!);
|
||||||
|
|
||||||
// Then it exports keys and encrypts them
|
// Then it exports keys and encrypts them
|
||||||
await waitFor(() => expect(exportRoomKeys).toHaveBeenCalled());
|
await waitFor(() => expect(exportRoomKeysAsJson).toHaveBeenCalled());
|
||||||
await waitFor(() =>
|
await waitFor(() =>
|
||||||
expect(MegolmExportEncryption.encryptMegolmKeyFile).toHaveBeenCalledWith(JSON.stringify(keys), passphrase),
|
expect(MegolmExportEncryption.encryptMegolmKeyFile).toHaveBeenCalledWith(JSON.stringify(keys), passphrase),
|
||||||
);
|
);
|
||||||
|
|
|
@ -71,10 +71,10 @@ describe("ImportE2eKeysDialog", () => {
|
||||||
const cli = createTestClient();
|
const cli = createTestClient();
|
||||||
const onFinished = jest.fn();
|
const onFinished = jest.fn();
|
||||||
const file = new File(["test"], "file.txt", { type: "text/plain" });
|
const file = new File(["test"], "file.txt", { type: "text/plain" });
|
||||||
const importRoomKeys = jest.fn();
|
const importRoomKeysAsJson = jest.fn();
|
||||||
cli.getCrypto = () => {
|
cli.getCrypto = () => {
|
||||||
return {
|
return {
|
||||||
importRoomKeys,
|
importRoomKeysAsJson,
|
||||||
} as unknown as CryptoApi;
|
} as unknown as CryptoApi;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -90,6 +90,6 @@ describe("ImportE2eKeysDialog", () => {
|
||||||
await userEvent.paste("passphrase");
|
await userEvent.paste("passphrase");
|
||||||
fireEvent.click(container.querySelector("[type=submit]")!);
|
fireEvent.click(container.querySelector("[type=submit]")!);
|
||||||
|
|
||||||
await waitFor(() => expect(importRoomKeys).toHaveBeenCalled());
|
await waitFor(() => expect(importRoomKeysAsJson).toHaveBeenCalled());
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue