]>
Commit | Line | Data |
---|---|---|
1 | import * as express from 'express' | |
2 | import { body } from 'express-validator/check' | |
3 | import { | |
4 | isSignatureCreatorValid, isSignatureTypeValid, | |
5 | isSignatureValueValid | |
6 | } from '../../../helpers/custom-validators/activitypub/signature' | |
7 | import { isDateValid } from '../../../helpers/custom-validators/misc' | |
8 | import { logger } from '../../../helpers/logger' | |
9 | import { areValidationErrors } from '../utils' | |
10 | ||
11 | const signatureValidator = [ | |
12 | body('signature.type') | |
13 | .optional() | |
14 | .custom(isSignatureTypeValid).withMessage('Should have a valid signature type'), | |
15 | body('signature.created') | |
16 | .optional() | |
17 | .custom(isDateValid).withMessage('Should have a valid signature created date'), | |
18 | body('signature.creator') | |
19 | .optional() | |
20 | .custom(isSignatureCreatorValid).withMessage('Should have a valid signature creator'), | |
21 | body('signature.signatureValue') | |
22 | .optional() | |
23 | .custom(isSignatureValueValid).withMessage('Should have a valid signature value'), | |
24 | ||
25 | (req: express.Request, res: express.Response, next: express.NextFunction) => { | |
26 | logger.debug('Checking activitypub signature parameter', { parameters: { signature: req.body.signature } }) | |
27 | ||
28 | if (areValidationErrors(req, res)) return | |
29 | ||
30 | return next() | |
31 | } | |
32 | ] | |
33 | ||
34 | // --------------------------------------------------------------------------- | |
35 | ||
36 | export { | |
37 | signatureValidator | |
38 | } |