From 6ee794347c3aabafe2437e275a38a5e279dc54de Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Mon, 27 Feb 2023 16:54:32 +0000 Subject: [PATCH 1/2] Fix spec compliance issue around encrypted `m.relates_to` --- src/models/event.ts | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/src/models/event.ts b/src/models/event.ts index d4baa5b224b..d6623ae3f97 100644 --- a/src/models/event.ts +++ b/src/models/event.ts @@ -576,13 +576,7 @@ export class MatrixEvent extends TypedEventEmitter Date: Mon, 27 Feb 2023 17:19:50 +0000 Subject: [PATCH 2/2] Add test --- spec/unit/models/event.spec.ts | 36 +++++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/spec/unit/models/event.spec.ts b/spec/unit/models/event.spec.ts index dd21893a52c..85058a56b83 100644 --- a/spec/unit/models/event.spec.ts +++ b/spec/unit/models/event.spec.ts @@ -16,7 +16,7 @@ limitations under the License. import { MatrixEvent, MatrixEventEvent } from "../../../src/models/event"; import { emitPromise } from "../../test-utils/test-utils"; -import { Crypto } from "../../../src/crypto"; +import { Crypto, IEventDecryptionResult } from "../../../src/crypto"; describe("MatrixEvent", () => { it("should create copies of itself", () => { @@ -182,4 +182,38 @@ describe("MatrixEvent", () => { expect(encryptedEvent.getType()).toEqual("m.room.message"); }); }); + + describe("replyEventId", () => { + it("should ignore 'm.relates_to' from encrypted content even if cleartext lacks one", async () => { + const eventId = "test_encrypted_event"; + const encryptedEvent = new MatrixEvent({ + event_id: eventId, + type: "m.room.encrypted", + content: { + ciphertext: "secrets", + }, + }); + + const crypto = { + decryptEvent: jest.fn().mockImplementationOnce(() => { + return Promise.resolve({ + clearEvent: { + type: "m.room.message", + content: { + "m.relates_to": { + "m.in_reply_to": { + event_id: "!anotherEvent", + }, + }, + }, + }, + }); + }), + } as unknown as Crypto; + + await encryptedEvent.attemptDecryption(crypto); + expect(encryptedEvent.getType()).toEqual("m.room.message"); + expect(encryptedEvent.replyEventId).toBeUndefined(); + }); + }); });