File tree Expand file tree Collapse file tree 3 files changed +30
-0
lines changed Expand file tree Collapse file tree 3 files changed +30
-0
lines changed Original file line number Diff line number Diff line change @@ -93,6 +93,10 @@ export class Storage {
9393
9494 mustBeValidBucketName ( data . name )
9595
96+ if ( data . name . toLowerCase ( ) === 'public' ) {
97+ throw ERRORS . InvalidBucketName ( data . name )
98+ }
99+
96100 const bucketData : Parameters < Database [ 'createBucket' ] > [ 0 ] = data
97101
98102 if ( typeof data . fileSizeLimit === 'number' || typeof data . fileSizeLimit === 'string' ) {
Original file line number Diff line number Diff line change @@ -235,6 +235,24 @@ describe('testing POST bucket', () => {
235235 expect ( response . statusCode ) . toBe ( 400 )
236236 } )
237237
238+ test ( 'user is not able to create a bucket with the name "public"' , async ( ) => {
239+ const response = await appInstance . inject ( {
240+ method : 'POST' ,
241+ url : `/bucket` ,
242+ headers : {
243+ authorization : `Bearer ${ process . env . AUTHENTICATED_KEY } ` ,
244+ } ,
245+ payload : {
246+ name : 'pUbLiC' ,
247+ } ,
248+ } )
249+
250+ expect ( response . statusCode ) . toBe ( 400 )
251+ const { statusCode, error } = await response . json ( )
252+ expect ( statusCode ) . toBe ( '400' )
253+ expect ( error ) . toBe ( 'Invalid Input' )
254+ } )
255+
238256 test ( 'user is not able to create a bucket with the leading and trailing spaces' , async ( ) => {
239257 const response = await appInstance . inject ( {
240258 method : 'POST' ,
Original file line number Diff line number Diff line change @@ -111,6 +111,14 @@ describe('S3 Protocol', () => {
111111 expect ( Location ) . toBeTruthy ( )
112112 } )
113113
114+ it ( 'cannot create a bucket named "public"' , async ( ) => {
115+ const createBucketRequest = new CreateBucketCommand ( {
116+ Bucket : 'public' ,
117+ } )
118+
119+ await expect ( client . send ( createBucketRequest ) ) . rejects . toThrow ( 'Bucket name invalid' )
120+ } )
121+
114122 it ( 'can get bucket versioning' , async ( ) => {
115123 const bucket = await createBucket ( client )
116124 const bucketVersioningCommand = new GetBucketVersioningCommand ( {
You can’t perform that action at this time.
0 commit comments