From 1d67af58cbf7e258ed044b0f0c990bb8f12b11c6 Mon Sep 17 00:00:00 2001 From: Richard van der Hoff Date: Mon, 17 Jun 2024 18:49:05 +0100 Subject: [PATCH] fixup! Remove support for legacy crypto stack in `StorageManager` --- test/utils/StorageManager-test.ts | 99 +++++++++---------------------- 1 file changed, 27 insertions(+), 72 deletions(-) diff --git a/test/utils/StorageManager-test.ts b/test/utils/StorageManager-test.ts index 786e20caea75..e2eb172581f5 100644 --- a/test/utils/StorageManager-test.ts +++ b/test/utils/StorageManager-test.ts @@ -20,7 +20,6 @@ import { IDBFactory } from "fake-indexeddb"; import { IndexedDBCryptoStore } from "matrix-js-sdk/src/matrix"; import * as StorageManager from "../../src/utils/StorageManager"; -import SettingsStore from "../../src/settings/SettingsStore"; const LEGACY_CRYPTO_STORE_NAME = "matrix-js-sdk:crypto"; const RUST_CRYPTO_STORE_NAME = "matrix-js-sdk::matrix-sdk-crypto"; @@ -77,98 +76,54 @@ describe("StorageManager", () => { indexedDB = new IDBFactory(); }); - describe("with `feature_rust_crypto` enabled", () => { - beforeEach(() => { - jest.spyOn(SettingsStore, "getValue").mockImplementation(async (key) => { - if (key === "feature_rust_crypto") { - return true; - } - throw new Error(`Unknown key ${key}`); - }); - }); + it("should not be ok if sync store but no crypto store", async () => { + const result = await StorageManager.checkConsistency(); + expect(result.healthy).toBe(true); + expect(result.dataInCryptoStore).toBe(false); + }); - it("should not be ok if sync store but no crypto store", async () => { - const result = await StorageManager.checkConsistency(); - expect(result.healthy).toBe(true); - expect(result.dataInCryptoStore).toBe(false); - }); + it("should be ok if sync store and a rust crypto store", async () => { + await createDB(RUST_CRYPTO_STORE_NAME); - it("should be ok if sync store and a rust crypto store", async () => { - await createDB(RUST_CRYPTO_STORE_NAME); + const result = await StorageManager.checkConsistency(); + expect(result.healthy).toBe(true); + expect(result.dataInCryptoStore).toBe(true); + }); + + describe("without rust store", () => { + it("should be ok if there is non migrated legacy crypto store", async () => { + await populateLegacyStore(undefined); const result = await StorageManager.checkConsistency(); expect(result.healthy).toBe(true); expect(result.dataInCryptoStore).toBe(true); }); - describe("without rust store", () => { - it("should be ok if there is non migrated legacy crypto store", async () => { - await populateLegacyStore(undefined); - - const result = await StorageManager.checkConsistency(); - expect(result.healthy).toBe(true); - expect(result.dataInCryptoStore).toBe(true); - }); - - it("should be ok if legacy store in MigrationState `NOT_STARTED`", async () => { - await populateLegacyStore(0 /* MigrationState.NOT_STARTED*/); - - const result = await StorageManager.checkConsistency(); - expect(result.healthy).toBe(true); - expect(result.dataInCryptoStore).toBe(true); - }); - - it("should not be ok if MigrationState greater than `NOT_STARTED`", async () => { - await populateLegacyStore(1 /*INITIAL_DATA_MIGRATED*/); - - const result = await StorageManager.checkConsistency(); - expect(result.healthy).toBe(true); - expect(result.dataInCryptoStore).toBe(false); - }); + it("should be ok if legacy store in MigrationState `NOT_STARTED`", async () => { + await populateLegacyStore(0 /* MigrationState.NOT_STARTED*/); - it("should not be healthy if no indexeddb", async () => { - // eslint-disable-next-line no-global-assign - indexedDB = {} as IDBFactory; - - const result = await StorageManager.checkConsistency(); - expect(result.healthy).toBe(false); - - // eslint-disable-next-line no-global-assign - indexedDB = new IDBFactory(); - }); - }); - }); - - describe("with `feature_rust_crypto` disabled", () => { - beforeEach(() => { - jest.spyOn(SettingsStore, "getValue").mockImplementation(async (key) => { - if (key === "feature_rust_crypto") { - return false; - } - throw new Error(`Unknown key ${key}`); - }); - }); - - it("should not be ok if sync store but no crypto store", async () => { const result = await StorageManager.checkConsistency(); expect(result.healthy).toBe(true); - expect(result.dataInCryptoStore).toBe(false); + expect(result.dataInCryptoStore).toBe(true); }); - it("should not be ok if sync store but no crypto store and a rust store", async () => { - await createDB(RUST_CRYPTO_STORE_NAME); + it("should not be ok if MigrationState greater than `NOT_STARTED`", async () => { + await populateLegacyStore(1 /*INITIAL_DATA_MIGRATED*/); const result = await StorageManager.checkConsistency(); expect(result.healthy).toBe(true); expect(result.dataInCryptoStore).toBe(false); }); - it("should be healthy if sync store and a legacy crypto store", async () => { - await createDB(LEGACY_CRYPTO_STORE_NAME); + it("should not be healthy if no indexeddb", async () => { + // eslint-disable-next-line no-global-assign + indexedDB = {} as IDBFactory; const result = await StorageManager.checkConsistency(); - expect(result.healthy).toBe(true); - expect(result.dataInCryptoStore).toBe(true); + expect(result.healthy).toBe(false); + + // eslint-disable-next-line no-global-assign + indexedDB = new IDBFactory(); }); }); });