From f410e71bfa2e9ea6bf8de50e5be570f866501bfe Mon Sep 17 00:00:00 2001 From: Faye Duxovni Date: Wed, 28 Sep 2022 12:36:09 -0400 Subject: [PATCH] Fix missing return when receiving an invitation without shared history (#2710) --- spec/integ/matrix-client-syncing.spec.ts | 71 +++++++++++++++++++ .../store/indexeddb-crypto-store-backend.ts | 1 + 2 files changed, 72 insertions(+) diff --git a/spec/integ/matrix-client-syncing.spec.ts b/spec/integ/matrix-client-syncing.spec.ts index a22e0a257..03126c506 100644 --- a/spec/integ/matrix-client-syncing.spec.ts +++ b/spec/integ/matrix-client-syncing.spec.ts @@ -14,6 +14,8 @@ See the License for the specific language governing permissions and limitations under the License. */ +import 'fake-indexeddb/auto'; + import { Optional } from "matrix-events-sdk/lib/types"; import HttpBackend from "matrix-mock-request"; @@ -25,6 +27,8 @@ import { RoomMemberEvent, UNSTABLE_MSC2716_MARKER, MatrixClient, + ClientEvent, + IndexedDBCryptoStore, } from "../../src"; import * as utils from "../test-utils/test-utils"; import { TestClient } from "../TestClient"; @@ -1428,3 +1432,70 @@ describe("MatrixClient syncing", () => { return utils.syncPromise(client, numSyncs); } }); + +describe("MatrixClient syncing (IndexedDB version)", () => { + const selfUserId = "@alice:localhost"; + const selfAccessToken = "aseukfgwef"; + const syncData = { + next_batch: "batch_token", + rooms: {}, + presence: {}, + }; + + it("should emit ClientEvent.Room when invited while using indexeddb crypto store", async () => { + const idbTestClient = new TestClient( + selfUserId, + "DEVICE", + selfAccessToken, + undefined, + { cryptoStore: new IndexedDBCryptoStore(global.indexedDB, "tests") }, + ); + const idbHttpBackend = idbTestClient.httpBackend; + const idbClient = idbTestClient.client; + idbHttpBackend.when("GET", "/versions").respond(200, {}); + idbHttpBackend.when("GET", "/pushrules").respond(200, {}); + idbHttpBackend.when("POST", "/filter").respond(200, { filter_id: "a filter id" }); + + await idbClient.initCrypto(); + + const roomId = "!invite:example.org"; + + // First sync: an invite + const inviteSyncRoomSection = { + invite: { + [roomId]: { + invite_state: { + events: [{ + type: "m.room.member", + state_key: selfUserId, + content: { + membership: "invite", + }, + }], + }, + }, + }, + }; + idbHttpBackend.when("GET", "/sync").respond(200, { + ...syncData, + rooms: inviteSyncRoomSection, + }); + + // First fire: an initial invite + let fires = 0; + idbClient.once(ClientEvent.Room, (room) => { + fires++; + expect(room.roomId).toBe(roomId); + }); + + // noinspection ES6MissingAwait + idbClient.startClient(); + await idbHttpBackend.flushAllExpected(); + + expect(fires).toBe(1); + + idbHttpBackend.verifyNoOutstandingExpectation(); + idbClient.stopClient(); + idbHttpBackend.stop(); + }); +}); diff --git a/src/crypto/store/indexeddb-crypto-store-backend.ts b/src/crypto/store/indexeddb-crypto-store-backend.ts index 64a2d6f9a..32539305d 100644 --- a/src/crypto/store/indexeddb-crypto-store-backend.ts +++ b/src/crypto/store/indexeddb-crypto-store-backend.ts @@ -908,6 +908,7 @@ export class Backend implements CryptoStore { const cursor = cursorReq.result; if (!cursor) { resolve([]); + return; } const data = cursor.value; cursor.delete();