fix: whitelister les champs autorisés sur create/update (mass assignment)

This commit is contained in:
2026-07-04 15:08:19 +04:00
parent 1d54d287e1
commit 90c048a282
6 changed files with 108 additions and 8 deletions
@@ -99,4 +99,21 @@ describe('commentaire.create', () => {
await expect(controller.create(ctx)).rejects.toThrow('Informations manquantes.')
expect(paroleDbQuery.findOne).not.toHaveBeenCalled()
})
it('ignore les champs non autorisés du payload (mass assignment)', async () => {
const {strapi, commentaireDocuments} = buildStrapi()
const controller = createController({strapi})
const ctx = buildCtx(buildData({publishedAt: '2020-01-01'}))
await controller.create(ctx)
expect(commentaireDocuments.create).toHaveBeenCalledWith({
data: {
contenu: 'Un commentaire',
datePublication: '2026-07-04',
user: dbUser.id,
parole: dbParole.id
}
})
})
})