X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Fmiddlewares%2Fvalidators%2Factivitypub%2Fsignature.ts;h=f2f7d58487882f84a287581c8ccf39342e1332c7;hb=10363c74c1d869f0e0c7bc4d0367b1f34d1bb6a4;hp=d41bb6a8d6e387062ef21c0a30607fde98e4577c;hpb=3fd3ab2d34d512b160a5e6084d7609be7b4f4452;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/middlewares/validators/activitypub/signature.ts b/server/middlewares/validators/activitypub/signature.ts index d41bb6a8d..f2f7d5848 100644 --- a/server/middlewares/validators/activitypub/signature.ts +++ b/server/middlewares/validators/activitypub/signature.ts @@ -1,18 +1,30 @@ import * as express from 'express' -import { body } from 'express-validator/check' -import { logger } from '../../../helpers' -import { isSignatureCreatorValid, isSignatureTypeValid, isSignatureValueValid } from '../../../helpers/custom-validators/activitypub' +import { body } from 'express-validator' +import { + isSignatureCreatorValid, + isSignatureTypeValid, + isSignatureValueValid +} from '../../../helpers/custom-validators/activitypub/signature' import { isDateValid } from '../../../helpers/custom-validators/misc' -import { areValidationErrors } from '../utils' +import { logger } from '../../../helpers/logger' +import { areValidationErrors } from '../shared' const signatureValidator = [ - body('signature.type').custom(isSignatureTypeValid).withMessage('Should have a valid signature type'), - body('signature.created').custom(isDateValid).withMessage('Should have a valid signature created date'), - body('signature.creator').custom(isSignatureCreatorValid).withMessage('Should have a valid signature creator'), - body('signature.signatureValue').custom(isSignatureValueValid).withMessage('Should have a valid signature value'), + body('signature.type') + .optional() + .custom(isSignatureTypeValid).withMessage('Should have a valid signature type'), + body('signature.created') + .optional() + .custom(isDateValid).withMessage('Should have a signature created date that conforms to ISO 8601'), + body('signature.creator') + .optional() + .custom(isSignatureCreatorValid).withMessage('Should have a valid signature creator'), + body('signature.signatureValue') + .optional() + .custom(isSignatureValueValid).withMessage('Should have a valid signature value'), (req: express.Request, res: express.Response, next: express.NextFunction) => { - logger.debug('Checking activitypub signature parameter', { parameters: { signature: req.body.signature } }) + logger.debug('Checking Linked Data Signature parameter', { parameters: { signature: req.body.signature } }) if (areValidationErrors(req, res)) return