Skip to content

Commit d593e61

Browse files
committed
fix: catch lightning urls when passed via -r attribute
1 parent be1d8a8 commit d593e61

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

src/common.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,14 @@ export class Common {
2929
}
3030
}
3131
public static async resolveLoginUrl(instanceUrl: Optional<string>): Promise<Optional<string>> {
32+
const logger = await Logger.child('Common', { tag: 'resolveLoginUrl' });
3233
if (instanceUrl) {
34+
if (instanceUrl.includes('lightning.force.com')) {
35+
logger.warn(messages.getMessage('invalidInstanceUrl'));
36+
throw new SfdxError(messages.getMessage('invalidInstanceUrl'), 'URL_WARNING');
37+
}
3338
return instanceUrl;
3439
}
35-
const logger = await Logger.child('Common', { tag: 'resolveLoginUrl' });
3640
let loginUrl: string;
3741
try {
3842
const project = await SfdxProject.resolve();

test/common.test.ts

+11-2
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ describe('common unit tests', () => {
5656
const loginUrl = await Common.resolveLoginUrl(undefined);
5757
expect(loginUrl).to.equal(SfdcUrl.PRODUCTION);
5858
});
59-
it('should throw on lightning login URL', async () => {
59+
it('should throw on lightning login URL in sfdcLoginUrl propery', async () => {
6060
sandbox.stub(SfdxProject.prototype, 'resolveProjectConfig').resolves({
6161
packageDirectories: [
6262
{
@@ -69,7 +69,16 @@ describe('common unit tests', () => {
6969
});
7070
try {
7171
await Common.resolveLoginUrl(undefined);
72-
expect(1).to.equal('This test is failing because it is expecting an error that is never thrown');
72+
sinon.assert.fail('This test is failing because it is expecting an error that is never thrown');
73+
} catch (error) {
74+
const err = error as SfdxError;
75+
expect(err.name).to.equal('URL_WARNING');
76+
}
77+
});
78+
it('should throw on lightning login URL passed in to resolveLoginUrl()', async () => {
79+
try {
80+
await Common.resolveLoginUrl('https://shanedevhub.lightning.force.com');
81+
sinon.assert.fail('This test is failing because it is expecting an error that is never thrown');
7382
} catch (error) {
7483
const err = error as SfdxError;
7584
expect(err.name).to.equal('URL_WARNING');

0 commit comments

Comments
 (0)