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

Sm/handle unknown federated configs #834

Merged
merged 3 commits into from
May 11, 2023
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
7 changes: 5 additions & 2 deletions src/config/configAggregator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -207,9 +207,12 @@ export class ConfigAggregator extends AsyncOptionalCreatable<ConfigAggregator.Op
}
}
return match;
} else {
throw messages.createError('unknownConfigKey', [key]);
}
const matchFromNewKey = this.getAllowedProperties().find((element) => key === element.newKey);
if (matchFromNewKey) {
return matchFromNewKey;
}
throw messages.createError('unknownConfigKey', [key]);
}

/**
Expand Down
49 changes: 44 additions & 5 deletions test/unit/config/configAggregatorTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
/* eslint-disable @typescript-eslint/no-unsafe-call */
import * as fs from 'fs';
import { assert, expect, config as chaiConfig } from 'chai';
import { Config, ConfigProperties, SfdxPropertyKeys } from '../../../src/config/config';
import { ConfigAggregator } from '../../../src/config/configAggregator';
import { Config, ConfigProperties, SFDX_ALLOWED_PROPERTIES, SfdxPropertyKeys } from '../../../src/config/config';
import { ConfigAggregator, ConfigInfo } from '../../../src/config/configAggregator';
import { ConfigFile } from '../../../src/config/configFile';
import { Messages, OrgConfigProperties, Lifecycle } from '../../../src/exported';
import { Messages, OrgConfigProperties, Lifecycle, ORG_CONFIG_ALLOWED_PROPERTIES } from '../../../src/exported';
import { TestContext } from '../../../src/testSetup';

// if you add to this, make sure you use both the old and new name
Expand All @@ -23,6 +23,8 @@ Messages.importMessagesDirectory(__dirname);
const messages = Messages.loadMessages('@salesforce/core', 'config');
const envMessages = Messages.loadMessages('@salesforce/core', 'envVars');

const telemtryConfigFilter = (i: ConfigInfo) => i.key !== 'disable-telemetry';

describe('ConfigAggregator', () => {
let id: string;
let warnStub: sinon.SinonStub;
Expand Down Expand Up @@ -106,7 +108,7 @@ describe('ConfigAggregator', () => {
$$.SANDBOX.stub(fs, 'readFile').resolves({});

const aggregator = await ConfigAggregator.create();
const info = aggregator.getConfigInfo()[0];
const info = aggregator.getConfigInfo().filter(telemtryConfigFilter)[0];
expect(info.key).to.equal('target-org');
expect(info.value).to.equal('test');
expect(info.location).to.equal('Environment');
Expand All @@ -116,7 +118,7 @@ describe('ConfigAggregator', () => {
$$.SANDBOX.stub(fs.promises, 'readFile').resolves('{ "invalid": "entry", "org-api-version": 49.0 }');

const aggregator = await ConfigAggregator.create();
const info = aggregator.getConfigInfo()[0];
const info = aggregator.getConfigInfo().filter(telemtryConfigFilter)[0];
expect(info.key).to.equal('org-api-version');
expect(info.value).to.equal(49.0);
expect(info.location).to.equal('Local');
Expand Down Expand Up @@ -287,4 +289,41 @@ describe('ConfigAggregator', () => {
expect(ConfigAggregator.getValue(OrgConfigProperties.ORG_API_VERSION)?.value, expected);
});
});

describe('getPropertyMeta', () => {
it('key is current, has matching meta', async () => {
const aggregator = await ConfigAggregator.create();
expect(aggregator.getPropertyMeta(OrgConfigProperties.ORG_API_VERSION)).to.equal(
ORG_CONFIG_ALLOWED_PROPERTIES.find((meta) => meta.key === OrgConfigProperties.ORG_API_VERSION)
);
expect(warnStub.callCount).to.equal(0);
});
it('key is deprecated, has matching meta', async () => {
const aggregator = await ConfigAggregator.create();
expect(aggregator.getPropertyMeta(SfdxPropertyKeys.INSTANCE_URL)).to.equal(
SFDX_ALLOWED_PROPERTIES.find((meta) => meta.key === SfdxPropertyKeys.INSTANCE_URL)
);
expect(warnStub.callCount).to.equal(1);
});
describe('old key is known, new key comes from outside sfdx-core, but has matching meta for old key', () => {
it('permanent generic example', async () => {
// this scenario happens for 'org-metadata-rest-deploy' because 'restDeploy' is still in core, and knows its new key,
// but that config lives in PDR
// we want to fall back to avoid "Error (1): Unknown config name: org-metadata-rest-deploy."
const aggregator = await ConfigAggregator.create();
// simulate 'restDeploy`
const oldConfigMeta = { key: 'oldProp', deprecated: true, newKey: 'newProp', description: 'whatever' };
aggregator.addAllowedProperties([oldConfigMeta]);
expect(aggregator.getPropertyMeta('newProp')).to.equal(oldConfigMeta);
expect(warnStub.callCount).to.equal(0);
});
it('org-metadata-rest-deploy finds restDeploy', async () => {
const aggregator = await ConfigAggregator.create();
expect(aggregator.getPropertyMeta('org-metadata-rest-deploy')).to.equal(
SFDX_ALLOWED_PROPERTIES.find((meta) => meta.key === SfdxPropertyKeys.REST_DEPLOY)
);
expect(warnStub.callCount).to.equal(0);
});
});
});
});