Skip to content

Commit

Permalink
fix(sfdxauthurl): error handling regression
Browse files Browse the repository at this point in the history
  • Loading branch information
RodEsp committed Mar 17, 2021
1 parent 6548a72 commit 11535e1
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 8 deletions.
11 changes: 4 additions & 7 deletions src/commands/auth/sfdxurl/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,17 +63,14 @@ export default class Store extends SfdxCommand {
? await this.getUrlFromJson(authFile)
: await fs.readFile(authFile, 'utf8');

let oauth2Options: AuthFields;
try {
oauth2Options = AuthInfo.parseSfdxAuthUrl(sfdxAuthUrl);
} catch (e) {
this.ux.error(
if (!sfdxAuthUrl) {
throw new Error(
`Error getting the auth URL from file ${authFile}. Please ensure it meets the description shown in the documentation for this command.`
);
this.ux.error(this.statics.description);
return;
}

const oauth2Options = AuthInfo.parseSfdxAuthUrl(sfdxAuthUrl);

const authInfo = await AuthInfo.create({ oauth2Options });
await authInfo.save();

Expand Down
20 changes: 19 additions & 1 deletion test/commands/auth/sfdxurl/store.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { AuthFields, AuthInfo, fs } from '@salesforce/core';
import { MockTestOrgData } from '@salesforce/core/lib/testSetup';
import { StubbedType, stubInterface, stubMethod } from '@salesforce/ts-sinon';
import { UX } from '@salesforce/command';
import { parseJson } from '../../../testHelper';
import { parseJson, parseJsonError } from '../../../testHelper';

interface Options {
authInfoCreateFails?: boolean;
Expand Down Expand Up @@ -93,6 +93,24 @@ describe('auth:sfdxurl:store', async () => {
}
);

test
.do(async () => {
await prepareStubs({ fileDoesNotExist: true });
$$.SANDBOX.stub(fs, 'readJson').callsFake(async () => ({
result: { notASfdxAuthUrl: 'force://PlatformCLI::CoffeeAndBacon@su0503.my.salesforce.com' },
}));
})
.stdout()
.command(['auth:sfdxurl:store', '-f', 'path/to/key.json', '--json'])
.it("should error out when it doesn't find a url in a JSON file", (ctx) => {
const response = parseJsonError(ctx.stdout);
expect(response.status).to.equal(1);
// eslint-disable-next-line no-console
expect(response.message).to.equal(
'Error getting the auth URL from file path/to/key.json. Please ensure it meets the description shown in the documentation for this command.'
);
});

test
.do(async () => prepareStubs())
.stdout()
Expand Down

0 comments on commit 11535e1

Please sign in to comment.