Skip to content

Commit

Permalink
fix: error message for display + accessToken
Browse files Browse the repository at this point in the history
  • Loading branch information
mshanemc committed Jan 25, 2021
1 parent 9e476f1 commit 3464ab3
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 3 deletions.
4 changes: 3 additions & 1 deletion messages/display.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
{
"description": "displays information about a user of a scratch org",
"examples": ["sfdx force:user:display", "sfdx force:user:display -u [email protected] --json"]
"examples": ["sfdx force:user:display", "sfdx force:user:display -u [email protected] --json"],
"accessTokenError": "This command does not accept an access token for a username",
"accessTokenAction": "Use a username or an alias"
}
8 changes: 6 additions & 2 deletions src/commands/force/user/display.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import * as os from 'os';
import { SfdxCommand } from '@salesforce/command';
import { Aliases, AuthFields, AuthInfo, Connection, Logger, Messages } from '@salesforce/core';
import { Aliases, AuthFields, AuthInfo, Connection, Logger, Messages, SfdxError, sfdc } from '@salesforce/core';
import { getString } from '@salesforce/ts-types';

Messages.importMessagesDirectory(__dirname);
Expand All @@ -34,7 +34,11 @@ export class UserDisplayCommand extends SfdxCommand {

public async run(): Promise<Result> {
this.logger = await Logger.child(this.constructor.name);

if (sfdc.matchesAccessToken(this.flags.targetusername)) {
throw new SfdxError(messages.getMessage('accessTokenError'), 'accessTokenError', [
messages.getMessage('accessTokenAction'),
]);
}
const username: string = this.org.getUsername();
const userAuthDataArray: AuthInfo[] = await this.org.readUserAuthFiles();
// userAuthDataArray contains all of the Org's users AuthInfo, we just need the default or -u, which is in the username variable
Expand Down
16 changes: 16 additions & 0 deletions test/commands/user/display.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,4 +114,20 @@ describe('force:user:display', () => {
const result = JSON.parse(ctx.stdout).result;
expect(result).to.deep.equal(expected);
});

test
.stdout()
.command([
'force:user:display',
'--json',
'--targetusername',
'00D54000000GxYk!ARwAQOZEBxYvKxKlNJfvJEGyj7fNj6TA61Fn5RxJzaYm79hR9IYjx2x147a2GH2DGtne21DW.g_8DD0rzNF.COIAXcmq0FfJ',
'--targetdevhubusername',
'[email protected]',
])
.it('should throw when username is an accessToken', (ctx) => {
const response = JSON.parse(ctx.stdout);
expect(response.status).to.equal(1);
expect(response.name).to.equal('accessTokenError');
});
});

0 comments on commit 3464ab3

Please sign in to comment.