You've already forked matrix-js-sdk
mirror of
https://github.com/matrix-org/matrix-js-sdk.git
synced 2025-08-09 10:22:46 +03:00
Add AsJson forms of the key import/export methods (#4057)
This commit is contained in:
@@ -383,7 +383,7 @@ describe("RustCrypto", () => {
|
||||
);
|
||||
});
|
||||
|
||||
describe(".importRoomKeys and .exportRoomKeys", () => {
|
||||
describe("importing and exporting room keys", () => {
|
||||
let rustCrypto: RustCrypto;
|
||||
|
||||
beforeEach(
|
||||
@@ -416,6 +416,29 @@ describe("RustCrypto", () => {
|
||||
|
||||
expect(aSession).toStrictEqual(exportedKey);
|
||||
});
|
||||
|
||||
it("should import and export keys as JSON", async () => {
|
||||
const someRoomKeys = testData.MEGOLM_SESSION_DATA_ARRAY;
|
||||
let importTotal = 0;
|
||||
const opt: ImportRoomKeysOpts = {
|
||||
progressCallback: (stage) => {
|
||||
importTotal = stage.total ?? 0;
|
||||
},
|
||||
};
|
||||
await rustCrypto.importRoomKeysAsJson(JSON.stringify(someRoomKeys), opt);
|
||||
|
||||
expect(importTotal).toBe(someRoomKeys.length);
|
||||
|
||||
const keys: Array<IMegolmSessionData> = JSON.parse(await rustCrypto.exportRoomKeysAsJson());
|
||||
expect(Array.isArray(keys)).toBeTruthy();
|
||||
expect(keys.length).toBe(someRoomKeys.length);
|
||||
|
||||
const aSession = someRoomKeys[0];
|
||||
|
||||
const exportedKey = keys.find((k) => k.session_id == aSession.session_id);
|
||||
|
||||
expect(aSession).toStrictEqual(exportedKey);
|
||||
});
|
||||
});
|
||||
|
||||
describe("call preprocess methods", () => {
|
||||
|
Reference in New Issue
Block a user