-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
affa27c
commit d6c9d5d
Showing
6 changed files
with
91 additions
and
7 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
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 |
---|---|---|
|
@@ -22,6 +22,10 @@ You can also create a JSON file that has a top-level property named sfdxAuthUrl | |
|
||
Path to a file that contains the Salesforce DX authorization URL. | ||
|
||
# flags.sfdx-url-stdin.summary | ||
|
||
Read sfdx auth url from stdin | ||
|
||
# examples | ||
|
||
- Authorize an org using the SFDX authorization URL in the files/authFile.json file: | ||
|
@@ -31,3 +35,7 @@ Path to a file that contains the Salesforce DX authorization URL. | |
- Similar to previous example, but set the org as your default and give it an alias MyDefaultOrg: | ||
|
||
<%= config.bin %> <%= command.id %> --sfdx-url-file files/authFile.json --set-default --alias MyDefaultOrg | ||
|
||
- Authorize an org reading the SFDX authorization URL from stdin: | ||
|
||
echo 'force://PlatformCLI::[email protected]' | <%= config.bin %> <%= command.id %> --sfdx-url-stdin --set-default --alias MyDefaultOrg |
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 |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/* | ||
* Copyright (c) 2023, salesforce.com, inc. | ||
* All rights reserved. | ||
* Licensed under the BSD 3-Clause license. | ||
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause | ||
*/ | ||
export function read(): Promise<string | undefined> { | ||
return new Promise((resolve) => { | ||
const stdin = process.openStdin(); | ||
stdin.setEncoding('utf-8'); | ||
|
||
let data = ''; | ||
stdin.on('data', (chunk) => { | ||
data += chunk; | ||
}); | ||
|
||
stdin.on('end', () => { | ||
resolve(data); | ||
}); | ||
|
||
if (stdin.isTTY) { | ||
resolve(''); | ||
} | ||
}); | ||
} |
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 |
---|---|---|
|
@@ -13,6 +13,7 @@ import { Config } from '@oclif/core'; | |
import { StubbedType, stubInterface } from '@salesforce/ts-sinon'; | ||
import { SfCommand } from '@salesforce/sf-plugins-core'; | ||
import LoginSfdxUrl from '../../../../src/commands/org/login/sfdx-url'; | ||
import * as stdin from '../../../../src/stdin'; | ||
|
||
interface Options { | ||
authInfoCreateFails?: boolean; | ||
|
@@ -91,7 +92,7 @@ describe('org:login:sfdx-url', () => { | |
const response = await store.run(); | ||
expect.fail(`Should have thrown an error. Response: ${JSON.stringify(response)}`); | ||
} catch (e) { | ||
expect((e as Error).message).to.includes('Error getting the auth URL from file'); | ||
expect((e as Error).message).to.includes('Error retrieving the auth URL'); | ||
} | ||
}); | ||
|
||
|
@@ -213,4 +214,23 @@ describe('org:login:sfdx-url', () => { | |
await store.run(); | ||
expect(authInfoStub.save.callCount).to.equal(1); | ||
}); | ||
|
||
it('should return auth fields when reading auth url from stdin', async () => { | ||
await prepareStubs({ fileDoesNotExist: true }); | ||
$$.SANDBOX.stub(stdin, 'read').resolves('force://PlatformCLI::[email protected]'); | ||
const store = new LoginSfdxUrl(['--sfdx-url-stdin', '--json'], {} as Config); | ||
const response = await store.run(); | ||
expect(response.username).to.equal(testData.username); | ||
}); | ||
|
||
it('should throw error when passing both sfdx-url-stdin and sfdx-url-file', async () => { | ||
const store = new LoginSfdxUrl(['--sfdx-url-stdin', '--sfdx-url-file', 'path/to/key.txt', '--json'], {} as Config); | ||
|
||
try { | ||
const response = await store.run(); | ||
expect.fail(`Should have thrown an error. Response: ${JSON.stringify(response)}`); | ||
} catch (e) { | ||
expect((e as Error).message).to.includes('--sfdx-url-file cannot also be provided when using --sfdx-url-stdin'); | ||
} | ||
}); | ||
}); |