From b83aa546617b6428dc1c4f66857e6b367903fd93 Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Fri, 29 May 2020 14:49:35 +0100 Subject: [PATCH] Test the verification request timeouts of 10m and 2m Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> --- .../verification/verification_request.spec.js | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/spec/unit/crypto/verification/verification_request.spec.js b/spec/unit/crypto/verification/verification_request.spec.js index ac9b0f8df..a90d04824 100644 --- a/spec/unit/crypto/verification/verification_request.spec.js +++ b/spec/unit/crypto/verification/verification_request.spec.js @@ -119,6 +119,8 @@ async function distributeEvent(ownRequest, theirRequest, event) { await theirRequest.channel.handleEvent(event, theirRequest, true); } +jest.useFakeTimers(); + describe("verification request unit tests", function() { beforeAll(function() { setupWebcrypto(); @@ -246,4 +248,38 @@ describe("verification request unit tests", function() { expect(bob1Request.done).toBe(true); expect(bob2Request.done).toBe(true); }); + + it("request times out after 10 minutes", async function() { + const alice = makeMockClient("@alice:matrix.tld", "device1"); + const bob = makeMockClient("@bob:matrix.tld", "device1"); + const aliceRequest = new VerificationRequest( + new InRoomChannel(alice, "!room", bob.getUserId()), new Map(), alice); + await aliceRequest.sendRequest(); + const [requestEvent] = alice.popEvents(); + await aliceRequest.channel.handleEvent(requestEvent, aliceRequest, true, + true, true); + + expect(aliceRequest.cancelled).toBe(false); + expect(aliceRequest._cancellingUserId).toBe(undefined); + jest.advanceTimersByTime(10 * 60 * 1000); + expect(aliceRequest._cancellingUserId).toBe(alice.getUserId()); + }); + + it("request times out 2 minutes after receipt", async function() { + const alice = makeMockClient("@alice:matrix.tld", "device1"); + const bob = makeMockClient("@bob:matrix.tld", "device1"); + const aliceRequest = new VerificationRequest( + new InRoomChannel(alice, "!room", bob.getUserId()), new Map(), alice); + await aliceRequest.sendRequest(); + const [requestEvent] = alice.popEvents(); + const bobRequest = new VerificationRequest( + new InRoomChannel(bob, "!room"), new Map(), bob); + + await bobRequest.channel.handleEvent(requestEvent, bobRequest, true); + + expect(bobRequest.cancelled).toBe(false); + expect(bobRequest._cancellingUserId).toBe(undefined); + jest.advanceTimersByTime(2 * 60 * 1000); + expect(bobRequest._cancellingUserId).toBe(bob.getUserId()); + }); });