Fix secret storage not being used due to bad import (#2029)

This commit is contained in:
Michael Telatynski 2024-12-10 14:39:02 +00:00 committed by GitHub
parent 5bef889f83
commit 5d688c375a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 28 additions and 8 deletions

View File

@ -6,6 +6,8 @@ SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only
Please see LICENSE files in the repository root for full details. Please see LICENSE files in the repository root for full details.
*/ */
import { platform } from "node:os";
import { test, expect } from "../../element-desktop-test.js"; import { test, expect } from "../../element-desktop-test.js";
declare global { declare global {
@ -17,6 +19,7 @@ declare global {
supportsEventIndexing(): Promise<boolean>; supportsEventIndexing(): Promise<boolean>;
} }
| undefined; | undefined;
createPickleKey(userId: string, deviceId: string): Promise<string | null>;
}; };
}; };
} }
@ -24,17 +27,32 @@ declare global {
test.describe("App launch", () => { test.describe("App launch", () => {
test.slow(); test.slow();
test("should launch and render the welcome view successfully and support seshat", async ({ page }) => {
test.beforeEach(async ({ page }) => {
await page.locator("#matrixchat").waitFor(); await page.locator("#matrixchat").waitFor();
await page.locator(".mx_Welcome").waitFor(); await page.locator(".mx_Welcome").waitFor();
});
test("should launch and render the welcome view successfully", async ({ page }) => {
await expect(page).toHaveURL("vector://vector/webapp/#/welcome"); await expect(page).toHaveURL("vector://vector/webapp/#/welcome");
await expect(page).toHaveScreenshot(); await expect(page).toHaveScreenshot();
});
const supported = await page.evaluate<boolean>(async () => { test("should launch and render the welcome view successfully and support seshat", async ({ page }) => {
const indexManager = window.mxPlatformPeg.get()?.getEventIndexingManager(); await expect(
return await indexManager?.supportsEventIndexing(); page.evaluate<boolean>(async () => {
}); return window.mxPlatformPeg.get().getEventIndexingManager()?.supportsEventIndexing();
}),
).resolves.toBeTruthy();
});
expect(supported).toBe(true); test("should launch and render the welcome view successfully and support keytar", async ({ page }) => {
test.skip(platform() === "linux", "This test does not yet support Linux");
await expect(
page.evaluate<string | null>(async () => {
return await window.mxPlatformPeg.get().createPickleKey("@user:server", "ABCDEF");
}),
).resolves.not.toBeNull();
}); });
}); });

View File

@ -157,7 +157,9 @@ ipcMain.on("ipcCall", async function (_ev: IpcMainEvent, payload) {
case "createPickleKey": case "createPickleKey":
try { try {
const pickleKey = await randomArray(32); const pickleKey = await randomArray(32);
await keytar?.setPassword("element.io", `${args[0]}|${args[1]}`, pickleKey); // We purposefully throw if keytar is not available so the caller can handle it
// rather than sending them a pickle key we did not store on their behalf.
await keytar!.setPassword("element.io", `${args[0]}|${args[1]}`, pickleKey);
ret = pickleKey; ret = pickleKey;
} catch { } catch {
ret = null; ret = null;

View File

@ -9,7 +9,7 @@ import type * as Keytar from "keytar"; // Hak dependency type
let keytar: typeof Keytar | undefined; let keytar: typeof Keytar | undefined;
try { try {
keytar = await import("keytar"); ({ default: keytar } = await import("keytar"));
} catch (e) { } catch (e) {
if ((<NodeJS.ErrnoException>e).code === "MODULE_NOT_FOUND") { if ((<NodeJS.ErrnoException>e).code === "MODULE_NOT_FOUND") {
console.log("Keytar isn't installed; secure key storage is disabled."); console.log("Keytar isn't installed; secure key storage is disabled.");