@@ -16,7 +16,7 @@ limitations under the License.
1616
1717import { MatrixEvent , MatrixEventEvent } from "../../../src/models/event" ;
1818import { emitPromise } from "../../test-utils/test-utils" ;
19- import { Crypto } from "../../../src/crypto" ;
19+ import { Crypto , IEventDecryptionResult } from "../../../src/crypto" ;
2020
2121describe ( "MatrixEvent" , ( ) => {
2222 it ( "should create copies of itself" , ( ) => {
@@ -182,4 +182,38 @@ describe("MatrixEvent", () => {
182182 expect ( encryptedEvent . getType ( ) ) . toEqual ( "m.room.message" ) ;
183183 } ) ;
184184 } ) ;
185+
186+ describe ( "replyEventId" , ( ) => {
187+ it ( "should ignore 'm.relates_to' from encrypted content even if cleartext lacks one" , async ( ) => {
188+ const eventId = "test_encrypted_event" ;
189+ const encryptedEvent = new MatrixEvent ( {
190+ event_id : eventId ,
191+ type : "m.room.encrypted" ,
192+ content : {
193+ ciphertext : "secrets" ,
194+ } ,
195+ } ) ;
196+
197+ const crypto = {
198+ decryptEvent : jest . fn ( ) . mockImplementationOnce ( ( ) => {
199+ return Promise . resolve < IEventDecryptionResult > ( {
200+ clearEvent : {
201+ type : "m.room.message" ,
202+ content : {
203+ "m.relates_to" : {
204+ "m.in_reply_to" : {
205+ event_id : "!anotherEvent" ,
206+ } ,
207+ } ,
208+ } ,
209+ } ,
210+ } ) ;
211+ } ) ,
212+ } as unknown as Crypto ;
213+
214+ await encryptedEvent . attemptDecryption ( crypto ) ;
215+ expect ( encryptedEvent . getType ( ) ) . toEqual ( "m.room.message" ) ;
216+ expect ( encryptedEvent . replyEventId ) . toBeUndefined ( ) ;
217+ } ) ;
218+ } ) ;
185219} ) ;
0 commit comments