Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import Secrets from './config-manager-pull-secrets';
import ServiceObjects from './config-manager-pull-service-objects';
import Services from './config-manager-pull-services';
import Terms from './config-manager-pull-terms-and-conditions';
import Test from './config-manager-pull-test';
import Test from '../../conn/conn-test';
import Themes from './config-manager-pull-themes';
import UiConfig from './config-manager-pull-uiConfig';
import Variables from './config-manager-pull-variables';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import Schedules from './config-manager-push-schedules';
import SecretMappings from './config-manager-push-secret-mappings';
import ServiceObjects from './config-manager-push-service-objects';
import TermsAndConditions from './config-manager-push-terms-and-conditions';
import Test from '../../conn/conn-test';
import Themes from './config-manager-push-themes';
import UiConfig from './config-manager-push-ui-config';

Expand Down Expand Up @@ -57,6 +58,7 @@ export default function setup() {
program.addCommand(CustomNodes().name('custom-nodes'));
program.addCommand(CSP().name('csp'));
program.addCommand(Restart().name('restart'));
program.addCommand(Test().name('test'));
program.addCommand(Journeys().name('journeys'));

return program;
Expand Down
26 changes: 26 additions & 0 deletions src/cli/conn/conn-test.ts
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;
}
3 changes: 3 additions & 0 deletions src/cli/conn/conn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import DeleteCmd from './conn-delete.js';
import DescribeCmd from './conn-describe.js';
import ListCmd from './conn-list.js';
import SaveCmd from './conn-save.js';
import TestCmd from './conn-test.js';

export default function setup() {
const program = new FrodoStubCommand('conn')
Expand All @@ -22,5 +23,7 @@ export default function setup() {

program.addCommand(ListCmd().name('list'));

program.addCommand(TestCmd().name('test'));

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.
"
`;
11 changes: 11 additions & 0 deletions test/client_cli/en/config-manager-push-test.test.js

Copy link
Copy Markdown

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 test as well

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
"
`;
73 changes: 73 additions & 0 deletions test/e2e/config-manager-push-test.e2e.test.js

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm thinking we should have a test for testFail as well where we attempt connecting using invalid credentials. That would look something like this:

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 config-manager-pull-test and conn-test to match these tests exactly, with the only difference being the command being run.

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

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use await testSuccess(CMD, env); here

});
});
Loading