Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>
This commit is contained in:
Michael Telatynski 2025-04-11 16:25:14 +01:00
parent c2e6f80efb
commit bb314423bf
No known key found for this signature in database
GPG Key ID: A2B008A5F49F5D0D
2 changed files with 30 additions and 12 deletions

View File

@ -7,6 +7,7 @@ Please see LICENSE files in the repository root for full details.
*/ */
import { platform } from "node:os"; import { platform } from "node:os";
import keytar from "keytar-forked";
import { test, expect } from "../../element-desktop-test.js"; import { test, expect } from "../../element-desktop-test.js";
@ -19,6 +20,7 @@ declare global {
supportsEventIndexing(): Promise<boolean>; supportsEventIndexing(): Promise<boolean>;
} }
| undefined; | undefined;
getPickleKey(userId: string, deviceId: string): Promise<string | null>;
createPickleKey(userId: string, deviceId: string): Promise<string | null>; createPickleKey(userId: string, deviceId: string): Promise<string | null>;
}; };
}; };
@ -46,17 +48,33 @@ test.describe("App launch", () => {
).resolves.toBeTruthy(); ).resolves.toBeTruthy();
}); });
test("should launch and render the welcome view successfully and support safeStorage", async ({ page }) => { test.describe("safeStorage", () => {
// test.skip(platform() === "linux", "This test does not yet support Linux"); test.skip(platform() === "linux", "The linux runner has no compatible wallet/keychain");
test.skip(platform() === "darwin", "The macOS runner's keychain is not available");
const userId = "@user:server";
const deviceId = "ABCDEF";
test("should be supported", async ({ page }) => {
await expect( await expect(
page.evaluate<string | null>(async () => { page.evaluate(() => window.mxPlatformPeg.get().createPickleKey(userId, deviceId)),
return await window.mxPlatformPeg.get().createPickleKey("@user:server", "ABCDEF");
}),
).resolves.not.toBeNull(); ).resolves.not.toBeNull();
}); });
// TODO test keytar migration 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);
});
});
});
test.describe("--no-update", () => { test.describe("--no-update", () => {
test.use({ test.use({

View File

@ -89,10 +89,10 @@ export class Store extends ElectronStore<{
* @throws if safeStorage is not available. * @throws if safeStorage is not available.
*/ */
public async migrate(): Promise<void> { public async migrate(): Promise<void> {
console.log("Store migration: started");
if (this.has("safeStorage")) return; if (this.has("safeStorage")) return;
console.info("Store migration: started");
if (!safeStorage.isEncryptionAvailable()) { 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"); 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(LEGACY_KEYTAR_SERVICE)),
...(await keytar.findCredentials(KEYTAR_SERVICE)), ...(await keytar.findCredentials(KEYTAR_SERVICE)),
]; ];
console.log("Store migration:", credentials);
for (const cred of credentials) { for (const cred of credentials) {
await this.deleteSecret(cred.account); // delete from keytar & keytar legacy await this.deleteSecret(cred.account); // delete from keytar & keytar legacy
await this.setSecret(cred.account, cred.password); // write to safeStorage & keytar for downgrade compatibility await this.setSecret(cred.account, cred.password); // write to safeStorage & keytar for downgrade compatibility
} }
console.info(`Store migration done: found ${credentials.length} credentials`);
} }
/** /**