Skip to content

Commit c270b91

Browse files
committed
Updated the jsdoc and some logics
Signed-off-by: Aayush Chouhan <[email protected]>
1 parent 0b8a0a1 commit c270b91

File tree

2 files changed

+20
-17
lines changed

2 files changed

+20
-17
lines changed

src/manage_nsfs/manage_nsfs_validations.js

+11-4
Original file line numberDiff line numberDiff line change
@@ -212,15 +212,22 @@ function validate_boolean_string_value(value) {
212212
}
213213

214214
/**
215-
* validate_no_leading_whitespace validates that a given value is not empty or whitespace-only
215+
* validate_no_leading_whitespace validates the given value does not contain leading whitespace or is not entirely whitespace.
216+
*
217+
* ### CLI Parsing Behavior:
218+
* When passing arguments via CLI, if a flag's value starts with a space or consists only of whitespace,
219+
* the shell may treat it differently:
220+
* - **Leading spaces** might be preserved when quoted (`--access_key=" 123abc"`).
221+
* - **Unquoted values with spaces** may cause incorrect parsing (`--access_key= 123abc` is interpreted as an empty value).
222+
*
216223
* @param {string} option
217224
* @param {string} value
218225
* @throws {ManageCLIError}
219226
*/
220227
function validate_no_leading_whitespace(option, value) {
221228
// ensure values are not empty or whitespace only strings
222229
if (value.trim() === '') {
223-
const details = `flag ${option} cannot have an empty value or contain only whitespace. Please provide a valid value for ${option}`;
230+
const details = `flag ${option} cannot start with a space, as leading whitespace is not allowed. Please provide a valid value for ${option} without leading spaces`;
224231
throw_cli_error(ManageCLIError.InvalidArgument, details);
225232
}
226233
}
@@ -588,8 +595,8 @@ function _validate_access_keys(access_key, secret_key) {
588595
throw_cli_error(ManageCLIError.MissingAccountAccessKeyFlag);
589596
}
590597

591-
// checking access_key and secret_key do not contain only whitespace
592-
if (access_key && secret_key) {
598+
// checking access_key and secret_key do not contain leading space
599+
if (access_key !== undefined && secret_key !== undefined) {
593600
validate_no_leading_whitespace('access_key', access_key);
594601
validate_no_leading_whitespace('secret_key', secret_key);
595602
}

src/test/unit_tests/jest_tests/test_nc_nsfs_account_cli.test.js

+9-13
Original file line numberDiff line numberDiff line change
@@ -103,26 +103,22 @@ describe('manage nsfs cli account flow', () => {
103103
assert_account(account_symlink, account_options);
104104
});
105105

106-
it('should fail - cli create account invalid access_key(leading space in access_key)', async () => {
107-
const { type, name, uid, gid, secret_key } = defaults;
106+
it('should fail - cli create account invalid access_key (leading space in access_key)', async () => {
107+
const { type, name, uid, gid, access_key, secret_key } = defaults;
108108
const account_options = { config_root, name, uid, gid, secret_key};
109109
const action = ACTIONS.ADD;
110110
const command = create_command(type, action, account_options);
111-
const flag = 'access_key';
112-
const value = ' 12345678912345678ABC'; // leading space for access_key
113-
const res = await exec_manage_cli_add_leading_space_option(command, flag, value);
114-
expect(JSON.parse(res.stdout).error.message).toBe(ManageCLIError.InvalidArgument.message);
111+
const res = await exec_manage_cli_add_leading_space_option(command, 'access_key', access_key);
112+
expect(JSON.parse(res.stdout).error.code).toBe(ManageCLIError.InvalidArgument.code);
115113
});
116114

117-
it('should fail - cli create account invalid secret_key(leading space in secret_key)', async () => {
118-
const { type, name, uid, gid, access_key } = defaults;
115+
it('should fail - cli create account invalid secret_key (leading space in secret_key)', async () => {
116+
const { type, name, uid, gid, access_key, secret_key } = defaults;
119117
const account_options = { config_root, name, uid, gid, access_key};
120118
const action = ACTIONS.ADD;
121119
const command = create_command(type, action, account_options);
122-
const flag = 'secret_key';
123-
const value = ' a234567891234567891212345678912345678912'; // leading space for secret_key
124-
const res = await exec_manage_cli_add_leading_space_option(command, flag, value);
125-
expect(JSON.parse(res.stdout).error.message).toBe(ManageCLIError.InvalidArgument.message);
120+
const res = await exec_manage_cli_add_leading_space_option(command, 'secret_key', secret_key);
121+
expect(JSON.parse(res.stdout).error.code).toBe(ManageCLIError.InvalidArgument.code);
126122
});
127123

128124
it('should fail - cli update account invalid access_key - invalid size', async () => {
@@ -2233,7 +2229,7 @@ async function exec_manage_cli_add_empty_option(command, option) {
22332229
}
22342230

22352231
/**
2236-
* exec_manage_cli_add_leading_space_option adds a flag with value having leading space
2232+
* exec_manage_cli_add_leading_space_option modifies the command by appending a flag with a value that includes a leading space to test CLI parsing behavior
22372233
* @param {string} command
22382234
* @param {string} option
22392235
* @param {string} value

0 commit comments

Comments
 (0)