Skip to content

Commit 0f8a5c1

Browse files
author
Kyrylo Hrechykhin
committed
add possibility to ignore not supported fuses
1 parent 5bc642a commit 0f8a5c1

File tree

3 files changed

+48
-12
lines changed

3 files changed

+48
-12
lines changed

src/config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ export enum FuseV1Options {
1818
export type FuseV1Config<T = boolean> = {
1919
version: FuseVersion.V1;
2020
resetAdHocDarwinSignature?: boolean;
21+
ignoreNotSupportedFuses?: boolean;
2122
} & Partial<Record<FuseV1Options, T>>;
2223

2324
export type FuseConfig<T = boolean> = FuseV1Config<T>;

src/index.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,13 @@ const buildFuseV1Wire = (config: FuseV1Config, wireLength: number) => {
1515
(fuseOption) => parseInt(fuseOption, 10) >= wireLength,
1616
);
1717
if (badFuseOption !== undefined) {
18-
throw new Error(
19-
`Trying to configure ${
20-
FuseV1Options[badFuseOption as any]
21-
} but the fuse wire in this version of Electron is not long enough`,
22-
);
18+
if (!config.ignoreNotSupportedFuses) {
19+
throw new Error(
20+
`Trying to configure ${
21+
FuseV1Options[badFuseOption as any]
22+
} but the fuse wire in this version of Electron is not long enough`,
23+
);
24+
}
2325
}
2426

2527
return [

test/index.spec.ts

Lines changed: 40 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ describe('getCurrentFuseWire()', () => {
2020
});
2121

2222
it('should return the expected defaults for Electron v20.0.0', async () => {
23-
const electronPath = await getElectronLocally('20.0.0', 'darwin', 'x64');
23+
const electronPath = await getElectronLocally('20.0.0', process.platform, process.arch);
2424
expect(readableFuseWire(await getCurrentFuseWire(electronPath))).toMatchInlineSnapshot(`
2525
{
2626
"EnableCookieEncryption": "DISABLE",
@@ -35,16 +35,18 @@ describe('getCurrentFuseWire()', () => {
3535
});
3636

3737
for (const [platform, arch] of supportedPlatforms) {
38-
it(`should work on ${platform}/${arch}`, async () => {
39-
const electronPath = await getElectronLocally('20.0.0', platform, arch);
40-
await expect(getCurrentFuseWire(electronPath)).resolves.toBeTruthy();
41-
});
38+
if (process.platform === platform) {
39+
it(`should work on ${platform}/${arch}`, async () => {
40+
const electronPath = await getElectronLocally('20.0.0', platform, arch);
41+
await expect(getCurrentFuseWire(electronPath)).resolves.toBeTruthy();
42+
});
43+
}
4244
}
4345
});
4446

4547
describe('flipFuses()', () => {
4648
it('should allow toggling a single fuse', async () => {
47-
const electronPath = await getElectronLocally('20.0.0', 'darwin', 'x64');
49+
const electronPath = await getElectronLocally('20.0.0', process.platform, process.arch);
4850
expect((await getCurrentFuseWire(electronPath))[FuseV1Options.EnableCookieEncryption]).toEqual(
4951
FuseState.DISABLE,
5052
);
@@ -59,7 +61,7 @@ describe('flipFuses()', () => {
5961
});
6062

6163
it('should allow toggling multiple fuses', async () => {
62-
const electronPath = await getElectronLocally('20.0.0', 'darwin', 'x64');
64+
const electronPath = await getElectronLocally('20.0.0', process.platform, process.arch);
6365
expect((await getCurrentFuseWire(electronPath))[FuseV1Options.EnableCookieEncryption]).toEqual(
6466
FuseState.DISABLE,
6567
);
@@ -79,6 +81,37 @@ describe('flipFuses()', () => {
7981
).toEqual(FuseState.ENABLE);
8082
});
8183

84+
it('should throw exception by default if unsupported fuse is specified', async () => {
85+
const electronPath = await getElectronLocally('20.0.0', process.platform, process.arch);
86+
const fuseConfig = await getCurrentFuseWire(electronPath);
87+
expect(FuseV1Options.LoadBrowserProcessSpecificV8Snapshot in fuseConfig).toBeFalsy();
88+
89+
await expect(
90+
flipFuses(electronPath, {
91+
version: FuseVersion.V1,
92+
[FuseV1Options.LoadBrowserProcessSpecificV8Snapshot]: true,
93+
}),
94+
).rejects.toThrow('LoadBrowserProcessSpecificV8Snapshot');
95+
});
96+
97+
it('should toggle only supported fuses if ignoreNotSupportedFuses is true', async () => {
98+
const electronPath = await getElectronLocally('20.0.0', process.platform, process.arch);
99+
const fuseConfig = await getCurrentFuseWire(electronPath);
100+
expect(FuseV1Options.LoadBrowserProcessSpecificV8Snapshot in fuseConfig).toBeFalsy();
101+
expect(fuseConfig[FuseV1Options.EnableCookieEncryption]).toEqual(FuseState.DISABLE);
102+
103+
await flipFuses(electronPath, {
104+
version: FuseVersion.V1,
105+
ignoreNotSupportedFuses: true,
106+
[FuseV1Options.EnableCookieEncryption]: true,
107+
[FuseV1Options.LoadBrowserProcessSpecificV8Snapshot]: true,
108+
});
109+
110+
const newFuseConfig = await getCurrentFuseWire(electronPath);
111+
expect(FuseV1Options.LoadBrowserProcessSpecificV8Snapshot in newFuseConfig).toBeFalsy();
112+
expect(newFuseConfig[FuseV1Options.EnableCookieEncryption]).toEqual(FuseState.ENABLE);
113+
});
114+
82115
if (process.platform === 'darwin') {
83116
it('should work on universal macOS applications', async () => {
84117
const electronPathX64 = await getElectronLocally('20.0.0', 'darwin', 'x64');

0 commit comments

Comments
 (0)