aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/helpers/custom-validators
diff options
context:
space:
mode:
authorChocobozzz <florian.bigard@gmail.com>2017-11-14 10:57:56 +0100
committerChocobozzz <florian.bigard@gmail.com>2017-11-27 19:40:51 +0100
commite34c85e527100c0b5c44567bd951e95be41b8d7e (patch)
tree39697c5a4dda2c2e07142a8522538db783fce2fd /server/helpers/custom-validators
parent1e1265b36c09df1465aa2b4866815c957b6a532e (diff)
downloadPeerTube-e34c85e527100c0b5c44567bd951e95be41b8d7e.tar.gz
PeerTube-e34c85e527100c0b5c44567bd951e95be41b8d7e.tar.zst
PeerTube-e34c85e527100c0b5c44567bd951e95be41b8d7e.zip
Fix issues on server start
Diffstat (limited to 'server/helpers/custom-validators')
-rw-r--r--server/helpers/custom-validators/activitypub/account.ts7
-rw-r--r--server/helpers/custom-validators/activitypub/misc.ts10
-rw-r--r--server/helpers/custom-validators/activitypub/videos.ts7
-rw-r--r--server/helpers/custom-validators/video-channels.ts8
-rw-r--r--server/helpers/custom-validators/videos.ts6
5 files changed, 31 insertions, 7 deletions
diff --git a/server/helpers/custom-validators/activitypub/account.ts b/server/helpers/custom-validators/activitypub/account.ts
index 8a7d1b7fe..acd2b8058 100644
--- a/server/helpers/custom-validators/activitypub/account.ts
+++ b/server/helpers/custom-validators/activitypub/account.ts
@@ -3,6 +3,7 @@ import * as validator from 'validator'
3import { exists, isUUIDValid } from '../misc' 3import { exists, isUUIDValid } from '../misc'
4import { isActivityPubUrlValid } from './misc' 4import { isActivityPubUrlValid } from './misc'
5import { isUserUsernameValid } from '../users' 5import { isUserUsernameValid } from '../users'
6import { CONSTRAINTS_FIELDS } from '../../../initializers/constants'
6 7
7function isAccountEndpointsObjectValid (endpointObject: any) { 8function isAccountEndpointsObjectValid (endpointObject: any) {
8 return isAccountSharedInboxValid(endpointObject.sharedInbox) 9 return isAccountSharedInboxValid(endpointObject.sharedInbox)
@@ -34,7 +35,8 @@ function isAccountPublicKeyValid (publicKey: string) {
34 return exists(publicKey) && 35 return exists(publicKey) &&
35 typeof publicKey === 'string' && 36 typeof publicKey === 'string' &&
36 publicKey.startsWith('-----BEGIN PUBLIC KEY-----') && 37 publicKey.startsWith('-----BEGIN PUBLIC KEY-----') &&
37 publicKey.endsWith('-----END PUBLIC KEY-----') 38 publicKey.endsWith('-----END PUBLIC KEY-----') &&
39 validator.isLength(publicKey, CONSTRAINTS_FIELDS.ACCOUNTS.PUBLIC_KEY)
38} 40}
39 41
40function isAccountIdValid (id: string) { 42function isAccountIdValid (id: string) {
@@ -73,7 +75,8 @@ function isAccountPrivateKeyValid (privateKey: string) {
73 return exists(privateKey) && 75 return exists(privateKey) &&
74 typeof privateKey === 'string' && 76 typeof privateKey === 'string' &&
75 privateKey.startsWith('-----BEGIN RSA PRIVATE KEY-----') && 77 privateKey.startsWith('-----BEGIN RSA PRIVATE KEY-----') &&
76 privateKey.endsWith('-----END RSA PRIVATE KEY-----') 78 privateKey.endsWith('-----END RSA PRIVATE KEY-----') &&
79 validator.isLength(privateKey, CONSTRAINTS_FIELDS.ACCOUNTS.PRIVATE_KEY)
77} 80}
78 81
79function isRemoteAccountValid (remoteAccount: any) { 82function isRemoteAccountValid (remoteAccount: any) {
diff --git a/server/helpers/custom-validators/activitypub/misc.ts b/server/helpers/custom-validators/activitypub/misc.ts
index f049f5a8c..a94c36b51 100644
--- a/server/helpers/custom-validators/activitypub/misc.ts
+++ b/server/helpers/custom-validators/activitypub/misc.ts
@@ -1,4 +1,7 @@
1import * as validator from 'validator'
1import { exists } from '../misc' 2import { exists } from '../misc'
3import { isTestInstance } from '../../core-utils'
4import { CONSTRAINTS_FIELDS } from '../../../initializers/constants'
2 5
3function isActivityPubUrlValid (url: string) { 6function isActivityPubUrlValid (url: string) {
4 const isURLOptions = { 7 const isURLOptions = {
@@ -9,7 +12,12 @@ function isActivityPubUrlValid (url: string) {
9 protocols: [ 'http', 'https' ] 12 protocols: [ 'http', 'https' ]
10 } 13 }
11 14
12 return exists(url) && validator.isURL(url, isURLOptions) 15 // We validate 'localhost', so we don't have the top level domain
16 if (isTestInstance()) {
17 isURLOptions.require_tld = false
18 }
19
20 return exists(url) && validator.isURL(url, isURLOptions) && validator.isLength(url, CONSTRAINTS_FIELDS.ACCOUNTS.URL)
13} 21}
14 22
15function isBaseActivityValid (activity: any, type: string) { 23function isBaseActivityValid (activity: any, type: string) {
diff --git a/server/helpers/custom-validators/activitypub/videos.ts b/server/helpers/custom-validators/activitypub/videos.ts
index 9233a1359..8f6d50f50 100644
--- a/server/helpers/custom-validators/activitypub/videos.ts
+++ b/server/helpers/custom-validators/activitypub/videos.ts
@@ -10,7 +10,8 @@ import {
10 isVideoTruncatedDescriptionValid, 10 isVideoTruncatedDescriptionValid,
11 isVideoDurationValid, 11 isVideoDurationValid,
12 isVideoNameValid, 12 isVideoNameValid,
13 isVideoTagValid 13 isVideoTagValid,
14 isVideoUrlValid
14} from '../videos' 15} from '../videos'
15import { isVideoChannelDescriptionValid, isVideoChannelNameValid } from '../video-channels' 16import { isVideoChannelDescriptionValid, isVideoChannelNameValid } from '../video-channels'
16import { isBaseActivityValid } from './misc' 17import { isBaseActivityValid } from './misc'
@@ -93,7 +94,7 @@ function isRemoteVideoContentValid (mediaType: string, content: string) {
93 94
94function isRemoteVideoIconValid (icon: any) { 95function isRemoteVideoIconValid (icon: any) {
95 return icon.type === 'Image' && 96 return icon.type === 'Image' &&
96 validator.isURL(icon.url) && 97 isVideoUrlValid(icon.url) &&
97 icon.mediaType === 'image/jpeg' && 98 icon.mediaType === 'image/jpeg' &&
98 validator.isInt(icon.width, { min: 0 }) && 99 validator.isInt(icon.width, { min: 0 }) &&
99 validator.isInt(icon.height, { min: 0 }) 100 validator.isInt(icon.height, { min: 0 })
@@ -111,7 +112,7 @@ function setValidRemoteVideoUrls (video: any) {
111function isRemoteVideoUrlValid (url: any) { 112function isRemoteVideoUrlValid (url: any) {
112 return url.type === 'Link' && 113 return url.type === 'Link' &&
113 ACTIVITY_PUB.VIDEO_URL_MIME_TYPES.indexOf(url.mimeType) !== -1 && 114 ACTIVITY_PUB.VIDEO_URL_MIME_TYPES.indexOf(url.mimeType) !== -1 &&
114 validator.isURL(url.url) && 115 isVideoUrlValid(url.url) &&
115 validator.isInt(url.width, { min: 0 }) && 116 validator.isInt(url.width, { min: 0 }) &&
116 validator.isInt(url.size, { min: 0 }) 117 validator.isInt(url.size, { min: 0 })
117} 118}
diff --git a/server/helpers/custom-validators/video-channels.ts b/server/helpers/custom-validators/video-channels.ts
index acc42f4a4..5787c3850 100644
--- a/server/helpers/custom-validators/video-channels.ts
+++ b/server/helpers/custom-validators/video-channels.ts
@@ -8,9 +8,14 @@ import { database as db, CONSTRAINTS_FIELDS } from '../../initializers'
8import { VideoChannelInstance } from '../../models' 8import { VideoChannelInstance } from '../../models'
9import { logger } from '../logger' 9import { logger } from '../logger'
10import { exists } from './misc' 10import { exists } from './misc'
11import { isActivityPubUrlValid } from './index'
11 12
12const VIDEO_CHANNELS_CONSTRAINTS_FIELDS = CONSTRAINTS_FIELDS.VIDEO_CHANNELS 13const VIDEO_CHANNELS_CONSTRAINTS_FIELDS = CONSTRAINTS_FIELDS.VIDEO_CHANNELS
13 14
15function isVideoChannelUrlValid (value: string) {
16 return isActivityPubUrlValid(value)
17}
18
14function isVideoChannelDescriptionValid (value: string) { 19function isVideoChannelDescriptionValid (value: string) {
15 return value === null || validator.isLength(value, VIDEO_CHANNELS_CONSTRAINTS_FIELDS.DESCRIPTION) 20 return value === null || validator.isLength(value, VIDEO_CHANNELS_CONSTRAINTS_FIELDS.DESCRIPTION)
16} 21}
@@ -53,5 +58,6 @@ export {
53 isVideoChannelDescriptionValid, 58 isVideoChannelDescriptionValid,
54 isVideoChannelNameValid, 59 isVideoChannelNameValid,
55 isVideoChannelUUIDValid, 60 isVideoChannelUUIDValid,
56 checkVideoChannelExists 61 checkVideoChannelExists,
62 isVideoChannelUrlValid
57} 63}
diff --git a/server/helpers/custom-validators/videos.ts b/server/helpers/custom-validators/videos.ts
index 487b3d646..715119cf6 100644
--- a/server/helpers/custom-validators/videos.ts
+++ b/server/helpers/custom-validators/videos.ts
@@ -19,6 +19,7 @@ import { isArray, exists } from './misc'
19import { VideoInstance } from '../../models' 19import { VideoInstance } from '../../models'
20import { logger } from '../../helpers' 20import { logger } from '../../helpers'
21import { VideoRateType } from '../../../shared' 21import { VideoRateType } from '../../../shared'
22import { isActivityPubUrlValid } from './activitypub/misc'
22 23
23const VIDEOS_CONSTRAINTS_FIELDS = CONSTRAINTS_FIELDS.VIDEOS 24const VIDEOS_CONSTRAINTS_FIELDS = CONSTRAINTS_FIELDS.VIDEOS
24const VIDEO_ABUSES_CONSTRAINTS_FIELDS = CONSTRAINTS_FIELDS.VIDEO_ABUSES 25const VIDEO_ABUSES_CONSTRAINTS_FIELDS = CONSTRAINTS_FIELDS.VIDEO_ABUSES
@@ -33,6 +34,10 @@ function isRemoteVideoCategoryValid (value: string) {
33 return validator.isInt('' + value) 34 return validator.isInt('' + value)
34} 35}
35 36
37function isVideoUrlValid (value: string) {
38 return isActivityPubUrlValid(value)
39}
40
36function isVideoLicenceValid (value: number) { 41function isVideoLicenceValid (value: number) {
37 return VIDEO_LICENCES[value] !== undefined 42 return VIDEO_LICENCES[value] !== undefined
38} 43}
@@ -219,5 +224,6 @@ export {
219 isVideoTagValid, 224 isVideoTagValid,
220 isRemoteVideoCategoryValid, 225 isRemoteVideoCategoryValid,
221 isRemoteVideoLicenceValid, 226 isRemoteVideoLicenceValid,
227 isVideoUrlValid,
222 isRemoteVideoLanguageValid 228 isRemoteVideoLanguageValid
223} 229}