generated from salesforcecli/plugin-template
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #18 from salesforcecli/wr/savePasswordToFile
chore: save encrypted password to authfile
- Loading branch information
Showing
8 changed files
with
222 additions
and
90 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
"description": "create a user for a scratch org", | ||
"examples": [ | ||
"sfdx force:user:create", | ||
"sfdx force:user:create -a testuser1 -f config/project-user-def.json", | ||
"sfdx force:user:create -a testuser1 -f config/project-user-def.json profileName='Chatter Free User'", | ||
"sfdx force:user:create [email protected] [email protected] permsets=DreamHouse", | ||
"sfdx force:user:create -f config/project-user-def.json [email protected] generatepassword=true" | ||
], | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,7 +8,7 @@ | |
/* eslint-disable @typescript-eslint/ban-ts-ignore */ | ||
|
||
import { $$, expect, test } from '@salesforce/command/lib/test'; | ||
import { Aliases, Connection, DefaultUserFields, fs, Org, User } from '@salesforce/core'; | ||
import { Aliases, Connection, DefaultUserFields, fs, Logger, Org, User } from '@salesforce/core'; | ||
import { stubMethod } from '@salesforce/ts-sinon'; | ||
import { IConfig } from '@oclif/config'; | ||
import UserCreateCommand from '../../../src/commands/force/user/create'; | ||
|
@@ -61,7 +61,7 @@ describe('force:user:create', () => { | |
}); | ||
}); | ||
|
||
async function prepareStubs(throws: { license?: boolean; duplicate?: boolean } = {}, readsFile = false) { | ||
async function prepareStubs(throws: { license?: boolean; duplicate?: boolean } = {}, readsFile?) { | ||
stubMethod($$.SANDBOX, Org.prototype, 'getConnection').callsFake(() => Connection.prototype); | ||
stubMethod($$.SANDBOX, DefaultUserFields, 'create').resolves({ | ||
getFields: () => { | ||
|
@@ -94,7 +94,11 @@ describe('force:user:create', () => { | |
} | ||
|
||
if (readsFile) { | ||
stubMethod($$.SANDBOX, fs, 'readJson').resolves({ generatepassword: true }); | ||
stubMethod($$.SANDBOX, Connection.prototype, 'query').resolves({ | ||
records: [{ Id: '12345678' }], | ||
}); | ||
stubMethod($$.SANDBOX, Logger.prototype, 'debug'); | ||
stubMethod($$.SANDBOX, fs, 'readJson').resolves(readsFile); | ||
} | ||
} | ||
|
||
|
@@ -131,7 +135,7 @@ describe('force:user:create', () => { | |
|
||
test | ||
.do(async () => { | ||
await prepareStubs({}, true); | ||
await prepareStubs({}, { generatepassword: true }); | ||
}) | ||
.stdout() | ||
.command([ | ||
|
@@ -165,6 +169,48 @@ describe('force:user:create', () => { | |
expect(result).to.deep.equal(expected); | ||
}); | ||
|
||
test | ||
.do(async () => { | ||
await prepareStubs({}, { generatepassword: true, profileName: 'System Administrator' }); | ||
}) | ||
.stdout() | ||
.command([ | ||
'force:user:create', | ||
'--json', | ||
'--definitionfile', | ||
'parent/child/file.json', | ||
'--targetusername', | ||
'[email protected]', | ||
'--targetdevhubusername', | ||
'[email protected]', | ||
'[email protected]', | ||
'generatepassword=false', | ||
"profileName='Chatter Free User'", | ||
]) | ||
// we set generatepassword=false in the varargs, in the definitionfile we have generatepassword=true, so we SHOULD NOT generate a password | ||
// we should override the profileName with 'Chatter Free User' | ||
.it( | ||
'will merge fields from the cli args, and the definitionfile correctly, preferring cli args, cli args > file > default', | ||
(ctx) => { | ||
const expected = { | ||
alias: 'testAlias', | ||
email: '[email protected]', | ||
emailEncodingKey: 'UTF-8', | ||
id: '0052D0000043PawWWR', | ||
languageLocaleKey: 'en_US', | ||
lastName: 'User', | ||
localeSidKey: 'en_US', | ||
orgId: 'abc123', | ||
// note the new profileId 12345678 -> Chatter Free User from var args | ||
profileId: '12345678', | ||
timeZoneSidKey: 'America/Los_Angeles', | ||
username: '[email protected]', | ||
}; | ||
const result = JSON.parse(ctx.stdout).result; | ||
expect(result).to.deep.equal(expected); | ||
} | ||
); | ||
|
||
test | ||
.do(async () => { | ||
await prepareStubs({ license: true }, false); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,11 +6,11 @@ | |
*/ | ||
|
||
import { $$, expect, test } from '@salesforce/command/lib/test'; | ||
import { Aliases, Connection, Org } from '@salesforce/core'; | ||
import { Aliases, ConfigAggregator, Connection, Org } from '@salesforce/core'; | ||
import { stubMethod } from '@salesforce/ts-sinon'; | ||
|
||
describe('force:user:list', () => { | ||
async function prepareStubs() { | ||
async function prepareStubs(defaultUser?: boolean) { | ||
stubMethod($$.SANDBOX, Org.prototype, 'getConnection').callsFake(() => Connection.prototype); | ||
stubMethod($$.SANDBOX, Org.prototype, 'readUserAuthFiles').returns([ | ||
{ | ||
|
@@ -28,7 +28,11 @@ describe('force:user:list', () => { | |
}, | ||
]); | ||
stubMethod($$.SANDBOX, Org.prototype, 'getOrgId').returns('abc123'); | ||
stubMethod($$.SANDBOX, Aliases, 'fetch').resolves('testAlias'); | ||
stubMethod($$.SANDBOX, Aliases.prototype, 'getKeysByValue').returns(['testAlias']); | ||
if (defaultUser) { | ||
const cfa = ConfigAggregator.getInstance(); | ||
stubMethod($$.SANDBOX, cfa, 'getLocalConfig').returns({ get: () => 'testAlias' }); | ||
} | ||
stubMethod($$.SANDBOX, Connection.prototype, 'query') | ||
.withArgs('SELECT username, profileid, id FROM User') | ||
.resolves({ | ||
|
@@ -60,6 +64,31 @@ describe('force:user:list', () => { | |
}); | ||
} | ||
|
||
test | ||
.do(async () => { | ||
await prepareStubs(); | ||
}) | ||
.stdout() | ||
.command(['force:user:list', '--json', '--targetusername', 'testUser', '--targetdevhubusername', '[email protected]']) | ||
.it('should display the correct information from the default user', (ctx) => { | ||
// testUser1@test.com is aliased to testUser | ||
const expected = [ | ||
{ | ||
defaultMarker: '', | ||
alias: 'testAlias', | ||
username: '[email protected]', | ||
profileName: 'Analytics Cloud Integration User', | ||
orgId: 'abc123', | ||
accessToken: 'accessToken', | ||
instanceUrl: 'instanceURL', | ||
loginUrl: 'login.test.com', | ||
userId: '0052D0000043PbGQAU', | ||
}, | ||
]; | ||
const result = JSON.parse(ctx.stdout).result; | ||
expect(result).to.deep.equal(expected); | ||
}); | ||
|
||
test | ||
.do(async () => { | ||
await prepareStubs(); | ||
|
@@ -73,7 +102,39 @@ describe('force:user:list', () => { | |
'--targetdevhubusername', | ||
'[email protected]', | ||
]) | ||
.it('should display the correct information from the default user', (ctx) => { | ||
.it('should display the correct information from the default user with alias', (ctx) => { | ||
// testUser1@test.com is aliased to testUser | ||
const expected = [ | ||
{ | ||
defaultMarker: '', | ||
alias: 'testAlias', | ||
username: '[email protected]', | ||
profileName: 'Analytics Cloud Integration User', | ||
orgId: 'abc123', | ||
accessToken: 'accessToken', | ||
instanceUrl: 'instanceURL', | ||
loginUrl: 'login.test.com', | ||
userId: '0052D0000043PbGQAU', | ||
}, | ||
]; | ||
const result = JSON.parse(ctx.stdout).result; | ||
expect(result).to.deep.equal(expected); | ||
}); | ||
|
||
test | ||
.do(async () => { | ||
await prepareStubs(true); | ||
}) | ||
.stdout() | ||
.command([ | ||
'force:user:list', | ||
'--json', | ||
'--targetusername', | ||
'[email protected]', | ||
'--targetdevhubusername', | ||
'[email protected]', | ||
]) | ||
.it('should display the correct information from the default user with alias and it default', (ctx) => { | ||
// testUser1@test.com is aliased to testUser | ||
const expected = [ | ||
{ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -67,6 +67,7 @@ describe('force:user:password:generate', () => { | |
]; | ||
const result = JSON.parse(ctx.stdout).result; | ||
expect(result).to.deep.equal(expected); | ||
expect(authInfoStub.update.callCount).to.equal(2); | ||
}); | ||
|
||
test | ||
|
@@ -77,6 +78,7 @@ describe('force:user:password:generate', () => { | |
const expected = [{ username: '[email protected]', password: 'abc' }]; | ||
const result = JSON.parse(ctx.stdout).result; | ||
expect(result).to.deep.equal(expected); | ||
expect(authInfoStub.update.callCount).to.equal(1); | ||
}); | ||
|
||
test | ||
|
@@ -89,5 +91,6 @@ describe('force:user:password:generate', () => { | |
expect(result.message).to.equal(messages.getMessage('noSelfSetError')); | ||
expect(result.status).to.equal(1); | ||
expect(result.name).to.equal('noSelfSetError'); | ||
expect(authInfoStub.update.callCount).to.equal(0); | ||
}); | ||
}); |
Oops, something went wrong.