|
16 | 16 |
|
17 | 17 | import { Connection, Messages, User } from '@salesforce/core'; |
18 | 18 | import { MockTestOrgData, TestContext } from '@salesforce/core/testSetup'; |
| 19 | +import { stubSfCommandUx } from '@salesforce/sf-plugins-core'; |
19 | 20 | import { assert, expect } from 'chai'; |
20 | 21 | // dirty import to stub something we don't want to export from sfdx-core |
21 | 22 | import { SecureBuffer } from '../../../node_modules/@salesforce/core/lib/crypto/secureBuffer.js'; |
@@ -83,16 +84,44 @@ describe('org:generate:password', () => { |
83 | 84 | expect(result).to.deep.equal(expected); |
84 | 85 | expect(queryStub.callCount).to.equal(1); |
85 | 86 | }); |
86 | | - it('should generate a new passsword of length 12', async () => { |
87 | | - await prepareStubs(false, false); |
88 | | - const result = (await GenerateUserPasswordCommand.run([ |
89 | | - '--target-org', |
90 | | - testOrg.username, |
91 | | - '-l', |
92 | | - '12', |
93 | | - '--json', |
94 | | - ])) as PasswordData; |
95 | | - expect(result.password.length).to.equal(12); |
| 87 | + |
| 88 | + describe('--length handling', () => { |
| 89 | + it('when no length is specified, password should default to length 20', async () => { |
| 90 | + await prepareStubs(false, false); |
| 91 | + const result = (await GenerateUserPasswordCommand.run([ |
| 92 | + '--target-org', |
| 93 | + testOrg.username, |
| 94 | + '--json', |
| 95 | + ])) as PasswordData; |
| 96 | + |
| 97 | + expect(result.password.length).to.equal(20); |
| 98 | + }); |
| 99 | + |
| 100 | + it('when length <20 is specified, logs info-level message and defaults to 20', async () => { |
| 101 | + await prepareStubs(false, false); |
| 102 | + const uxStubs = stubSfCommandUx($$.SANDBOX); |
| 103 | + const result = (await GenerateUserPasswordCommand.run([ |
| 104 | + '--target-org', |
| 105 | + testOrg.username, |
| 106 | + '--length', |
| 107 | + '12', |
| 108 | + '--json', |
| 109 | + ])) as PasswordData; |
| 110 | + expect(result.password.length).to.equal(20); |
| 111 | + expect(uxStubs.warn.args.flat()).to.include(messages.getMessage('defaultingToLength20Password')); |
| 112 | + }); |
| 113 | + |
| 114 | + it('when length >20 is specified, length is used as-is', async () => { |
| 115 | + await prepareStubs(false, false); |
| 116 | + const result = (await GenerateUserPasswordCommand.run([ |
| 117 | + '--target-org', |
| 118 | + testOrg.username, |
| 119 | + '--length', |
| 120 | + '50', |
| 121 | + '--json', |
| 122 | + ])) as PasswordData; |
| 123 | + expect(result.password.length).to.equal(50); |
| 124 | + }); |
96 | 125 | }); |
97 | 126 | it('should throw the correct error with warning message', async () => { |
98 | 127 | await prepareStubs(true); |
|
0 commit comments