Skip to content

Commit e5c5686

Browse files
committed
Added test to validate access_keys leading space
Signed-off-by: Aayush Chouhan <[email protected]>
1 parent 3d4b6ba commit e5c5686

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

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

+39
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,28 @@ 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;
108+
const account_options = { config_root, name, uid, gid, secret_key};
109+
const action = ACTIONS.ADD;
110+
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);
115+
});
116+
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;
119+
const account_options = { config_root, name, uid, gid, access_key};
120+
const action = ACTIONS.ADD;
121+
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);
126+
});
127+
106128
it('should fail - cli update account invalid access_key - invalid size', async () => {
107129
const { type, secret_key, name, new_buckets_path, uid, gid } = defaults;
108130
const account_options = { config_root, access_key: 'abc', secret_key, name, new_buckets_path, uid, gid };
@@ -2210,6 +2232,23 @@ async function exec_manage_cli_add_empty_option(command, option) {
22102232
return res;
22112233
}
22122234

2235+
/**
2236+
* exec_manage_cli_add_leading_space_option adds a flag with value having leading space
2237+
* @param {string} command
2238+
* @param {string} option
2239+
* @param {string} value
2240+
*/
2241+
async function exec_manage_cli_add_leading_space_option(command, option, value) {
2242+
const changed_command = command + ` --${option}= ${value}`;
2243+
let res;
2244+
try {
2245+
res = await os_util.exec(changed_command, { return_stdout: true });
2246+
} catch (e) {
2247+
res = e;
2248+
}
2249+
return res;
2250+
}
2251+
22132252
/**
22142253
* create_command would create the string needed to run the CLI command
22152254
* @param {string} type

0 commit comments

Comments
 (0)