fix: refuser par défaut is-payload-owner sans en-tête Authorization
This commit is contained in:
@@ -26,11 +26,11 @@ function buildPolicyContext({authorization, payloadUserId}) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
describe('is-payload-owner policy', () => {
|
describe('is-payload-owner policy', () => {
|
||||||
it("autorise quand aucun en-tête d'autorisation n'est présent", async () => {
|
it("refuse quand aucun en-tête d'autorisation n'est présent", async () => {
|
||||||
const strapi = buildStrapi(999)
|
const strapi = buildStrapi(999)
|
||||||
const policyContext = buildPolicyContext({authorization: undefined, payloadUserId: 1})
|
const policyContext = buildPolicyContext({authorization: undefined, payloadUserId: 1})
|
||||||
|
|
||||||
await expect(isPayloadOwner(policyContext, {}, {strapi})).resolves.toBe(true)
|
await expect(isPayloadOwner(policyContext, {}, {strapi})).rejects.toThrow('Opération non autorisée')
|
||||||
})
|
})
|
||||||
|
|
||||||
it('autorise quand le user du JWT correspond au user du payload', async () => {
|
it('autorise quand le user du JWT correspond au user du payload', async () => {
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ module.exports = async (policyContext, config, {strapi}) => {
|
|||||||
const {request} = policyContext
|
const {request} = policyContext
|
||||||
|
|
||||||
if (!request?.header?.authorization) {
|
if (!request?.header?.authorization) {
|
||||||
return true
|
throw new UnauthorizedError('Opération non autorisée')
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|||||||
Reference in New Issue
Block a user