Skip to content

Commit

Permalink
Merge pull request #372 from forcedotcom/td/nothrowonconfig
Browse files Browse the repository at this point in the history
fix: no throw on unknown config value
  • Loading branch information
peternhale authored Feb 11, 2021
2 parents b214da3 + cbb91e1 commit 45e4613
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/config/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,7 @@ export class Config extends ConfigFile<ConfigFile.Options> {
*/
private async cryptProperties(encrypt: boolean): Promise<void> {
const hasEncryptedProperties = this.entries().some(([key]) => {
return !!ensure(Config.propertyConfigMap[key]).encrypted;
return !!Config.propertyConfigMap[key]?.encrypted;
});

if (hasEncryptedProperties) {
Expand Down
1 change: 1 addition & 0 deletions src/config/configAggregator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,7 @@ export class ConfigAggregator extends AsyncOptionalCreatable<JsonMap> {
*/
public getConfigInfo(): ConfigInfo[] {
const infos = Object.keys(this.getConfig())
.filter((key) => this.getAllowedProperties().some((element) => key === element.key))
.map((key) => this.getInfo(key))
.filter((info): info is ConfigInfo => !!info);
return sortBy(infos, 'key');
Expand Down
12 changes: 11 additions & 1 deletion test/unit/config/configAggregatorTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ describe('ConfigAggregator', () => {
expect(aggregator.getLocation(Config.DEFAULT_USERNAME)).to.equal('Environment');
});

it('configInfo', async () => {
it('configInfo with env', async () => {
process.env.SFDX_DEFAULTUSERNAME = 'test';
$$.SANDBOX.stub(fs, 'readJson').returns(Promise.resolve({}));

Expand All @@ -170,5 +170,15 @@ describe('ConfigAggregator', () => {
expect(info.value).to.equal('test');
expect(info.location).to.equal('Environment');
});

it('configInfo ignores invalid entries', async () => {
$$.SANDBOX.stub(fs, 'readJsonMap').returns(Promise.resolve({ invalid: 'entry', apiVersion: 49.0 }));

const aggregator: ConfigAggregator = await ConfigAggregator.create();
const info = aggregator.getConfigInfo()[0];
expect(info.key).to.equal('apiVersion');
expect(info.value).to.equal(49.0);
expect(info.location).to.equal('Local');
});
});
});
9 changes: 9 additions & 0 deletions test/unit/config/configTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,15 @@ describe('Config', () => {

expect(writeStub.called).to.be.true;
});

it('calls ConfigFile.read with unknown key and does not throw on crypt', async () => {
stubMethod($$.SANDBOX, ConfigFile.prototype, ConfigFile.prototype.read.name).callsFake(async function () {
this.setContentsFromObject({ unknown: 'unknown config key and value' });
});

const config: Config = await Config.create(Config.getDefaultOptions(true));
expect(config).to.exist;
});
});

describe('allowed properties', () => {
Expand Down

0 comments on commit 45e4613

Please sign in to comment.