From bb314423bfc4c170dccd79bc1574d6ab572ac54d Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Fri, 11 Apr 2025 16:25:14 +0100 Subject: [PATCH] Iterate Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> --- playwright/e2e/launch/launch.spec.ts | 36 +++++++++++++++++++++------- src/store.ts | 6 ++--- 2 files changed, 30 insertions(+), 12 deletions(-) diff --git a/playwright/e2e/launch/launch.spec.ts b/playwright/e2e/launch/launch.spec.ts index 6d98bead..f47ebcbc 100644 --- a/playwright/e2e/launch/launch.spec.ts +++ b/playwright/e2e/launch/launch.spec.ts @@ -7,6 +7,7 @@ Please see LICENSE files in the repository root for full details. */ import { platform } from "node:os"; +import keytar from "keytar-forked"; import { test, expect } from "../../element-desktop-test.js"; @@ -19,6 +20,7 @@ declare global { supportsEventIndexing(): Promise; } | undefined; + getPickleKey(userId: string, deviceId: string): Promise; createPickleKey(userId: string, deviceId: string): Promise; }; }; @@ -46,18 +48,34 @@ test.describe("App launch", () => { ).resolves.toBeTruthy(); }); - test("should launch and render the welcome view successfully and support safeStorage", async ({ page }) => { - // test.skip(platform() === "linux", "This test does not yet support Linux"); + test.describe("safeStorage", () => { + test.skip(platform() === "linux", "The linux runner has no compatible wallet/keychain"); + test.skip(platform() === "darwin", "The macOS runner's keychain is not available"); - await expect( - page.evaluate(async () => { - return await window.mxPlatformPeg.get().createPickleKey("@user:server", "ABCDEF"); - }), - ).resolves.not.toBeNull(); + const userId = "@user:server"; + const deviceId = "ABCDEF"; + + test("should be supported", async ({ page }) => { + await expect( + page.evaluate(() => window.mxPlatformPeg.get().createPickleKey(userId, deviceId)), + ).resolves.not.toBeNull(); + }); + + test.describe("migrate from keytar", () => { + const pickleKey = "DEADBEEF1234"; + + test.beforeEach(async () => { + await keytar.setPassword("element.io", `${userId}|${deviceId}`, pickleKey); + }); + + test("should migrate successfully", async ({ page }) => { + await expect( + page.evaluate(() => window.mxPlatformPeg.get().getPickleKey(userId, deviceId)), + ).resolves.toBe(pickleKey); + }); + }); }); - // TODO test keytar migration - test.describe("--no-update", () => { test.use({ extraArgs: ["--no-update"], diff --git a/src/store.ts b/src/store.ts index 98b57fd5..272822c7 100644 --- a/src/store.ts +++ b/src/store.ts @@ -89,10 +89,10 @@ export class Store extends ElectronStore<{ * @throws if safeStorage is not available. */ public async migrate(): Promise { - console.log("Store migration: started"); if (this.has("safeStorage")) return; + console.info("Store migration: started"); if (!safeStorage.isEncryptionAvailable()) { - console.log("Store migration: safeStorage is not available"); + console.error("Store migration: safeStorage is not available"); throw new Error("safeStorage is not available"); } @@ -100,11 +100,11 @@ export class Store extends ElectronStore<{ ...(await keytar.findCredentials(LEGACY_KEYTAR_SERVICE)), ...(await keytar.findCredentials(KEYTAR_SERVICE)), ]; - console.log("Store migration:", credentials); for (const cred of credentials) { await this.deleteSecret(cred.account); // delete from keytar & keytar legacy await this.setSecret(cred.account, cred.password); // write to safeStorage & keytar for downgrade compatibility } + console.info(`Store migration done: found ${credentials.length} credentials`); } /**