diff --git a/spec/unit/rust-crypto/rust-crypto.spec.ts b/spec/unit/rust-crypto/rust-crypto.spec.ts index de93bc9771d..5ce8e2372f6 100644 --- a/spec/unit/rust-crypto/rust-crypto.spec.ts +++ b/spec/unit/rust-crypto/rust-crypto.spec.ts @@ -329,6 +329,46 @@ describe("initRustCrypto", () => { } }, 10000); + it("turns on tracing when tracingEnabled is true", async () => { + const mockStore = { free: jest.fn() } as unknown as StoreHandle; + jest.spyOn(StoreHandle, "open").mockResolvedValue(mockStore); + const tracingSpy = jest.spyOn(RustSdkCryptoJs.Tracing.prototype, 'turnOn').mockImplementation(() => {}); + + await initRustCrypto({ + logger, + http: {} as MatrixClient["http"], + userId: TEST_USER, + deviceId: TEST_DEVICE_ID, + secretStorage: {} as ServerSideSecretStorage, + cryptoCallbacks: {} as CryptoCallbacks, + storePrefix: "storePrefix", + tracingEnabled: true, // Assuming you've added this parameter + }); + + expect(tracingSpy).toHaveBeenCalled(); + tracingSpy.mockRestore(); // Clean up the spy + }); + + it("turns off tracing when tracingEnabled is false", async () => { + const mockStore = { free: jest.fn() } as unknown as StoreHandle; + jest.spyOn(StoreHandle, "open").mockResolvedValue(mockStore); + const tracingSpy = jest.spyOn(RustSdkCryptoJs.Tracing.prototype, 'turnOff').mockImplementation(() => {}); + + await initRustCrypto({ + logger, + http: {} as MatrixClient["http"], + userId: TEST_USER, + deviceId: TEST_DEVICE_ID, + secretStorage: {} as ServerSideSecretStorage, + cryptoCallbacks: {} as CryptoCallbacks, + storePrefix: "storePrefix", + tracingEnabled: false, // Assuming you've added this parameter + }); + + expect(tracingSpy).toHaveBeenCalled(); + tracingSpy.mockRestore(); // Clean up the spy + }); + it("migrates data from a legacy crypto store when secret are not encrypted", async () => { const PICKLE_KEY = "pickle1234"; const legacyStore = new MemoryCryptoStore(); diff --git a/src/rust-crypto/index.ts b/src/rust-crypto/index.ts index 61f15a192a1..e90a214b886 100644 --- a/src/rust-crypto/index.ts +++ b/src/rust-crypto/index.ts @@ -84,22 +84,29 @@ export async function initRustCrypto(args: { /** The pickle key for `legacyCryptoStore` */ legacyPickleKey?: string; - /** * A callback which will receive progress updates on migration from `legacyCryptoStore`. * * Called with (-1, -1) to mark the end of migration. */ legacyMigrationProgressListener?: (progress: number, total: number) => void; + /** + * Whether to enable tracing. Defaults to true. + */ + tracingEnabled?: boolean; }): Promise { - const { logger } = args; + const { logger, tracingEnabled = true } = args; // initialise the rust matrix-sdk-crypto-wasm, if it hasn't already been done logger.debug("Initialising Rust crypto-sdk WASM artifact"); await RustSdkCryptoJs.initAsync(); - // enable tracing in the rust-sdk - new RustSdkCryptoJs.Tracing(RustSdkCryptoJs.LoggerLevel.Debug).turnOn(); + // Enable tracing in the rust-sdk based on the parameter + if (tracingEnabled) { + new RustSdkCryptoJs.Tracing(RustSdkCryptoJs.LoggerLevel.Debug).turnOn(); + } else { + // Do not initialize tracing when disabled + } logger.debug("Opening Rust CryptoStore"); let storeHandle;