@@ -114,7 +114,7 @@ function encryptMegolmEvent(opts: {
114114 }
115115
116116 return {
117- event_id : 'test_megolm_event' ,
117+ event_id : 'test_megolm_event_' + Math . random ( ) ,
118118 content : {
119119 algorithm : "m.megolm.v1.aes-sha2" ,
120120 ciphertext : opts . groupSession . encrypt ( JSON . stringify ( plaintext ) ) ,
@@ -980,4 +980,69 @@ describe("megolm", () => {
980980 expect ( decryptedEvent . getContent ( ) ) . toEqual ( { } ) ;
981981 expect ( decryptedEvent . getClearContent ( ) ) . toBeUndefined ( ) ;
982982 } ) ;
983+
984+ it (
985+ "should successfully decrypt bundled redaction events that don't include a room_id in their /sync data" ,
986+ async ( ) => {
987+ await aliceTestClient . start ( ) ;
988+ const p2pSession = await createOlmSession ( testOlmAccount , aliceTestClient ) ;
989+ const groupSession = new Olm . OutboundGroupSession ( ) ;
990+ groupSession . create ( ) ;
991+
992+ // make the room_key event
993+ const roomKeyEncrypted = encryptGroupSessionKey ( {
994+ senderKey : testSenderKey ,
995+ recipient : aliceTestClient ,
996+ p2pSession : p2pSession ,
997+ groupSession : groupSession ,
998+ room_id : ROOM_ID ,
999+ } ) ;
1000+
1001+ // encrypt a message with the group session
1002+ const messageEncrypted = encryptMegolmEvent ( {
1003+ senderKey : testSenderKey ,
1004+ groupSession : groupSession ,
1005+ room_id : ROOM_ID ,
1006+ } ) ;
1007+
1008+ const redactionEncrypted = encryptMegolmEvent ( {
1009+ senderKey : testSenderKey ,
1010+ groupSession : groupSession ,
1011+ plaintext : {
1012+ room_id : ROOM_ID ,
1013+ type : "m.room.redaction" ,
1014+ redacts : messageEncrypted . event_id ,
1015+ content : { reason : "redaction test" } ,
1016+ } ,
1017+ } ) ;
1018+
1019+ const messageEncryptedWithRedaction = {
1020+ ...messageEncrypted ,
1021+ unsigned : { redacted_because : redactionEncrypted } ,
1022+ } ;
1023+
1024+ const syncResponse = {
1025+ next_batch : 1 ,
1026+ to_device : {
1027+ events : [ roomKeyEncrypted ] ,
1028+ } ,
1029+ rooms : {
1030+ join : {
1031+ [ ROOM_ID ] : { timeline : { events : [ messageEncryptedWithRedaction ] } } ,
1032+ } ,
1033+ } ,
1034+ } ;
1035+
1036+ aliceTestClient . httpBackend . when ( "GET" , "/sync" ) . respond ( 200 , syncResponse ) ;
1037+ await aliceTestClient . flushSync ( ) ;
1038+
1039+ const room = aliceTestClient . client . getRoom ( ROOM_ID ) ;
1040+ const event = room . getLiveTimeline ( ) . getEvents ( ) [ 0 ] ;
1041+ expect ( event . isEncrypted ( ) ) . toBe ( true ) ;
1042+ await event . attemptDecryption ( aliceTestClient . client . crypto ) ;
1043+ expect ( event . getContent ( ) ) . toEqual ( { } ) ;
1044+ const redactionEvent : any = event . getRedactionEvent ( ) ;
1045+ expect ( redactionEvent . content . reason ) . toEqual ( "redaction test" ) ;
1046+ } ,
1047+ ) ;
9831048} ) ;
0 commit comments