Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/storage/storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,10 @@ export class Storage {

mustBeValidBucketName(data.name)

if (data.name.toLowerCase() === 'public') {
throw ERRORS.InvalidBucketName(data.name)
}

const bucketData: Parameters<Database['createBucket']>[0] = data

if (typeof data.fileSizeLimit === 'number' || typeof data.fileSizeLimit === 'string') {
Expand Down
18 changes: 18 additions & 0 deletions src/test/bucket.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,24 @@ describe('testing POST bucket', () => {
expect(response.statusCode).toBe(400)
})

test('user is not able to create a bucket with the name "public"', async () => {
const response = await appInstance.inject({
method: 'POST',
url: `/bucket`,
headers: {
authorization: `Bearer ${process.env.AUTHENTICATED_KEY}`,
},
payload: {
name: 'pUbLiC',
},
})

expect(response.statusCode).toBe(400)
const { statusCode, error } = await response.json()
expect(statusCode).toBe('400')
expect(error).toBe('Invalid Input')
})

test('user is not able to create a bucket with the leading and trailing spaces', async () => {
const response = await appInstance.inject({
method: 'POST',
Expand Down
8 changes: 8 additions & 0 deletions src/test/s3-protocol.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,14 @@ describe('S3 Protocol', () => {
expect(Location).toBeTruthy()
})

it('cannot create a bucket named "public"', async () => {
const createBucketRequest = new CreateBucketCommand({
Bucket: 'public',
})

await expect(client.send(createBucketRequest)).rejects.toThrow('Bucket name invalid')
})

it('can get bucket versioning', async () => {
const bucket = await createBucket(client)
const bucketVersioningCommand = new GetBucketVersioningCommand({
Expand Down
Loading