Skip to content
Permalink
Browse files

fix(generic): ensure config proxy doesn't prevent access to built-ins

ISSUES CLOSED: #336
  • Loading branch information
gerges authored and MarshallOfSound committed Sep 26, 2017
1 parent 6c5f60b commit 070478896c7cc2e84e3cc2d81ae7786e31a7df37
Showing with 21 additions and 4 deletions.
  1. +10 −2 src/util/forge-config.js
  2. +10 −1 test/fast/forge-config_spec.js
  3. +1 −1 test/fixture/dummy_js_conf/forge.config.js
@@ -18,11 +18,19 @@ const proxify = (object, envPrefix) => {

return new Proxy(newObject, {
get(target, name) {
if (target.hasOwnProperty(name)) return target[name]; // eslint-disable-line no-prototype-builtins
if (typeof name === 'string') {
// eslint-disable-next-line no-prototype-builtins
if (!target.hasOwnProperty(name) && typeof name === 'string') {
const envValue = process.env[`${envPrefix}_${underscoreCase(name)}`];
if (envValue) return envValue;
}
return target[name];
},
getOwnPropertyDescriptor(target, name) {
const envValue = process.env[`${envPrefix}_${underscoreCase(name)}`];
// eslint-disable-next-line no-prototype-builtins
if (target.hasOwnProperty(name) || envValue) {
return { configurable: true, enumerable: true };
}
},
});
};
@@ -37,10 +37,19 @@ describe('forge-config', () => {
},
}));
});
it('should allow access to built-ins of proxied objects', async () => {
const conf = await findConfig(path.resolve(__dirname, '../fixture/dummy_js_conf'));
expect(conf.electronPackagerConfig.baz.hasOwnProperty).to.be.a('function');
process.env.ELECTRON_FORGE_S3_SECRET_ACCESS_KEY = 'SecretyThing';
// eslint-disable-next-line no-prototype-builtins
expect(conf.s3.hasOwnProperty('secretAccessKey')).to.equal(true);
delete process.env.ELECTRON_FORGE_S3_SECRET_ACCESS_KEY;
});


it('should resolve the JS file exports in config.forge points to a JS file', async () => {
expect(JSON.parse(JSON.stringify(await findConfig(path.resolve(__dirname, '../fixture/dummy_js_conf'))))).to.be.deep.equal(Object.assign({}, defaults, {
electronPackagerConfig: { foo: 'bar' },
electronPackagerConfig: { foo: 'bar', baz: {} },
}));
});

@@ -5,7 +5,7 @@ module.exports = {
linux: ['deb', 'rpm'],
mas: ['zip'],
},
electronPackagerConfig: { foo: 'bar' },
electronPackagerConfig: { foo: 'bar', baz: {} },
electronWinstallerConfig: {},
electronInstallerDebian: {},
electronInstallerRedhat: {},

0 comments on commit 0704788

Please sign in to comment.
You can’t perform that action at this time.