@@ -380,6 +380,53 @@ mocha.describe('bucket operations - namespace_fs', function() {
380380 console . log ( inspect ( res ) ) ;
381381 await fs_utils . file_must_exist ( path . join ( s3_new_buckets_path , bucket_name + '-s3' ) ) ;
382382 } ) ;
383+ mocha . it ( 'create s3 bucket with x-nsfs-bucket-path' , async function ( ) {
384+ // only NC supports creating buckets on custom paths
385+ if ( ! is_nc_coretest ) this . skip ( ) ; // eslint-disable-line no-invalid-this
386+ const new_buckets_path = get_new_buckets_path_by_test_env ( tmp_fs_root , s3_new_buckets_dir ) ;
387+ const x_nsfs_bucket_path = `${ new_buckets_path } ${ bucket_name } -custom-path` ;
388+ s3_correct_uid_default_nsr . middlewareStack . add (
389+ ( next , context ) => args => {
390+ args . request . headers [ config . NSFS_USER_BUCKET_PATH_HTTP_HEADER ] = x_nsfs_bucket_path ;
391+ return next ( args ) ;
392+ } ,
393+ {
394+ step : "finalizeRequest" ,
395+ name : "addCustomHeader" ,
396+ }
397+ ) ;
398+ const res = await s3_correct_uid_default_nsr . createBucket ( { Bucket : bucket_name + '-s3-custom' , } ) ;
399+ console . log ( inspect ( res ) ) ;
400+ await fs_utils . file_must_exist ( x_nsfs_bucket_path ) ;
401+ s3_correct_uid_default_nsr . middlewareStack . remove ( "addCustomHeader" ) ;
402+ } ) ;
403+
404+ mocha . it ( 'create s3 bucket with x-nsfs-bucket-path fail as directory exists' , async function ( ) {
405+ // only NC supports creating buckets on custom paths
406+ if ( ! is_nc_coretest ) this . skip ( ) ; // eslint-disable-line no-invalid-this
407+ const new_buckets_path = get_new_buckets_path_by_test_env ( tmp_fs_root , s3_new_buckets_dir ) ;
408+ const x_nsfs_bucket_path = `${ new_buckets_path } ${ bucket_name } -custom-path` ; // already created in previous test
409+ // this is the path that was created if x_nsfs_bucket_path header wasn't used
410+ const no_x_nsfs_bucket_path = `${ new_buckets_path } ${ bucket_name } -s3-custom-fail` ;
411+ s3_correct_uid_default_nsr . middlewareStack . add (
412+ ( next , context ) => args => {
413+ args . request . headers [ config . NSFS_USER_BUCKET_PATH_HTTP_HEADER ] = x_nsfs_bucket_path ;
414+ return next ( args ) ;
415+ } ,
416+ {
417+ step : "finalizeRequest" ,
418+ name : "addCustomHeader" ,
419+ }
420+ ) ;
421+ try {
422+ const res = await s3_correct_uid_default_nsr . createBucket ( { Bucket : bucket_name + '-s3-custom-fail' , } ) ;
423+ assert . fail ( inspect ( res ) ) ;
424+ } catch ( err ) {
425+ assert . strictEqual ( err . Code , 'BucketAlreadyExists' ) ;
426+ }
427+ await fs_utils . file_must_not_exist ( no_x_nsfs_bucket_path ) ;
428+ s3_correct_uid_default_nsr . middlewareStack . remove ( "addCustomHeader" ) ;
429+ } ) ;
383430
384431 mocha . it ( 'get bucket acl - rpc bucket' , async function ( ) {
385432 const res = await s3_correct_uid_default_nsr . getBucketAcl ( { Bucket : first_bucket } ) ;
0 commit comments