Skip to content
Merged
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
3 changes: 3 additions & 0 deletions src/storage/uploader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -498,6 +498,9 @@ export async function fileUploadFromRequest(
}
}
} catch (e) {
if (e instanceof StorageBackendError) {
throw e
}
throw ERRORS.NoContentProvided(e as Error)
}
} else {
Expand Down
26 changes: 25 additions & 1 deletion src/test/object.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -592,7 +592,7 @@ describe('testing POST object via multipart upload', () => {
expect(response.statusCode).toBe(400)
})

test('return 400 when uploading an object with a not allowed mime-type', async () => {
test('return 400 when uploading an object with a not allowed mime-type (binary path)', async () => {
const form = new FormData()
form.append('file', fs.createReadStream(`./src/test/assets/sadcat.jpg`))
const headers = Object.assign({}, form.getHeaders(), {
Expand All @@ -616,6 +616,30 @@ describe('testing POST object via multipart upload', () => {
expect(S3Backend.prototype.uploadObject).not.toHaveBeenCalled()
})

test('return 400 when uploading a multipart form-data object with a not allowed mime-type', async () => {
const form = new FormData()
form.append('file', fs.createReadStream(`./src/test/assets/sadcat.jpg`))
form.append('contentType', 'image/png')
const headers = Object.assign({}, form.getHeaders(), {
authorization: `Bearer ${await serviceKeyAsync}`,
'x-upsert': 'true',
})

const response = await appInstance.inject({
method: 'POST',
url: '/object/public-limit-mime-types/sadcat-upload23.png',
headers,
payload: form,
})
expect(response.statusCode).toBe(400)
expect(await response.json()).toEqual({
error: 'invalid_mime_type',
message: `mime type image/png is not supported`,
statusCode: '415',
})
expect(S3Backend.prototype.uploadObject).not.toHaveBeenCalled()
})

test('return 400 when uploading an object with a malformed mime-type', async () => {
const form = new FormData()
form.append('file', fs.createReadStream(`./src/test/assets/sadcat.jpg`))
Expand Down