@@ -23,6 +23,12 @@ const timeout = 50000;
23
23
const config = require ( '../../../../config' ) ;
24
24
const config_fs_account_options = { show_secrets : true , decrypt_secret_key : true } ;
25
25
26
+ const quoted_type = Object . freeze ( {
27
+ SPACE_ONLY : "s" , // space only
28
+ QUOTE_SPACE : "qs" , // quote then space
29
+ SPACE_QUOTE : "sq" , // space then quote
30
+ } ) ;
31
+
26
32
// eslint-disable-next-line max-lines-per-function
27
33
describe ( 'manage nsfs cli account flow' , ( ) => {
28
34
describe ( 'cli create account' , ( ) => {
@@ -103,6 +109,33 @@ describe('manage nsfs cli account flow', () => {
103
109
assert_account ( account_symlink , account_options ) ;
104
110
} ) ;
105
111
112
+ it ( 'should fail - cli create account invalid new_buckets_path (leading space in new_buckets_path)' , async ( ) => {
113
+ const { type, name, uid, gid, new_buckets_path } = defaults ;
114
+ const account_options = { config_root, name, uid, gid} ; // will add new_buckets_path with leading space later
115
+ const action = ACTIONS . ADD ;
116
+ const command = create_command ( type , action , account_options ) ;
117
+ const res = await exec_manage_cli_add_leading_space_option ( command , 'new_buckets_path' , new_buckets_path , quoted_type . SPACE_ONLY ) ;
118
+ expect ( JSON . parse ( res . stdout ) . error . code ) . toBe ( ManageCLIError . InvalidArgument . code ) ;
119
+ } ) ;
120
+
121
+ it ( 'should fail - cli create account invalid new_buckets_path (leading space in quoted new_buckets_path)' , async ( ) => {
122
+ const { type, name, uid, gid, new_buckets_path } = defaults ;
123
+ const account_options = { config_root, name, uid, gid} ; // will add quoted new_buckets_path with leading space later
124
+ const action = ACTIONS . ADD ;
125
+ const command = create_command ( type , action , account_options ) ;
126
+ const res = await exec_manage_cli_add_leading_space_option ( command , 'new_buckets_path' , new_buckets_path , quoted_type . SPACE_QUOTE ) ;
127
+ expect ( JSON . parse ( res . stdout ) . error . code ) . toBe ( ManageCLIError . InvalidArgument . code ) ;
128
+ } ) ;
129
+
130
+ it ( 'should fail - cli create account invalid new_buckets_path (quoted leading space in new_buckets_path)' , async ( ) => {
131
+ const { type, name, uid, gid, new_buckets_path } = defaults ;
132
+ const account_options = { config_root, name, uid, gid} ; // will add new_buckets_path with quoted leading space later
133
+ const action = ACTIONS . ADD ;
134
+ const command = create_command ( type , action , account_options ) ;
135
+ const res = await exec_manage_cli_add_leading_space_option ( command , 'new_buckets_path' , new_buckets_path , quoted_type . QUOTE_SPACE ) ;
136
+ expect ( JSON . parse ( res . stdout ) . error . code ) . toBe ( ManageCLIError . InvalidAccountNewBucketsPath . code ) ; // should get this error if space is also quoted with the value
137
+ } ) ;
138
+
106
139
it ( 'should fail - cli update account invalid access_key - invalid size' , async ( ) => {
107
140
const { type, secret_key, name, new_buckets_path, uid, gid } = defaults ;
108
141
const account_options = { config_root, access_key : 'abc' , secret_key, name, new_buckets_path, uid, gid } ;
@@ -2218,6 +2251,52 @@ async function exec_manage_cli_add_empty_option(command, option) {
2218
2251
return res ;
2219
2252
}
2220
2253
2254
+ /**
2255
+ * exec_manage_cli_add_leading_space_option modifies the command by appending a flag with a value(quoted or non-quoted) that includes a leading space to test CLI parsing behavior
2256
+ * @param {string } command
2257
+ * @param {string } option
2258
+ * @param {string } value
2259
+ * @param {"s" | "qs" | "sq" | "default" } quoted
2260
+ *
2261
+ * @examples
2262
+ * - await exec_manage_cli_add_leading_space_option("cli_command", "flag", "val", quoted_type.SPACE_ONLY);
2263
+ * // cli_command --flag= val (Space before value)
2264
+ *
2265
+ * - await exec_manage_cli_add_leading_space_option("cli_command", "flag", "val", quoted_type.QUOTE_SPACE);
2266
+ * // cli_command --flag=" val" (quote then space)
2267
+ *
2268
+ * - await exec_manage_cli_add_leading_space_option("cli_command", "flag", "val", quoted_type.SPACE_QUOTE);
2269
+ * // cli_command --flag= "val" (space then quote)
2270
+ *
2271
+ * - await exec_manage_cli_add_leading_space_option("cli_command", "flag", "val");
2272
+ * // cli_command --flag=val (No special formatting)
2273
+ */
2274
+ async function exec_manage_cli_add_leading_space_option ( command , option , value , quoted = "default" ) {
2275
+ let changed_command ;
2276
+
2277
+ switch ( quoted ) {
2278
+ case quoted_type . SPACE_ONLY :
2279
+ changed_command = `${ command } --${ option } = ${ value } ` ;
2280
+ break ;
2281
+ case quoted_type . QUOTE_SPACE :
2282
+ changed_command = `${ command } --${ option } =" ${ value } "` ;
2283
+ break ;
2284
+ case quoted_type . SPACE_QUOTE :
2285
+ changed_command = `${ command } --${ option } = "${ value } "` ;
2286
+ break ;
2287
+ default :
2288
+ changed_command = `${ command } --${ option } =${ value } ` ;
2289
+ }
2290
+
2291
+ let res ;
2292
+ try {
2293
+ res = await os_util . exec ( changed_command , { return_stdout : true } ) ;
2294
+ } catch ( e ) {
2295
+ res = e ;
2296
+ }
2297
+ return res ;
2298
+ }
2299
+
2221
2300
/**
2222
2301
* create_command would create the string needed to run the CLI command
2223
2302
* @param {string } type
0 commit comments