@@ -95,6 +95,7 @@ mocha.describe('nsfs nc health', function() {
95
95
} ) ;
96
96
97
97
mocha . describe ( 'health check' , function ( ) {
98
+ this . timeout ( 10000 ) ; // eslint-disable-line no-invalid-this
98
99
const new_buckets_path = `${ root_path } new_buckets_path_user1/` ;
99
100
const account1_options = {
100
101
name : 'account1' ,
@@ -107,7 +108,14 @@ mocha.describe('nsfs nc health', function() {
107
108
path : new_buckets_path + '/bucket1' ,
108
109
owner : account1_options . name
109
110
} ;
111
+ const account2_options = {
112
+ name : 'account2' ,
113
+ uid : process . getuid ( ) ,
114
+ gid : process . getgid ( ) ,
115
+ new_buckets_path : new_buckets_path
116
+ } ;
110
117
const account_inaccessible_options = { name : 'account_inaccessible' , uid : 999 , gid : 999 , new_buckets_path : bucket_storage_path } ;
118
+ const bucket_inaccessible_options = { name : 'bucket2' , path : bucket_storage_path + '/bucket2' , owner : account_inaccessible_options . name } ;
111
119
const account_inaccessible_dn_options = { name : 'account_inaccessible_dn' , user : 'inaccessible_dn' , new_buckets_path : bucket_storage_path } ;
112
120
const invalid_account_dn_options = { name : 'invalid_account_dn' , user : 'invalid_account_dn' , new_buckets_path : bucket_storage_path } ;
113
121
const fs_users = {
@@ -118,6 +126,8 @@ mocha.describe('nsfs nc health', function() {
118
126
}
119
127
} ;
120
128
mocha . before ( async ( ) => {
129
+ this . timeout ( 5000 ) ; // eslint-disable-line no-invalid-this
130
+ config . NSFS_NC_CONF_DIR = config_root ;
121
131
const https_port = 6443 ;
122
132
Health = new NSFSHealth ( { config_root, https_port, config_fs } ) ;
123
133
await fs_utils . create_fresh_path ( new_buckets_path ) ;
@@ -126,6 +136,7 @@ mocha.describe('nsfs nc health', function() {
126
136
await fs_utils . file_must_exist ( new_buckets_path + '/bucket1' ) ;
127
137
await exec_manage_cli ( TYPES . ACCOUNT , ACTIONS . ADD , { config_root, ...account1_options } ) ;
128
138
await exec_manage_cli ( TYPES . BUCKET , ACTIONS . ADD , { config_root, ...bucket1_options } ) ;
139
+ await fs_utils . file_must_exist ( path . join ( config_root , 'master_keys.json' ) ) ;
129
140
const get_service_memory_usage = sinon . stub ( Health , "get_service_memory_usage" ) ;
130
141
get_service_memory_usage . onFirstCall ( ) . returns ( Promise . resolve ( 100 ) ) ;
131
142
for ( const user of Object . values ( fs_users ) ) {
@@ -134,13 +145,15 @@ mocha.describe('nsfs nc health', function() {
134
145
} ) ;
135
146
136
147
mocha . after ( async ( ) => {
148
+ this . timeout ( 5000 ) ; // eslint-disable-line no-invalid-this
137
149
fs_utils . folder_delete ( new_buckets_path ) ;
138
150
fs_utils . folder_delete ( path . join ( new_buckets_path , 'bucket1' ) ) ;
139
151
await exec_manage_cli ( TYPES . BUCKET , ACTIONS . DELETE , { config_root, name : bucket1_options . name } ) ;
140
152
await exec_manage_cli ( TYPES . ACCOUNT , ACTIONS . DELETE , { config_root, name : account1_options . name } ) ;
141
153
for ( const user of Object . values ( fs_users ) ) {
142
154
await delete_fs_user_by_platform ( user . distinguished_name ) ;
143
155
}
156
+ await fs_utils . folder_delete ( config_root ) ;
144
157
} ) ;
145
158
146
159
mocha . afterEach ( async ( ) => {
@@ -209,10 +222,13 @@ mocha.describe('nsfs nc health', function() {
209
222
} ) ;
210
223
211
224
mocha . it ( 'NSFS bucket with invalid storage path' , async function ( ) {
225
+ this . timeout ( 5000 ) ; // eslint-disable-line no-invalid-this
212
226
Health . get_service_state . restore ( ) ;
213
227
Health . get_endpoint_response . restore ( ) ;
228
+ const resp = await exec_manage_cli ( TYPES . ACCOUNT , ACTIONS . ADD , { config_root, ...account2_options } ) ;
229
+ const parsed_res = JSON . parse ( resp ) . response . reply ;
214
230
// create it manually because we can not skip invalid storage path check on the CLI
215
- const bucket_invalid = { _id : mongo_utils . mongoObjectId ( ) , name : 'bucket_invalid' , path : new_buckets_path + '/bucket1/invalid' , owner : account1_options . name } ;
231
+ const bucket_invalid = { _id : mongo_utils . mongoObjectId ( ) , name : 'bucket_invalid' , path : new_buckets_path + '/bucket1/invalid' , owner_account : parsed_res . _id } ;
216
232
await test_utils . write_manual_config_file ( TYPES . BUCKET , config_fs , bucket_invalid ) ;
217
233
const get_service_state = sinon . stub ( Health , "get_service_state" ) ;
218
234
get_service_state . onFirstCall ( ) . returns ( Promise . resolve ( { service_status : 'active' , pid : 1000 } ) )
@@ -223,7 +239,81 @@ mocha.describe('nsfs nc health', function() {
223
239
assert . strictEqual ( health_status . status , 'OK' ) ;
224
240
assert . strictEqual ( health_status . checks . buckets_status . invalid_buckets . length , 1 ) ;
225
241
assert . strictEqual ( health_status . checks . buckets_status . invalid_buckets [ 0 ] . name , bucket_invalid . name ) ;
242
+ assert . strictEqual ( health_status . checks . buckets_status . invalid_buckets [ 0 ] . code , "STORAGE_NOT_EXIST" ) ;
226
243
await exec_manage_cli ( TYPES . BUCKET , ACTIONS . DELETE , { config_root, name : bucket_invalid . name } ) ;
244
+ await exec_manage_cli ( TYPES . ACCOUNT , ACTIONS . DELETE , { config_root, name : account2_options . name } ) ;
245
+ } ) ;
246
+
247
+ mocha . it ( 'Bucket with inaccessible path - uid gid' , async function ( ) {
248
+ this . timeout ( 5000 ) ; // eslint-disable-line no-invalid-this
249
+ await config_fs . create_config_json_file ( JSON . stringify ( { NC_DISABLE_ACCESS_CHECK : true } ) ) ;
250
+ await exec_manage_cli ( TYPES . ACCOUNT , ACTIONS . ADD , { config_root, ...account_inaccessible_options } ) ;
251
+ await exec_manage_cli ( TYPES . BUCKET , ACTIONS . ADD , { config_root, ...bucket_inaccessible_options } ) ;
252
+ await config_fs . delete_config_json_file ( ) ;
253
+ Health . get_service_state . restore ( ) ;
254
+ Health . get_endpoint_response . restore ( ) ;
255
+ Health . all_account_details = true ;
256
+ Health . all_bucket_details = true ;
257
+ const get_service_state = sinon . stub ( Health , "get_service_state" ) ;
258
+ get_service_state . onFirstCall ( ) . returns ( Promise . resolve ( { service_status : 'active' , pid : 1000 } ) )
259
+ . onSecondCall ( ) . returns ( Promise . resolve ( { service_status : 'active' , pid : 2000 } ) ) ;
260
+ const get_endpoint_response = sinon . stub ( Health , "get_endpoint_response" ) ;
261
+ get_endpoint_response . onFirstCall ( ) . returns ( Promise . resolve ( { response : { response_code : 'RUNNING' , total_fork_count : 0 } } ) ) ;
262
+ const health_status = await Health . nc_nsfs_health ( ) ;
263
+ assert . strictEqual ( health_status . checks . buckets_status . invalid_buckets . length , 1 ) ;
264
+ assert . strictEqual ( health_status . checks . buckets_status . invalid_buckets [ 0 ] . code , "ACCESS_DENIED" ) ;
265
+ assert . strictEqual ( health_status . checks . buckets_status . invalid_buckets [ 0 ] . name , bucket_inaccessible_options . name ) ;
266
+ assert . strictEqual ( health_status . checks . accounts_status . valid_accounts . length , 1 ) ;
267
+ assert . strictEqual ( health_status . checks . accounts_status . invalid_accounts . length , 1 ) ;
268
+ assert . strictEqual ( health_status . checks . accounts_status . invalid_accounts [ 0 ] . code , "ACCESS_DENIED" ) ;
269
+ assert . strictEqual ( health_status . checks . accounts_status . invalid_accounts [ 0 ] . name , account_inaccessible_options . name ) ;
270
+
271
+ await exec_manage_cli ( TYPES . BUCKET , ACTIONS . DELETE , { config_root, name : bucket_inaccessible_options . name } ) ;
272
+ await exec_manage_cli ( TYPES . ACCOUNT , ACTIONS . DELETE , { config_root, name : account_inaccessible_options . name } ) ;
273
+ } ) ;
274
+
275
+ mocha . it ( 'Bucket with inaccessible owner' , async function ( ) {
276
+ this . timeout ( 5000 ) ; // eslint-disable-line no-invalid-this
277
+ //create bucket manually, cli wont allow bucket with invalid owner
278
+ const bucket_invalid_owner = { _id : mongo_utils . mongoObjectId ( ) , name : 'bucket_invalid_account' , path : new_buckets_path + '/bucket_account' , owner_account : 'invalid_account' } ;
279
+ await test_utils . write_manual_config_file ( TYPES . BUCKET , config_fs , bucket_invalid_owner ) ;
280
+ Health . get_service_state . restore ( ) ;
281
+ Health . get_endpoint_response . restore ( ) ;
282
+ Health . all_account_details = true ;
283
+ Health . all_bucket_details = true ;
284
+ const get_service_state = sinon . stub ( Health , "get_service_state" ) ;
285
+ get_service_state . onFirstCall ( ) . returns ( Promise . resolve ( { service_status : 'active' , pid : 1000 } ) )
286
+ . onSecondCall ( ) . returns ( Promise . resolve ( { service_status : 'active' , pid : 2000 } ) ) ;
287
+ const get_endpoint_response = sinon . stub ( Health , "get_endpoint_response" ) ;
288
+ get_endpoint_response . onFirstCall ( ) . returns ( Promise . resolve ( { response : { response_code : 'RUNNING' , total_fork_count : 0 } } ) ) ;
289
+ const health_status = await Health . nc_nsfs_health ( ) ;
290
+ assert . strictEqual ( health_status . checks . buckets_status . invalid_buckets . length , 1 ) ;
291
+ assert . strictEqual ( health_status . checks . buckets_status . invalid_buckets [ 0 ] . code , "INVALID_ACCOUNT_OWNER" ) ;
292
+ assert . strictEqual ( health_status . checks . buckets_status . invalid_buckets [ 0 ] . name , 'bucket_invalid_account' ) ;
293
+
294
+ await exec_manage_cli ( TYPES . BUCKET , ACTIONS . DELETE , { config_root, name : 'bucket_invalid_account' } ) ;
295
+ } ) ;
296
+
297
+ mocha . it ( 'Bucket with empty owner' , async function ( ) {
298
+ this . timeout ( 5000 ) ; // eslint-disable-line no-invalid-this
299
+ //create bucket manually, cli wont allow bucket with empty owner
300
+ const bucket_invalid_owner = { _id : mongo_utils . mongoObjectId ( ) , name : 'bucket_invalid_account' , path : new_buckets_path + '/bucket_account' } ;
301
+ await test_utils . write_manual_config_file ( TYPES . BUCKET , config_fs , bucket_invalid_owner ) ;
302
+ Health . get_service_state . restore ( ) ;
303
+ Health . get_endpoint_response . restore ( ) ;
304
+ Health . all_account_details = true ;
305
+ Health . all_bucket_details = true ;
306
+ const get_service_state = sinon . stub ( Health , "get_service_state" ) ;
307
+ get_service_state . onFirstCall ( ) . returns ( Promise . resolve ( { service_status : 'active' , pid : 1000 } ) )
308
+ . onSecondCall ( ) . returns ( Promise . resolve ( { service_status : 'active' , pid : 2000 } ) ) ;
309
+ const get_endpoint_response = sinon . stub ( Health , "get_endpoint_response" ) ;
310
+ get_endpoint_response . onFirstCall ( ) . returns ( Promise . resolve ( { response : { response_code : 'RUNNING' , total_fork_count : 0 } } ) ) ;
311
+ const health_status = await Health . nc_nsfs_health ( ) ;
312
+ assert . strictEqual ( health_status . checks . buckets_status . invalid_buckets . length , 1 ) ;
313
+ assert . strictEqual ( health_status . checks . buckets_status . invalid_buckets [ 0 ] . code , "MISSING_ACCOUNT_OWNER" ) ;
314
+ assert . strictEqual ( health_status . checks . buckets_status . invalid_buckets [ 0 ] . name , 'bucket_invalid_account' ) ;
315
+
316
+ await exec_manage_cli ( TYPES . BUCKET , ACTIONS . DELETE , { config_root, name : 'bucket_invalid_account' } ) ;
227
317
} ) ;
228
318
229
319
mocha . it ( 'NSFS invalid bucket schema json' , async function ( ) {
@@ -527,4 +617,3 @@ mocha.describe('nsfs nc health', function() {
527
617
} ) ;
528
618
} ) ;
529
619
} ) ;
530
-
0 commit comments