diff --git a/src/config/config.ts b/src/config/config.ts index c15ef74c15..caa8908f20 100644 --- a/src/config/config.ts +++ b/src/config/config.ts @@ -425,7 +425,7 @@ export class Config extends ConfigFile { */ private async cryptProperties(encrypt: boolean): Promise { const hasEncryptedProperties = this.entries().some(([key]) => { - return !!ensure(Config.propertyConfigMap[key]).encrypted; + return !!Config.propertyConfigMap[key]?.encrypted; }); if (hasEncryptedProperties) { diff --git a/src/config/configAggregator.ts b/src/config/configAggregator.ts index aaf8bf5d87..e9c44395ff 100644 --- a/src/config/configAggregator.ts +++ b/src/config/configAggregator.ts @@ -245,6 +245,7 @@ export class ConfigAggregator extends AsyncOptionalCreatable { */ 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'); diff --git a/test/unit/config/configAggregatorTest.ts b/test/unit/config/configAggregatorTest.ts index 8b60798c5a..f74df6fc98 100644 --- a/test/unit/config/configAggregatorTest.ts +++ b/test/unit/config/configAggregatorTest.ts @@ -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({})); @@ -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'); + }); }); }); diff --git a/test/unit/config/configTest.ts b/test/unit/config/configTest.ts index 00fcecad8c..3c2f69064a 100644 --- a/test/unit/config/configTest.ts +++ b/test/unit/config/configTest.ts @@ -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', () => {