diff options
author | Chocobozzz <florian.bigard@gmail.com> | 2017-11-09 17:51:58 +0100 |
---|---|---|
committer | Chocobozzz <florian.bigard@gmail.com> | 2017-11-27 19:40:51 +0100 |
commit | e4f97babf701481b55cc10fb3448feab5f97c867 (patch) | |
tree | af37402a594dc5ff09f71ecb0687e8cfe4cdb471 /server/middlewares/validators | |
parent | 343ad675f2a26c15b86150a9a3552e619d5d44f4 (diff) | |
download | PeerTube-e4f97babf701481b55cc10fb3448feab5f97c867.tar.gz PeerTube-e4f97babf701481b55cc10fb3448feab5f97c867.tar.zst PeerTube-e4f97babf701481b55cc10fb3448feab5f97c867.zip |
Begin activitypub
Diffstat (limited to 'server/middlewares/validators')
-rw-r--r-- | server/middlewares/validators/account.ts | 53 | ||||
-rw-r--r-- | server/middlewares/validators/activitypub/index.ts (renamed from server/middlewares/validators/remote/index.ts) | 0 | ||||
-rw-r--r-- | server/middlewares/validators/activitypub/pods.ts (renamed from server/middlewares/validators/remote/pods.ts) | 0 | ||||
-rw-r--r-- | server/middlewares/validators/activitypub/signature.ts | 30 | ||||
-rw-r--r-- | server/middlewares/validators/activitypub/videos.ts (renamed from server/middlewares/validators/remote/videos.ts) | 0 | ||||
-rw-r--r-- | server/middlewares/validators/index.ts | 3 | ||||
-rw-r--r-- | server/middlewares/validators/remote/signature.ts | 22 |
7 files changed, 85 insertions, 23 deletions
diff --git a/server/middlewares/validators/account.ts b/server/middlewares/validators/account.ts new file mode 100644 index 000000000..5abe942d6 --- /dev/null +++ b/server/middlewares/validators/account.ts | |||
@@ -0,0 +1,53 @@ | |||
1 | import { param } from 'express-validator/check' | ||
2 | import * as express from 'express' | ||
3 | |||
4 | import { database as db } from '../../initializers/database' | ||
5 | import { checkErrors } from './utils' | ||
6 | import { | ||
7 | logger, | ||
8 | isUserUsernameValid, | ||
9 | isUserPasswordValid, | ||
10 | isUserVideoQuotaValid, | ||
11 | isUserDisplayNSFWValid, | ||
12 | isUserRoleValid, | ||
13 | isAccountNameValid | ||
14 | } from '../../helpers' | ||
15 | import { AccountInstance } from '../../models' | ||
16 | |||
17 | const localAccountValidator = [ | ||
18 | param('name').custom(isAccountNameValid).withMessage('Should have a valid account name'), | ||
19 | |||
20 | (req: express.Request, res: express.Response, next: express.NextFunction) => { | ||
21 | logger.debug('Checking localAccountValidator parameters', { parameters: req.params }) | ||
22 | |||
23 | checkErrors(req, res, () => { | ||
24 | checkLocalAccountExists(req.params.name, res, next) | ||
25 | }) | ||
26 | } | ||
27 | ] | ||
28 | |||
29 | // --------------------------------------------------------------------------- | ||
30 | |||
31 | export { | ||
32 | localAccountValidator | ||
33 | } | ||
34 | |||
35 | // --------------------------------------------------------------------------- | ||
36 | |||
37 | function checkLocalAccountExists (name: string, res: express.Response, callback: (err: Error, account: AccountInstance) => void) { | ||
38 | db.Account.loadLocalAccountByName(name) | ||
39 | .then(account => { | ||
40 | if (!account) { | ||
41 | return res.status(404) | ||
42 | .send({ error: 'Account not found' }) | ||
43 | .end() | ||
44 | } | ||
45 | |||
46 | res.locals.account = account | ||
47 | return callback(null, account) | ||
48 | }) | ||
49 | .catch(err => { | ||
50 | logger.error('Error in account request validator.', err) | ||
51 | return res.sendStatus(500) | ||
52 | }) | ||
53 | } | ||
diff --git a/server/middlewares/validators/remote/index.ts b/server/middlewares/validators/activitypub/index.ts index f1f26043e..f1f26043e 100644 --- a/server/middlewares/validators/remote/index.ts +++ b/server/middlewares/validators/activitypub/index.ts | |||
diff --git a/server/middlewares/validators/remote/pods.ts b/server/middlewares/validators/activitypub/pods.ts index f917b61ee..f917b61ee 100644 --- a/server/middlewares/validators/remote/pods.ts +++ b/server/middlewares/validators/activitypub/pods.ts | |||
diff --git a/server/middlewares/validators/activitypub/signature.ts b/server/middlewares/validators/activitypub/signature.ts new file mode 100644 index 000000000..0ce15c1f6 --- /dev/null +++ b/server/middlewares/validators/activitypub/signature.ts | |||
@@ -0,0 +1,30 @@ | |||
1 | import { body } from 'express-validator/check' | ||
2 | import * as express from 'express' | ||
3 | |||
4 | import { | ||
5 | logger, | ||
6 | isDateValid, | ||
7 | isSignatureTypeValid, | ||
8 | isSignatureCreatorValid, | ||
9 | isSignatureValueValid | ||
10 | } from '../../../helpers' | ||
11 | import { checkErrors } from '../utils' | ||
12 | |||
13 | const signatureValidator = [ | ||
14 | body('signature.type').custom(isSignatureTypeValid).withMessage('Should have a valid signature type'), | ||
15 | body('signature.created').custom(isDateValid).withMessage('Should have a valid signature created date'), | ||
16 | body('signature.creator').custom(isSignatureCreatorValid).withMessage('Should have a valid signature creator'), | ||
17 | body('signature.signatureValue').custom(isSignatureValueValid).withMessage('Should have a valid signature value'), | ||
18 | |||
19 | (req: express.Request, res: express.Response, next: express.NextFunction) => { | ||
20 | logger.debug('Checking activitypub signature parameter', { parameters: { signature: req.body.signature } }) | ||
21 | |||
22 | checkErrors(req, res, next) | ||
23 | } | ||
24 | ] | ||
25 | |||
26 | // --------------------------------------------------------------------------- | ||
27 | |||
28 | export { | ||
29 | signatureValidator | ||
30 | } | ||
diff --git a/server/middlewares/validators/remote/videos.ts b/server/middlewares/validators/activitypub/videos.ts index 497320cc1..497320cc1 100644 --- a/server/middlewares/validators/remote/videos.ts +++ b/server/middlewares/validators/activitypub/videos.ts | |||
diff --git a/server/middlewares/validators/index.ts b/server/middlewares/validators/index.ts index 247f6039e..46c00d679 100644 --- a/server/middlewares/validators/index.ts +++ b/server/middlewares/validators/index.ts | |||
@@ -1,5 +1,6 @@ | |||
1 | export * from './account' | ||
1 | export * from './oembed' | 2 | export * from './oembed' |
2 | export * from './remote' | 3 | export * from './activitypub' |
3 | export * from './pagination' | 4 | export * from './pagination' |
4 | export * from './pods' | 5 | export * from './pods' |
5 | export * from './sort' | 6 | export * from './sort' |
diff --git a/server/middlewares/validators/remote/signature.ts b/server/middlewares/validators/remote/signature.ts deleted file mode 100644 index d3937b515..000000000 --- a/server/middlewares/validators/remote/signature.ts +++ /dev/null | |||
@@ -1,22 +0,0 @@ | |||
1 | import { body } from 'express-validator/check' | ||
2 | import * as express from 'express' | ||
3 | |||
4 | import { logger, isHostValid } from '../../../helpers' | ||
5 | import { checkErrors } from '../utils' | ||
6 | |||
7 | const signatureValidator = [ | ||
8 | body('signature.host').custom(isHostValid).withMessage('Should have a signature host'), | ||
9 | body('signature.signature').not().isEmpty().withMessage('Should have a signature'), | ||
10 | |||
11 | (req: express.Request, res: express.Response, next: express.NextFunction) => { | ||
12 | logger.debug('Checking signature parameters', { parameters: { signature: req.body.signature } }) | ||
13 | |||
14 | checkErrors(req, res, next) | ||
15 | } | ||
16 | ] | ||
17 | |||
18 | // --------------------------------------------------------------------------- | ||
19 | |||
20 | export { | ||
21 | signatureValidator | ||
22 | } | ||