Audit sécurité/qualité : corrections critiques, tests, CI et lint #4
@@ -59,4 +59,15 @@ describe('artiste.create', () => {
|
||||
|
||||
expect(artisteDocuments.create).toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('refuse sans planter quand data.user est absent', async () => {
|
||||
const {strapi} = buildStrapi({dbUser})
|
||||
const controller = createController({strapi})
|
||||
const ctx = buildCtx(buildData({user: undefined}))
|
||||
|
||||
await controller.create(ctx)
|
||||
|
||||
expect(ctx.badRequest).toHaveBeenCalled()
|
||||
expect(strapi.documents).not.toHaveBeenCalled()
|
||||
})
|
||||
})
|
||||
|
||||
@@ -12,6 +12,10 @@ module.exports = createCoreController('api::artiste.artiste', ({strapi}) => ({
|
||||
const {body} = ctx.request
|
||||
let {data} = body
|
||||
|
||||
if (!data?.user?.documentId) {
|
||||
return ctx.badRequest('Informations manquantes.')
|
||||
}
|
||||
|
||||
const user = await strapi.documents('plugin::users-permissions.user').findOne({
|
||||
documentId: body.data.user.documentId
|
||||
})
|
||||
|
||||
@@ -81,4 +81,22 @@ describe('commentaire.create', () => {
|
||||
await expect(controller.create(ctx)).rejects.toThrow('Texte introuvable.')
|
||||
expect(commentaireDocuments.create).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('refuse sans planter quand data.user est absent', async () => {
|
||||
const {strapi, userDbQuery} = buildStrapi()
|
||||
const controller = createController({strapi})
|
||||
const ctx = buildCtx(buildData({user: undefined}))
|
||||
|
||||
await expect(controller.create(ctx)).rejects.toThrow('Informations manquantes.')
|
||||
expect(userDbQuery.findOne).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('refuse sans planter quand data.parole est absent', async () => {
|
||||
const {strapi, paroleDbQuery} = buildStrapi()
|
||||
const controller = createController({strapi})
|
||||
const ctx = buildCtx(buildData({parole: undefined}))
|
||||
|
||||
await expect(controller.create(ctx)).rejects.toThrow('Informations manquantes.')
|
||||
expect(paroleDbQuery.findOne).not.toHaveBeenCalled()
|
||||
})
|
||||
})
|
||||
|
||||
@@ -8,6 +8,10 @@ module.exports = createCoreController('api::commentaire.commentaire', ({strapi})
|
||||
const {body} = ctx.request
|
||||
let {data} = body
|
||||
|
||||
if (!data?.user?.id || !data?.parole) {
|
||||
throw new ApplicationError('Informations manquantes.')
|
||||
}
|
||||
|
||||
const user = await strapi.db.query('plugin::users-permissions.user').findOne({
|
||||
where: {id: data.user.id}
|
||||
})
|
||||
|
||||
@@ -66,4 +66,26 @@ describe('parole.create', () => {
|
||||
|
||||
expect(paroleDocuments.create).toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('refuse sans planter quand data.user est absent', async () => {
|
||||
const {strapi, userDocuments} = buildStrapi({dbUser, artiste})
|
||||
const controller = createController({strapi})
|
||||
const ctx = buildCtx(buildData({user: undefined}))
|
||||
|
||||
await controller.create(ctx)
|
||||
|
||||
expect(ctx.badRequest).toHaveBeenCalled()
|
||||
expect(userDocuments.findOne).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('refuse sans planter quand data.artistes est vide', async () => {
|
||||
const {strapi, artisteDocuments} = buildStrapi({dbUser, artiste})
|
||||
const controller = createController({strapi})
|
||||
const ctx = buildCtx(buildData({artistes: []}))
|
||||
|
||||
await controller.create(ctx)
|
||||
|
||||
expect(ctx.badRequest).toHaveBeenCalled()
|
||||
expect(artisteDocuments.findOne).not.toHaveBeenCalled()
|
||||
})
|
||||
})
|
||||
|
||||
@@ -69,6 +69,11 @@ module.exports = createCoreController('api::parole.parole', ({strapi}) => ({
|
||||
async create(ctx) {
|
||||
const {body} = ctx.request
|
||||
const {data} = body
|
||||
|
||||
if (!data?.user?.documentId || !data?.artistes?.[0]?.documentId) {
|
||||
return ctx.badRequest('Informations manquantes.')
|
||||
}
|
||||
|
||||
strapi.service('api::parole.parole').validateParoles(data.titre, data.transcription)
|
||||
|
||||
const user = await strapi.documents('plugin::users-permissions.user').findOne({
|
||||
|
||||
Reference in New Issue
Block a user