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
* renamed: spec/unit/login.spec.js -> spec/unit/login.spec.ts * type test client * renamed: spec/unit/interactive-auth.spec.js -> spec/unit/interactive-auth.spec.ts * fix ts issues in interactive-auth.spec * renamed: spec/unit/filter.spec.js -> spec/unit/filter.spec.ts * fix ts in filter.spec * renamed: spec/unit/event.spec.js -> spec/unit/event.spec.ts * ts in event.spec * renamed: spec/unit/pushprocessor.spec.js -> spec/unit/pushprocessor.spec.ts * fix ts in pushprocessor.spec * fix ts in realtime-callbacks.spec * renamed: spec/unit/content-repo.spec.js -> spec/unit/content-repo.spec.ts * fix signature for getHttpUriForMxc * pr fixes
66 lines
2.3 KiB
TypeScript
66 lines
2.3 KiB
TypeScript
/*
|
|
Copyright 2017 New Vector Ltd
|
|
Copyright 2019, 2022 The Matrix.org Foundation C.I.C.
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
you may not use this file except in compliance with the License.
|
|
You may obtain a copy of the License at
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
See the License for the specific language governing permissions and
|
|
limitations under the License.
|
|
*/
|
|
|
|
import { MatrixEvent } from "../../src/models/event";
|
|
|
|
describe("MatrixEvent", () => {
|
|
describe(".attemptDecryption", () => {
|
|
let encryptedEvent;
|
|
const eventId = 'test_encrypted_event';
|
|
|
|
beforeEach(() => {
|
|
encryptedEvent = new MatrixEvent({
|
|
event_id: eventId,
|
|
type: 'm.room.encrypted',
|
|
content: {
|
|
ciphertext: 'secrets',
|
|
},
|
|
});
|
|
});
|
|
|
|
it('should retry decryption if a retry is queued', async () => {
|
|
const eventAttemptDecryptionSpy = jest.spyOn(encryptedEvent, 'attemptDecryption');
|
|
|
|
const crypto = {
|
|
decryptEvent: jest.fn()
|
|
.mockImplementationOnce(() => {
|
|
// schedule a second decryption attempt while
|
|
// the first one is still running.
|
|
encryptedEvent.attemptDecryption(crypto);
|
|
|
|
const error = new Error("nope");
|
|
error.name = 'DecryptionError';
|
|
return Promise.reject(error);
|
|
})
|
|
.mockImplementationOnce(() => {
|
|
return Promise.resolve({
|
|
clearEvent: {
|
|
type: 'm.room.message',
|
|
},
|
|
});
|
|
}),
|
|
};
|
|
|
|
await encryptedEvent.attemptDecryption(crypto);
|
|
|
|
expect(eventAttemptDecryptionSpy).toHaveBeenCalledTimes(2);
|
|
expect(crypto.decryptEvent).toHaveBeenCalledTimes(2);
|
|
expect(encryptedEvent.getType()).toEqual('m.room.message');
|
|
});
|
|
});
|
|
});
|