From 3a1cdd37a32f1b5479d7ae04bb5710d8dc44de9c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Van=20Rompay?= Date: Wed, 15 Jan 2020 17:22:39 +0100 Subject: [PATCH] move export test with other Olm tests to have active sessions --- spec/unit/crypto/algorithms/olm.spec.js | 42 +++++++++++-------------- 1 file changed, 19 insertions(+), 23 deletions(-) diff --git a/spec/unit/crypto/algorithms/olm.spec.js b/spec/unit/crypto/algorithms/olm.spec.js index 87b48e5fb..b6be13a45 100644 --- a/spec/unit/crypto/algorithms/olm.spec.js +++ b/spec/unit/crypto/algorithms/olm.spec.js @@ -41,29 +41,7 @@ async function setupSession(initiator, opponent) { return sid; } -describe("OlmDevice", () => { - if (!global.Olm) { - logger.warn('Not running megolm unit tests: libolm not present'); - return; - } - - beforeAll(function() { - return global.Olm.init(); - }); - - let olmDevice; - - beforeEach(async function() { - olmDevice = makeOlmDevice(); - await olmDevice.init(); - }); - - it('exports picked account and olm sessions', async function() { - console.log('EXPORT RESULT:', await olmDevice.export()); - }); -}); - -describe("OlmDecryption", function() { +describe("OlmDevice", function() { if (!global.Olm) { logger.warn('Not running megolm unit tests: libolm not present'); return; @@ -103,6 +81,24 @@ describe("OlmDecryption", function() { ); }); + it('exports picked account and olm sessions', async function() { + await setupSession(aliceOlmDevice, bobOlmDevice); + + let exported = await aliceOlmDevice.export(); + expect(exported).toHaveProperty('pickleKey'); + expect(exported).toHaveProperty('pickledAccount'); + expect(exported).toHaveProperty('sessions'); + expect(Array.isArray(exported.sessions)).toBe(true); + expect(exported.sessions[0]).toEqual( + expect.objectContaining({ + session: expect.any(String), + lastReceivedMessageTs: expect.any(Number), + deviceKey: expect.any(String), + sessionId: expect.any(String), + }) + ); + }); + it("creates only one session at a time", async function() { // if we call ensureOlmSessionsForDevices multiple times, it should // only try to create one session at a time, even if the server is