Skip to content
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

fix: no throw on unknown config value #372

Merged
merged 2 commits into from
Feb 11, 2021
Merged
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
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