@@ -16,7 +16,6 @@ limitations under the License.
1616
1717import { MatrixEvent , MatrixEventEvent } from "../../../src/models/event" ;
1818import { emitPromise } from "../../test-utils/test-utils" ;
19- import { EventType } from "../../../src" ;
2019import { Crypto } from "../../../src/crypto" ;
2120
2221describe ( "MatrixEvent" , ( ) => {
@@ -88,22 +87,6 @@ describe("MatrixEvent", () => {
8887 expect ( ev . getWireContent ( ) . ciphertext ) . toBeUndefined ( ) ;
8988 } ) ;
9089
91- it ( "should abort decryption if fails with an error other than a DecryptionError" , async ( ) => {
92- const ev = new MatrixEvent ( {
93- type : EventType . RoomMessageEncrypted ,
94- content : {
95- body : "Test" ,
96- } ,
97- event_id : "$event1:server" ,
98- } ) ;
99- await ev . attemptDecryption ( {
100- decryptEvent : jest . fn ( ) . mockRejectedValue ( new Error ( "Not a DecryptionError" ) ) ,
101- } as unknown as Crypto ) ;
102- expect ( ev . isEncrypted ( ) ) . toBeTruthy ( ) ;
103- expect ( ev . isBeingDecrypted ( ) ) . toBeFalsy ( ) ;
104- expect ( ev . isDecryptionFailure ( ) ) . toBeFalsy ( ) ;
105- } ) ;
106-
10790 describe ( "applyVisibilityEvent" , ( ) => {
10891 it ( "should emit VisibilityChange if a change was made" , async ( ) => {
10992 const ev = new MatrixEvent ( {
@@ -134,6 +117,21 @@ describe("MatrixEvent", () => {
134117 } ) ;
135118 } ) ;
136119
120+ it ( "should report decryption errors" , async ( ) => {
121+ const crypto = {
122+ decryptEvent : jest . fn ( ) . mockRejectedValue ( new Error ( "test error" ) ) ,
123+ } as unknown as Crypto ;
124+
125+ await encryptedEvent . attemptDecryption ( crypto ) ;
126+ expect ( encryptedEvent . isEncrypted ( ) ) . toBeTruthy ( ) ;
127+ expect ( encryptedEvent . isBeingDecrypted ( ) ) . toBeFalsy ( ) ;
128+ expect ( encryptedEvent . isDecryptionFailure ( ) ) . toBeTruthy ( ) ;
129+ expect ( encryptedEvent . getContent ( ) ) . toEqual ( {
130+ msgtype : "m.bad.encrypted" ,
131+ body : "** Unable to decrypt: Error: test error **" ,
132+ } ) ;
133+ } ) ;
134+
137135 it ( "should retry decryption if a retry is queued" , async ( ) => {
138136 const eventAttemptDecryptionSpy = jest . spyOn ( encryptedEvent , "attemptDecryption" ) ;
139137
0 commit comments