You've already forked matrix-js-sdk
mirror of
https://github.com/matrix-org/matrix-js-sdk.git
synced 2025-11-26 17:03:12 +03:00
Fix the tests and add a test
This commit is contained in:
@@ -1025,4 +1025,68 @@ describe("megolm", function() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("Alice can decrypt a message with falsey content", function() {
|
||||||
|
return aliceTestClient.start().then(() => {
|
||||||
|
return createOlmSession(testOlmAccount, aliceTestClient);
|
||||||
|
}).then((p2pSession) => {
|
||||||
|
const groupSession = new Olm.OutboundGroupSession();
|
||||||
|
groupSession.create();
|
||||||
|
|
||||||
|
// make the room_key event
|
||||||
|
const roomKeyEncrypted = encryptGroupSessionKey({
|
||||||
|
senderKey: testSenderKey,
|
||||||
|
recipient: aliceTestClient,
|
||||||
|
p2pSession: p2pSession,
|
||||||
|
groupSession: groupSession,
|
||||||
|
room_id: ROOM_ID,
|
||||||
|
});
|
||||||
|
|
||||||
|
const plaintext = {
|
||||||
|
type: "m.room.message",
|
||||||
|
content: undefined,
|
||||||
|
room_id: ROOM_ID,
|
||||||
|
}
|
||||||
|
|
||||||
|
const messageEncrypted = {
|
||||||
|
event_id: 'test_megolm_event',
|
||||||
|
content: {
|
||||||
|
algorithm: "m.megolm.v1.aes-sha2",
|
||||||
|
ciphertext: groupSession.encrypt(JSON.stringify(plaintext)),
|
||||||
|
device_id: "testDevice",
|
||||||
|
sender_key: testSenderKey,
|
||||||
|
session_id: groupSession.session_id(),
|
||||||
|
},
|
||||||
|
type: "m.room.encrypted",
|
||||||
|
};
|
||||||
|
|
||||||
|
// Alice gets both the events in a single sync
|
||||||
|
const syncResponse = {
|
||||||
|
next_batch: 1,
|
||||||
|
to_device: {
|
||||||
|
events: [roomKeyEncrypted],
|
||||||
|
},
|
||||||
|
rooms: {
|
||||||
|
join: {},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
syncResponse.rooms.join[ROOM_ID] = {
|
||||||
|
timeline: {
|
||||||
|
events: [messageEncrypted],
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
aliceTestClient.httpBackend.when("GET", "/sync").respond(200, syncResponse);
|
||||||
|
return aliceTestClient.flushSync();
|
||||||
|
}).then(function() {
|
||||||
|
const room = aliceTestClient.client.getRoom(ROOM_ID);
|
||||||
|
const event = room.getLiveTimeline().getEvents()[0];
|
||||||
|
expect(event.isEncrypted()).toBe(true);
|
||||||
|
return testUtils.awaitDecryption(event);
|
||||||
|
}).then((event) => {
|
||||||
|
expect(event.getRoomId()).toEqual(ROOM_ID);
|
||||||
|
expect(event.getContent()).toEqual({});
|
||||||
|
expect(event.getClearContent()).toBeUndefined();
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -534,7 +534,7 @@ export class MatrixEvent extends EventEmitter {
|
|||||||
throw new Error("Attempt to decrypt event which isn't encrypted");
|
throw new Error("Attempt to decrypt event which isn't encrypted");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.isDecryptionFailure()) {
|
if (this.clearEvent?.content && this.clearEvent.content.msgtype !== "m.bad.encrypted") {
|
||||||
// we may want to just ignore this? let's start with rejecting it.
|
// we may want to just ignore this? let's start with rejecting it.
|
||||||
throw new Error(
|
throw new Error(
|
||||||
"Attempt to decrypt event which has already been decrypted",
|
"Attempt to decrypt event which has already been decrypted",
|
||||||
|
|||||||
Reference in New Issue
Block a user