test: uploads return correct content type headers (#8182)

This commit is contained in:
Dan Ribbens
2024-09-12 07:21:10 -04:00
committed by GitHub
parent 6e94884d18
commit c34401dc4b
2 changed files with 23 additions and 1 deletions

View File

@@ -19,6 +19,10 @@ export async function checkFileAccess({
return disableEndpoints
}
if (filename.includes('../') || filename.includes('..\\')) {
throw new Forbidden(req.t)
}
const accessResult = await executeAccess({ isReadingStaticFile: true, req }, config.access.read)
if (typeof accessResult === 'object') {

View File

@@ -216,7 +216,6 @@ describe('Collections - Uploads', () => {
expect(doc.filename).toBeDefined()
})
})
describe('update', () => {
it('should replace image and delete old files - by ID', async () => {
const filePath = path.resolve(dirname, './image.png')
@@ -344,6 +343,25 @@ describe('Collections - Uploads', () => {
expect(await fileExists(path.join(dirname, doc.filename))).toBe(false)
})
})
describe('read', () => {
it('should return the media document with the correct file type', async () => {
const filePath = path.resolve(dirname, './image.png')
const file = await getFileByPath(filePath)
file.name = 'renamed.png'
const mediaDoc = (await payload.create({
collection: mediaSlug,
data: {},
file,
})) as unknown as Media
const response = await restClient.GET(`/${mediaSlug}/file/${mediaDoc.filename}`)
expect(response.status).toBe(200)
expect(response.headers.get('content-type')).toContain('image/png')
})
})
})
describe('Local API', () => {