Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #12781 from strapi/hotfix/sanitize-medias
Fix sanitize media
- Loading branch information
Showing
5 changed files
with
114 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
93 changes: 93 additions & 0 deletions
93
packages/core/strapi/tests/api/populate/sanitize.test.e2e.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
'use strict'; | ||
|
||
const fs = require('fs'); | ||
const path = require('path'); | ||
|
||
const { createTestBuilder } = require('../../../../../../test/helpers/builder'); | ||
const { createStrapiInstance } = require('../../../../../../test/helpers/strapi'); | ||
const { | ||
createContentAPIRequest, | ||
createAuthRequest, | ||
} = require('../../../../../../test/helpers/request'); | ||
|
||
const builder = createTestBuilder(); | ||
|
||
let strapi; | ||
let rq; | ||
|
||
const schemas = { | ||
contentTypes: { | ||
a: { | ||
kind: 'collectionType', | ||
displayName: 'a', | ||
singularName: 'a', | ||
pluralName: 'as', | ||
attributes: { | ||
cover: { type: 'media' }, | ||
}, | ||
}, | ||
}, | ||
}; | ||
|
||
const getFixtures = file => { | ||
return [ | ||
{ | ||
cover: file.id, | ||
}, | ||
]; | ||
}; | ||
|
||
const uploadFile = async () => { | ||
const strapi = await createStrapiInstance(); | ||
const rq = await createAuthRequest({ strapi }); | ||
|
||
const res = await rq({ | ||
method: 'POST', | ||
url: '/upload', | ||
formData: { | ||
files: fs.createReadStream(path.join(__dirname, 'rec.jpg')), | ||
}, | ||
}); | ||
|
||
await strapi.destroy(); | ||
|
||
return res.body[0]; | ||
}; | ||
|
||
describe('Sanitize populated entries', () => { | ||
beforeAll(async () => { | ||
const file = await uploadFile(); | ||
|
||
await builder | ||
.addContentTypes(Object.values(schemas.contentTypes)) | ||
.addFixtures(schemas.contentTypes.a.singularName, getFixtures(file)) | ||
.build(); | ||
|
||
strapi = await createStrapiInstance(); | ||
rq = createContentAPIRequest({ strapi }); | ||
}); | ||
|
||
afterAll(async () => { | ||
await strapi.destroy(); | ||
await builder.cleanup(); | ||
}); | ||
|
||
describe('Populate simple media', () => { | ||
test('Media can be populated without restricted attributes', async () => { | ||
const { status, body } = await rq.get(`/${schemas.contentTypes.a.pluralName}`, { | ||
qs: { | ||
populate: { | ||
cover: { | ||
populate: '*', | ||
}, | ||
}, | ||
}, | ||
}); | ||
|
||
expect(status).toBe(200); | ||
expect(body.data[0].attributes.cover).toBeDefined(); | ||
expect(body.data[0].attributes.cover.data.attributes.createdBy).toBeUndefined(); | ||
expect(body.data[0].attributes.cover.data.attributes.updatedBy).toBeUndefined(); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters