From 8fe19b64922ebe3c9fce9375c3df8985c098c33f Mon Sep 17 00:00:00 2001 From: Nils Hanff Date: Thu, 31 Aug 2023 13:55:42 +0200 Subject: [PATCH] Add platform secret functions to ElectronPlatform Signed-off-by: Nils Hanff --- src/vector/platform/ElectronPlatform.tsx | 18 ++++++++++ .../vector/platform/ElectronPlatform-test.ts | 35 +++++++++++++++++++ 2 files changed, 53 insertions(+) diff --git a/src/vector/platform/ElectronPlatform.tsx b/src/vector/platform/ElectronPlatform.tsx index d77c31c3d8..10292fd5e5 100644 --- a/src/vector/platform/ElectronPlatform.tsx +++ b/src/vector/platform/ElectronPlatform.tsx @@ -403,6 +403,24 @@ export default class ElectronPlatform extends VectorBasePlatform { return true; } + public async getPlatformSecret(key: string): Promise { + return await this.ipc.call("getSecret", key).catch((error) => { + logger.info(`Failed to connect to password storage to get ${key}`, error); + }); + } + + public async savePlatformSecret(key: string, value: string): Promise { + return await this.ipc.call("saveSecret", key, value).catch((error) => { + logger.info(`Failed to connect to password storage to save ${key}`, error); + }); + } + + public async destroyPlatformSecret(key: string): Promise { + return await this.ipc.call("destroySecret", key).catch((error) => { + logger.info(`Failed to connect to password storage to destroy ${key}`, error); + }); + } + public async getPickleKey(userId: string, deviceId: string): Promise { try { return await this.ipc.call("getPickleKey", userId, deviceId); diff --git a/test/unit-tests/vector/platform/ElectronPlatform-test.ts b/test/unit-tests/vector/platform/ElectronPlatform-test.ts index 128bacc99b..3e7cc71962 100644 --- a/test/unit-tests/vector/platform/ElectronPlatform-test.ts +++ b/test/unit-tests/vector/platform/ElectronPlatform-test.ts @@ -284,6 +284,41 @@ describe("ElectronPlatform", () => { }); }); + describe("generic secrets", () => { + const secretKey = "secret-key"; + const secretValue = "secret-value"; + + it("makes correct ipc call to get secret", () => { + const platform = new ElectronPlatform(); + mockElectron.send.mockClear(); + platform.getPlatformSecret(secretKey); + + const [, { name, args }] = mockElectron.send.mock.calls[0]; + expect(name).toEqual("getSecret"); + expect(args).toEqual([secretKey]); + }); + + it("makes correct ipc call to save secret", () => { + const platform = new ElectronPlatform(); + mockElectron.send.mockClear(); + platform.savePlatformSecret(secretKey, secretValue); + + const [, { name, args }] = mockElectron.send.mock.calls[0]; + expect(name).toEqual("saveSecret"); + expect(args).toEqual([secretKey, secretValue]); + }); + + it("makes correct ipc call to destroy pickle key", () => { + const platform = new ElectronPlatform(); + mockElectron.send.mockClear(); + platform.destroyPlatformSecret(secretKey); + + const [, { name, args }] = mockElectron.send.mock.calls[0]; + expect(name).toEqual("destroySecret"); + expect(args).toEqual([secretKey]); + }); + }); + describe("versions", () => { it("calls install update", () => { const platform = new ElectronPlatform();