Skip to content
Merged
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
/*
** Copyright (c) 2024 Oracle and/or its affiliates. All rights reserved.
** Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
*/

'use strict';

const AuthenticateActionResult = require('../../../../src/services/actionresult/AuthenticateActionResult');
const SetupOutputHandler = require('../../../../src/commands/account/setup/SetupOutputHandler');

const AUTH_MODE = {
OAUTH: 'OAUTH',
REUSE: 'REUSE',
};

const accountInfoMock = {
companyName: 'companyName',
roleName: 'roleName',
authId: 'authId',
};

describe('parse()', () => {
const originalProcessEnv = process.env;

let setupOutputHandler;
let consoleLoggerResultMock = jest.fn();
let consoleoggerWarningMock = jest.fn();

beforeEach(() => {
consoleLoggerResultMock = jest.fn();
consoleoggerWarningMock = jest.fn();
const ConsoleLogger = jest.fn(() => ({
result: consoleLoggerResultMock,
warning: consoleoggerWarningMock,
}));
setupOutputHandler = new SetupOutputHandler({ log: new ConsoleLogger() });
});

describe('log result with password rotation warning', () => {
beforeEach(() => {
process.env = {
...originalProcessEnv,
SUITECLOUD_FALLBACK_PASSKEY: 'SUITECLOUD_FALLBACK_PASSKEY',
}
});

afterEach(() => {
process.env = originalProcessEnv;
});

it.each([['new', AUTH_MODE.OAUTH], ['reuse', AUTH_MODE.OAUTH]])('should show %s authorization result and password rotation warning', (modeString, mode) => {
const authenticateActionResult = AuthenticateActionResult.Builder.success()
.withMode(mode)
.withAuthId('authId')
.withAccountInfo(accountInfoMock)
.build();

setupOutputHandler.parse(authenticateActionResult);

expect(consoleLoggerResultMock).toHaveBeenNthCalledWith(1, 'The account has been authenticated for the following company and role: companyName [roleName]. This project will use the authentication ID "authId" as default. If you want to change your default credentials, run "suitecloud account:setup" again.',);
expect(consoleLoggerResultMock).toHaveBeenNthCalledWith(2, 'The account has been successfully set up.')
expect(consoleoggerWarningMock).toHaveBeenNthCalledWith(1, 'Authentication is currently using the credentials key in fallback mode. If you choose to continue using fallback mode, you should update the key regularly, ideally every week.');
});
});

it.each([['new', AUTH_MODE.OAUTH], ['reuse', AUTH_MODE.OAUTH]])('should show %s authorization result without password rotation warning', (modeString, mode) => {
const authenticateActionResult = AuthenticateActionResult.Builder.success()
.withMode(mode)
.withAuthId('authId')
.withAccountInfo(accountInfoMock)
.build();

setupOutputHandler.parse(authenticateActionResult);

expect(consoleLoggerResultMock).toHaveBeenNthCalledWith(1, 'The account has been authenticated for the following company and role: companyName [roleName]. This project will use the authentication ID "authId" as default. If you want to change your default credentials, run "suitecloud account:setup" again.',);
expect(consoleLoggerResultMock).toHaveBeenNthCalledWith(2, 'The account has been successfully set up.')
expect(consoleoggerWarningMock).toHaveBeenCalledTimes(0);
});
});
1 change: 1 addition & 0 deletions packages/node-cli/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@
"COMMAND_SETUPACCOUNT_QUESTIONS_CHOICES_SELECT_AUTHID_EXISTING_AUTH_ID_URL_NOT_PRODUCTION": "| {0}",
"COMMAND_SETUPACCOUNT_QUESTIONS_URL": "Enter your NetSuite domain:",
"COMMAND_SETUPACCOUNT_MESSAGES_CANCEL_SETUP": "The setupaccount process has been canceled.",
"COMMAND_SETUPACCOUNT_MESSAGES_ROTATE_PASSWORD_WARNING": "Authentication is currently using the credentials key in fallback mode. If you choose to continue using fallback mode, you should update the key regularly, ideally every week.",
"COMMAND_SETUPACCOUNT_MESSAGES_SELECT_CONFIGURED_AUTHID": "Select a configured authentication ID:",
"COMMAND_SETUPACCOUNT_OUTPUT_NEW_OAUTH": "The account has been authenticated for the following company and role: {0} [{1}]. This project will use the authentication ID \"{2}\" as default. If you want to change your default credentials, run \"suitecloud account:setup\" again.",
"COMMAND_SETUPACCOUNT_OUTPUT_REUSED_AUTH_ID": "This project will use the authentication ID \"{0}\" as default for the following company and role: {1} [{2}]. If you want to change your default credentials, run \"suitecloud account:setup\" again.",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const BaseOutputHandler = require('../../base/BaseOutputHandler');
const NodeTranslationService = require('../../../services/NodeTranslationService');

const {
COMMAND_SETUPACCOUNT: { OUTPUT },
COMMAND_SETUPACCOUNT: { MESSAGES, OUTPUT },
UTILS: { AUTHENTICATION },
} = require('../../../services/TranslationKeys');

Expand Down Expand Up @@ -47,6 +47,11 @@ module.exports = class SetupOutputHandler extends BaseOutputHandler {

this._log.result(resultMessage);
this._log.result(NodeTranslationService.getMessage(AUTHENTICATION.SUCCESS_SETUP));

if (actionResult.isSuccess() && process.env.SUITECLOUD_FALLBACK_PASSKEY) {
this._log.warning(NodeTranslationService.getMessage(MESSAGES.ROTATE_PASSWORD_WARNING));
}

return actionResult;
}
};
1 change: 1 addition & 0 deletions packages/node-cli/src/services/TranslationKeys.js
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,7 @@ module.exports = {
},
MESSAGES: {
CANCEL_SETUP: 'COMMAND_SETUPACCOUNT_MESSAGES_CANCEL_SETUP',
ROTATE_PASSWORD_WARNING: 'COMMAND_SETUPACCOUNT_MESSAGES_ROTATE_PASSWORD_WARNING',
SELECT_CONFIGURED_AUTHID: 'COMMAND_SETUPACCOUNT_MESSAGES_SELECT_CONFIGURED_AUTHID',
},
OUTPUT: {
Expand Down