Skip to content

Commit b86589b

Browse files
Merge pull request #21 from salesforcecli/sm/user-display-access-token
fix: error message for display + accessToken
2 parents 2eb63f6 + 6cd7bb9 commit b86589b

File tree

3 files changed

+25
-3
lines changed

3 files changed

+25
-3
lines changed

messages/display.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
{
22
"description": "displays information about a user of a scratch org",
3-
"examples": ["sfdx force:user:display", "sfdx force:user:display -u me@my.org --json"]
3+
"examples": ["sfdx force:user:display", "sfdx force:user:display -u me@my.org --json"],
4+
"accessTokenError": "This command doesn't accept an access token for a username.",
5+
"accessTokenAction": "Specify a username or an alias."
46
}

src/commands/force/user/display.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

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

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

3535
public async run(): Promise<Result> {
3636
this.logger = await Logger.child(this.constructor.name);
37-
37+
if (sfdc.matchesAccessToken(this.flags.targetusername)) {
38+
throw new SfdxError(messages.getMessage('accessTokenError'), 'accessTokenError', [
39+
messages.getMessage('accessTokenAction'),
40+
]);
41+
}
3842
const username: string = this.org.getUsername();
3943
const userAuthDataArray: AuthInfo[] = await this.org.readUserAuthFiles();
4044
// userAuthDataArray contains all of the Org's users AuthInfo, we just need the default or -u, which is in the username variable

test/commands/user/display.test.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,4 +114,20 @@ describe('force:user:display', () => {
114114
const result = JSON.parse(ctx.stdout).result;
115115
expect(result).to.deep.equal(expected);
116116
});
117+
118+
test
119+
.stdout()
120+
.command([
121+
'force:user:display',
122+
'--json',
123+
'--targetusername',
124+
'00D54000000GxYk!ARwAQOZEBxYvKxKlNJfvJEGyj7fNj6TA61Fn5RxJzaYm79hR9IYjx2x147a2GH2DGtne21DW.g_8DD0rzNF.COIAXcmq0FfJ',
125+
'--targetdevhubusername',
126+
'devhub@test.com',
127+
])
128+
.it('should throw when username is an accessToken', (ctx) => {
129+
const response = JSON.parse(ctx.stdout);
130+
expect(response.status).to.equal(1);
131+
expect(response.name).to.equal('accessTokenError');
132+
});
117133
});

0 commit comments

Comments
 (0)