Skip to content

Add functions for generic secret management to ElectronPlatform interface #26405

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

Closed
Closed
Show file tree
Hide file tree
Changes from all 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
18 changes: 18 additions & 0 deletions src/vector/platform/ElectronPlatform.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,24 @@ export default class ElectronPlatform extends VectorBasePlatform {
return true;
}

public async getPlatformSecret(key: string): Promise<string | null> {
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<string | null> {
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<void> {
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<string | null> {
try {
return await this.ipc.call("getPickleKey", userId, deviceId);
Expand Down
35 changes: 35 additions & 0 deletions test/unit-tests/vector/platform/ElectronPlatform-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down