Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option for MatrixClient.initRustCrypto() to disable tracing. #4462

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions spec/unit/rust-crypto/rust-crypto.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
15 changes: 11 additions & 4 deletions src/rust-crypto/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<RustCrypto> {
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 {
new RustSdkCryptoJs.Tracing(RustSdkCryptoJs.LoggerLevel.Off).turnOn();
}

logger.debug("Opening Rust CryptoStore");
let storeHandle;
Expand Down