-
Notifications
You must be signed in to change notification settings - Fork 2
feat: add config-manager push test #124
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| import { getTokens } from '../../ops/AuthenticateOps'; | ||
| import { printMessage, verboseMessage } from '../../utils/Console'; | ||
| import { FrodoCommand } from '../FrodoCommand'; | ||
|
|
||
| export default function setup() { | ||
| const program = new FrodoCommand('frodo conn test'); | ||
| program | ||
| .description('Test connection and authentication.') | ||
| .action(async (host, realm, user, password, options, command) => { | ||
| command.handleDefaultArgsAndOpts( | ||
| host, | ||
| realm, | ||
| user, | ||
| password, | ||
| options, | ||
| command | ||
| ); | ||
| verboseMessage('Test connection and authentication'); | ||
| if (await getTokens()) { | ||
| printMessage('Connected and authenticated successfully'); | ||
| } else { | ||
| process.exit(1); | ||
| } | ||
| }); | ||
| return program; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| // Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
|
||
| exports[`CLI help interface for 'test' should be expected english 1`] = ` | ||
| "Usage: frodo config-manager push test [options] [host] [realm] [username] [password] | ||
|
|
||
| [Experimental] Test connection and authentication. | ||
|
|
||
| Arguments: | ||
| host AM base URL, e.g.: https://cdk.iam.example.com/am. To use a | ||
| connection profile, just specify a unique substring or | ||
| alias. | ||
| realm Realm. Specify realm as '/' for the root realm or 'realm' or | ||
| '/parent/child' otherwise. (default: "alpha" for Identity | ||
| Cloud tenants, "/" otherwise.) | ||
| username Username to login with. Must be an admin user with | ||
| appropriate rights to manage authentication journeys/trees. | ||
| If given without a password, and it matches the username | ||
| already stored in the connection profile for the target | ||
| host, frodo uses that profile's stored password instead of | ||
| requiring it on the command line. | ||
| password Password. | ||
|
|
||
| Options: | ||
| -h, --help Help | ||
| -hh, --help-more Help with all options. | ||
| -hhh, --help-all Help with all options, environment variables, and usage | ||
| examples. | ||
| " | ||
| `; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| import cp from 'child_process'; | ||
| import { promisify } from 'util'; | ||
|
|
||
| const exec = promisify(cp.exec); | ||
| const CMD = 'frodo config-manager push test --help'; | ||
| const { stdout } = await exec(CMD); | ||
|
|
||
| test("CLI help interface for 'test' should be expected english", async () => { | ||
| expect(stdout).toMatchSnapshot(); | ||
| }); | ||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| // Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
|
||
| exports[`frodo config-manager push "frodo config-manager push test": should receive access tokens" 1`] = `""`; | ||
|
|
||
| exports[`frodo config-manager push "frodo config-manager push test": should receive access tokens" 2`] = ` | ||
| "Experimental feature in use: 'frodo config-manager push test'. This feature may change without notice. | ||
| Authenticated successfully | ||
| " | ||
| `; |
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm thinking we should have a test for test('"frodo config-manager push test": should fail connection with invalid credentials"', async () => {
const CMD = `frodo config-manager push test ${c.host} ${c.realm} username password`;
await testFail(CMD, env);
});The other thing is we'll want the tests for |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
| /** | ||
| * Follow this process to write e2e tests for the CLI project: | ||
| * | ||
| * 1. Test if all the necessary mocks for your tests already exist. | ||
| * In mock mode, run the command you want to test with the same arguments | ||
| * and parameters exactly as you want to test it, for example: | ||
| * | ||
| * $ FRODO_MOCK=1 frodo conn save https://openam-frodo-dev.forgeblocks.com/am volker.scheuber@forgerock.com Sup3rS3cr3t! | ||
| * | ||
| * If your command completes without errors and with the expected results, | ||
| * all the required mocks already exist and you are good to write your | ||
| * test and skip to step #4. | ||
| * | ||
| * If, however, your command fails and you see errors like the one below, | ||
| * you know you need to record the mock responses first: | ||
| * | ||
| * [Polly] [adapter:node-http] Recording for the following request is not found and `recordIfMissing` is `false`. | ||
| * | ||
| * 2. Record mock responses for your exact command. | ||
| * In mock record mode, run the command you want to test with the same arguments | ||
| * and parameters exactly as you want to test it, for example: | ||
| * | ||
| * $ FRODO_MOCK=record frodo conn save https://openam-frodo-dev.forgeblocks.com/am volker.scheuber@forgerock.com Sup3rS3cr3t! | ||
| * | ||
| * Wait until you see all the Polly instances (mock recording adapters) have | ||
| * shutdown before you try to run step #1 again. | ||
| * Messages like these indicate mock recording adapters shutting down: | ||
| * | ||
| * Polly instance 'conn/4' stopping in 3s... | ||
| * Polly instance 'conn/4' stopping in 2s... | ||
| * Polly instance 'conn/save/3' stopping in 3s... | ||
| * Polly instance 'conn/4' stopping in 1s... | ||
| * Polly instance 'conn/save/3' stopping in 2s... | ||
| * Polly instance 'conn/4' stopped. | ||
| * Polly instance 'conn/save/3' stopping in 1s... | ||
| * Polly instance 'conn/save/3' stopped. | ||
| * | ||
| * 3. Validate your freshly recorded mock responses are complete and working. | ||
| * Re-run the exact command you want to test in mock mode (see step #1). | ||
| * | ||
| * 4. Write your test. | ||
| * Make sure to use the exact command including number of arguments and params. | ||
| * | ||
| * 5. Commit both your test and your new recordings to the repository. | ||
| * Your tests are likely going to reside outside the frodo-lib project but | ||
| * the recordings must be committed to the frodo-lib project. | ||
| */ | ||
|
|
||
| /* | ||
| FRODO_MOCK=record FRODO_NO_CACHE=1 FRODO_HOST=https://openam-frodo-dev.forgeblocks.com/am frodo config-manager push test | ||
|
|
||
| */ | ||
|
|
||
|
|
||
| import { getEnv } from './utils/TestUtils'; | ||
| import { connection as c } from './utils/TestConfig'; | ||
| import cp from 'child_process'; | ||
| import { promisify } from 'util'; | ||
|
|
||
| process.env['FRODO_MOCK'] = '1'; | ||
| process.env['FRODO_CONNECTION_PROFILES_PATH'] = | ||
| './test/e2e/env/Connections.json'; | ||
| const env = getEnv(c); | ||
| const exec = promisify(cp.exec); | ||
|
|
||
| describe('frodo config-manager push', () => { | ||
| test('"frodo config-manager push test": should receive access tokens"', async () => { | ||
| const CMD = `frodo config-manager push test`; | ||
| const output = await exec(CMD, env); | ||
| expect(output.stdout).toMatchSnapshot(); | ||
| expect(output.stderr).toMatchSnapshot(); | ||
|
Comment on lines
+69
to
+71
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use |
||
| }); | ||
| }); | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We'll need a test like this for
frodo conn testas well