diff options
author | Chocobozzz <florian.bigard@gmail.com> | 2017-11-14 17:31:26 +0100 |
---|---|---|
committer | Chocobozzz <florian.bigard@gmail.com> | 2017-11-27 19:40:51 +0100 |
commit | 350e31d6b64e4973dfa5e9f7b46841cb09aeb1ad (patch) | |
tree | f4191f3c04a5230fcf8ca3d6ca3248643fc4151d /server/middlewares/validators | |
parent | e34c85e527100c0b5c44567bd951e95be41b8d7e (diff) | |
download | PeerTube-350e31d6b64e4973dfa5e9f7b46841cb09aeb1ad.tar.gz PeerTube-350e31d6b64e4973dfa5e9f7b46841cb09aeb1ad.tar.zst PeerTube-350e31d6b64e4973dfa5e9f7b46841cb09aeb1ad.zip |
Follow works
Diffstat (limited to 'server/middlewares/validators')
-rw-r--r-- | server/middlewares/validators/account.ts | 10 | ||||
-rw-r--r-- | server/middlewares/validators/activitypub/activity.ts | 7 | ||||
-rw-r--r-- | server/middlewares/validators/index.ts | 1 | ||||
-rw-r--r-- | server/middlewares/validators/webfinger.ts | 42 |
4 files changed, 50 insertions, 10 deletions
diff --git a/server/middlewares/validators/account.ts b/server/middlewares/validators/account.ts index 3ccf2ea21..58eeed3cc 100644 --- a/server/middlewares/validators/account.ts +++ b/server/middlewares/validators/account.ts | |||
@@ -8,13 +8,13 @@ import { | |||
8 | isUserVideoQuotaValid, | 8 | isUserVideoQuotaValid, |
9 | logger | 9 | logger |
10 | } from '../../helpers' | 10 | } from '../../helpers' |
11 | import { isAccountNameWithHostValid } from '../../helpers/custom-validators/video-accounts' | 11 | import { isAccountNameValid } from '../../helpers/custom-validators/accounts' |
12 | import { database as db } from '../../initializers/database' | 12 | import { database as db } from '../../initializers/database' |
13 | import { AccountInstance } from '../../models' | 13 | import { AccountInstance } from '../../models' |
14 | import { checkErrors } from './utils' | 14 | import { checkErrors } from './utils' |
15 | 15 | ||
16 | const localAccountValidator = [ | 16 | const localAccountValidator = [ |
17 | param('nameWithHost').custom(isAccountNameWithHostValid).withMessage('Should have a valid account with domain name (myuser@domain.tld)'), | 17 | param('name').custom(isAccountNameValid).withMessage('Should have a valid account name'), |
18 | 18 | ||
19 | (req: express.Request, res: express.Response, next: express.NextFunction) => { | 19 | (req: express.Request, res: express.Response, next: express.NextFunction) => { |
20 | logger.debug('Checking localAccountValidator parameters', { parameters: req.params }) | 20 | logger.debug('Checking localAccountValidator parameters', { parameters: req.params }) |
@@ -33,10 +33,8 @@ export { | |||
33 | 33 | ||
34 | // --------------------------------------------------------------------------- | 34 | // --------------------------------------------------------------------------- |
35 | 35 | ||
36 | function checkLocalAccountExists (nameWithHost: string, res: express.Response, callback: (err: Error, account: AccountInstance) => void) { | 36 | function checkLocalAccountExists (name: string, res: express.Response, callback: (err: Error, account: AccountInstance) => void) { |
37 | const [ name, host ] = nameWithHost.split('@') | 37 | db.Account.loadLocalByName(name) |
38 | |||
39 | db.Account.loadLocalAccountByNameAndPod(name, host) | ||
40 | .then(account => { | 38 | .then(account => { |
41 | if (!account) { | 39 | if (!account) { |
42 | return res.status(404) | 40 | return res.status(404) |
diff --git a/server/middlewares/validators/activitypub/activity.ts b/server/middlewares/validators/activitypub/activity.ts index 78a6d1444..0de8b2d85 100644 --- a/server/middlewares/validators/activitypub/activity.ts +++ b/server/middlewares/validators/activitypub/activity.ts | |||
@@ -1,11 +1,10 @@ | |||
1 | import { body } from 'express-validator/check' | ||
2 | import * as express from 'express' | 1 | import * as express from 'express' |
3 | 2 | import { body } from 'express-validator/check' | |
4 | import { logger, isRootActivityValid } from '../../../helpers' | 3 | import { isRootActivityValid, logger } from '../../../helpers' |
5 | import { checkErrors } from '../utils' | 4 | import { checkErrors } from '../utils' |
6 | 5 | ||
7 | const activityPubValidator = [ | 6 | const activityPubValidator = [ |
8 | body('data').custom(isRootActivityValid), | 7 | body('').custom((value, { req }) => isRootActivityValid(req.body)), |
9 | 8 | ||
10 | (req: express.Request, res: express.Response, next: express.NextFunction) => { | 9 | (req: express.Request, res: express.Response, next: express.NextFunction) => { |
11 | logger.debug('Checking activity pub parameters', { parameters: req.body }) | 10 | logger.debug('Checking activity pub parameters', { parameters: req.body }) |
diff --git a/server/middlewares/validators/index.ts b/server/middlewares/validators/index.ts index 46c00d679..92a4bad28 100644 --- a/server/middlewares/validators/index.ts +++ b/server/middlewares/validators/index.ts | |||
@@ -8,3 +8,4 @@ export * from './users' | |||
8 | export * from './videos' | 8 | export * from './videos' |
9 | export * from './video-blacklist' | 9 | export * from './video-blacklist' |
10 | export * from './video-channels' | 10 | export * from './video-channels' |
11 | export * from './webfinger' | ||
diff --git a/server/middlewares/validators/webfinger.ts b/server/middlewares/validators/webfinger.ts new file mode 100644 index 000000000..068e03ad7 --- /dev/null +++ b/server/middlewares/validators/webfinger.ts | |||
@@ -0,0 +1,42 @@ | |||
1 | import { query } from 'express-validator/check' | ||
2 | import * as express from 'express' | ||
3 | |||
4 | import { checkErrors } from './utils' | ||
5 | import { logger, isWebfingerResourceValid } from '../../helpers' | ||
6 | import { database as db } from '../../initializers' | ||
7 | |||
8 | const webfingerValidator = [ | ||
9 | query('resource').custom(isWebfingerResourceValid).withMessage('Should have a valid webfinger resource'), | ||
10 | |||
11 | (req: express.Request, res: express.Response, next: express.NextFunction) => { | ||
12 | logger.debug('Checking webfinger parameters', { parameters: req.query }) | ||
13 | |||
14 | checkErrors(req, res, () => { | ||
15 | // Remove 'acct:' from the beginning of the string | ||
16 | const nameWithHost = req.query.resource.substr(5) | ||
17 | const [ name, ] = nameWithHost.split('@') | ||
18 | |||
19 | db.Account.loadLocalByName(name) | ||
20 | .then(account => { | ||
21 | if (!account) { | ||
22 | return res.status(404) | ||
23 | .send({ error: 'Account not found' }) | ||
24 | .end() | ||
25 | } | ||
26 | |||
27 | res.locals.account = account | ||
28 | return next() | ||
29 | }) | ||
30 | .catch(err => { | ||
31 | logger.error('Error in webfinger validator.', err) | ||
32 | return res.sendStatus(500) | ||
33 | }) | ||
34 | }) | ||
35 | } | ||
36 | ] | ||
37 | |||
38 | // --------------------------------------------------------------------------- | ||
39 | |||
40 | export { | ||
41 | webfingerValidator | ||
42 | } | ||