aboutsummaryrefslogtreecommitdiffhomepage
path: root/server
diff options
context:
space:
mode:
authorRigel Kent <sendmemail@rigelk.eu>2020-12-07 14:32:36 +0100
committerGitHub <noreply@github.com>2020-12-07 14:32:36 +0100
commit2d53be0267acc49cda46707b885096193a1f4e9c (patch)
tree887061a34bc67f40acbb96a6278f9544bf83caeb /server
parentadc1f09c0dbd997f34028c1c82d1c118dc8ead80 (diff)
downloadPeerTube-2d53be0267acc49cda46707b885096193a1f4e9c.tar.gz
PeerTube-2d53be0267acc49cda46707b885096193a1f4e9c.tar.zst
PeerTube-2d53be0267acc49cda46707b885096193a1f4e9c.zip
replace numbers with typed http status codes (#3409)
Diffstat (limited to 'server')
-rw-r--r--server/controllers/activitypub/inbox.ts3
-rw-r--r--server/controllers/api/abuse.ts7
-rw-r--r--server/controllers/api/bulk.ts5
-rw-r--r--server/controllers/api/index.ts3
-rw-r--r--server/controllers/api/oauth-clients.ts3
-rw-r--r--server/controllers/api/plugins.ts11
-rw-r--r--server/controllers/api/search.ts5
-rw-r--r--server/controllers/api/server/contact.ts3
-rw-r--r--server/controllers/api/server/follows.ts9
-rw-r--r--server/controllers/api/server/redundancy.ts7
-rw-r--r--server/controllers/api/server/server-blocklist.ts9
-rw-r--r--server/controllers/api/users/index.ts19
-rw-r--r--server/controllers/api/users/me.ts5
-rw-r--r--server/controllers/api/users/my-blocklist.ts9
-rw-r--r--server/controllers/api/users/my-history.ts5
-rw-r--r--server/controllers/api/users/my-notifications.ts7
-rw-r--r--server/controllers/api/users/my-subscriptions.ts7
-rw-r--r--server/controllers/api/video-channel.ts5
-rw-r--r--server/controllers/api/video-playlist.ts13
-rw-r--r--server/controllers/api/videos/blacklist.ts7
-rw-r--r--server/controllers/api/videos/captions.ts5
-rw-r--r--server/controllers/api/videos/comment.ts7
-rw-r--r--server/controllers/api/videos/import.ts3
-rw-r--r--server/controllers/api/videos/index.ts15
-rw-r--r--server/controllers/api/videos/live.ts3
-rw-r--r--server/controllers/api/videos/ownership.ts9
-rw-r--r--server/controllers/api/videos/rate.ts5
-rw-r--r--server/controllers/api/videos/watching.ts5
-rw-r--r--server/controllers/client.ts7
-rw-r--r--server/controllers/lazy-static.ts11
-rw-r--r--server/controllers/live.ts3
-rw-r--r--server/controllers/plugins.ts13
-rw-r--r--server/controllers/static.ts17
-rw-r--r--server/helpers/custom-validators/video-comments.ts13
-rw-r--r--server/helpers/custom-validators/video-imports.ts3
-rw-r--r--server/helpers/custom-validators/video-ownership.ts5
-rw-r--r--server/helpers/express-utils.ts5
-rw-r--r--server/helpers/middlewares/abuses.ts3
-rw-r--r--server/helpers/middlewares/accounts.ts5
-rw-r--r--server/helpers/middlewares/video-blacklists.ts3
-rw-r--r--server/helpers/middlewares/video-captions.ts3
-rw-r--r--server/helpers/middlewares/video-channels.ts3
-rw-r--r--server/helpers/middlewares/video-playlists.ts3
-rw-r--r--server/helpers/middlewares/videos.ts13
-rw-r--r--server/lib/auth.ts7
-rw-r--r--server/lib/client-html.ts11
-rw-r--r--server/middlewares/activitypub.ts15
-rw-r--r--server/middlewares/oauth.ts3
-rw-r--r--server/middlewares/servers.ts3
-rw-r--r--server/middlewares/user-right.ts4
-rw-r--r--server/middlewares/validators/abuse.ts21
-rw-r--r--server/middlewares/validators/activitypub/activity.ts7
-rw-r--r--server/middlewares/validators/blocklist.ts9
-rw-r--r--server/middlewares/validators/bulk.ts3
-rw-r--r--server/middlewares/validators/config.ts11
-rw-r--r--server/middlewares/validators/feeds.ts5
-rw-r--r--server/middlewares/validators/follows.ts15
-rw-r--r--server/middlewares/validators/oembed.ts15
-rw-r--r--server/middlewares/validators/plugins.ts23
-rw-r--r--server/middlewares/validators/redundancy.ts23
-rw-r--r--server/middlewares/validators/server.ts13
-rw-r--r--server/middlewares/validators/themes.ts5
-rw-r--r--server/middlewares/validators/user-subscriptions.ts3
-rw-r--r--server/middlewares/validators/users.ts55
-rw-r--r--server/middlewares/validators/utils.ts4
-rw-r--r--server/middlewares/validators/videos/video-blacklist.ts3
-rw-r--r--server/middlewares/validators/videos/video-channels.ts19
-rw-r--r--server/middlewares/validators/videos/video-comments.ts13
-rw-r--r--server/middlewares/validators/videos/video-imports.ts9
-rw-r--r--server/middlewares/validators/videos/video-live.ts21
-rw-r--r--server/middlewares/validators/videos/video-playlists.ts27
-rw-r--r--server/middlewares/validators/videos/video-rates.ts3
-rw-r--r--server/middlewares/validators/videos/video-shares.ts3
-rw-r--r--server/middlewares/validators/videos/video-watch.ts3
-rw-r--r--server/middlewares/validators/videos/videos.ts23
-rw-r--r--server/middlewares/validators/webfinger.ts7
-rw-r--r--server/tests/api/activitypub/security.ts17
-rw-r--r--server/tests/api/check-params/abuses.ts97
-rw-r--r--server/tests/api/check-params/blocklist.ts77
-rw-r--r--server/tests/api/check-params/bulk.ts11
-rw-r--r--server/tests/api/check-params/config.ts23
-rw-r--r--server/tests/api/check-params/debug.ts7
-rw-r--r--server/tests/api/check-params/follows.ts49
-rw-r--r--server/tests/api/check-params/jobs.ts5
-rw-r--r--server/tests/api/check-params/live.ts43
-rw-r--r--server/tests/api/check-params/logs.ts15
-rw-r--r--server/tests/api/check-params/plugins.ts69
-rw-r--r--server/tests/api/check-params/redundancy.ts33
-rw-r--r--server/tests/api/check-params/search.ts59
-rw-r--r--server/tests/api/check-params/services.ts17
-rw-r--r--server/tests/api/check-params/user-notifications.ts31
-rw-r--r--server/tests/api/check-params/user-subscriptions.ts51
-rw-r--r--server/tests/api/check-params/users.ts210
-rw-r--r--server/tests/api/check-params/video-blacklist.ts82
-rw-r--r--server/tests/api/check-params/video-captions.ts41
-rw-r--r--server/tests/api/check-params/video-channels.ts35
-rw-r--r--server/tests/api/check-params/video-comments.ts109
-rw-r--r--server/tests/api/check-params/video-imports.ts32
-rw-r--r--server/tests/api/check-params/video-playlists.ts114
-rw-r--r--server/tests/api/check-params/videos-filter.ts23
-rw-r--r--server/tests/api/check-params/videos-history.ts47
-rw-r--r--server/tests/api/check-params/videos.ts57
-rw-r--r--server/tests/api/redundancy/redundancy.ts5
-rw-r--r--server/tests/api/users/users.ts49
-rw-r--r--server/tests/api/videos/video-transcoder.ts11
-rw-r--r--server/tests/api/videos/videos-filter.ts3
-rw-r--r--server/tests/cli/prune-storage.ts5
-rw-r--r--server/tests/client.ts31
-rw-r--r--server/tests/external-plugins/auto-mute.ts7
-rw-r--r--server/tests/misc-endpoints.ts23
-rw-r--r--server/tests/plugins/external-auth.ts47
-rw-r--r--server/tests/plugins/plugin-helpers.ts3
-rw-r--r--server/tests/plugins/plugin-router.ts9
113 files changed, 1338 insertions, 899 deletions
diff --git a/server/controllers/activitypub/inbox.ts b/server/controllers/activitypub/inbox.ts
index 8b42478ee..67b2c0d66 100644
--- a/server/controllers/activitypub/inbox.ts
+++ b/server/controllers/activitypub/inbox.ts
@@ -7,6 +7,7 @@ import { asyncMiddleware, checkSignature, localAccountValidator, localVideoChann
7import { activityPubValidator } from '../../middlewares/validators/activitypub/activity' 7import { activityPubValidator } from '../../middlewares/validators/activitypub/activity'
8import { queue } from 'async' 8import { queue } from 'async'
9import { MActorDefault, MActorSignature } from '../../types/models' 9import { MActorDefault, MActorSignature } from '../../types/models'
10import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes'
10 11
11const inboxRouter = express.Router() 12const inboxRouter = express.Router()
12 13
@@ -79,5 +80,5 @@ function inboxController (req: express.Request, res: express.Response) {
79 inboxActor: accountOrChannel ? accountOrChannel.Actor : undefined 80 inboxActor: accountOrChannel ? accountOrChannel.Actor : undefined
80 }) 81 })
81 82
82 return res.status(204).end() 83 return res.status(HttpStatusCode.NO_CONTENT_204).end()
83} 84}
diff --git a/server/controllers/api/abuse.ts b/server/controllers/api/abuse.ts
index 25d6e2ab0..0ab74bdff 100644
--- a/server/controllers/api/abuse.ts
+++ b/server/controllers/api/abuse.ts
@@ -6,6 +6,7 @@ import { AbuseModel } from '@server/models/abuse/abuse'
6import { AbuseMessageModel } from '@server/models/abuse/abuse-message' 6import { AbuseMessageModel } from '@server/models/abuse/abuse-message'
7import { getServerActor } from '@server/models/application/application' 7import { getServerActor } from '@server/models/application/application'
8import { abusePredefinedReasonsMap } from '@shared/core-utils/abuse' 8import { abusePredefinedReasonsMap } from '@shared/core-utils/abuse'
9import { HttpStatusCode } from '@shared/core-utils/miscs/http-error-codes'
9import { AbuseCreate, AbuseState, UserRight } from '../../../shared' 10import { AbuseCreate, AbuseState, UserRight } from '../../../shared'
10import { getFormattedObjects } from '../../helpers/utils' 11import { getFormattedObjects } from '../../helpers/utils'
11import { sequelizeTypescript } from '../../initializers/database' 12import { sequelizeTypescript } from '../../initializers/database'
@@ -141,7 +142,7 @@ async function updateAbuse (req: express.Request, res: express.Response) {
141 142
142 // Do not send the delete to other instances, we updated OUR copy of this abuse 143 // Do not send the delete to other instances, we updated OUR copy of this abuse
143 144
144 return res.sendStatus(204) 145 return res.sendStatus(HttpStatusCode.NO_CONTENT_204)
145} 146}
146 147
147async function deleteAbuse (req: express.Request, res: express.Response) { 148async function deleteAbuse (req: express.Request, res: express.Response) {
@@ -153,7 +154,7 @@ async function deleteAbuse (req: express.Request, res: express.Response) {
153 154
154 // Do not send the delete to other instances, we delete OUR copy of this abuse 155 // Do not send the delete to other instances, we delete OUR copy of this abuse
155 156
156 return res.sendStatus(204) 157 return res.sendStatus(HttpStatusCode.NO_CONTENT_204)
157} 158}
158 159
159async function reportAbuse (req: express.Request, res: express.Response) { 160async function reportAbuse (req: express.Request, res: express.Response) {
@@ -243,5 +244,5 @@ async function deleteAbuseMessage (req: express.Request, res: express.Response)
243 return abuseMessage.destroy({ transaction: t }) 244 return abuseMessage.destroy({ transaction: t })
244 }) 245 })
245 246
246 return res.sendStatus(204) 247 return res.sendStatus(HttpStatusCode.NO_CONTENT_204)
247} 248}
diff --git a/server/controllers/api/bulk.ts b/server/controllers/api/bulk.ts
index 1fe139c92..649351029 100644
--- a/server/controllers/api/bulk.ts
+++ b/server/controllers/api/bulk.ts
@@ -2,8 +2,9 @@ import * as express from 'express'
2import { asyncMiddleware, authenticate } from '../../middlewares' 2import { asyncMiddleware, authenticate } from '../../middlewares'
3import { bulkRemoveCommentsOfValidator } from '@server/middlewares/validators/bulk' 3import { bulkRemoveCommentsOfValidator } from '@server/middlewares/validators/bulk'
4import { VideoCommentModel } from '@server/models/video/video-comment' 4import { VideoCommentModel } from '@server/models/video/video-comment'
5import { BulkRemoveCommentsOfBody } from '@shared/models/bulk/bulk-remove-comments-of-body.model'
6import { removeComment } from '@server/lib/video-comment' 5import { removeComment } from '@server/lib/video-comment'
6import { BulkRemoveCommentsOfBody } from '@shared/models/bulk/bulk-remove-comments-of-body.model'
7import { HttpStatusCode } from '@shared/core-utils/miscs/http-error-codes'
7 8
8const bulkRouter = express.Router() 9const bulkRouter = express.Router()
9 10
@@ -33,7 +34,7 @@ async function bulkRemoveCommentsOf (req: express.Request, res: express.Response
33 const comments = await VideoCommentModel.listForBulkDelete(account, filter) 34 const comments = await VideoCommentModel.listForBulkDelete(account, filter)
34 35
35 // Don't wait result 36 // Don't wait result
36 res.sendStatus(204) 37 res.sendStatus(HttpStatusCode.NO_CONTENT_204)
37 38
38 for (const comment of comments) { 39 for (const comment of comments) {
39 await removeComment(comment) 40 await removeComment(comment)
diff --git a/server/controllers/api/index.ts b/server/controllers/api/index.ts
index eda9e04d1..7ade1df3a 100644
--- a/server/controllers/api/index.ts
+++ b/server/controllers/api/index.ts
@@ -1,6 +1,7 @@
1import * as cors from 'cors' 1import * as cors from 'cors'
2import * as express from 'express' 2import * as express from 'express'
3import * as RateLimit from 'express-rate-limit' 3import * as RateLimit from 'express-rate-limit'
4import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes'
4import { badRequest } from '../../helpers/express-utils' 5import { badRequest } from '../../helpers/express-utils'
5import { CONFIG } from '../../initializers/config' 6import { CONFIG } from '../../initializers/config'
6import { abuseRouter } from './abuse' 7import { abuseRouter } from './abuse'
@@ -56,5 +57,5 @@ export { apiRouter }
56// --------------------------------------------------------------------------- 57// ---------------------------------------------------------------------------
57 58
58function pong (req: express.Request, res: express.Response) { 59function pong (req: express.Request, res: express.Response) {
59 return res.send('pong').status(200).end() 60 return res.send('pong').status(HttpStatusCode.OK_200).end()
60} 61}
diff --git a/server/controllers/api/oauth-clients.ts b/server/controllers/api/oauth-clients.ts
index b2de8bcf5..c21e2298d 100644
--- a/server/controllers/api/oauth-clients.ts
+++ b/server/controllers/api/oauth-clients.ts
@@ -1,5 +1,6 @@
1import * as express from 'express' 1import * as express from 'express'
2import { OAuthClientLocal } from '../../../shared' 2import { OAuthClientLocal } from '../../../shared'
3import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes'
3import { logger } from '../../helpers/logger' 4import { logger } from '../../helpers/logger'
4import { CONFIG } from '../../initializers/config' 5import { CONFIG } from '../../initializers/config'
5import { asyncMiddleware } from '../../middlewares' 6import { asyncMiddleware } from '../../middlewares'
@@ -23,7 +24,7 @@ async function getLocalClient (req: express.Request, res: express.Response, next
23 // Don't make this check if this is a test instance 24 // Don't make this check if this is a test instance
24 if (process.env.NODE_ENV !== 'test' && req.get('host') !== headerHostShouldBe) { 25 if (process.env.NODE_ENV !== 'test' && req.get('host') !== headerHostShouldBe) {
25 logger.info('Getting client tokens for host %s is forbidden (expected %s).', req.get('host'), headerHostShouldBe) 26 logger.info('Getting client tokens for host %s is forbidden (expected %s).', req.get('host'), headerHostShouldBe)
26 return res.type('json').status(403).end() 27 return res.type('json').status(HttpStatusCode.FORBIDDEN_403).end()
27 } 28 }
28 29
29 const client = await OAuthClientModel.loadFirstClient() 30 const client = await OAuthClientModel.loadFirstClient()
diff --git a/server/controllers/api/plugins.ts b/server/controllers/api/plugins.ts
index f8a0d19ca..1c0b5edb1 100644
--- a/server/controllers/api/plugins.ts
+++ b/server/controllers/api/plugins.ts
@@ -27,6 +27,7 @@ import { listAvailablePluginsFromIndex } from '../../lib/plugins/plugin-index'
27import { PeertubePluginIndexList } from '../../../shared/models/plugins/peertube-plugin-index-list.model' 27import { PeertubePluginIndexList } from '../../../shared/models/plugins/peertube-plugin-index-list.model'
28import { RegisteredServerSettings } from '../../../shared/models/plugins/register-server-setting.model' 28import { RegisteredServerSettings } from '../../../shared/models/plugins/register-server-setting.model'
29import { PublicServerSetting } from '../../../shared/models/plugins/public-server.setting' 29import { PublicServerSetting } from '../../../shared/models/plugins/public-server.setting'
30import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes'
30 31
31const pluginRouter = express.Router() 32const pluginRouter = express.Router()
32 33
@@ -140,7 +141,7 @@ async function installPlugin (req: express.Request, res: express.Response) {
140 return res.json(plugin.toFormattedJSON()) 141 return res.json(plugin.toFormattedJSON())
141 } catch (err) { 142 } catch (err) {
142 logger.warn('Cannot install plugin %s.', toInstall, { err }) 143 logger.warn('Cannot install plugin %s.', toInstall, { err })
143 return res.sendStatus(400) 144 return res.sendStatus(HttpStatusCode.BAD_REQUEST_400)
144 } 145 }
145} 146}
146 147
@@ -155,7 +156,7 @@ async function updatePlugin (req: express.Request, res: express.Response) {
155 return res.json(plugin.toFormattedJSON()) 156 return res.json(plugin.toFormattedJSON())
156 } catch (err) { 157 } catch (err) {
157 logger.warn('Cannot update plugin %s.', toUpdate, { err }) 158 logger.warn('Cannot update plugin %s.', toUpdate, { err })
158 return res.sendStatus(400) 159 return res.sendStatus(HttpStatusCode.BAD_REQUEST_400)
159 } 160 }
160} 161}
161 162
@@ -164,7 +165,7 @@ async function uninstallPlugin (req: express.Request, res: express.Response) {
164 165
165 await PluginManager.Instance.uninstall(body.npmName) 166 await PluginManager.Instance.uninstall(body.npmName)
166 167
167 return res.sendStatus(204) 168 return res.sendStatus(HttpStatusCode.NO_CONTENT_204)
168} 169}
169 170
170function getPublicPluginSettings (req: express.Request, res: express.Response) { 171function getPublicPluginSettings (req: express.Request, res: express.Response) {
@@ -193,7 +194,7 @@ async function updatePluginSettings (req: express.Request, res: express.Response
193 194
194 await PluginManager.Instance.onSettingsChanged(plugin.name, plugin.settings) 195 await PluginManager.Instance.onSettingsChanged(plugin.name, plugin.settings)
195 196
196 return res.sendStatus(204) 197 return res.sendStatus(HttpStatusCode.NO_CONTENT_204)
197} 198}
198 199
199async function listAvailablePlugins (req: express.Request, res: express.Response) { 200async function listAvailablePlugins (req: express.Request, res: express.Response) {
@@ -202,7 +203,7 @@ async function listAvailablePlugins (req: express.Request, res: express.Response
202 const resultList = await listAvailablePluginsFromIndex(query) 203 const resultList = await listAvailablePluginsFromIndex(query)
203 204
204 if (!resultList) { 205 if (!resultList) {
205 return res.status(503) 206 return res.status(HttpStatusCode.SERVICE_UNAVAILABLE_503)
206 .json({ error: 'Plugin index unavailable. Please retry later' }) 207 .json({ error: 'Plugin index unavailable. Please retry later' })
207 .end() 208 .end()
208 } 209 }
diff --git a/server/controllers/api/search.ts b/server/controllers/api/search.ts
index 6e2d11d93..353fd171b 100644
--- a/server/controllers/api/search.ts
+++ b/server/controllers/api/search.ts
@@ -6,6 +6,7 @@ import { getOrCreateVideoAndAccountAndChannel } from '@server/lib/activitypub/vi
6import { AccountBlocklistModel } from '@server/models/account/account-blocklist' 6import { AccountBlocklistModel } from '@server/models/account/account-blocklist'
7import { getServerActor } from '@server/models/application/application' 7import { getServerActor } from '@server/models/application/application'
8import { ServerBlocklistModel } from '@server/models/server/server-blocklist' 8import { ServerBlocklistModel } from '@server/models/server/server-blocklist'
9import { HttpStatusCode } from '@shared/core-utils/miscs/http-error-codes'
9import { ResultList, Video, VideoChannel } from '@shared/models' 10import { ResultList, Video, VideoChannel } from '@shared/models'
10import { SearchTargetQuery } from '@shared/models/search/search-target-query.model' 11import { SearchTargetQuery } from '@shared/models/search/search-target-query.model'
11import { VideoChannelsSearchQuery, VideosSearchQuery } from '../../../shared/models/search' 12import { VideoChannelsSearchQuery, VideosSearchQuery } from '../../../shared/models/search'
@@ -99,7 +100,7 @@ async function searchVideoChannelsIndex (query: VideoChannelsSearchQuery, res: e
99 } catch (err) { 100 } catch (err) {
100 logger.warn('Cannot use search index to make video channels search.', { err }) 101 logger.warn('Cannot use search index to make video channels search.', { err })
101 102
102 return res.sendStatus(500) 103 return res.sendStatus(HttpStatusCode.INTERNAL_SERVER_ERROR_500)
103 } 104 }
104} 105}
105 106
@@ -191,7 +192,7 @@ async function searchVideosIndex (query: VideosSearchQuery, res: express.Respons
191 } catch (err) { 192 } catch (err) {
192 logger.warn('Cannot use search index to make video search.', { err }) 193 logger.warn('Cannot use search index to make video search.', { err })
193 194
194 return res.sendStatus(500) 195 return res.sendStatus(HttpStatusCode.INTERNAL_SERVER_ERROR_500)
195 } 196 }
196} 197}
197 198
diff --git a/server/controllers/api/server/contact.ts b/server/controllers/api/server/contact.ts
index de02ffc0b..caddc0909 100644
--- a/server/controllers/api/server/contact.ts
+++ b/server/controllers/api/server/contact.ts
@@ -3,6 +3,7 @@ import { asyncMiddleware, contactAdministratorValidator } from '../../../middlew
3import { Redis } from '../../../lib/redis' 3import { Redis } from '../../../lib/redis'
4import { Emailer } from '../../../lib/emailer' 4import { Emailer } from '../../../lib/emailer'
5import { ContactForm } from '../../../../shared/models/server' 5import { ContactForm } from '../../../../shared/models/server'
6import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
6 7
7const contactRouter = express.Router() 8const contactRouter = express.Router()
8 9
@@ -18,7 +19,7 @@ async function contactAdministrator (req: express.Request, res: express.Response
18 19
19 await Redis.Instance.setContactFormIp(req.ip) 20 await Redis.Instance.setContactFormIp(req.ip)
20 21
21 return res.status(204).end() 22 return res.status(HttpStatusCode.NO_CONTENT_204).end()
22} 23}
23 24
24// --------------------------------------------------------------------------- 25// ---------------------------------------------------------------------------
diff --git a/server/controllers/api/server/follows.ts b/server/controllers/api/server/follows.ts
index 517d1897e..80025bc5b 100644
--- a/server/controllers/api/server/follows.ts
+++ b/server/controllers/api/server/follows.ts
@@ -28,6 +28,7 @@ import { removeRedundanciesOfServer } from '../../../lib/redundancy'
28import { sequelizeTypescript } from '../../../initializers/database' 28import { sequelizeTypescript } from '../../../initializers/database'
29import { autoFollowBackIfNeeded } from '../../../lib/activitypub/follow' 29import { autoFollowBackIfNeeded } from '../../../lib/activitypub/follow'
30import { getServerActor } from '@server/models/application/application' 30import { getServerActor } from '@server/models/application/application'
31import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
31 32
32const serverFollowsRouter = express.Router() 33const serverFollowsRouter = express.Router()
33serverFollowsRouter.get('/following', 34serverFollowsRouter.get('/following',
@@ -138,7 +139,7 @@ async function followInstance (req: express.Request, res: express.Response) {
138 JobQueue.Instance.createJob({ type: 'activitypub-follow', payload }) 139 JobQueue.Instance.createJob({ type: 'activitypub-follow', payload })
139 } 140 }
140 141
141 return res.status(204).end() 142 return res.status(HttpStatusCode.NO_CONTENT_204).end()
142} 143}
143 144
144async function removeFollowing (req: express.Request, res: express.Response) { 145async function removeFollowing (req: express.Request, res: express.Response) {
@@ -159,7 +160,7 @@ async function removeFollowing (req: express.Request, res: express.Response) {
159 await follow.destroy({ transaction: t }) 160 await follow.destroy({ transaction: t })
160 }) 161 })
161 162
162 return res.status(204).end() 163 return res.status(HttpStatusCode.NO_CONTENT_204).end()
163} 164}
164 165
165async function removeOrRejectFollower (req: express.Request, res: express.Response) { 166async function removeOrRejectFollower (req: express.Request, res: express.Response) {
@@ -169,7 +170,7 @@ async function removeOrRejectFollower (req: express.Request, res: express.Respon
169 170
170 await follow.destroy() 171 await follow.destroy()
171 172
172 return res.status(204).end() 173 return res.status(HttpStatusCode.NO_CONTENT_204).end()
173} 174}
174 175
175async function acceptFollower (req: express.Request, res: express.Response) { 176async function acceptFollower (req: express.Request, res: express.Response) {
@@ -182,5 +183,5 @@ async function acceptFollower (req: express.Request, res: express.Response) {
182 183
183 await autoFollowBackIfNeeded(follow) 184 await autoFollowBackIfNeeded(follow)
184 185
185 return res.status(204).end() 186 return res.status(HttpStatusCode.NO_CONTENT_204).end()
186} 187}
diff --git a/server/controllers/api/server/redundancy.ts b/server/controllers/api/server/redundancy.ts
index 1ced0759e..7c13dc21b 100644
--- a/server/controllers/api/server/redundancy.ts
+++ b/server/controllers/api/server/redundancy.ts
@@ -19,6 +19,7 @@ import { removeRedundanciesOfServer, removeVideoRedundancy } from '../../../lib/
19import { logger } from '../../../helpers/logger' 19import { logger } from '../../../helpers/logger'
20import { VideoRedundancyModel } from '@server/models/redundancy/video-redundancy' 20import { VideoRedundancyModel } from '@server/models/redundancy/video-redundancy'
21import { JobQueue } from '@server/lib/job-queue' 21import { JobQueue } from '@server/lib/job-queue'
22import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
22 23
23const serverRedundancyRouter = express.Router() 24const serverRedundancyRouter = express.Router()
24 25
@@ -89,13 +90,13 @@ async function addVideoRedundancy (req: express.Request, res: express.Response)
89 payload 90 payload
90 }) 91 })
91 92
92 return res.sendStatus(204) 93 return res.sendStatus(HttpStatusCode.NO_CONTENT_204)
93} 94}
94 95
95async function removeVideoRedundancyController (req: express.Request, res: express.Response) { 96async function removeVideoRedundancyController (req: express.Request, res: express.Response) {
96 await removeVideoRedundancy(res.locals.videoRedundancy) 97 await removeVideoRedundancy(res.locals.videoRedundancy)
97 98
98 return res.sendStatus(204) 99 return res.sendStatus(HttpStatusCode.NO_CONTENT_204)
99} 100}
100 101
101async function updateRedundancy (req: express.Request, res: express.Response) { 102async function updateRedundancy (req: express.Request, res: express.Response) {
@@ -109,5 +110,5 @@ async function updateRedundancy (req: express.Request, res: express.Response) {
109 removeRedundanciesOfServer(server.id) 110 removeRedundanciesOfServer(server.id)
110 .catch(err => logger.error('Cannot remove redundancy of %s.', server.host, { err })) 111 .catch(err => logger.error('Cannot remove redundancy of %s.', server.host, { err }))
111 112
112 return res.sendStatus(204) 113 return res.sendStatus(HttpStatusCode.NO_CONTENT_204)
113} 114}
diff --git a/server/controllers/api/server/server-blocklist.ts b/server/controllers/api/server/server-blocklist.ts
index 78e8a7e09..6e341c0fb 100644
--- a/server/controllers/api/server/server-blocklist.ts
+++ b/server/controllers/api/server/server-blocklist.ts
@@ -25,6 +25,7 @@ import {
25} from '../../../middlewares/validators' 25} from '../../../middlewares/validators'
26import { AccountBlocklistModel } from '../../../models/account/account-blocklist' 26import { AccountBlocklistModel } from '../../../models/account/account-blocklist'
27import { ServerBlocklistModel } from '../../../models/server/server-blocklist' 27import { ServerBlocklistModel } from '../../../models/server/server-blocklist'
28import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
28 29
29const serverBlocklistRouter = express.Router() 30const serverBlocklistRouter = express.Router()
30 31
@@ -108,7 +109,7 @@ async function blockAccount (req: express.Request, res: express.Response) {
108 forUserId: null // For all users 109 forUserId: null // For all users
109 }).catch(err => logger.error('Cannot remove notifications after an account mute.', { err })) 110 }).catch(err => logger.error('Cannot remove notifications after an account mute.', { err }))
110 111
111 return res.status(204).end() 112 return res.status(HttpStatusCode.NO_CONTENT_204).end()
112} 113}
113 114
114async function unblockAccount (req: express.Request, res: express.Response) { 115async function unblockAccount (req: express.Request, res: express.Response) {
@@ -116,7 +117,7 @@ async function unblockAccount (req: express.Request, res: express.Response) {
116 117
117 await removeAccountFromBlocklist(accountBlock) 118 await removeAccountFromBlocklist(accountBlock)
118 119
119 return res.status(204).end() 120 return res.status(HttpStatusCode.NO_CONTENT_204).end()
120} 121}
121 122
122async function listBlockedServers (req: express.Request, res: express.Response) { 123async function listBlockedServers (req: express.Request, res: express.Response) {
@@ -145,7 +146,7 @@ async function blockServer (req: express.Request, res: express.Response) {
145 forUserId: null // For all users 146 forUserId: null // For all users
146 }).catch(err => logger.error('Cannot remove notifications after a server mute.', { err })) 147 }).catch(err => logger.error('Cannot remove notifications after a server mute.', { err }))
147 148
148 return res.status(204).end() 149 return res.status(HttpStatusCode.NO_CONTENT_204).end()
149} 150}
150 151
151async function unblockServer (req: express.Request, res: express.Response) { 152async function unblockServer (req: express.Request, res: express.Response) {
@@ -153,5 +154,5 @@ async function unblockServer (req: express.Request, res: express.Response) {
153 154
154 await removeServerFromBlocklist(serverBlock) 155 await removeServerFromBlocklist(serverBlock)
155 156
156 return res.status(204).end() 157 return res.status(HttpStatusCode.NO_CONTENT_204).end()
157} 158}
diff --git a/server/controllers/api/users/index.ts b/server/controllers/api/users/index.ts
index 5b113feac..d743a9912 100644
--- a/server/controllers/api/users/index.ts
+++ b/server/controllers/api/users/index.ts
@@ -52,6 +52,7 @@ import { myVideosHistoryRouter } from './my-history'
52import { myNotificationsRouter } from './my-notifications' 52import { myNotificationsRouter } from './my-notifications'
53import { mySubscriptionsRouter } from './my-subscriptions' 53import { mySubscriptionsRouter } from './my-subscriptions'
54import { myVideoPlaylistsRouter } from './my-video-playlists' 54import { myVideoPlaylistsRouter } from './my-video-playlists'
55import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
55 56
56const auditLogger = auditLoggerFactory('users') 57const auditLogger = auditLoggerFactory('users')
57 58
@@ -255,7 +256,7 @@ async function registerUser (req: express.Request, res: express.Response) {
255 256
256 Hooks.runAction('action:api.user.registered', { body, user, account, videoChannel }) 257 Hooks.runAction('action:api.user.registered', { body, user, account, videoChannel })
257 258
258 return res.type('json').status(204).end() 259 return res.type('json').status(HttpStatusCode.NO_CONTENT_204).end()
259} 260}
260 261
261async function unblockUser (req: express.Request, res: express.Response) { 262async function unblockUser (req: express.Request, res: express.Response) {
@@ -265,7 +266,7 @@ async function unblockUser (req: express.Request, res: express.Response) {
265 266
266 Hooks.runAction('action:api.user.unblocked', { user }) 267 Hooks.runAction('action:api.user.unblocked', { user })
267 268
268 return res.status(204).end() 269 return res.status(HttpStatusCode.NO_CONTENT_204).end()
269} 270}
270 271
271async function blockUser (req: express.Request, res: express.Response) { 272async function blockUser (req: express.Request, res: express.Response) {
@@ -276,7 +277,7 @@ async function blockUser (req: express.Request, res: express.Response) {
276 277
277 Hooks.runAction('action:api.user.blocked', { user }) 278 Hooks.runAction('action:api.user.blocked', { user })
278 279
279 return res.status(204).end() 280 return res.status(HttpStatusCode.NO_CONTENT_204).end()
280} 281}
281 282
282function getUser (req: express.Request, res: express.Response) { 283function getUser (req: express.Request, res: express.Response) {
@@ -310,7 +311,7 @@ async function removeUser (req: express.Request, res: express.Response) {
310 311
311 Hooks.runAction('action:api.user.deleted', { user }) 312 Hooks.runAction('action:api.user.deleted', { user })
312 313
313 return res.sendStatus(204) 314 return res.sendStatus(HttpStatusCode.NO_CONTENT_204)
314} 315}
315 316
316async function updateUser (req: express.Request, res: express.Response) { 317async function updateUser (req: express.Request, res: express.Response) {
@@ -338,7 +339,7 @@ async function updateUser (req: express.Request, res: express.Response) {
338 339
339 // Don't need to send this update to followers, these attributes are not federated 340 // Don't need to send this update to followers, these attributes are not federated
340 341
341 return res.sendStatus(204) 342 return res.sendStatus(HttpStatusCode.NO_CONTENT_204)
342} 343}
343 344
344async function askResetUserPassword (req: express.Request, res: express.Response) { 345async function askResetUserPassword (req: express.Request, res: express.Response) {
@@ -348,7 +349,7 @@ async function askResetUserPassword (req: express.Request, res: express.Response
348 const url = WEBSERVER.URL + '/reset-password?userId=' + user.id + '&verificationString=' + verificationString 349 const url = WEBSERVER.URL + '/reset-password?userId=' + user.id + '&verificationString=' + verificationString
349 await Emailer.Instance.addPasswordResetEmailJob(user.username, user.email, url) 350 await Emailer.Instance.addPasswordResetEmailJob(user.username, user.email, url)
350 351
351 return res.status(204).end() 352 return res.status(HttpStatusCode.NO_CONTENT_204).end()
352} 353}
353 354
354async function resetUserPassword (req: express.Request, res: express.Response) { 355async function resetUserPassword (req: express.Request, res: express.Response) {
@@ -358,7 +359,7 @@ async function resetUserPassword (req: express.Request, res: express.Response) {
358 await user.save() 359 await user.save()
359 await Redis.Instance.removePasswordVerificationString(user.id) 360 await Redis.Instance.removePasswordVerificationString(user.id)
360 361
361 return res.status(204).end() 362 return res.status(HttpStatusCode.NO_CONTENT_204).end()
362} 363}
363 364
364async function reSendVerifyUserEmail (req: express.Request, res: express.Response) { 365async function reSendVerifyUserEmail (req: express.Request, res: express.Response) {
@@ -366,7 +367,7 @@ async function reSendVerifyUserEmail (req: express.Request, res: express.Respons
366 367
367 await sendVerifyUserEmail(user) 368 await sendVerifyUserEmail(user)
368 369
369 return res.status(204).end() 370 return res.status(HttpStatusCode.NO_CONTENT_204).end()
370} 371}
371 372
372async function verifyUserEmail (req: express.Request, res: express.Response) { 373async function verifyUserEmail (req: express.Request, res: express.Response) {
@@ -380,7 +381,7 @@ async function verifyUserEmail (req: express.Request, res: express.Response) {
380 381
381 await user.save() 382 await user.save()
382 383
383 return res.status(204).end() 384 return res.status(HttpStatusCode.NO_CONTENT_204).end()
384} 385}
385 386
386async function changeUserBlock (res: express.Response, user: MUserAccountDefault, block: boolean, reason?: string) { 387async function changeUserBlock (res: express.Response, user: MUserAccountDefault, block: boolean, reason?: string) {
diff --git a/server/controllers/api/users/me.ts b/server/controllers/api/users/me.ts
index b490518fc..3d2a325fe 100644
--- a/server/controllers/api/users/me.ts
+++ b/server/controllers/api/users/me.ts
@@ -28,6 +28,7 @@ import { AccountVideoRateModel } from '../../../models/account/account-video-rat
28import { UserModel } from '../../../models/account/user' 28import { UserModel } from '../../../models/account/user'
29import { VideoModel } from '../../../models/video/video' 29import { VideoModel } from '../../../models/video/video'
30import { VideoImportModel } from '../../../models/video/video-import' 30import { VideoImportModel } from '../../../models/video/video-import'
31import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
31 32
32const reqAvatarFile = createReqFiles([ 'avatarfile' ], MIMETYPES.IMAGE.MIMETYPE_EXT, { avatarfile: CONFIG.STORAGE.TMP_DIR }) 33const reqAvatarFile = createReqFiles([ 'avatarfile' ], MIMETYPES.IMAGE.MIMETYPE_EXT, { avatarfile: CONFIG.STORAGE.TMP_DIR })
33 34
@@ -162,7 +163,7 @@ async function deleteMe (req: express.Request, res: express.Response) {
162 163
163 await user.destroy() 164 await user.destroy()
164 165
165 return res.sendStatus(204) 166 return res.sendStatus(HttpStatusCode.NO_CONTENT_204)
166} 167}
167 168
168async function updateMe (req: express.Request, res: express.Response) { 169async function updateMe (req: express.Request, res: express.Response) {
@@ -210,7 +211,7 @@ async function updateMe (req: express.Request, res: express.Response) {
210 await sendVerifyUserEmail(user, true) 211 await sendVerifyUserEmail(user, true)
211 } 212 }
212 213
213 return res.sendStatus(204) 214 return res.sendStatus(HttpStatusCode.NO_CONTENT_204)
214} 215}
215 216
216async function updateMyAvatar (req: express.Request, res: express.Response) { 217async function updateMyAvatar (req: express.Request, res: express.Response) {
diff --git a/server/controllers/api/users/my-blocklist.ts b/server/controllers/api/users/my-blocklist.ts
index 6eba22d52..faaef3ac0 100644
--- a/server/controllers/api/users/my-blocklist.ts
+++ b/server/controllers/api/users/my-blocklist.ts
@@ -22,6 +22,7 @@ import { addAccountInBlocklist, addServerInBlocklist, removeAccountFromBlocklist
22import { ServerBlocklistModel } from '../../../models/server/server-blocklist' 22import { ServerBlocklistModel } from '../../../models/server/server-blocklist'
23import { UserNotificationModel } from '@server/models/account/user-notification' 23import { UserNotificationModel } from '@server/models/account/user-notification'
24import { logger } from '@server/helpers/logger' 24import { logger } from '@server/helpers/logger'
25import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
25 26
26const myBlocklistRouter = express.Router() 27const myBlocklistRouter = express.Router()
27 28
@@ -99,7 +100,7 @@ async function blockAccount (req: express.Request, res: express.Response) {
99 forUserId: user.id 100 forUserId: user.id
100 }).catch(err => logger.error('Cannot remove notifications after an account mute.', { err })) 101 }).catch(err => logger.error('Cannot remove notifications after an account mute.', { err }))
101 102
102 return res.status(204).end() 103 return res.status(HttpStatusCode.NO_CONTENT_204).end()
103} 104}
104 105
105async function unblockAccount (req: express.Request, res: express.Response) { 106async function unblockAccount (req: express.Request, res: express.Response) {
@@ -107,7 +108,7 @@ async function unblockAccount (req: express.Request, res: express.Response) {
107 108
108 await removeAccountFromBlocklist(accountBlock) 109 await removeAccountFromBlocklist(accountBlock)
109 110
110 return res.status(204).end() 111 return res.status(HttpStatusCode.NO_CONTENT_204).end()
111} 112}
112 113
113async function listBlockedServers (req: express.Request, res: express.Response) { 114async function listBlockedServers (req: express.Request, res: express.Response) {
@@ -136,7 +137,7 @@ async function blockServer (req: express.Request, res: express.Response) {
136 forUserId: user.id 137 forUserId: user.id
137 }).catch(err => logger.error('Cannot remove notifications after a server mute.', { err })) 138 }).catch(err => logger.error('Cannot remove notifications after a server mute.', { err }))
138 139
139 return res.status(204).end() 140 return res.status(HttpStatusCode.NO_CONTENT_204).end()
140} 141}
141 142
142async function unblockServer (req: express.Request, res: express.Response) { 143async function unblockServer (req: express.Request, res: express.Response) {
@@ -144,5 +145,5 @@ async function unblockServer (req: express.Request, res: express.Response) {
144 145
145 await removeServerFromBlocklist(serverBlock) 146 await removeServerFromBlocklist(serverBlock)
146 147
147 return res.status(204).end() 148 return res.status(HttpStatusCode.NO_CONTENT_204).end()
148} 149}
diff --git a/server/controllers/api/users/my-history.ts b/server/controllers/api/users/my-history.ts
index dc915977f..80d4dc748 100644
--- a/server/controllers/api/users/my-history.ts
+++ b/server/controllers/api/users/my-history.ts
@@ -10,6 +10,7 @@ import {
10import { getFormattedObjects } from '../../../helpers/utils' 10import { getFormattedObjects } from '../../../helpers/utils'
11import { UserVideoHistoryModel } from '../../../models/account/user-video-history' 11import { UserVideoHistoryModel } from '../../../models/account/user-video-history'
12import { sequelizeTypescript } from '../../../initializers/database' 12import { sequelizeTypescript } from '../../../initializers/database'
13import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
13 14
14const myVideosHistoryRouter = express.Router() 15const myVideosHistoryRouter = express.Router()
15 16
@@ -50,5 +51,7 @@ async function removeUserHistory (req: express.Request, res: express.Response) {
50 return UserVideoHistoryModel.removeUserHistoryBefore(user, beforeDate, t) 51 return UserVideoHistoryModel.removeUserHistoryBefore(user, beforeDate, t)
51 }) 52 })
52 53
53 return res.type('json').status(204).end() 54 return res.type('json')
55 .status(HttpStatusCode.NO_CONTENT_204)
56 .end()
54} 57}
diff --git a/server/controllers/api/users/my-notifications.ts b/server/controllers/api/users/my-notifications.ts
index 050866960..5f5e4c5e6 100644
--- a/server/controllers/api/users/my-notifications.ts
+++ b/server/controllers/api/users/my-notifications.ts
@@ -19,6 +19,7 @@ import {
19} from '../../../middlewares/validators/user-notifications' 19} from '../../../middlewares/validators/user-notifications'
20import { UserNotificationSetting } from '../../../../shared/models/users' 20import { UserNotificationSetting } from '../../../../shared/models/users'
21import { UserNotificationSettingModel } from '../../../models/account/user-notification-setting' 21import { UserNotificationSettingModel } from '../../../models/account/user-notification-setting'
22import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
22 23
23const myNotificationsRouter = express.Router() 24const myNotificationsRouter = express.Router()
24 25
@@ -84,7 +85,7 @@ async function updateNotificationSettings (req: express.Request, res: express.Re
84 85
85 await UserNotificationSettingModel.update(values, query) 86 await UserNotificationSettingModel.update(values, query)
86 87
87 return res.status(204).end() 88 return res.status(HttpStatusCode.NO_CONTENT_204).end()
88} 89}
89 90
90async function listUserNotifications (req: express.Request, res: express.Response) { 91async function listUserNotifications (req: express.Request, res: express.Response) {
@@ -100,7 +101,7 @@ async function markAsReadUserNotifications (req: express.Request, res: express.R
100 101
101 await UserNotificationModel.markAsRead(user.id, req.body.ids) 102 await UserNotificationModel.markAsRead(user.id, req.body.ids)
102 103
103 return res.status(204).end() 104 return res.status(HttpStatusCode.NO_CONTENT_204).end()
104} 105}
105 106
106async function markAsReadAllUserNotifications (req: express.Request, res: express.Response) { 107async function markAsReadAllUserNotifications (req: express.Request, res: express.Response) {
@@ -108,5 +109,5 @@ async function markAsReadAllUserNotifications (req: express.Request, res: expres
108 109
109 await UserNotificationModel.markAllAsRead(user.id) 110 await UserNotificationModel.markAllAsRead(user.id)
110 111
111 return res.status(204).end() 112 return res.status(HttpStatusCode.NO_CONTENT_204).end()
112} 113}
diff --git a/server/controllers/api/users/my-subscriptions.ts b/server/controllers/api/users/my-subscriptions.ts
index 66b33c477..ec77ddd7a 100644
--- a/server/controllers/api/users/my-subscriptions.ts
+++ b/server/controllers/api/users/my-subscriptions.ts
@@ -27,6 +27,7 @@ import {
27import { ActorFollowModel } from '../../../models/activitypub/actor-follow' 27import { ActorFollowModel } from '../../../models/activitypub/actor-follow'
28import { VideoModel } from '../../../models/video/video' 28import { VideoModel } from '../../../models/video/video'
29import { sendUndoFollow } from '@server/lib/activitypub/send' 29import { sendUndoFollow } from '@server/lib/activitypub/send'
30import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
30 31
31const mySubscriptionsRouter = express.Router() 32const mySubscriptionsRouter = express.Router()
32 33
@@ -126,7 +127,7 @@ function addUserSubscription (req: express.Request, res: express.Response) {
126 127
127 JobQueue.Instance.createJob({ type: 'activitypub-follow', payload }) 128 JobQueue.Instance.createJob({ type: 'activitypub-follow', payload })
128 129
129 return res.status(204).end() 130 return res.status(HttpStatusCode.NO_CONTENT_204).end()
130} 131}
131 132
132function getUserSubscription (req: express.Request, res: express.Response) { 133function getUserSubscription (req: express.Request, res: express.Response) {
@@ -144,7 +145,9 @@ async function deleteUserSubscription (req: express.Request, res: express.Respon
144 return subscription.destroy({ transaction: t }) 145 return subscription.destroy({ transaction: t })
145 }) 146 })
146 147
147 return res.type('json').status(204).end() 148 return res.type('json')
149 .status(HttpStatusCode.NO_CONTENT_204)
150 .end()
148} 151}
149 152
150async function getUserSubscriptions (req: express.Request, res: express.Response) { 153async function getUserSubscriptions (req: express.Request, res: express.Response) {
diff --git a/server/controllers/api/video-channel.ts b/server/controllers/api/video-channel.ts
index 45c936978..5c96950c5 100644
--- a/server/controllers/api/video-channel.ts
+++ b/server/controllers/api/video-channel.ts
@@ -38,6 +38,7 @@ import { AccountModel } from '../../models/account/account'
38import { VideoModel } from '../../models/video/video' 38import { VideoModel } from '../../models/video/video'
39import { VideoChannelModel } from '../../models/video/video-channel' 39import { VideoChannelModel } from '../../models/video/video-channel'
40import { VideoPlaylistModel } from '../../models/video/video-playlist' 40import { VideoPlaylistModel } from '../../models/video/video-playlist'
41import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes'
41 42
42const auditLogger = auditLoggerFactory('channels') 43const auditLogger = auditLoggerFactory('channels')
43const reqAvatarFile = createReqFiles([ 'avatarfile' ], MIMETYPES.IMAGE.MIMETYPE_EXT, { avatarfile: CONFIG.STORAGE.TMP_DIR }) 44const reqAvatarFile = createReqFiles([ 'avatarfile' ], MIMETYPES.IMAGE.MIMETYPE_EXT, { avatarfile: CONFIG.STORAGE.TMP_DIR })
@@ -212,7 +213,7 @@ async function updateVideoChannel (req: express.Request, res: express.Response)
212 throw err 213 throw err
213 } 214 }
214 215
215 res.type('json').status(204).end() 216 res.type('json').status(HttpStatusCode.NO_CONTENT_204).end()
216 217
217 // Don't process in a transaction, and after the response because it could be long 218 // Don't process in a transaction, and after the response because it could be long
218 if (doBulkVideoUpdate) { 219 if (doBulkVideoUpdate) {
@@ -232,7 +233,7 @@ async function removeVideoChannel (req: express.Request, res: express.Response)
232 logger.info('Video channel %s deleted.', videoChannelInstance.Actor.url) 233 logger.info('Video channel %s deleted.', videoChannelInstance.Actor.url)
233 }) 234 })
234 235
235 return res.type('json').status(204).end() 236 return res.type('json').status(HttpStatusCode.NO_CONTENT_204).end()
236} 237}
237 238
238async function getVideoChannel (req: express.Request, res: express.Response) { 239async function getVideoChannel (req: express.Request, res: express.Response) {
diff --git a/server/controllers/api/video-playlist.ts b/server/controllers/api/video-playlist.ts
index fb08a63b2..f3dc8b2a9 100644
--- a/server/controllers/api/video-playlist.ts
+++ b/server/controllers/api/video-playlist.ts
@@ -42,6 +42,7 @@ import {
42import { AccountModel } from '../../models/account/account' 42import { AccountModel } from '../../models/account/account'
43import { VideoPlaylistModel } from '../../models/video/video-playlist' 43import { VideoPlaylistModel } from '../../models/video/video-playlist'
44import { VideoPlaylistElementModel } from '../../models/video/video-playlist-element' 44import { VideoPlaylistElementModel } from '../../models/video/video-playlist-element'
45import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes'
45 46
46const reqThumbnailFile = createReqFiles([ 'thumbnailfile' ], MIMETYPES.IMAGE.MIMETYPE_EXT, { thumbnailfile: CONFIG.STORAGE.TMP_DIR }) 47const reqThumbnailFile = createReqFiles([ 'thumbnailfile' ], MIMETYPES.IMAGE.MIMETYPE_EXT, { thumbnailfile: CONFIG.STORAGE.TMP_DIR })
47 48
@@ -271,7 +272,7 @@ async function updateVideoPlaylist (req: express.Request, res: express.Response)
271 throw err 272 throw err
272 } 273 }
273 274
274 return res.type('json').status(204).end() 275 return res.type('json').status(HttpStatusCode.NO_CONTENT_204).end()
275} 276}
276 277
277async function removeVideoPlaylist (req: express.Request, res: express.Response) { 278async function removeVideoPlaylist (req: express.Request, res: express.Response) {
@@ -285,7 +286,7 @@ async function removeVideoPlaylist (req: express.Request, res: express.Response)
285 logger.info('Video playlist %s deleted.', videoPlaylistInstance.uuid) 286 logger.info('Video playlist %s deleted.', videoPlaylistInstance.uuid)
286 }) 287 })
287 288
288 return res.type('json').status(204).end() 289 return res.type('json').status(HttpStatusCode.NO_CONTENT_204).end()
289} 290}
290 291
291async function addVideoInPlaylist (req: express.Request, res: express.Response) { 292async function addVideoInPlaylist (req: express.Request, res: express.Response) {
@@ -351,7 +352,7 @@ async function updateVideoPlaylistElement (req: express.Request, res: express.Re
351 352
352 logger.info('Element of position %d of playlist %s updated.', playlistElement.position, videoPlaylist.uuid) 353 logger.info('Element of position %d of playlist %s updated.', playlistElement.position, videoPlaylist.uuid)
353 354
354 return res.type('json').status(204).end() 355 return res.type('json').status(HttpStatusCode.NO_CONTENT_204).end()
355} 356}
356 357
357async function removeVideoFromPlaylist (req: express.Request, res: express.Response) { 358async function removeVideoFromPlaylist (req: express.Request, res: express.Response) {
@@ -379,7 +380,7 @@ async function removeVideoFromPlaylist (req: express.Request, res: express.Respo
379 sendUpdateVideoPlaylist(videoPlaylist, undefined) 380 sendUpdateVideoPlaylist(videoPlaylist, undefined)
380 .catch(err => logger.error('Cannot send video playlist update.', { err })) 381 .catch(err => logger.error('Cannot send video playlist update.', { err }))
381 382
382 return res.type('json').status(204).end() 383 return res.type('json').status(HttpStatusCode.NO_CONTENT_204).end()
383} 384}
384 385
385async function reorderVideosPlaylist (req: express.Request, res: express.Response) { 386async function reorderVideosPlaylist (req: express.Request, res: express.Response) {
@@ -391,7 +392,7 @@ async function reorderVideosPlaylist (req: express.Request, res: express.Respons
391 const reorderLength: number = body.reorderLength || 1 392 const reorderLength: number = body.reorderLength || 1
392 393
393 if (start === insertAfter) { 394 if (start === insertAfter) {
394 return res.status(204).end() 395 return res.status(HttpStatusCode.NO_CONTENT_204).end()
395 } 396 }
396 397
397 // Example: if we reorder position 2 and insert after position 5 (so at position 6): # 1 2 3 4 5 6 7 8 9 398 // Example: if we reorder position 2 and insert after position 5 (so at position 6): # 1 2 3 4 5 6 7 8 9
@@ -432,7 +433,7 @@ async function reorderVideosPlaylist (req: express.Request, res: express.Respons
432 videoPlaylist.uuid, insertAfter, start, start + reorderLength - 1 433 videoPlaylist.uuid, insertAfter, start, start + reorderLength - 1
433 ) 434 )
434 435
435 return res.type('json').status(204).end() 436 return res.type('json').status(HttpStatusCode.NO_CONTENT_204).end()
436} 437}
437 438
438async function getVideoPlaylistVideos (req: express.Request, res: express.Response) { 439async function getVideoPlaylistVideos (req: express.Request, res: express.Response) {
diff --git a/server/controllers/api/videos/blacklist.ts b/server/controllers/api/videos/blacklist.ts
index 3b25ceea2..fa8448c86 100644
--- a/server/controllers/api/videos/blacklist.ts
+++ b/server/controllers/api/videos/blacklist.ts
@@ -18,6 +18,7 @@ import {
18 videosBlacklistUpdateValidator 18 videosBlacklistUpdateValidator
19} from '../../../middlewares' 19} from '../../../middlewares'
20import { VideoBlacklistModel } from '../../../models/video/video-blacklist' 20import { VideoBlacklistModel } from '../../../models/video/video-blacklist'
21import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
21 22
22const blacklistRouter = express.Router() 23const blacklistRouter = express.Router()
23 24
@@ -69,7 +70,7 @@ async function addVideoToBlacklistController (req: express.Request, res: express
69 70
70 logger.info('Video %s blacklisted.', videoInstance.uuid) 71 logger.info('Video %s blacklisted.', videoInstance.uuid)
71 72
72 return res.type('json').sendStatus(204) 73 return res.type('json').sendStatus(HttpStatusCode.NO_CONTENT_204)
73} 74}
74 75
75async function updateVideoBlacklistController (req: express.Request, res: express.Response) { 76async function updateVideoBlacklistController (req: express.Request, res: express.Response) {
@@ -81,7 +82,7 @@ async function updateVideoBlacklistController (req: express.Request, res: expres
81 return videoBlacklist.save({ transaction: t }) 82 return videoBlacklist.save({ transaction: t })
82 }) 83 })
83 84
84 return res.type('json').sendStatus(204) 85 return res.type('json').sendStatus(HttpStatusCode.NO_CONTENT_204)
85} 86}
86 87
87async function listBlacklist (req: express.Request, res: express.Response) { 88async function listBlacklist (req: express.Request, res: express.Response) {
@@ -104,5 +105,5 @@ async function removeVideoFromBlacklistController (req: express.Request, res: ex
104 105
105 logger.info('Video %s removed from blacklist.', video.uuid) 106 logger.info('Video %s removed from blacklist.', video.uuid)
106 107
107 return res.type('json').sendStatus(204) 108 return res.type('json').sendStatus(HttpStatusCode.NO_CONTENT_204)
108} 109}
diff --git a/server/controllers/api/videos/captions.ts b/server/controllers/api/videos/captions.ts
index c4e2ee72c..bf82e2c19 100644
--- a/server/controllers/api/videos/captions.ts
+++ b/server/controllers/api/videos/captions.ts
@@ -11,6 +11,7 @@ import { moveAndProcessCaptionFile } from '../../../helpers/captions-utils'
11import { CONFIG } from '../../../initializers/config' 11import { CONFIG } from '../../../initializers/config'
12import { sequelizeTypescript } from '../../../initializers/database' 12import { sequelizeTypescript } from '../../../initializers/database'
13import { MVideoCaptionVideo } from '@server/types/models' 13import { MVideoCaptionVideo } from '@server/types/models'
14import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
14 15
15const reqVideoCaptionAdd = createReqFiles( 16const reqVideoCaptionAdd = createReqFiles(
16 [ 'captionfile' ], 17 [ 'captionfile' ],
@@ -72,7 +73,7 @@ async function addVideoCaption (req: express.Request, res: express.Response) {
72 await federateVideoIfNeeded(video, false, t) 73 await federateVideoIfNeeded(video, false, t)
73 }) 74 })
74 75
75 return res.status(204).end() 76 return res.status(HttpStatusCode.NO_CONTENT_204).end()
76} 77}
77 78
78async function deleteVideoCaption (req: express.Request, res: express.Response) { 79async function deleteVideoCaption (req: express.Request, res: express.Response) {
@@ -88,5 +89,5 @@ async function deleteVideoCaption (req: express.Request, res: express.Response)
88 89
89 logger.info('Video caption %s of video %s deleted.', videoCaption.language, video.uuid) 90 logger.info('Video caption %s of video %s deleted.', videoCaption.language, video.uuid)
90 91
91 return res.type('json').status(204).end() 92 return res.type('json').status(HttpStatusCode.NO_CONTENT_204).end()
92} 93}
diff --git a/server/controllers/api/videos/comment.ts b/server/controllers/api/videos/comment.ts
index 020d0b104..752a33596 100644
--- a/server/controllers/api/videos/comment.ts
+++ b/server/controllers/api/videos/comment.ts
@@ -29,6 +29,7 @@ import {
29} from '../../../middlewares/validators' 29} from '../../../middlewares/validators'
30import { AccountModel } from '../../../models/account/account' 30import { AccountModel } from '../../../models/account/account'
31import { VideoCommentModel } from '../../../models/video/video-comment' 31import { VideoCommentModel } from '../../../models/video/video-comment'
32import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
32 33
33const auditLogger = auditLoggerFactory('comments') 34const auditLogger = auditLoggerFactory('comments')
34const videoCommentRouter = express.Router() 35const videoCommentRouter = express.Router()
@@ -161,7 +162,7 @@ async function listVideoThreadComments (req: express.Request, res: express.Respo
161 } 162 }
162 163
163 if (resultList.data.length === 0) { 164 if (resultList.data.length === 0) {
164 return res.sendStatus(404) 165 return res.sendStatus(HttpStatusCode.NOT_FOUND_404)
165 } 166 }
166 167
167 return res.json(buildFormattedCommentTree(resultList)) 168 return res.json(buildFormattedCommentTree(resultList))
@@ -218,5 +219,7 @@ async function removeVideoComment (req: express.Request, res: express.Response)
218 219
219 auditLogger.delete(getAuditIdFromRes(res), new CommentAuditView(videoCommentInstance.toFormattedJSON())) 220 auditLogger.delete(getAuditIdFromRes(res), new CommentAuditView(videoCommentInstance.toFormattedJSON()))
220 221
221 return res.type('json').status(204).end() 222 return res.type('json')
223 .status(HttpStatusCode.NO_CONTENT_204)
224 .end()
222} 225}
diff --git a/server/controllers/api/videos/import.ts b/server/controllers/api/videos/import.ts
index bc5fea7aa..cd9ba046d 100644
--- a/server/controllers/api/videos/import.ts
+++ b/server/controllers/api/videos/import.ts
@@ -36,6 +36,7 @@ import { asyncMiddleware, asyncRetryTransactionMiddleware, authenticate, videoIm
36import { VideoModel } from '../../../models/video/video' 36import { VideoModel } from '../../../models/video/video'
37import { VideoCaptionModel } from '../../../models/video/video-caption' 37import { VideoCaptionModel } from '../../../models/video/video-caption'
38import { VideoImportModel } from '../../../models/video/video-import' 38import { VideoImportModel } from '../../../models/video/video-import'
39import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
39 40
40const auditLogger = auditLoggerFactory('video-imports') 41const auditLogger = auditLoggerFactory('video-imports')
41const videoImportsRouter = express.Router() 42const videoImportsRouter = express.Router()
@@ -146,7 +147,7 @@ async function addYoutubeDLImport (req: express.Request, res: express.Response)
146 } catch (err) { 147 } catch (err) {
147 logger.info('Cannot fetch information from import for URL %s.', targetUrl, { err }) 148 logger.info('Cannot fetch information from import for URL %s.', targetUrl, { err })
148 149
149 return res.status(400).json({ 150 return res.status(HttpStatusCode.BAD_REQUEST_400).json({
150 error: 'Cannot fetch remote information of this URL.' 151 error: 'Cannot fetch remote information of this URL.'
151 }).end() 152 }).end()
152 } 153 }
diff --git a/server/controllers/api/videos/index.ts b/server/controllers/api/videos/index.ts
index 71a0f97e2..e1c775180 100644
--- a/server/controllers/api/videos/index.ts
+++ b/server/controllers/api/videos/index.ts
@@ -66,6 +66,7 @@ import { liveRouter } from './live'
66import { ownershipVideoRouter } from './ownership' 66import { ownershipVideoRouter } from './ownership'
67import { rateVideoRouter } from './rate' 67import { rateVideoRouter } from './rate'
68import { watchingRouter } from './watching' 68import { watchingRouter } from './watching'
69import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
69 70
70const auditLogger = auditLoggerFactory('videos') 71const auditLogger = auditLoggerFactory('videos')
71const videosRouter = express.Router() 72const videosRouter = express.Router()
@@ -178,7 +179,7 @@ async function addVideo (req: express.Request, res: express.Response) {
178 // Set timeout to 10 minutes, as Express's default is 2 minutes 179 // Set timeout to 10 minutes, as Express's default is 2 minutes
179 req.setTimeout(1000 * 60 * 10, () => { 180 req.setTimeout(1000 * 60 * 10, () => {
180 logger.error('Upload video has timed out.') 181 logger.error('Upload video has timed out.')
181 return res.sendStatus(408) 182 return res.sendStatus(HttpStatusCode.REQUEST_TIMEOUT_408)
182 }) 183 })
183 184
184 const videoPhysicalFile = req.files['videofile'][0] 185 const videoPhysicalFile = req.files['videofile'][0]
@@ -394,7 +395,9 @@ async function updateVideo (req: express.Request, res: express.Response) {
394 throw err 395 throw err
395 } 396 }
396 397
397 return res.type('json').status(204).end() 398 return res.type('json')
399 .status(HttpStatusCode.NO_CONTENT_204)
400 .end()
398} 401}
399 402
400async function getVideo (req: express.Request, res: express.Response) { 403async function getVideo (req: express.Request, res: express.Response) {
@@ -421,7 +424,7 @@ async function viewVideo (req: express.Request, res: express.Response) {
421 const exists = await Redis.Instance.doesVideoIPViewExist(ip, immutableVideoAttrs.uuid) 424 const exists = await Redis.Instance.doesVideoIPViewExist(ip, immutableVideoAttrs.uuid)
422 if (exists) { 425 if (exists) {
423 logger.debug('View for ip %s and video %s already exists.', ip, immutableVideoAttrs.uuid) 426 logger.debug('View for ip %s and video %s already exists.', ip, immutableVideoAttrs.uuid)
424 return res.sendStatus(204) 427 return res.sendStatus(HttpStatusCode.NO_CONTENT_204)
425 } 428 }
426 429
427 const video = await VideoModel.load(immutableVideoAttrs.id) 430 const video = await VideoModel.load(immutableVideoAttrs.id)
@@ -454,7 +457,7 @@ async function viewVideo (req: express.Request, res: express.Response) {
454 457
455 Hooks.runAction('action:api.video.viewed', { video, ip }) 458 Hooks.runAction('action:api.video.viewed', { video, ip })
456 459
457 return res.sendStatus(204) 460 return res.sendStatus(HttpStatusCode.NO_CONTENT_204)
458} 461}
459 462
460async function getVideoDescription (req: express.Request, res: express.Response) { 463async function getVideoDescription (req: express.Request, res: express.Response) {
@@ -517,5 +520,7 @@ async function removeVideo (req: express.Request, res: express.Response) {
517 520
518 Hooks.runAction('action:api.video.deleted', { video: videoInstance }) 521 Hooks.runAction('action:api.video.deleted', { video: videoInstance })
519 522
520 return res.type('json').status(204).end() 523 return res.type('json')
524 .status(HttpStatusCode.NO_CONTENT_204)
525 .end()
521} 526}
diff --git a/server/controllers/api/videos/live.ts b/server/controllers/api/videos/live.ts
index e67d89612..04d2494ce 100644
--- a/server/controllers/api/videos/live.ts
+++ b/server/controllers/api/videos/live.ts
@@ -16,6 +16,7 @@ import { sequelizeTypescript } from '../../../initializers/database'
16import { createVideoMiniatureFromExisting } from '../../../lib/thumbnail' 16import { createVideoMiniatureFromExisting } from '../../../lib/thumbnail'
17import { asyncMiddleware, asyncRetryTransactionMiddleware, authenticate } from '../../../middlewares' 17import { asyncMiddleware, asyncRetryTransactionMiddleware, authenticate } from '../../../middlewares'
18import { VideoModel } from '../../../models/video/video' 18import { VideoModel } from '../../../models/video/video'
19import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
19 20
20const liveRouter = express.Router() 21const liveRouter = express.Router()
21 22
@@ -75,7 +76,7 @@ async function updateLiveVideo (req: express.Request, res: express.Response) {
75 76
76 await federateVideoIfNeeded(video, false) 77 await federateVideoIfNeeded(video, false)
77 78
78 return res.sendStatus(204) 79 return res.sendStatus(HttpStatusCode.NO_CONTENT_204)
79} 80}
80 81
81async function addLiveVideo (req: express.Request, res: express.Response) { 82async function addLiveVideo (req: express.Request, res: express.Response) {
diff --git a/server/controllers/api/videos/ownership.ts b/server/controllers/api/videos/ownership.ts
index d76fee51d..86adb6c69 100644
--- a/server/controllers/api/videos/ownership.ts
+++ b/server/controllers/api/videos/ownership.ts
@@ -19,6 +19,7 @@ import { changeVideoChannelShare } from '../../../lib/activitypub/share'
19import { sendUpdateVideo } from '../../../lib/activitypub/send' 19import { sendUpdateVideo } from '../../../lib/activitypub/send'
20import { VideoModel } from '../../../models/video/video' 20import { VideoModel } from '../../../models/video/video'
21import { MVideoFullLight } from '@server/types/models' 21import { MVideoFullLight } from '@server/types/models'
22import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
22 23
23const ownershipVideoRouter = express.Router() 24const ownershipVideoRouter = express.Router()
24 25
@@ -80,7 +81,9 @@ async function giveVideoOwnership (req: express.Request, res: express.Response)
80 }) 81 })
81 82
82 logger.info('Ownership change for video %s created.', videoInstance.name) 83 logger.info('Ownership change for video %s created.', videoInstance.name)
83 return res.type('json').status(204).end() 84 return res.type('json')
85 .status(HttpStatusCode.NO_CONTENT_204)
86 .end()
84} 87}
85 88
86async function listVideoOwnership (req: express.Request, res: express.Response) { 89async function listVideoOwnership (req: express.Request, res: express.Response) {
@@ -119,7 +122,7 @@ async function acceptOwnership (req: express.Request, res: express.Response) {
119 videoChangeOwnership.status = VideoChangeOwnershipStatus.ACCEPTED 122 videoChangeOwnership.status = VideoChangeOwnershipStatus.ACCEPTED
120 await videoChangeOwnership.save({ transaction: t }) 123 await videoChangeOwnership.save({ transaction: t })
121 124
122 return res.sendStatus(204) 125 return res.sendStatus(HttpStatusCode.NO_CONTENT_204)
123 }) 126 })
124} 127}
125 128
@@ -130,6 +133,6 @@ async function refuseOwnership (req: express.Request, res: express.Response) {
130 videoChangeOwnership.status = VideoChangeOwnershipStatus.REFUSED 133 videoChangeOwnership.status = VideoChangeOwnershipStatus.REFUSED
131 await videoChangeOwnership.save({ transaction: t }) 134 await videoChangeOwnership.save({ transaction: t })
132 135
133 return res.sendStatus(204) 136 return res.sendStatus(HttpStatusCode.NO_CONTENT_204)
134 }) 137 })
135} 138}
diff --git a/server/controllers/api/videos/rate.ts b/server/controllers/api/videos/rate.ts
index df1eddb4f..520932c63 100644
--- a/server/controllers/api/videos/rate.ts
+++ b/server/controllers/api/videos/rate.ts
@@ -7,6 +7,7 @@ import { asyncMiddleware, asyncRetryTransactionMiddleware, authenticate, videoUp
7import { AccountModel } from '../../../models/account/account' 7import { AccountModel } from '../../../models/account/account'
8import { AccountVideoRateModel } from '../../../models/account/account-video-rate' 8import { AccountVideoRateModel } from '../../../models/account/account-video-rate'
9import { sequelizeTypescript } from '../../../initializers/database' 9import { sequelizeTypescript } from '../../../initializers/database'
10import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
10 11
11const rateVideoRouter = express.Router() 12const rateVideoRouter = express.Router()
12 13
@@ -78,5 +79,7 @@ async function rateVideo (req: express.Request, res: express.Response) {
78 logger.info('Account video rate for video %s of account %s updated.', videoInstance.name, accountInstance.name) 79 logger.info('Account video rate for video %s of account %s updated.', videoInstance.name, accountInstance.name)
79 }) 80 })
80 81
81 return res.type('json').status(204).end() 82 return res.type('json')
83 .status(HttpStatusCode.NO_CONTENT_204)
84 .end()
82} 85}
diff --git a/server/controllers/api/videos/watching.ts b/server/controllers/api/videos/watching.ts
index 036e16f3a..627f12aa9 100644
--- a/server/controllers/api/videos/watching.ts
+++ b/server/controllers/api/videos/watching.ts
@@ -2,6 +2,7 @@ import * as express from 'express'
2import { UserWatchingVideo } from '../../../../shared' 2import { UserWatchingVideo } from '../../../../shared'
3import { asyncMiddleware, asyncRetryTransactionMiddleware, authenticate, videoWatchingValidator } from '../../../middlewares' 3import { asyncMiddleware, asyncRetryTransactionMiddleware, authenticate, videoWatchingValidator } from '../../../middlewares'
4import { UserVideoHistoryModel } from '../../../models/account/user-video-history' 4import { UserVideoHistoryModel } from '../../../models/account/user-video-history'
5import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
5 6
6const watchingRouter = express.Router() 7const watchingRouter = express.Router()
7 8
@@ -31,5 +32,7 @@ async function userWatchVideo (req: express.Request, res: express.Response) {
31 currentTime: body.currentTime 32 currentTime: body.currentTime
32 }) 33 })
33 34
34 return res.type('json').status(204).end() 35 return res.type('json')
36 .status(HttpStatusCode.NO_CONTENT_204)
37 .end()
35} 38}
diff --git a/server/controllers/client.ts b/server/controllers/client.ts
index 592233676..49e6fd661 100644
--- a/server/controllers/client.ts
+++ b/server/controllers/client.ts
@@ -8,6 +8,7 @@ import { logger } from '../helpers/logger'
8import { ACCEPT_HEADERS, STATIC_MAX_AGE } from '../initializers/constants' 8import { ACCEPT_HEADERS, STATIC_MAX_AGE } from '../initializers/constants'
9import { ClientHtml } from '../lib/client-html' 9import { ClientHtml } from '../lib/client-html'
10import { asyncMiddleware, embedCSP } from '../middlewares' 10import { asyncMiddleware, embedCSP } from '../middlewares'
11import { HttpStatusCode } from '@shared/core-utils'
11 12
12const clientsRouter = express.Router() 13const clientsRouter = express.Router()
13 14
@@ -87,7 +88,7 @@ clientsRouter.use('/client', express.static(distPath, { maxAge: STATIC_MAX_AGE.C
87 88
88// 404 for static files not found 89// 404 for static files not found
89clientsRouter.use('/client/*', (req: express.Request, res: express.Response) => { 90clientsRouter.use('/client/*', (req: express.Request, res: express.Response) => {
90 res.sendStatus(404) 91 res.sendStatus(HttpStatusCode.NOT_FOUND_404)
91}) 92})
92 93
93// Always serve index client page (the client is a single page application, let it handle routing) 94// Always serve index client page (the client is a single page application, let it handle routing)
@@ -114,7 +115,7 @@ function serveServerTranslations (req: express.Request, res: express.Response) {
114 return res.sendFile(path, { maxAge: STATIC_MAX_AGE.SERVER }) 115 return res.sendFile(path, { maxAge: STATIC_MAX_AGE.SERVER })
115 } 116 }
116 117
117 return res.sendStatus(404) 118 return res.sendStatus(HttpStatusCode.NOT_FOUND_404)
118} 119}
119 120
120async function serveIndexHTML (req: express.Request, res: express.Response) { 121async function serveIndexHTML (req: express.Request, res: express.Response) {
@@ -127,7 +128,7 @@ async function serveIndexHTML (req: express.Request, res: express.Response) {
127 } 128 }
128 } 129 }
129 130
130 return res.status(404).end() 131 return res.status(HttpStatusCode.INTERNAL_SERVER_ERROR_500).end()
131} 132}
132 133
133async function generateEmbedHtmlPage (req: express.Request, res: express.Response) { 134async function generateEmbedHtmlPage (req: express.Request, res: express.Response) {
diff --git a/server/controllers/lazy-static.ts b/server/controllers/lazy-static.ts
index 1ff99e90c..5c6369c9e 100644
--- a/server/controllers/lazy-static.ts
+++ b/server/controllers/lazy-static.ts
@@ -6,6 +6,7 @@ import { asyncMiddleware } from '../middlewares'
6import { AvatarModel } from '../models/avatar/avatar' 6import { AvatarModel } from '../models/avatar/avatar'
7import { logger } from '../helpers/logger' 7import { logger } from '../helpers/logger'
8import { avatarPathUnsafeCache, pushAvatarProcessInQueue } from '../lib/avatar' 8import { avatarPathUnsafeCache, pushAvatarProcessInQueue } from '../lib/avatar'
9import { HttpStatusCode } from '../../shared/core-utils/miscs/http-error-codes'
9 10
10const lazyStaticRouter = express.Router() 11const lazyStaticRouter = express.Router()
11 12
@@ -44,10 +45,10 @@ async function getAvatar (req: express.Request, res: express.Response) {
44 } 45 }
45 46
46 const avatar = await AvatarModel.loadByName(filename) 47 const avatar = await AvatarModel.loadByName(filename)
47 if (!avatar) return res.sendStatus(404) 48 if (!avatar) return res.sendStatus(HttpStatusCode.NOT_FOUND_404)
48 49
49 if (avatar.onDisk === false) { 50 if (avatar.onDisk === false) {
50 if (!avatar.fileUrl) return res.sendStatus(404) 51 if (!avatar.fileUrl) return res.sendStatus(HttpStatusCode.NOT_FOUND_404)
51 52
52 logger.info('Lazy serve remote avatar image %s.', avatar.fileUrl) 53 logger.info('Lazy serve remote avatar image %s.', avatar.fileUrl)
53 54
@@ -55,7 +56,7 @@ async function getAvatar (req: express.Request, res: express.Response) {
55 await pushAvatarProcessInQueue({ filename: avatar.filename, fileUrl: avatar.fileUrl }) 56 await pushAvatarProcessInQueue({ filename: avatar.filename, fileUrl: avatar.fileUrl })
56 } catch (err) { 57 } catch (err) {
57 logger.warn('Cannot process remote avatar %s.', avatar.fileUrl, { err }) 58 logger.warn('Cannot process remote avatar %s.', avatar.fileUrl, { err })
58 return res.sendStatus(404) 59 return res.sendStatus(HttpStatusCode.NOT_FOUND_404)
59 } 60 }
60 61
61 avatar.onDisk = true 62 avatar.onDisk = true
@@ -71,7 +72,7 @@ async function getAvatar (req: express.Request, res: express.Response) {
71 72
72async function getPreview (req: express.Request, res: express.Response) { 73async function getPreview (req: express.Request, res: express.Response) {
73 const result = await VideosPreviewCache.Instance.getFilePath(req.params.uuid) 74 const result = await VideosPreviewCache.Instance.getFilePath(req.params.uuid)
74 if (!result) return res.sendStatus(404) 75 if (!result) return res.sendStatus(HttpStatusCode.NOT_FOUND_404)
75 76
76 return res.sendFile(result.path, { maxAge: STATIC_MAX_AGE.SERVER }) 77 return res.sendFile(result.path, { maxAge: STATIC_MAX_AGE.SERVER })
77} 78}
@@ -81,7 +82,7 @@ async function getVideoCaption (req: express.Request, res: express.Response) {
81 videoId: req.params.videoId, 82 videoId: req.params.videoId,
82 language: req.params.captionLanguage 83 language: req.params.captionLanguage
83 }) 84 })
84 if (!result) return res.sendStatus(404) 85 if (!result) return res.sendStatus(HttpStatusCode.NOT_FOUND_404)
85 86
86 return res.sendFile(result.path, { maxAge: STATIC_MAX_AGE.SERVER }) 87 return res.sendFile(result.path, { maxAge: STATIC_MAX_AGE.SERVER })
87} 88}
diff --git a/server/controllers/live.ts b/server/controllers/live.ts
index 5feadae72..ff48b0e21 100644
--- a/server/controllers/live.ts
+++ b/server/controllers/live.ts
@@ -2,6 +2,7 @@ import * as cors from 'cors'
2import * as express from 'express' 2import * as express from 'express'
3import { mapToJSON } from '@server/helpers/core-utils' 3import { mapToJSON } from '@server/helpers/core-utils'
4import { LiveManager } from '@server/lib/live-manager' 4import { LiveManager } from '@server/lib/live-manager'
5import { HttpStatusCode } from '@shared/core-utils/miscs/http-error-codes'
5 6
6const liveRouter = express.Router() 7const liveRouter = express.Router()
7 8
@@ -24,7 +25,7 @@ function getSegmentsSha256 (req: express.Request, res: express.Response) {
24 const result = LiveManager.Instance.getSegmentsSha256(videoUUID) 25 const result = LiveManager.Instance.getSegmentsSha256(videoUUID)
25 26
26 if (!result) { 27 if (!result) {
27 return res.sendStatus(404) 28 return res.sendStatus(HttpStatusCode.NOT_FOUND_404)
28 } 29 }
29 30
30 return res.json(mapToJSON(result)) 31 return res.json(mapToJSON(result))
diff --git a/server/controllers/plugins.ts b/server/controllers/plugins.ts
index 7b947bb6e..18c6613e2 100644
--- a/server/controllers/plugins.ts
+++ b/server/controllers/plugins.ts
@@ -4,9 +4,10 @@ import { join } from 'path'
4import { PluginManager, RegisteredPlugin } from '../lib/plugins/plugin-manager' 4import { PluginManager, RegisteredPlugin } from '../lib/plugins/plugin-manager'
5import { getPluginValidator, pluginStaticDirectoryValidator, getExternalAuthValidator } from '../middlewares/validators/plugins' 5import { getPluginValidator, pluginStaticDirectoryValidator, getExternalAuthValidator } from '../middlewares/validators/plugins'
6import { serveThemeCSSValidator } from '../middlewares/validators/themes' 6import { serveThemeCSSValidator } from '../middlewares/validators/themes'
7import { HttpStatusCode } from '../../shared/core-utils/miscs/http-error-codes'
8import { getCompleteLocale, is18nLocale } from '../../shared/core-utils/i18n'
7import { PluginType } from '../../shared/models/plugins/plugin.type' 9import { PluginType } from '../../shared/models/plugins/plugin.type'
8import { isTestInstance } from '../helpers/core-utils' 10import { isTestInstance } from '../helpers/core-utils'
9import { getCompleteLocale, is18nLocale } from '../../shared/core-utils/i18n'
10import { logger } from '@server/helpers/logger' 11import { logger } from '@server/helpers/logger'
11 12
12const sendFileOptions = { 13const sendFileOptions = {
@@ -96,7 +97,7 @@ function getPluginTranslations (req: express.Request, res: express.Response) {
96 return res.json(json) 97 return res.json(json)
97 } 98 }
98 99
99 return res.sendStatus(404) 100 return res.sendStatus(HttpStatusCode.NOT_FOUND_404)
100} 101}
101 102
102function servePluginStaticDirectory (req: express.Request, res: express.Response) { 103function servePluginStaticDirectory (req: express.Request, res: express.Response) {
@@ -106,7 +107,7 @@ function servePluginStaticDirectory (req: express.Request, res: express.Response
106 const [ directory, ...file ] = staticEndpoint.split('/') 107 const [ directory, ...file ] = staticEndpoint.split('/')
107 108
108 const staticPath = plugin.staticDirs[directory] 109 const staticPath = plugin.staticDirs[directory]
109 if (!staticPath) return res.sendStatus(404) 110 if (!staticPath) return res.sendStatus(HttpStatusCode.NOT_FOUND_404)
110 111
111 const filepath = file.join('/') 112 const filepath = file.join('/')
112 return res.sendFile(join(plugin.path, staticPath, filepath), sendFileOptions) 113 return res.sendFile(join(plugin.path, staticPath, filepath), sendFileOptions)
@@ -116,7 +117,7 @@ function servePluginCustomRoutes (req: express.Request, res: express.Response, n
116 const plugin: RegisteredPlugin = res.locals.registeredPlugin 117 const plugin: RegisteredPlugin = res.locals.registeredPlugin
117 const router = PluginManager.Instance.getRouter(plugin.npmName) 118 const router = PluginManager.Instance.getRouter(plugin.npmName)
118 119
119 if (!router) return res.sendStatus(404) 120 if (!router) return res.sendStatus(HttpStatusCode.NOT_FOUND_404)
120 121
121 return router(req, res, next) 122 return router(req, res, next)
122} 123}
@@ -126,7 +127,7 @@ function servePluginClientScripts (req: express.Request, res: express.Response)
126 const staticEndpoint = req.params.staticEndpoint 127 const staticEndpoint = req.params.staticEndpoint
127 128
128 const file = plugin.clientScripts[staticEndpoint] 129 const file = plugin.clientScripts[staticEndpoint]
129 if (!file) return res.sendStatus(404) 130 if (!file) return res.sendStatus(HttpStatusCode.NOT_FOUND_404)
130 131
131 return res.sendFile(join(plugin.path, staticEndpoint), sendFileOptions) 132 return res.sendFile(join(plugin.path, staticEndpoint), sendFileOptions)
132} 133}
@@ -136,7 +137,7 @@ function serveThemeCSSDirectory (req: express.Request, res: express.Response) {
136 const staticEndpoint = req.params.staticEndpoint 137 const staticEndpoint = req.params.staticEndpoint
137 138
138 if (plugin.css.includes(staticEndpoint) === false) { 139 if (plugin.css.includes(staticEndpoint) === false) {
139 return res.sendStatus(404) 140 return res.sendStatus(HttpStatusCode.NOT_FOUND_404)
140 } 141 }
141 142
142 return res.sendFile(join(plugin.path, staticEndpoint), sendFileOptions) 143 return res.sendFile(join(plugin.path, staticEndpoint), sendFileOptions)
diff --git a/server/controllers/static.ts b/server/controllers/static.ts
index e04c27b11..ff77452dd 100644
--- a/server/controllers/static.ts
+++ b/server/controllers/static.ts
@@ -26,6 +26,7 @@ import { MVideoFile, MVideoFullLight } from '@server/types/models'
26import { getTorrentFilePath, getVideoFilePath } from '@server/lib/video-paths' 26import { getTorrentFilePath, getVideoFilePath } from '@server/lib/video-paths'
27import { getThemeOrDefault } from '../lib/plugins/theme-utils' 27import { getThemeOrDefault } from '../lib/plugins/theme-utils'
28import { getEnabledResolutions, getRegisteredPlugins, getRegisteredThemes } from '@server/controllers/api/config' 28import { getEnabledResolutions, getRegisteredPlugins, getRegisteredThemes } from '@server/controllers/api/config'
29import { HttpStatusCode } from '@shared/core-utils/miscs/http-error-codes'
29 30
30const staticRouter = express.Router() 31const staticRouter = express.Router()
31 32
@@ -121,7 +122,7 @@ staticRouter.get('/robots.txt',
121// security.txt service 122// security.txt service
122staticRouter.get('/security.txt', 123staticRouter.get('/security.txt',
123 (_, res: express.Response) => { 124 (_, res: express.Response) => {
124 return res.redirect(301, '/.well-known/security.txt') 125 return res.redirect(HttpStatusCode.MOVED_PERMANENTLY_301, '/.well-known/security.txt')
125 } 126 }
126) 127)
127 128
@@ -331,7 +332,7 @@ async function generateNodeinfo (req: express.Request, res: express.Response) {
331 res.contentType('application/json; profile="http://nodeinfo.diaspora.software/ns/schema/2.0#"') 332 res.contentType('application/json; profile="http://nodeinfo.diaspora.software/ns/schema/2.0#"')
332 } else { 333 } else {
333 json = { error: 'Nodeinfo schema version not handled' } 334 json = { error: 'Nodeinfo schema version not handled' }
334 res.status(404) 335 res.status(HttpStatusCode.NOT_FOUND_404)
335 } 336 }
336 337
337 return res.send(json).end() 338 return res.send(json).end()
@@ -341,7 +342,7 @@ function downloadTorrent (req: express.Request, res: express.Response) {
341 const video = res.locals.videoAll 342 const video = res.locals.videoAll
342 343
343 const videoFile = getVideoFile(req, video.VideoFiles) 344 const videoFile = getVideoFile(req, video.VideoFiles)
344 if (!videoFile) return res.status(404).end() 345 if (!videoFile) return res.status(HttpStatusCode.NOT_FOUND_404).end()
345 346
346 return res.download(getTorrentFilePath(video, videoFile), `${video.name}-${videoFile.resolution}p.torrent`) 347 return res.download(getTorrentFilePath(video, videoFile), `${video.name}-${videoFile.resolution}p.torrent`)
347} 348}
@@ -350,10 +351,10 @@ function downloadHLSVideoFileTorrent (req: express.Request, res: express.Respons
350 const video = res.locals.videoAll 351 const video = res.locals.videoAll
351 352
352 const playlist = getHLSPlaylist(video) 353 const playlist = getHLSPlaylist(video)
353 if (!playlist) return res.status(404).end 354 if (!playlist) return res.status(HttpStatusCode.NOT_FOUND_404).end
354 355
355 const videoFile = getVideoFile(req, playlist.VideoFiles) 356 const videoFile = getVideoFile(req, playlist.VideoFiles)
356 if (!videoFile) return res.status(404).end() 357 if (!videoFile) return res.status(HttpStatusCode.NOT_FOUND_404).end()
357 358
358 return res.download(getTorrentFilePath(playlist, videoFile), `${video.name}-${videoFile.resolution}p-hls.torrent`) 359 return res.download(getTorrentFilePath(playlist, videoFile), `${video.name}-${videoFile.resolution}p-hls.torrent`)
359} 360}
@@ -362,7 +363,7 @@ function downloadVideoFile (req: express.Request, res: express.Response) {
362 const video = res.locals.videoAll 363 const video = res.locals.videoAll
363 364
364 const videoFile = getVideoFile(req, video.VideoFiles) 365 const videoFile = getVideoFile(req, video.VideoFiles)
365 if (!videoFile) return res.status(404).end() 366 if (!videoFile) return res.status(HttpStatusCode.NOT_FOUND_404).end()
366 367
367 return res.download(getVideoFilePath(video, videoFile), `${video.name}-${videoFile.resolution}p${videoFile.extname}`) 368 return res.download(getVideoFilePath(video, videoFile), `${video.name}-${videoFile.resolution}p${videoFile.extname}`)
368} 369}
@@ -370,10 +371,10 @@ function downloadVideoFile (req: express.Request, res: express.Response) {
370function downloadHLSVideoFile (req: express.Request, res: express.Response) { 371function downloadHLSVideoFile (req: express.Request, res: express.Response) {
371 const video = res.locals.videoAll 372 const video = res.locals.videoAll
372 const playlist = getHLSPlaylist(video) 373 const playlist = getHLSPlaylist(video)
373 if (!playlist) return res.status(404).end 374 if (!playlist) return res.status(HttpStatusCode.NOT_FOUND_404).end
374 375
375 const videoFile = getVideoFile(req, playlist.VideoFiles) 376 const videoFile = getVideoFile(req, playlist.VideoFiles)
376 if (!videoFile) return res.status(404).end() 377 if (!videoFile) return res.status(HttpStatusCode.NOT_FOUND_404).end()
377 378
378 const filename = `${video.name}-${videoFile.resolution}p-${playlist.getStringType()}${videoFile.extname}` 379 const filename = `${video.name}-${videoFile.resolution}p-${playlist.getStringType()}${videoFile.extname}`
379 return res.download(getVideoFilePath(playlist, videoFile), filename) 380 return res.download(getVideoFilePath(playlist, videoFile), filename)
diff --git a/server/helpers/custom-validators/video-comments.ts b/server/helpers/custom-validators/video-comments.ts
index 455ff4241..8d3ce580e 100644
--- a/server/helpers/custom-validators/video-comments.ts
+++ b/server/helpers/custom-validators/video-comments.ts
@@ -3,6 +3,7 @@ import validator from 'validator'
3import { VideoCommentModel } from '@server/models/video/video-comment' 3import { VideoCommentModel } from '@server/models/video/video-comment'
4import { CONSTRAINTS_FIELDS } from '../../initializers/constants' 4import { CONSTRAINTS_FIELDS } from '../../initializers/constants'
5import { MVideoId } from '@server/types/models' 5import { MVideoId } from '@server/types/models'
6import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes'
6 7
7const VIDEO_COMMENTS_CONSTRAINTS_FIELDS = CONSTRAINTS_FIELDS.VIDEO_COMMENTS 8const VIDEO_COMMENTS_CONSTRAINTS_FIELDS = CONSTRAINTS_FIELDS.VIDEO_COMMENTS
8 9
@@ -15,7 +16,7 @@ async function doesVideoCommentThreadExist (idArg: number | string, video: MVide
15 const videoComment = await VideoCommentModel.loadById(id) 16 const videoComment = await VideoCommentModel.loadById(id)
16 17
17 if (!videoComment) { 18 if (!videoComment) {
18 res.status(404) 19 res.status(HttpStatusCode.NOT_FOUND_404)
19 .json({ error: 'Video comment thread not found' }) 20 .json({ error: 'Video comment thread not found' })
20 .end() 21 .end()
21 22
@@ -23,7 +24,7 @@ async function doesVideoCommentThreadExist (idArg: number | string, video: MVide
23 } 24 }
24 25
25 if (videoComment.videoId !== video.id) { 26 if (videoComment.videoId !== video.id) {
26 res.status(400) 27 res.status(HttpStatusCode.BAD_REQUEST_400)
27 .json({ error: 'Video comment is not associated to this video.' }) 28 .json({ error: 'Video comment is not associated to this video.' })
28 .end() 29 .end()
29 30
@@ -31,7 +32,7 @@ async function doesVideoCommentThreadExist (idArg: number | string, video: MVide
31 } 32 }
32 33
33 if (videoComment.inReplyToCommentId !== null) { 34 if (videoComment.inReplyToCommentId !== null) {
34 res.status(400) 35 res.status(HttpStatusCode.BAD_REQUEST_400)
35 .json({ error: 'Video comment is not a thread.' }) 36 .json({ error: 'Video comment is not a thread.' })
36 .end() 37 .end()
37 38
@@ -47,7 +48,7 @@ async function doesVideoCommentExist (idArg: number | string, video: MVideoId, r
47 const videoComment = await VideoCommentModel.loadByIdAndPopulateVideoAndAccountAndReply(id) 48 const videoComment = await VideoCommentModel.loadByIdAndPopulateVideoAndAccountAndReply(id)
48 49
49 if (!videoComment) { 50 if (!videoComment) {
50 res.status(404) 51 res.status(HttpStatusCode.NOT_FOUND_404)
51 .json({ error: 'Video comment thread not found' }) 52 .json({ error: 'Video comment thread not found' })
52 .end() 53 .end()
53 54
@@ -55,7 +56,7 @@ async function doesVideoCommentExist (idArg: number | string, video: MVideoId, r
55 } 56 }
56 57
57 if (videoComment.videoId !== video.id) { 58 if (videoComment.videoId !== video.id) {
58 res.status(400) 59 res.status(HttpStatusCode.BAD_REQUEST_400)
59 .json({ error: 'Video comment is not associated to this video.' }) 60 .json({ error: 'Video comment is not associated to this video.' })
60 .end() 61 .end()
61 62
@@ -71,7 +72,7 @@ async function doesCommentIdExist (idArg: number | string, res: express.Response
71 const videoComment = await VideoCommentModel.loadByIdAndPopulateVideoAndAccountAndReply(id) 72 const videoComment = await VideoCommentModel.loadByIdAndPopulateVideoAndAccountAndReply(id)
72 73
73 if (!videoComment) { 74 if (!videoComment) {
74 res.status(404) 75 res.status(HttpStatusCode.NOT_FOUND_404)
75 .json({ error: 'Video comment thread not found' }) 76 .json({ error: 'Video comment thread not found' })
76 77
77 return false 78 return false
diff --git a/server/helpers/custom-validators/video-imports.ts b/server/helpers/custom-validators/video-imports.ts
index 33a1fa8ab..0063d3337 100644
--- a/server/helpers/custom-validators/video-imports.ts
+++ b/server/helpers/custom-validators/video-imports.ts
@@ -4,6 +4,7 @@ import { CONSTRAINTS_FIELDS, MIMETYPES, VIDEO_IMPORT_STATES } from '../../initia
4import { exists, isFileValid } from './misc' 4import { exists, isFileValid } from './misc'
5import * as express from 'express' 5import * as express from 'express'
6import { VideoImportModel } from '../../models/video/video-import' 6import { VideoImportModel } from '../../models/video/video-import'
7import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes'
7 8
8function isVideoImportTargetUrlValid (url: string) { 9function isVideoImportTargetUrlValid (url: string) {
9 const isURLOptions = { 10 const isURLOptions = {
@@ -35,7 +36,7 @@ async function doesVideoImportExist (id: number, res: express.Response) {
35 const videoImport = await VideoImportModel.loadAndPopulateVideo(id) 36 const videoImport = await VideoImportModel.loadAndPopulateVideo(id)
36 37
37 if (!videoImport) { 38 if (!videoImport) {
38 res.status(404) 39 res.status(HttpStatusCode.NOT_FOUND_404)
39 .json({ error: 'Video import not found' }) 40 .json({ error: 'Video import not found' })
40 .end() 41 .end()
41 42
diff --git a/server/helpers/custom-validators/video-ownership.ts b/server/helpers/custom-validators/video-ownership.ts
index ed5f8cc2f..ee3cebe10 100644
--- a/server/helpers/custom-validators/video-ownership.ts
+++ b/server/helpers/custom-validators/video-ownership.ts
@@ -2,13 +2,14 @@ import { Response } from 'express'
2import { VideoChangeOwnershipModel } from '../../models/video/video-change-ownership' 2import { VideoChangeOwnershipModel } from '../../models/video/video-change-ownership'
3import { MVideoChangeOwnershipFull } from '@server/types/models/video/video-change-ownership' 3import { MVideoChangeOwnershipFull } from '@server/types/models/video/video-change-ownership'
4import { MUserId } from '@server/types/models' 4import { MUserId } from '@server/types/models'
5import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes'
5 6
6export async function doesChangeVideoOwnershipExist (idArg: number | string, res: Response) { 7export async function doesChangeVideoOwnershipExist (idArg: number | string, res: Response) {
7 const id = parseInt(idArg + '', 10) 8 const id = parseInt(idArg + '', 10)
8 const videoChangeOwnership = await VideoChangeOwnershipModel.load(id) 9 const videoChangeOwnership = await VideoChangeOwnershipModel.load(id)
9 10
10 if (!videoChangeOwnership) { 11 if (!videoChangeOwnership) {
11 res.status(404) 12 res.status(HttpStatusCode.NOT_FOUND_404)
12 .json({ error: 'Video change ownership not found' }) 13 .json({ error: 'Video change ownership not found' })
13 .end() 14 .end()
14 15
@@ -24,7 +25,7 @@ export function checkUserCanTerminateOwnershipChange (user: MUserId, videoChange
24 return true 25 return true
25 } 26 }
26 27
27 res.status(403) 28 res.status(HttpStatusCode.FORBIDDEN_403)
28 .json({ error: 'Cannot terminate an ownership change of another user' }) 29 .json({ error: 'Cannot terminate an ownership change of another user' })
29 .end() 30 .end()
30 return false 31 return false
diff --git a/server/helpers/express-utils.ts b/server/helpers/express-utils.ts
index ba23557ba..c0d3f8f32 100644
--- a/server/helpers/express-utils.ts
+++ b/server/helpers/express-utils.ts
@@ -7,6 +7,7 @@ import { extname } from 'path'
7import { isArray } from './custom-validators/misc' 7import { isArray } from './custom-validators/misc'
8import { CONFIG } from '../initializers/config' 8import { CONFIG } from '../initializers/config'
9import { getExtFromMimetype } from './video' 9import { getExtFromMimetype } from './video'
10import { HttpStatusCode } from '../../shared/core-utils/miscs/http-error-codes'
10 11
11function buildNSFWFilter (res?: express.Response, paramNSFW?: string) { 12function buildNSFWFilter (res?: express.Response, paramNSFW?: string) {
12 if (paramNSFW === 'true') return true 13 if (paramNSFW === 'true') return true
@@ -61,7 +62,9 @@ function getHostWithPort (host: string) {
61} 62}
62 63
63function badRequest (req: express.Request, res: express.Response) { 64function badRequest (req: express.Request, res: express.Response) {
64 return res.type('json').status(400).end() 65 return res.type('json')
66 .status(HttpStatusCode.BAD_REQUEST_400)
67 .end()
65} 68}
66 69
67function createReqFiles ( 70function createReqFiles (
diff --git a/server/helpers/middlewares/abuses.ts b/server/helpers/middlewares/abuses.ts
index 59ba0d3ed..c53bd9efd 100644
--- a/server/helpers/middlewares/abuses.ts
+++ b/server/helpers/middlewares/abuses.ts
@@ -1,11 +1,12 @@
1import { Response } from 'express' 1import { Response } from 'express'
2import { AbuseModel } from '../../models/abuse/abuse' 2import { AbuseModel } from '../../models/abuse/abuse'
3import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes'
3 4
4async function doesAbuseExist (abuseId: number | string, res: Response) { 5async function doesAbuseExist (abuseId: number | string, res: Response) {
5 const abuse = await AbuseModel.loadByIdWithReporter(parseInt(abuseId + '', 10)) 6 const abuse = await AbuseModel.loadByIdWithReporter(parseInt(abuseId + '', 10))
6 7
7 if (!abuse) { 8 if (!abuse) {
8 res.status(404) 9 res.status(HttpStatusCode.NOT_FOUND_404)
9 .json({ error: 'Abuse not found' }) 10 .json({ error: 'Abuse not found' })
10 11
11 return false 12 return false
diff --git a/server/helpers/middlewares/accounts.ts b/server/helpers/middlewares/accounts.ts
index e9b981262..23470cac6 100644
--- a/server/helpers/middlewares/accounts.ts
+++ b/server/helpers/middlewares/accounts.ts
@@ -3,6 +3,7 @@ import { AccountModel } from '../../models/account/account'
3import * as Bluebird from 'bluebird' 3import * as Bluebird from 'bluebird'
4import { MAccountDefault } from '../../types/models' 4import { MAccountDefault } from '../../types/models'
5import { UserModel } from '@server/models/account/user' 5import { UserModel } from '@server/models/account/user'
6import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes'
6 7
7function doesAccountIdExist (id: number | string, res: Response, sendNotFound = true) { 8function doesAccountIdExist (id: number | string, res: Response, sendNotFound = true) {
8 const promise = AccountModel.load(parseInt(id + '', 10)) 9 const promise = AccountModel.load(parseInt(id + '', 10))
@@ -27,7 +28,7 @@ async function doesAccountExist (p: Bluebird<MAccountDefault>, res: Response, se
27 28
28 if (!account) { 29 if (!account) {
29 if (sendNotFound === true) { 30 if (sendNotFound === true) {
30 res.status(404) 31 res.status(HttpStatusCode.NOT_FOUND_404)
31 .json({ error: 'Account not found' }) 32 .json({ error: 'Account not found' })
32 } 33 }
33 34
@@ -43,7 +44,7 @@ async function doesUserFeedTokenCorrespond (id: number, token: string, res: Resp
43 const user = await UserModel.loadByIdWithChannels(parseInt(id + '', 10)) 44 const user = await UserModel.loadByIdWithChannels(parseInt(id + '', 10))
44 45
45 if (token !== user.feedToken) { 46 if (token !== user.feedToken) {
46 res.status(403) 47 res.status(HttpStatusCode.FORBIDDEN_403)
47 .json({ error: 'User and token mismatch' }) 48 .json({ error: 'User and token mismatch' })
48 49
49 return false 50 return false
diff --git a/server/helpers/middlewares/video-blacklists.ts b/server/helpers/middlewares/video-blacklists.ts
index c79420a0c..eda1324d3 100644
--- a/server/helpers/middlewares/video-blacklists.ts
+++ b/server/helpers/middlewares/video-blacklists.ts
@@ -1,11 +1,12 @@
1import { Response } from 'express' 1import { Response } from 'express'
2import { VideoBlacklistModel } from '../../models/video/video-blacklist' 2import { VideoBlacklistModel } from '../../models/video/video-blacklist'
3import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes'
3 4
4async function doesVideoBlacklistExist (videoId: number, res: Response) { 5async function doesVideoBlacklistExist (videoId: number, res: Response) {
5 const videoBlacklist = await VideoBlacklistModel.loadByVideoId(videoId) 6 const videoBlacklist = await VideoBlacklistModel.loadByVideoId(videoId)
6 7
7 if (videoBlacklist === null) { 8 if (videoBlacklist === null) {
8 res.status(404) 9 res.status(HttpStatusCode.NOT_FOUND_404)
9 .json({ error: 'Blacklisted video not found' }) 10 .json({ error: 'Blacklisted video not found' })
10 .end() 11 .end()
11 12
diff --git a/server/helpers/middlewares/video-captions.ts b/server/helpers/middlewares/video-captions.ts
index f5ce29807..10267eda1 100644
--- a/server/helpers/middlewares/video-captions.ts
+++ b/server/helpers/middlewares/video-captions.ts
@@ -1,12 +1,13 @@
1import { Response } from 'express' 1import { Response } from 'express'
2import { VideoCaptionModel } from '../../models/video/video-caption' 2import { VideoCaptionModel } from '../../models/video/video-caption'
3import { MVideoId } from '@server/types/models' 3import { MVideoId } from '@server/types/models'
4import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes'
4 5
5async function doesVideoCaptionExist (video: MVideoId, language: string, res: Response) { 6async function doesVideoCaptionExist (video: MVideoId, language: string, res: Response) {
6 const videoCaption = await VideoCaptionModel.loadByVideoIdAndLanguage(video.id, language) 7 const videoCaption = await VideoCaptionModel.loadByVideoIdAndLanguage(video.id, language)
7 8
8 if (!videoCaption) { 9 if (!videoCaption) {
9 res.status(404) 10 res.status(HttpStatusCode.NOT_FOUND_404)
10 .json({ error: 'Video caption not found' }) 11 .json({ error: 'Video caption not found' })
11 .end() 12 .end()
12 13
diff --git a/server/helpers/middlewares/video-channels.ts b/server/helpers/middlewares/video-channels.ts
index 6eecb8ee5..05499bb74 100644
--- a/server/helpers/middlewares/video-channels.ts
+++ b/server/helpers/middlewares/video-channels.ts
@@ -1,6 +1,7 @@
1import * as express from 'express' 1import * as express from 'express'
2import { VideoChannelModel } from '../../models/video/video-channel' 2import { VideoChannelModel } from '../../models/video/video-channel'
3import { MChannelAccountDefault } from '@server/types/models' 3import { MChannelAccountDefault } from '@server/types/models'
4import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes'
4 5
5async function doesLocalVideoChannelNameExist (name: string, res: express.Response) { 6async function doesLocalVideoChannelNameExist (name: string, res: express.Response) {
6 const videoChannel = await VideoChannelModel.loadLocalByNameAndPopulateAccount(name) 7 const videoChannel = await VideoChannelModel.loadLocalByNameAndPopulateAccount(name)
@@ -30,7 +31,7 @@ export {
30 31
31function processVideoChannelExist (videoChannel: MChannelAccountDefault, res: express.Response) { 32function processVideoChannelExist (videoChannel: MChannelAccountDefault, res: express.Response) {
32 if (!videoChannel) { 33 if (!videoChannel) {
33 res.status(404) 34 res.status(HttpStatusCode.NOT_FOUND_404)
34 .json({ error: 'Video channel not found' }) 35 .json({ error: 'Video channel not found' })
35 .end() 36 .end()
36 37
diff --git a/server/helpers/middlewares/video-playlists.ts b/server/helpers/middlewares/video-playlists.ts
index 344104f7c..d2dd80a35 100644
--- a/server/helpers/middlewares/video-playlists.ts
+++ b/server/helpers/middlewares/video-playlists.ts
@@ -1,6 +1,7 @@
1import * as express from 'express' 1import * as express from 'express'
2import { VideoPlaylistModel } from '../../models/video/video-playlist' 2import { VideoPlaylistModel } from '../../models/video/video-playlist'
3import { MVideoPlaylist } from '../../types/models/video/video-playlist' 3import { MVideoPlaylist } from '../../types/models/video/video-playlist'
4import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes'
4 5
5export type VideoPlaylistFetchType = 'summary' | 'all' 6export type VideoPlaylistFetchType = 'summary' | 'all'
6async function doesVideoPlaylistExist (id: number | string, res: express.Response, fetchType: VideoPlaylistFetchType = 'summary') { 7async function doesVideoPlaylistExist (id: number | string, res: express.Response, fetchType: VideoPlaylistFetchType = 'summary') {
@@ -27,7 +28,7 @@ export {
27 28
28function handleVideoPlaylist (videoPlaylist: MVideoPlaylist, res: express.Response) { 29function handleVideoPlaylist (videoPlaylist: MVideoPlaylist, res: express.Response) {
29 if (!videoPlaylist) { 30 if (!videoPlaylist) {
30 res.status(404) 31 res.status(HttpStatusCode.NOT_FOUND_404)
31 .json({ error: 'Video playlist not found' }) 32 .json({ error: 'Video playlist not found' })
32 .end() 33 .end()
33 34
diff --git a/server/helpers/middlewares/videos.ts b/server/helpers/middlewares/videos.ts
index 3904f762a..c5eb0607a 100644
--- a/server/helpers/middlewares/videos.ts
+++ b/server/helpers/middlewares/videos.ts
@@ -13,6 +13,7 @@ import {
13 MVideoWithRights 13 MVideoWithRights
14} from '@server/types/models' 14} from '@server/types/models'
15import { VideoFileModel } from '@server/models/video/video-file' 15import { VideoFileModel } from '@server/models/video/video-file'
16import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes'
16 17
17async function doesVideoExist (id: number | string, res: Response, fetchType: VideoFetchType = 'all') { 18async function doesVideoExist (id: number | string, res: Response, fetchType: VideoFetchType = 'all') {
18 const userId = res.locals.oauth ? res.locals.oauth.token.User.id : undefined 19 const userId = res.locals.oauth ? res.locals.oauth.token.User.id : undefined
@@ -20,7 +21,7 @@ async function doesVideoExist (id: number | string, res: Response, fetchType: Vi
20 const video = await fetchVideo(id, fetchType, userId) 21 const video = await fetchVideo(id, fetchType, userId)
21 22
22 if (video === null) { 23 if (video === null) {
23 res.status(404) 24 res.status(HttpStatusCode.NOT_FOUND_404)
24 .json({ error: 'Video not found' }) 25 .json({ error: 'Video not found' })
25 .end() 26 .end()
26 27
@@ -54,7 +55,7 @@ async function doesVideoExist (id: number | string, res: Response, fetchType: Vi
54 55
55async function doesVideoFileOfVideoExist (id: number, videoIdOrUUID: number | string, res: Response) { 56async function doesVideoFileOfVideoExist (id: number, videoIdOrUUID: number | string, res: Response) {
56 if (!await VideoFileModel.doesVideoExistForVideoFile(id, videoIdOrUUID)) { 57 if (!await VideoFileModel.doesVideoExistForVideoFile(id, videoIdOrUUID)) {
57 res.status(404) 58 res.status(HttpStatusCode.NOT_FOUND_404)
58 .json({ error: 'VideoFile matching Video not found' }) 59 .json({ error: 'VideoFile matching Video not found' })
59 .end() 60 .end()
60 61
@@ -68,7 +69,7 @@ async function doesVideoChannelOfAccountExist (channelId: number, user: MUserAcc
68 if (user.hasRight(UserRight.UPDATE_ANY_VIDEO) === true) { 69 if (user.hasRight(UserRight.UPDATE_ANY_VIDEO) === true) {
69 const videoChannel = await VideoChannelModel.loadAndPopulateAccount(channelId) 70 const videoChannel = await VideoChannelModel.loadAndPopulateAccount(channelId)
70 if (videoChannel === null) { 71 if (videoChannel === null) {
71 res.status(400) 72 res.status(HttpStatusCode.BAD_REQUEST_400)
72 .json({ error: 'Unknown video `video channel` on this instance.' }) 73 .json({ error: 'Unknown video `video channel` on this instance.' })
73 .end() 74 .end()
74 75
@@ -81,7 +82,7 @@ async function doesVideoChannelOfAccountExist (channelId: number, user: MUserAcc
81 82
82 const videoChannel = await VideoChannelModel.loadByIdAndAccount(channelId, user.Account.id) 83 const videoChannel = await VideoChannelModel.loadByIdAndAccount(channelId, user.Account.id)
83 if (videoChannel === null) { 84 if (videoChannel === null) {
84 res.status(400) 85 res.status(HttpStatusCode.BAD_REQUEST_400)
85 .json({ error: 'Unknown video `video channel` for this account.' }) 86 .json({ error: 'Unknown video `video channel` for this account.' })
86 .end() 87 .end()
87 88
@@ -95,7 +96,7 @@ async function doesVideoChannelOfAccountExist (channelId: number, user: MUserAcc
95function checkUserCanManageVideo (user: MUser, video: MVideoAccountLight, right: UserRight, res: Response, onlyOwned = true) { 96function checkUserCanManageVideo (user: MUser, video: MVideoAccountLight, right: UserRight, res: Response, onlyOwned = true) {
96 // Retrieve the user who did the request 97 // Retrieve the user who did the request
97 if (onlyOwned && video.isOwned() === false) { 98 if (onlyOwned && video.isOwned() === false) {
98 res.status(403) 99 res.status(HttpStatusCode.FORBIDDEN_403)
99 .json({ error: 'Cannot manage a video of another server.' }) 100 .json({ error: 'Cannot manage a video of another server.' })
100 .end() 101 .end()
101 return false 102 return false
@@ -106,7 +107,7 @@ function checkUserCanManageVideo (user: MUser, video: MVideoAccountLight, right:
106 // Or if s/he is the video's account 107 // Or if s/he is the video's account
107 const account = video.VideoChannel.Account 108 const account = video.VideoChannel.Account
108 if (user.hasRight(right) === false && account.userId !== user.id) { 109 if (user.hasRight(right) === false && account.userId !== user.id) {
109 res.status(403) 110 res.status(HttpStatusCode.FORBIDDEN_403)
110 .json({ error: 'Cannot manage a video of another user.' }) 111 .json({ error: 'Cannot manage a video of another user.' })
111 .end() 112 .end()
112 return false 113 return false
diff --git a/server/lib/auth.ts b/server/lib/auth.ts
index acf0da18a..466c9bdd4 100644
--- a/server/lib/auth.ts
+++ b/server/lib/auth.ts
@@ -13,6 +13,7 @@ import {
13} from '@server/types/plugins/register-server-auth.model' 13} from '@server/types/plugins/register-server-auth.model'
14import * as express from 'express' 14import * as express from 'express'
15import * as OAuthServer from 'express-oauth-server' 15import * as OAuthServer from 'express-oauth-server'
16import { HttpStatusCode } from '@shared/core-utils/miscs/http-error-codes'
16 17
17const oAuthServer = new OAuthServer({ 18const oAuthServer = new OAuthServer({
18 useErrorHandler: true, 19 useErrorHandler: true,
@@ -215,7 +216,7 @@ function proxifyExternalAuthBypass (req: express.Request, res: express.Response)
215 const obj = authBypassTokens.get(req.body.externalAuthToken) 216 const obj = authBypassTokens.get(req.body.externalAuthToken)
216 if (!obj) { 217 if (!obj) {
217 logger.error('Cannot authenticate user with unknown bypass token') 218 logger.error('Cannot authenticate user with unknown bypass token')
218 return res.sendStatus(400) 219 return res.sendStatus(HttpStatusCode.BAD_REQUEST_400)
219 } 220 }
220 221
221 const { expires, user, authName, npmName } = obj 222 const { expires, user, authName, npmName } = obj
@@ -223,12 +224,12 @@ function proxifyExternalAuthBypass (req: express.Request, res: express.Response)
223 const now = new Date() 224 const now = new Date()
224 if (now.getTime() > expires.getTime()) { 225 if (now.getTime() > expires.getTime()) {
225 logger.error('Cannot authenticate user with an expired external auth token') 226 logger.error('Cannot authenticate user with an expired external auth token')
226 return res.sendStatus(400) 227 return res.sendStatus(HttpStatusCode.BAD_REQUEST_400)
227 } 228 }
228 229
229 if (user.username !== req.body.username) { 230 if (user.username !== req.body.username) {
230 logger.error('Cannot authenticate user %s with invalid username %s.', req.body.username) 231 logger.error('Cannot authenticate user %s with invalid username %s.', req.body.username)
231 return res.sendStatus(400) 232 return res.sendStatus(HttpStatusCode.BAD_REQUEST_400)
232 } 233 }
233 234
234 // Bypass oauth library validation 235 // Bypass oauth library validation
diff --git a/server/lib/client-html.ts b/server/lib/client-html.ts
index 7d1d19588..a1a4a5316 100644
--- a/server/lib/client-html.ts
+++ b/server/lib/client-html.ts
@@ -22,6 +22,7 @@ import * as Bluebird from 'bluebird'
22import { CONFIG } from '../initializers/config' 22import { CONFIG } from '../initializers/config'
23import { logger } from '../helpers/logger' 23import { logger } from '../helpers/logger'
24import { MAccountActor, MChannelActor } from '../types/models' 24import { MAccountActor, MChannelActor } from '../types/models'
25import { HttpStatusCode } from '../../shared/core-utils/miscs/http-error-codes'
25 26
26type Tags = { 27type Tags = {
27 ogType: string 28 ogType: string
@@ -75,7 +76,7 @@ export class ClientHtml {
75 static async getWatchHTMLPage (videoId: string, req: express.Request, res: express.Response) { 76 static async getWatchHTMLPage (videoId: string, req: express.Request, res: express.Response) {
76 // Let Angular application handle errors 77 // Let Angular application handle errors
77 if (!validator.isInt(videoId) && !validator.isUUID(videoId, 4)) { 78 if (!validator.isInt(videoId) && !validator.isUUID(videoId, 4)) {
78 res.status(404) 79 res.status(HttpStatusCode.NOT_FOUND_404)
79 return ClientHtml.getIndexHTML(req, res) 80 return ClientHtml.getIndexHTML(req, res)
80 } 81 }
81 82
@@ -86,7 +87,7 @@ export class ClientHtml {
86 87
87 // Let Angular application handle errors 88 // Let Angular application handle errors
88 if (!video || video.privacy === VideoPrivacy.PRIVATE || video.privacy === VideoPrivacy.INTERNAL || video.VideoBlacklist) { 89 if (!video || video.privacy === VideoPrivacy.PRIVATE || video.privacy === VideoPrivacy.INTERNAL || video.VideoBlacklist) {
89 res.status(404) 90 res.status(HttpStatusCode.NOT_FOUND_404)
90 return html 91 return html
91 } 92 }
92 93
@@ -121,7 +122,7 @@ export class ClientHtml {
121 static async getWatchPlaylistHTMLPage (videoPlaylistId: string, req: express.Request, res: express.Response) { 122 static async getWatchPlaylistHTMLPage (videoPlaylistId: string, req: express.Request, res: express.Response) {
122 // Let Angular application handle errors 123 // Let Angular application handle errors
123 if (!validator.isInt(videoPlaylistId) && !validator.isUUID(videoPlaylistId, 4)) { 124 if (!validator.isInt(videoPlaylistId) && !validator.isUUID(videoPlaylistId, 4)) {
124 res.status(404) 125 res.status(HttpStatusCode.NOT_FOUND_404)
125 return ClientHtml.getIndexHTML(req, res) 126 return ClientHtml.getIndexHTML(req, res)
126 } 127 }
127 128
@@ -132,7 +133,7 @@ export class ClientHtml {
132 133
133 // Let Angular application handle errors 134 // Let Angular application handle errors
134 if (!videoPlaylist || videoPlaylist.privacy === VideoPlaylistPrivacy.PRIVATE) { 135 if (!videoPlaylist || videoPlaylist.privacy === VideoPlaylistPrivacy.PRIVATE) {
135 res.status(404) 136 res.status(HttpStatusCode.NOT_FOUND_404)
136 return html 137 return html
137 } 138 }
138 139
@@ -201,7 +202,7 @@ export class ClientHtml {
201 202
202 // Let Angular application handle errors 203 // Let Angular application handle errors
203 if (!entity) { 204 if (!entity) {
204 res.status(404) 205 res.status(HttpStatusCode.NOT_FOUND_404)
205 return ClientHtml.getIndexHTML(req, res) 206 return ClientHtml.getIndexHTML(req, res)
206 } 207 }
207 208
diff --git a/server/middlewares/activitypub.ts b/server/middlewares/activitypub.ts
index d00594059..ce94a2129 100644
--- a/server/middlewares/activitypub.ts
+++ b/server/middlewares/activitypub.ts
@@ -7,6 +7,7 @@ import { getOrCreateActorAndServerAndModel } from '../lib/activitypub/actor'
7import { loadActorUrlOrGetFromWebfinger } from '../helpers/webfinger' 7import { loadActorUrlOrGetFromWebfinger } from '../helpers/webfinger'
8import { isActorDeleteActivityValid } from '@server/helpers/custom-validators/activitypub/actor' 8import { isActorDeleteActivityValid } from '@server/helpers/custom-validators/activitypub/actor'
9import { getAPId } from '@server/helpers/activitypub' 9import { getAPId } from '@server/helpers/activitypub'
10import { HttpStatusCode } from '../../shared/core-utils/miscs/http-error-codes'
10 11
11async function checkSignature (req: Request, res: Response, next: NextFunction) { 12async function checkSignature (req: Request, res: Response, next: NextFunction) {
12 try { 13 try {
@@ -28,11 +29,11 @@ async function checkSignature (req: Request, res: Response, next: NextFunction)
28 const activity: ActivityDelete = req.body 29 const activity: ActivityDelete = req.body
29 if (isActorDeleteActivityValid(activity) && activity.object === activity.actor) { 30 if (isActorDeleteActivityValid(activity) && activity.object === activity.actor) {
30 logger.debug('Handling signature error on actor delete activity', { err }) 31 logger.debug('Handling signature error on actor delete activity', { err })
31 return res.sendStatus(204) 32 return res.sendStatus(HttpStatusCode.NO_CONTENT_204)
32 } 33 }
33 34
34 logger.warn('Error in ActivityPub signature checker.', { err }) 35 logger.warn('Error in ActivityPub signature checker.', { err })
35 return res.sendStatus(403) 36 return res.sendStatus(HttpStatusCode.FORBIDDEN_403)
36 } 37 }
37} 38}
38 39
@@ -70,13 +71,13 @@ async function checkHttpSignature (req: Request, res: Response) {
70 } catch (err) { 71 } catch (err) {
71 logger.warn('Invalid signature because of exception in signature parser', { reqBody: req.body, err }) 72 logger.warn('Invalid signature because of exception in signature parser', { reqBody: req.body, err })
72 73
73 res.status(403).json({ error: err.message }) 74 res.status(HttpStatusCode.FORBIDDEN_403).json({ error: err.message })
74 return false 75 return false
75 } 76 }
76 77
77 const keyId = parsed.keyId 78 const keyId = parsed.keyId
78 if (!keyId) { 79 if (!keyId) {
79 res.sendStatus(403) 80 res.sendStatus(HttpStatusCode.FORBIDDEN_403)
80 return false 81 return false
81 } 82 }
82 83
@@ -93,7 +94,7 @@ async function checkHttpSignature (req: Request, res: Response) {
93 if (verified !== true) { 94 if (verified !== true) {
94 logger.warn('Signature from %s is invalid', actorUrl, { parsed }) 95 logger.warn('Signature from %s is invalid', actorUrl, { parsed })
95 96
96 res.sendStatus(403) 97 res.sendStatus(HttpStatusCode.FORBIDDEN_403)
97 return false 98 return false
98 } 99 }
99 100
@@ -106,7 +107,7 @@ async function checkJsonLDSignature (req: Request, res: Response) {
106 const signatureObject: ActivityPubSignature = req.body.signature 107 const signatureObject: ActivityPubSignature = req.body.signature
107 108
108 if (!signatureObject || !signatureObject.creator) { 109 if (!signatureObject || !signatureObject.creator) {
109 res.sendStatus(403) 110 res.sendStatus(HttpStatusCode.FORBIDDEN_403)
110 return false 111 return false
111 } 112 }
112 113
@@ -120,7 +121,7 @@ async function checkJsonLDSignature (req: Request, res: Response) {
120 if (verified !== true) { 121 if (verified !== true) {
121 logger.warn('Signature not verified.', req.body) 122 logger.warn('Signature not verified.', req.body)
122 123
123 res.sendStatus(403) 124 res.sendStatus(HttpStatusCode.FORBIDDEN_403)
124 return false 125 return false
125 } 126 }
126 127
diff --git a/server/middlewares/oauth.ts b/server/middlewares/oauth.ts
index bd60a3639..ab5301415 100644
--- a/server/middlewares/oauth.ts
+++ b/server/middlewares/oauth.ts
@@ -3,6 +3,7 @@ import { Socket } from 'socket.io'
3import { oAuthServer } from '@server/lib/auth' 3import { oAuthServer } from '@server/lib/auth'
4import { logger } from '../helpers/logger' 4import { logger } from '../helpers/logger'
5import { getAccessToken } from '../lib/oauth-model' 5import { getAccessToken } from '../lib/oauth-model'
6import { HttpStatusCode } from '../../shared/core-utils/miscs/http-error-codes'
6 7
7function authenticate (req: express.Request, res: express.Response, next: express.NextFunction, authenticateInQuery = false) { 8function authenticate (req: express.Request, res: express.Response, next: express.NextFunction, authenticateInQuery = false) {
8 const options = authenticateInQuery ? { allowBearerTokensInQueryString: true } : {} 9 const options = authenticateInQuery ? { allowBearerTokensInQueryString: true } : {}
@@ -50,7 +51,7 @@ function authenticatePromiseIfNeeded (req: express.Request, res: express.Respons
50 // Already authenticated? (or tried to) 51 // Already authenticated? (or tried to)
51 if (res.locals.oauth?.token.User) return resolve() 52 if (res.locals.oauth?.token.User) return resolve()
52 53
53 if (res.locals.authenticated === false) return res.sendStatus(401) 54 if (res.locals.authenticated === false) return res.sendStatus(HttpStatusCode.UNAUTHORIZED_401)
54 55
55 authenticate(req, res, () => resolve(), authenticateInQuery) 56 authenticate(req, res, () => resolve(), authenticateInQuery)
56 }) 57 })
diff --git a/server/middlewares/servers.ts b/server/middlewares/servers.ts
index 9c0af443a..5e1c165f0 100644
--- a/server/middlewares/servers.ts
+++ b/server/middlewares/servers.ts
@@ -1,5 +1,6 @@
1import * as express from 'express' 1import * as express from 'express'
2import { getHostWithPort } from '../helpers/express-utils' 2import { getHostWithPort } from '../helpers/express-utils'
3import { HttpStatusCode } from '../../shared/core-utils/miscs/http-error-codes'
3 4
4function setBodyHostsPort (req: express.Request, res: express.Response, next: express.NextFunction) { 5function setBodyHostsPort (req: express.Request, res: express.Response, next: express.NextFunction) {
5 if (!req.body.hosts) return next() 6 if (!req.body.hosts) return next()
@@ -9,7 +10,7 @@ function setBodyHostsPort (req: express.Request, res: express.Response, next: ex
9 10
10 // Problem with the url parsing? 11 // Problem with the url parsing?
11 if (hostWithPort === null) { 12 if (hostWithPort === null) {
12 return res.sendStatus(500) 13 return res.sendStatus(HttpStatusCode.INTERNAL_SERVER_ERROR_500)
13 } 14 }
14 15
15 req.body.hosts[i] = hostWithPort 16 req.body.hosts[i] = hostWithPort
diff --git a/server/middlewares/user-right.ts b/server/middlewares/user-right.ts
index aaf0b323a..45dda4781 100644
--- a/server/middlewares/user-right.ts
+++ b/server/middlewares/user-right.ts
@@ -1,6 +1,7 @@
1import * as express from 'express' 1import * as express from 'express'
2import { UserRight } from '../../shared' 2import { UserRight } from '../../shared'
3import { logger } from '../helpers/logger' 3import { logger } from '../helpers/logger'
4import { HttpStatusCode } from '../../shared/core-utils/miscs/http-error-codes'
4 5
5function ensureUserHasRight (userRight: UserRight) { 6function ensureUserHasRight (userRight: UserRight) {
6 return function (req: express.Request, res: express.Response, next: express.NextFunction) { 7 return function (req: express.Request, res: express.Response, next: express.NextFunction) {
@@ -9,7 +10,8 @@ function ensureUserHasRight (userRight: UserRight) {
9 const message = `User ${user.username} does not have right ${userRight} to access to ${req.path}.` 10 const message = `User ${user.username} does not have right ${userRight} to access to ${req.path}.`
10 logger.info(message) 11 logger.info(message)
11 12
12 return res.status(403).json({ error: message }) 13 return res.status(HttpStatusCode.FORBIDDEN_403)
14 .json({ error: message })
13 } 15 }
14 16
15 return next() 17 return next()
diff --git a/server/middlewares/validators/abuse.ts b/server/middlewares/validators/abuse.ts
index 99403ca40..3b897fdef 100644
--- a/server/middlewares/validators/abuse.ts
+++ b/server/middlewares/validators/abuse.ts
@@ -19,6 +19,7 @@ import { doesAbuseExist, doesAccountIdExist, doesVideoExist } from '@server/help
19import { AbuseMessageModel } from '@server/models/abuse/abuse-message' 19import { AbuseMessageModel } from '@server/models/abuse/abuse-message'
20import { AbuseCreate, UserRight } from '@shared/models' 20import { AbuseCreate, UserRight } from '@shared/models'
21import { areValidationErrors } from './utils' 21import { areValidationErrors } from './utils'
22import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes'
22 23
23const abuseReportValidator = [ 24const abuseReportValidator = [
24 body('account.id') 25 body('account.id')
@@ -70,8 +71,8 @@ const abuseReportValidator = [
70 if (body.comment?.id && !await doesCommentIdExist(body.comment.id, res)) return 71 if (body.comment?.id && !await doesCommentIdExist(body.comment.id, res)) return
71 72
72 if (!body.video?.id && !body.account?.id && !body.comment?.id) { 73 if (!body.video?.id && !body.account?.id && !body.comment?.id) {
73 res.status(400) 74 res.status(HttpStatusCode.BAD_REQUEST_400)
74 .json({ error: 'video id or account id or comment id is required.' }) 75 .json({ error: 'video id or account id or comment id is required.' })
75 76
76 return 77 return
77 } 78 }
@@ -194,7 +195,8 @@ const getAbuseValidator = [
194 const message = `User ${user.username} does not have right to get abuse ${abuse.id}` 195 const message = `User ${user.username} does not have right to get abuse ${abuse.id}`
195 logger.warn(message) 196 logger.warn(message)
196 197
197 return res.status(403).json({ error: message }) 198 return res.status(HttpStatusCode.FORBIDDEN_403)
199 .json({ error: message })
198 } 200 }
199 201
200 return next() 202 return next()
@@ -207,9 +209,10 @@ const checkAbuseValidForMessagesValidator = [
207 209
208 const abuse = res.locals.abuse 210 const abuse = res.locals.abuse
209 if (abuse.ReporterAccount.isOwned() === false) { 211 if (abuse.ReporterAccount.isOwned() === false) {
210 return res.status(400).json({ 212 return res.status(HttpStatusCode.BAD_REQUEST_400)
211 error: 'This abuse was created by a user of your instance.' 213 .json({
212 }) 214 error: 'This abuse was created by a user of your instance.'
215 })
213 } 216 }
214 217
215 return next() 218 return next()
@@ -243,11 +246,13 @@ const deleteAbuseMessageValidator = [
243 const abuseMessage = await AbuseMessageModel.loadByIdAndAbuseId(messageId, abuse.id) 246 const abuseMessage = await AbuseMessageModel.loadByIdAndAbuseId(messageId, abuse.id)
244 247
245 if (!abuseMessage) { 248 if (!abuseMessage) {
246 return res.status(404).json({ error: 'Abuse message not found' }) 249 return res.status(HttpStatusCode.NOT_FOUND_404)
250 .json({ error: 'Abuse message not found' })
247 } 251 }
248 252
249 if (user.hasRight(UserRight.MANAGE_ABUSES) !== true && abuseMessage.accountId !== user.Account.id) { 253 if (user.hasRight(UserRight.MANAGE_ABUSES) !== true && abuseMessage.accountId !== user.Account.id) {
250 return res.status(403).json({ error: 'Cannot delete this abuse message' }) 254 return res.status(HttpStatusCode.FORBIDDEN_403)
255 .json({ error: 'Cannot delete this abuse message' })
251 } 256 }
252 257
253 res.locals.abuseMessage = abuseMessage 258 res.locals.abuseMessage = abuseMessage
diff --git a/server/middlewares/validators/activitypub/activity.ts b/server/middlewares/validators/activitypub/activity.ts
index 7350be5d5..255d8eb17 100644
--- a/server/middlewares/validators/activitypub/activity.ts
+++ b/server/middlewares/validators/activitypub/activity.ts
@@ -2,20 +2,23 @@ import * as express from 'express'
2import { isRootActivityValid } from '../../../helpers/custom-validators/activitypub/activity' 2import { isRootActivityValid } from '../../../helpers/custom-validators/activitypub/activity'
3import { logger } from '../../../helpers/logger' 3import { logger } from '../../../helpers/logger'
4import { getServerActor } from '@server/models/application/application' 4import { getServerActor } from '@server/models/application/application'
5import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
5 6
6async function activityPubValidator (req: express.Request, res: express.Response, next: express.NextFunction) { 7async function activityPubValidator (req: express.Request, res: express.Response, next: express.NextFunction) {
7 logger.debug('Checking activity pub parameters') 8 logger.debug('Checking activity pub parameters')
8 9
9 if (!isRootActivityValid(req.body)) { 10 if (!isRootActivityValid(req.body)) {
10 logger.warn('Incorrect activity parameters.', { activity: req.body }) 11 logger.warn('Incorrect activity parameters.', { activity: req.body })
11 return res.status(400).json({ error: 'Incorrect activity.' }) 12 return res.status(HttpStatusCode.BAD_REQUEST_400)
13 .json({ error: 'Incorrect activity.' })
12 } 14 }
13 15
14 const serverActor = await getServerActor() 16 const serverActor = await getServerActor()
15 const remoteActor = res.locals.signature.actor 17 const remoteActor = res.locals.signature.actor
16 if (serverActor.id === remoteActor.id) { 18 if (serverActor.id === remoteActor.id) {
17 logger.error('Receiving request in INBOX by ourselves!', req.body) 19 logger.error('Receiving request in INBOX by ourselves!', req.body)
18 return res.status(409).end() 20 return res.status(HttpStatusCode.CONFLICT_409)
21 .end()
19 } 22 }
20 23
21 return next() 24 return next()
diff --git a/server/middlewares/validators/blocklist.ts b/server/middlewares/validators/blocklist.ts
index c24fa9609..f61811a1a 100644
--- a/server/middlewares/validators/blocklist.ts
+++ b/server/middlewares/validators/blocklist.ts
@@ -9,6 +9,7 @@ import { ServerModel } from '../../models/server/server'
9import { WEBSERVER } from '../../initializers/constants' 9import { WEBSERVER } from '../../initializers/constants'
10import { doesAccountNameWithHostExist } from '../../helpers/middlewares' 10import { doesAccountNameWithHostExist } from '../../helpers/middlewares'
11import { getServerActor } from '@server/models/application/application' 11import { getServerActor } from '@server/models/application/application'
12import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes'
12 13
13const blockAccountValidator = [ 14const blockAccountValidator = [
14 body('accountName').exists().withMessage('Should have an account name with host'), 15 body('accountName').exists().withMessage('Should have an account name with host'),
@@ -23,7 +24,7 @@ const blockAccountValidator = [
23 const accountToBlock = res.locals.account 24 const accountToBlock = res.locals.account
24 25
25 if (user.Account.id === accountToBlock.id) { 26 if (user.Account.id === accountToBlock.id) {
26 res.status(409) 27 res.status(HttpStatusCode.CONFLICT_409)
27 .json({ error: 'You cannot block yourself.' }) 28 .json({ error: 'You cannot block yourself.' })
28 29
29 return 30 return
@@ -78,7 +79,7 @@ const blockServerValidator = [
78 const host: string = req.body.host 79 const host: string = req.body.host
79 80
80 if (host === WEBSERVER.HOST) { 81 if (host === WEBSERVER.HOST) {
81 return res.status(409) 82 return res.status(HttpStatusCode.CONFLICT_409)
82 .json({ error: 'You cannot block your own server.' }) 83 .json({ error: 'You cannot block your own server.' })
83 } 84 }
84 85
@@ -136,7 +137,7 @@ export {
136async function doesUnblockAccountExist (accountId: number, targetAccountId: number, res: express.Response) { 137async function doesUnblockAccountExist (accountId: number, targetAccountId: number, res: express.Response) {
137 const accountBlock = await AccountBlocklistModel.loadByAccountAndTarget(accountId, targetAccountId) 138 const accountBlock = await AccountBlocklistModel.loadByAccountAndTarget(accountId, targetAccountId)
138 if (!accountBlock) { 139 if (!accountBlock) {
139 res.status(404) 140 res.status(HttpStatusCode.NOT_FOUND_404)
140 .json({ error: 'Account block entry not found.' }) 141 .json({ error: 'Account block entry not found.' })
141 142
142 return false 143 return false
@@ -150,7 +151,7 @@ async function doesUnblockAccountExist (accountId: number, targetAccountId: numb
150async function doesUnblockServerExist (accountId: number, host: string, res: express.Response) { 151async function doesUnblockServerExist (accountId: number, host: string, res: express.Response) {
151 const serverBlock = await ServerBlocklistModel.loadByAccountAndHost(accountId, host) 152 const serverBlock = await ServerBlocklistModel.loadByAccountAndHost(accountId, host)
152 if (!serverBlock) { 153 if (!serverBlock) {
153 res.status(404) 154 res.status(HttpStatusCode.NOT_FOUND_404)
154 .json({ error: 'Server block entry not found.' }) 155 .json({ error: 'Server block entry not found.' })
155 156
156 return false 157 return false
diff --git a/server/middlewares/validators/bulk.ts b/server/middlewares/validators/bulk.ts
index f9b0f565a..cfb16d352 100644
--- a/server/middlewares/validators/bulk.ts
+++ b/server/middlewares/validators/bulk.ts
@@ -6,6 +6,7 @@ import { UserRight } from '@shared/models'
6import { BulkRemoveCommentsOfBody } from '@shared/models/bulk/bulk-remove-comments-of-body.model' 6import { BulkRemoveCommentsOfBody } from '@shared/models/bulk/bulk-remove-comments-of-body.model'
7import { logger } from '../../helpers/logger' 7import { logger } from '../../helpers/logger'
8import { areValidationErrors } from './utils' 8import { areValidationErrors } from './utils'
9import { HttpStatusCode } from '@shared/core-utils/miscs/http-error-codes'
9 10
10const bulkRemoveCommentsOfValidator = [ 11const bulkRemoveCommentsOfValidator = [
11 body('accountName').exists().withMessage('Should have an account name with host'), 12 body('accountName').exists().withMessage('Should have an account name with host'),
@@ -22,7 +23,7 @@ const bulkRemoveCommentsOfValidator = [
22 const body = req.body as BulkRemoveCommentsOfBody 23 const body = req.body as BulkRemoveCommentsOfBody
23 24
24 if (body.scope === 'instance' && user.hasRight(UserRight.REMOVE_ANY_VIDEO_COMMENT) !== true) { 25 if (body.scope === 'instance' && user.hasRight(UserRight.REMOVE_ANY_VIDEO_COMMENT) !== true) {
25 return res.status(403) 26 return res.status(HttpStatusCode.FORBIDDEN_403)
26 .json({ 27 .json({
27 error: 'User cannot remove any comments of this instance.' 28 error: 'User cannot remove any comments of this instance.'
28 }) 29 })
diff --git a/server/middlewares/validators/config.ts b/server/middlewares/validators/config.ts
index d0071ccc1..93de453a7 100644
--- a/server/middlewares/validators/config.ts
+++ b/server/middlewares/validators/config.ts
@@ -8,6 +8,7 @@ import { isUserNSFWPolicyValid, isUserVideoQuotaDailyValid, isUserVideoQuotaVali
8import { logger } from '../../helpers/logger' 8import { logger } from '../../helpers/logger'
9import { isThemeRegistered } from '../../lib/plugins/theme-utils' 9import { isThemeRegistered } from '../../lib/plugins/theme-utils'
10import { areValidationErrors } from './utils' 10import { areValidationErrors } from './utils'
11import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes'
11 12
12const customConfigUpdateValidator = [ 13const customConfigUpdateValidator = [
13 body('instance.name').exists().withMessage('Should have a valid instance name'), 14 body('instance.name').exists().withMessage('Should have a valid instance name'),
@@ -105,9 +106,9 @@ function checkInvalidConfigIfEmailDisabled (customConfig: CustomConfig, res: exp
105 if (isEmailEnabled()) return true 106 if (isEmailEnabled()) return true
106 107
107 if (customConfig.signup.requiresEmailVerification === true) { 108 if (customConfig.signup.requiresEmailVerification === true) {
108 res.status(400) 109 res.status(HttpStatusCode.BAD_REQUEST_400)
109 .send({ error: 'Emailer is disabled but you require signup email verification.' }) 110 .send({ error: 'Emailer is disabled but you require signup email verification.' })
110 .end() 111 .end()
111 return false 112 return false
112 } 113 }
113 114
@@ -118,7 +119,7 @@ function checkInvalidTranscodingConfig (customConfig: CustomConfig, res: express
118 if (customConfig.transcoding.enabled === false) return true 119 if (customConfig.transcoding.enabled === false) return true
119 120
120 if (customConfig.transcoding.webtorrent.enabled === false && customConfig.transcoding.hls.enabled === false) { 121 if (customConfig.transcoding.webtorrent.enabled === false && customConfig.transcoding.hls.enabled === false) {
121 res.status(400) 122 res.status(HttpStatusCode.BAD_REQUEST_400)
122 .send({ error: 'You need to enable at least webtorrent transcoding or hls transcoding' }) 123 .send({ error: 'You need to enable at least webtorrent transcoding or hls transcoding' })
123 .end() 124 .end()
124 return false 125 return false
@@ -131,7 +132,7 @@ function checkInvalidLiveConfig (customConfig: CustomConfig, res: express.Respon
131 if (customConfig.live.enabled === false) return true 132 if (customConfig.live.enabled === false) return true
132 133
133 if (customConfig.live.allowReplay === true && customConfig.transcoding.enabled === false) { 134 if (customConfig.live.allowReplay === true && customConfig.transcoding.enabled === false) {
134 res.status(400) 135 res.status(HttpStatusCode.BAD_REQUEST_400)
135 .send({ error: 'You cannot allow live replay if transcoding is not enabled' }) 136 .send({ error: 'You cannot allow live replay if transcoding is not enabled' })
136 .end() 137 .end()
137 return false 138 return false
diff --git a/server/middlewares/validators/feeds.ts b/server/middlewares/validators/feeds.ts
index 18469bad3..617661813 100644
--- a/server/middlewares/validators/feeds.ts
+++ b/server/middlewares/validators/feeds.ts
@@ -12,6 +12,7 @@ import {
12} from '../../helpers/middlewares' 12} from '../../helpers/middlewares'
13import { doesVideoExist } from '../../helpers/middlewares/videos' 13import { doesVideoExist } from '../../helpers/middlewares/videos'
14import { areValidationErrors } from './utils' 14import { areValidationErrors } from './utils'
15import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes'
15 16
16const feedsFormatValidator = [ 17const feedsFormatValidator = [
17 param('format').optional().custom(isValidRSSFeed).withMessage('Should have a valid format (rss, atom, json)'), 18 param('format').optional().custom(isValidRSSFeed).withMessage('Should have a valid format (rss, atom, json)'),
@@ -35,7 +36,7 @@ function setFeedFormatContentType (req: express.Request, res: express.Response,
35 if (req.accepts(acceptableContentTypes)) { 36 if (req.accepts(acceptableContentTypes)) {
36 res.set('Content-Type', req.accepts(acceptableContentTypes) as string) 37 res.set('Content-Type', req.accepts(acceptableContentTypes) as string)
37 } else { 38 } else {
38 return res.status(406) 39 return res.status(HttpStatusCode.NOT_ACCEPTABLE_406)
39 .json({ 40 .json({
40 message: `You should accept at least one of the following content-types: ${acceptableContentTypes.join(', ')}` 41 message: `You should accept at least one of the following content-types: ${acceptableContentTypes.join(', ')}`
41 }) 42 })
@@ -105,7 +106,7 @@ const videoCommentsFeedsValidator = [
105 if (areValidationErrors(req, res)) return 106 if (areValidationErrors(req, res)) return
106 107
107 if (req.query.videoId && (req.query.videoChannelId || req.query.videoChannelName)) { 108 if (req.query.videoId && (req.query.videoChannelId || req.query.videoChannelName)) {
108 return res.status(400) 109 return res.status(HttpStatusCode.BAD_REQUEST_400)
109 .json({ 110 .json({
110 message: 'videoId cannot be mixed with a channel filter' 111 message: 'videoId cannot be mixed with a channel filter'
111 }) 112 })
diff --git a/server/middlewares/validators/follows.ts b/server/middlewares/validators/follows.ts
index 2c1ddf2df..a590aca99 100644
--- a/server/middlewares/validators/follows.ts
+++ b/server/middlewares/validators/follows.ts
@@ -12,6 +12,7 @@ import { isActorTypeValid, isValidActorHandle } from '../../helpers/custom-valid
12import { MActorFollowActorsDefault } from '@server/types/models' 12import { MActorFollowActorsDefault } from '@server/types/models'
13import { isFollowStateValid } from '@server/helpers/custom-validators/follows' 13import { isFollowStateValid } from '@server/helpers/custom-validators/follows'
14import { getServerActor } from '@server/models/application/application' 14import { getServerActor } from '@server/models/application/application'
15import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes'
15 16
16const listFollowsValidator = [ 17const listFollowsValidator = [
17 query('state') 18 query('state')
@@ -34,7 +35,8 @@ const followValidator = [
34 (req: express.Request, res: express.Response, next: express.NextFunction) => { 35 (req: express.Request, res: express.Response, next: express.NextFunction) => {
35 // Force https if the administrator wants to make friends 36 // Force https if the administrator wants to make friends
36 if (isTestInstance() === false && WEBSERVER.SCHEME === 'http') { 37 if (isTestInstance() === false && WEBSERVER.SCHEME === 'http') {
37 return res.status(500) 38 return res
39 .status(HttpStatusCode.INTERNAL_SERVER_ERROR_500)
38 .json({ 40 .json({
39 error: 'Cannot follow on a non HTTPS web server.' 41 error: 'Cannot follow on a non HTTPS web server.'
40 }) 42 })
@@ -62,7 +64,7 @@ const removeFollowingValidator = [
62 64
63 if (!follow) { 65 if (!follow) {
64 return res 66 return res
65 .status(404) 67 .status(HttpStatusCode.NOT_FOUND_404)
66 .json({ 68 .json({
67 error: `Following ${req.params.host} not found.` 69 error: `Following ${req.params.host} not found.`
68 }) 70 })
@@ -95,7 +97,7 @@ const getFollowerValidator = [
95 97
96 if (!follow) { 98 if (!follow) {
97 return res 99 return res
98 .status(404) 100 .status(HttpStatusCode.NOT_FOUND_404)
99 .json({ 101 .json({
100 error: `Follower ${req.params.nameWithHost} not found.` 102 error: `Follower ${req.params.nameWithHost} not found.`
101 }) 103 })
@@ -113,7 +115,12 @@ const acceptOrRejectFollowerValidator = [
113 115
114 const follow = res.locals.follow 116 const follow = res.locals.follow
115 if (follow.state !== 'pending') { 117 if (follow.state !== 'pending') {
116 return res.status(400).json({ error: 'Follow is not in pending state.' }).end() 118 return res
119 .status(HttpStatusCode.BAD_REQUEST_400)
120 .json({
121 error: 'Follow is not in pending state.'
122 })
123 .end()
117 } 124 }
118 125
119 return next() 126 return next()
diff --git a/server/middlewares/validators/oembed.ts b/server/middlewares/validators/oembed.ts
index c9f9ea0c0..86623efcd 100644
--- a/server/middlewares/validators/oembed.ts
+++ b/server/middlewares/validators/oembed.ts
@@ -9,6 +9,7 @@ import { isIdOrUUIDValid } from '../../helpers/custom-validators/misc'
9import { logger } from '../../helpers/logger' 9import { logger } from '../../helpers/logger'
10import { WEBSERVER } from '../../initializers/constants' 10import { WEBSERVER } from '../../initializers/constants'
11import { areValidationErrors } from './utils' 11import { areValidationErrors } from './utils'
12import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes'
12 13
13const startVideoPlaylistsURL = WEBSERVER.SCHEME + '://' + join(WEBSERVER.HOST, 'videos', 'watch', 'playlist') + '/' 14const startVideoPlaylistsURL = WEBSERVER.SCHEME + '://' + join(WEBSERVER.HOST, 'videos', 'watch', 'playlist') + '/'
14const startVideosURL = WEBSERVER.SCHEME + '://' + join(WEBSERVER.HOST, 'videos', 'watch') + '/' 15const startVideosURL = WEBSERVER.SCHEME + '://' + join(WEBSERVER.HOST, 'videos', 'watch') + '/'
@@ -36,7 +37,7 @@ const oembedValidator = [
36 if (areValidationErrors(req, res)) return 37 if (areValidationErrors(req, res)) return
37 38
38 if (req.query.format !== undefined && req.query.format !== 'json') { 39 if (req.query.format !== undefined && req.query.format !== 'json') {
39 return res.status(501) 40 return res.status(HttpStatusCode.NOT_IMPLEMENTED_501)
40 .json({ error: 'Requested format is not implemented on server.' }) 41 .json({ error: 'Requested format is not implemented on server.' })
41 } 42 }
42 43
@@ -50,13 +51,13 @@ const oembedValidator = [
50 const matches = watchRegex.exec(url) 51 const matches = watchRegex.exec(url)
51 52
52 if (startIsOk === false || matches === null) { 53 if (startIsOk === false || matches === null) {
53 return res.status(400) 54 return res.status(HttpStatusCode.BAD_REQUEST_400)
54 .json({ error: 'Invalid url.' }) 55 .json({ error: 'Invalid url.' })
55 } 56 }
56 57
57 const elementId = matches[1] 58 const elementId = matches[1]
58 if (isIdOrUUIDValid(elementId) === false) { 59 if (isIdOrUUIDValid(elementId) === false) {
59 return res.status(400) 60 return res.status(HttpStatusCode.BAD_REQUEST_400)
60 .json({ error: 'Invalid video or playlist id.' }) 61 .json({ error: 'Invalid video or playlist id.' })
61 } 62 }
62 63
@@ -64,12 +65,12 @@ const oembedValidator = [
64 const video = await fetchVideo(elementId, 'all') 65 const video = await fetchVideo(elementId, 'all')
65 66
66 if (!video) { 67 if (!video) {
67 return res.status(404) 68 return res.status(HttpStatusCode.NOT_FOUND_404)
68 .json({ error: 'Video not found' }) 69 .json({ error: 'Video not found' })
69 } 70 }
70 71
71 if (video.privacy !== VideoPrivacy.PUBLIC) { 72 if (video.privacy !== VideoPrivacy.PUBLIC) {
72 return res.status(403) 73 return res.status(HttpStatusCode.FORBIDDEN_403)
73 .json({ error: 'Video is not public' }) 74 .json({ error: 'Video is not public' })
74 } 75 }
75 76
@@ -81,12 +82,12 @@ const oembedValidator = [
81 82
82 const videoPlaylist = await VideoPlaylistModel.loadWithAccountAndChannelSummary(elementId, undefined) 83 const videoPlaylist = await VideoPlaylistModel.loadWithAccountAndChannelSummary(elementId, undefined)
83 if (!videoPlaylist) { 84 if (!videoPlaylist) {
84 return res.status(404) 85 return res.status(HttpStatusCode.NOT_FOUND_404)
85 .json({ error: 'Video playlist not found' }) 86 .json({ error: 'Video playlist not found' })
86 } 87 }
87 88
88 if (videoPlaylist.privacy !== VideoPlaylistPrivacy.PUBLIC) { 89 if (videoPlaylist.privacy !== VideoPlaylistPrivacy.PUBLIC) {
89 return res.status(403) 90 return res.status(HttpStatusCode.FORBIDDEN_403)
90 .json({ error: 'Playlist is not public' }) 91 .json({ error: 'Playlist is not public' })
91 } 92 }
92 93
diff --git a/server/middlewares/validators/plugins.ts b/server/middlewares/validators/plugins.ts
index cba261dc0..bbac55a50 100644
--- a/server/middlewares/validators/plugins.ts
+++ b/server/middlewares/validators/plugins.ts
@@ -9,6 +9,7 @@ import { PluginModel } from '../../models/server/plugin'
9import { InstallOrUpdatePlugin } from '../../../shared/models/plugins/install-plugin.model' 9import { InstallOrUpdatePlugin } from '../../../shared/models/plugins/install-plugin.model'
10import { PluginType } from '../../../shared/models/plugins/plugin.type' 10import { PluginType } from '../../../shared/models/plugins/plugin.type'
11import { CONFIG } from '../../initializers/config' 11import { CONFIG } from '../../initializers/config'
12import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes'
12 13
13const getPluginValidator = (pluginType: PluginType, withVersion = true) => { 14const getPluginValidator = (pluginType: PluginType, withVersion = true) => {
14 const validators: (ValidationChain | express.Handler)[] = [ 15 const validators: (ValidationChain | express.Handler)[] = [
@@ -30,8 +31,8 @@ const getPluginValidator = (pluginType: PluginType, withVersion = true) => {
30 const npmName = PluginModel.buildNpmName(req.params.pluginName, pluginType) 31 const npmName = PluginModel.buildNpmName(req.params.pluginName, pluginType)
31 const plugin = PluginManager.Instance.getRegisteredPluginOrTheme(npmName) 32 const plugin = PluginManager.Instance.getRegisteredPluginOrTheme(npmName)
32 33
33 if (!plugin) return res.sendStatus(404) 34 if (!plugin) return res.sendStatus(HttpStatusCode.NOT_FOUND_404)
34 if (withVersion && plugin.version !== req.params.pluginVersion) return res.sendStatus(404) 35 if (withVersion && plugin.version !== req.params.pluginVersion) return res.sendStatus(HttpStatusCode.NOT_FOUND_404)
35 36
36 res.locals.registeredPlugin = plugin 37 res.locals.registeredPlugin = plugin
37 38
@@ -49,10 +50,10 @@ const getExternalAuthValidator = [
49 if (areValidationErrors(req, res)) return 50 if (areValidationErrors(req, res)) return
50 51
51 const plugin = res.locals.registeredPlugin 52 const plugin = res.locals.registeredPlugin
52 if (!plugin.registerHelpersStore) return res.sendStatus(404) 53 if (!plugin.registerHelpersStore) return res.sendStatus(HttpStatusCode.NOT_FOUND_404)
53 54
54 const externalAuth = plugin.registerHelpersStore.getExternalAuths().find(a => a.authName === req.params.authName) 55 const externalAuth = plugin.registerHelpersStore.getExternalAuths().find(a => a.authName === req.params.authName)
55 if (!externalAuth) return res.sendStatus(404) 56 if (!externalAuth) return res.sendStatus(HttpStatusCode.NOT_FOUND_404)
56 57
57 res.locals.externalAuth = externalAuth 58 res.locals.externalAuth = externalAuth
58 59
@@ -106,7 +107,7 @@ const installOrUpdatePluginValidator = [
106 107
107 const body: InstallOrUpdatePlugin = req.body 108 const body: InstallOrUpdatePlugin = req.body
108 if (!body.path && !body.npmName) { 109 if (!body.path && !body.npmName) {
109 return res.status(400) 110 return res.status(HttpStatusCode.BAD_REQUEST_400)
110 .json({ error: 'Should have either a npmName or a path' }) 111 .json({ error: 'Should have either a npmName or a path' })
111 .end() 112 .end()
112 } 113 }
@@ -137,9 +138,9 @@ const existingPluginValidator = [
137 138
138 const plugin = await PluginModel.loadByNpmName(req.params.npmName) 139 const plugin = await PluginModel.loadByNpmName(req.params.npmName)
139 if (!plugin) { 140 if (!plugin) {
140 return res.status(404) 141 return res.status(HttpStatusCode.NOT_FOUND_404)
141 .json({ error: 'Plugin not found' }) 142 .json({ error: 'Plugin not found' })
142 .end() 143 .end()
143 } 144 }
144 145
145 res.locals.plugin = plugin 146 res.locals.plugin = plugin
@@ -178,9 +179,9 @@ const listAvailablePluginsValidator = [
178 if (areValidationErrors(req, res)) return 179 if (areValidationErrors(req, res)) return
179 180
180 if (CONFIG.PLUGINS.INDEX.ENABLED === false) { 181 if (CONFIG.PLUGINS.INDEX.ENABLED === false) {
181 return res.status(400) 182 return res.status(HttpStatusCode.BAD_REQUEST_400)
182 .json({ error: 'Plugin index is not enabled' }) 183 .json({ error: 'Plugin index is not enabled' })
183 .end() 184 .end()
184 } 185 }
185 186
186 return next() 187 return next()
diff --git a/server/middlewares/validators/redundancy.ts b/server/middlewares/validators/redundancy.ts
index 8cd3bc33d..6d2dd39c9 100644
--- a/server/middlewares/validators/redundancy.ts
+++ b/server/middlewares/validators/redundancy.ts
@@ -8,6 +8,7 @@ import { isHostValid } from '../../helpers/custom-validators/servers'
8import { ServerModel } from '../../models/server/server' 8import { ServerModel } from '../../models/server/server'
9import { doesVideoExist } from '../../helpers/middlewares' 9import { doesVideoExist } from '../../helpers/middlewares'
10import { isVideoRedundancyTarget } from '@server/helpers/custom-validators/video-redundancies' 10import { isVideoRedundancyTarget } from '@server/helpers/custom-validators/video-redundancies'
11import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes'
11 12
12const videoFileRedundancyGetValidator = [ 13const videoFileRedundancyGetValidator = [
13 param('videoId').custom(isIdOrUUIDValid).not().isEmpty().withMessage('Should have a valid video id'), 14 param('videoId').custom(isIdOrUUIDValid).not().isEmpty().withMessage('Should have a valid video id'),
@@ -34,11 +35,11 @@ const videoFileRedundancyGetValidator = [
34 return f.resolution === paramResolution && (!req.params.fps || paramFPS) 35 return f.resolution === paramResolution && (!req.params.fps || paramFPS)
35 }) 36 })
36 37
37 if (!videoFile) return res.status(404).json({ error: 'Video file not found.' }) 38 if (!videoFile) return res.status(HttpStatusCode.NOT_FOUND_404).json({ error: 'Video file not found.' })
38 res.locals.videoFile = videoFile 39 res.locals.videoFile = videoFile
39 40
40 const videoRedundancy = await VideoRedundancyModel.loadLocalByFileId(videoFile.id) 41 const videoRedundancy = await VideoRedundancyModel.loadLocalByFileId(videoFile.id)
41 if (!videoRedundancy) return res.status(404).json({ error: 'Video redundancy not found.' }) 42 if (!videoRedundancy) return res.status(HttpStatusCode.NOT_FOUND_404).json({ error: 'Video redundancy not found.' })
42 res.locals.videoRedundancy = videoRedundancy 43 res.locals.videoRedundancy = videoRedundancy
43 44
44 return next() 45 return next()
@@ -64,11 +65,11 @@ const videoPlaylistRedundancyGetValidator = [
64 const paramPlaylistType = req.params.streamingPlaylistType as unknown as number // We casted to int above 65 const paramPlaylistType = req.params.streamingPlaylistType as unknown as number // We casted to int above
65 const videoStreamingPlaylist = video.VideoStreamingPlaylists.find(p => p.type === paramPlaylistType) 66 const videoStreamingPlaylist = video.VideoStreamingPlaylists.find(p => p.type === paramPlaylistType)
66 67
67 if (!videoStreamingPlaylist) return res.status(404).json({ error: 'Video playlist not found.' }) 68 if (!videoStreamingPlaylist) return res.status(HttpStatusCode.NOT_FOUND_404).json({ error: 'Video playlist not found.' })
68 res.locals.videoStreamingPlaylist = videoStreamingPlaylist 69 res.locals.videoStreamingPlaylist = videoStreamingPlaylist
69 70
70 const videoRedundancy = await VideoRedundancyModel.loadLocalByStreamingPlaylistId(videoStreamingPlaylist.id) 71 const videoRedundancy = await VideoRedundancyModel.loadLocalByStreamingPlaylistId(videoStreamingPlaylist.id)
71 if (!videoRedundancy) return res.status(404).json({ error: 'Video redundancy not found.' }) 72 if (!videoRedundancy) return res.status(HttpStatusCode.NOT_FOUND_404).json({ error: 'Video redundancy not found.' })
72 res.locals.videoRedundancy = videoRedundancy 73 res.locals.videoRedundancy = videoRedundancy
73 74
74 return next() 75 return next()
@@ -90,7 +91,7 @@ const updateServerRedundancyValidator = [
90 91
91 if (!server) { 92 if (!server) {
92 return res 93 return res
93 .status(404) 94 .status(HttpStatusCode.NOT_FOUND_404)
94 .json({ 95 .json({
95 error: `Server ${req.params.host} not found.` 96 error: `Server ${req.params.host} not found.`
96 }) 97 })
@@ -128,15 +129,15 @@ const addVideoRedundancyValidator = [
128 if (!await doesVideoExist(req.body.videoId, res, 'only-video')) return 129 if (!await doesVideoExist(req.body.videoId, res, 'only-video')) return
129 130
130 if (res.locals.onlyVideo.remote === false) { 131 if (res.locals.onlyVideo.remote === false) {
131 return res.status(400) 132 return res.status(HttpStatusCode.BAD_REQUEST_400)
132 .json({ error: 'Cannot create a redundancy on a local video' }) 133 .json({ error: 'Cannot create a redundancy on a local video' })
133 .end() 134 .end()
134 } 135 }
135 136
136 const alreadyExists = await VideoRedundancyModel.isLocalByVideoUUIDExists(res.locals.onlyVideo.uuid) 137 const alreadyExists = await VideoRedundancyModel.isLocalByVideoUUIDExists(res.locals.onlyVideo.uuid)
137 if (alreadyExists) { 138 if (alreadyExists) {
138 return res.status(409) 139 return res.status(HttpStatusCode.CONFLICT_409)
139 .json({ error: 'This video is already duplicated by your instance.' }) 140 .json({ error: 'This video is already duplicated by your instance.' })
140 } 141 }
141 142
142 return next() 143 return next()
@@ -155,7 +156,7 @@ const removeVideoRedundancyValidator = [
155 156
156 const redundancy = await VideoRedundancyModel.loadByIdWithVideo(parseInt(req.params.redundancyId, 10)) 157 const redundancy = await VideoRedundancyModel.loadByIdWithVideo(parseInt(req.params.redundancyId, 10))
157 if (!redundancy) { 158 if (!redundancy) {
158 return res.status(404) 159 return res.status(HttpStatusCode.NOT_FOUND_404)
159 .json({ error: 'Video redundancy not found' }) 160 .json({ error: 'Video redundancy not found' })
160 .end() 161 .end()
161 } 162 }
diff --git a/server/middlewares/validators/server.ts b/server/middlewares/validators/server.ts
index 6158c3363..fe6704716 100644
--- a/server/middlewares/validators/server.ts
+++ b/server/middlewares/validators/server.ts
@@ -7,6 +7,7 @@ import { body } from 'express-validator'
7import { isUserDisplayNameValid } from '../../helpers/custom-validators/users' 7import { isUserDisplayNameValid } from '../../helpers/custom-validators/users'
8import { Redis } from '../../lib/redis' 8import { Redis } from '../../lib/redis'
9import { CONFIG, isEmailEnabled } from '../../initializers/config' 9import { CONFIG, isEmailEnabled } from '../../initializers/config'
10import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes'
10 11
11const serverGetValidator = [ 12const serverGetValidator = [
12 body('host').custom(isHostValid).withMessage('Should have a valid host'), 13 body('host').custom(isHostValid).withMessage('Should have a valid host'),
@@ -18,9 +19,9 @@ const serverGetValidator = [
18 19
19 const server = await ServerModel.loadByHost(req.body.host) 20 const server = await ServerModel.loadByHost(req.body.host)
20 if (!server) { 21 if (!server) {
21 return res.status(404) 22 return res.status(HttpStatusCode.NOT_FOUND_404)
22 .send({ error: 'Server host not found.' }) 23 .send({ error: 'Server host not found.' })
23 .end() 24 .end()
24 } 25 }
25 26
26 res.locals.server = server 27 res.locals.server = server
@@ -44,14 +45,14 @@ const contactAdministratorValidator = [
44 45
45 if (CONFIG.CONTACT_FORM.ENABLED === false) { 46 if (CONFIG.CONTACT_FORM.ENABLED === false) {
46 return res 47 return res
47 .status(409) 48 .status(HttpStatusCode.CONFLICT_409)
48 .send({ error: 'Contact form is not enabled on this instance.' }) 49 .send({ error: 'Contact form is not enabled on this instance.' })
49 .end() 50 .end()
50 } 51 }
51 52
52 if (isEmailEnabled() === false) { 53 if (isEmailEnabled() === false) {
53 return res 54 return res
54 .status(409) 55 .status(HttpStatusCode.CONFLICT_409)
55 .send({ error: 'Emailer is not enabled on this instance.' }) 56 .send({ error: 'Emailer is not enabled on this instance.' })
56 .end() 57 .end()
57 } 58 }
@@ -60,7 +61,7 @@ const contactAdministratorValidator = [
60 logger.info('Refusing a contact form by %s: already sent one recently.', req.ip) 61 logger.info('Refusing a contact form by %s: already sent one recently.', req.ip)
61 62
62 return res 63 return res
63 .status(403) 64 .status(HttpStatusCode.FORBIDDEN_403)
64 .send({ error: 'You already sent a contact form recently.' }) 65 .send({ error: 'You already sent a contact form recently.' })
65 .end() 66 .end()
66 } 67 }
diff --git a/server/middlewares/validators/themes.ts b/server/middlewares/validators/themes.ts
index 82794656d..a726a567b 100644
--- a/server/middlewares/validators/themes.ts
+++ b/server/middlewares/validators/themes.ts
@@ -5,6 +5,7 @@ import { areValidationErrors } from './utils'
5import { isPluginNameValid, isPluginVersionValid } from '../../helpers/custom-validators/plugins' 5import { isPluginNameValid, isPluginVersionValid } from '../../helpers/custom-validators/plugins'
6import { PluginManager } from '../../lib/plugins/plugin-manager' 6import { PluginManager } from '../../lib/plugins/plugin-manager'
7import { isSafePath } from '../../helpers/custom-validators/misc' 7import { isSafePath } from '../../helpers/custom-validators/misc'
8import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes'
8 9
9const serveThemeCSSValidator = [ 10const serveThemeCSSValidator = [
10 param('themeName').custom(isPluginNameValid).withMessage('Should have a valid theme name'), 11 param('themeName').custom(isPluginNameValid).withMessage('Should have a valid theme name'),
@@ -19,11 +20,11 @@ const serveThemeCSSValidator = [
19 const theme = PluginManager.Instance.getRegisteredThemeByShortName(req.params.themeName) 20 const theme = PluginManager.Instance.getRegisteredThemeByShortName(req.params.themeName)
20 21
21 if (!theme || theme.version !== req.params.themeVersion) { 22 if (!theme || theme.version !== req.params.themeVersion) {
22 return res.sendStatus(404) 23 return res.sendStatus(HttpStatusCode.NOT_FOUND_404)
23 } 24 }
24 25
25 if (theme.css.includes(req.params.staticEndpoint) === false) { 26 if (theme.css.includes(req.params.staticEndpoint) === false) {
26 return res.sendStatus(404) 27 return res.sendStatus(HttpStatusCode.NOT_FOUND_404)
27 } 28 }
28 29
29 res.locals.registeredPlugin = theme 30 res.locals.registeredPlugin = theme
diff --git a/server/middlewares/validators/user-subscriptions.ts b/server/middlewares/validators/user-subscriptions.ts
index a54ecb704..0d0c8ccbf 100644
--- a/server/middlewares/validators/user-subscriptions.ts
+++ b/server/middlewares/validators/user-subscriptions.ts
@@ -6,6 +6,7 @@ import { ActorFollowModel } from '../../models/activitypub/actor-follow'
6import { areValidActorHandles, isValidActorHandle } from '../../helpers/custom-validators/activitypub/actor' 6import { areValidActorHandles, isValidActorHandle } from '../../helpers/custom-validators/activitypub/actor'
7import { toArray } from '../../helpers/custom-validators/misc' 7import { toArray } from '../../helpers/custom-validators/misc'
8import { WEBSERVER } from '../../initializers/constants' 8import { WEBSERVER } from '../../initializers/constants'
9import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes'
9 10
10const userSubscriptionListValidator = [ 11const userSubscriptionListValidator = [
11 query('search').optional().not().isEmpty().withMessage('Should have a valid search'), 12 query('search').optional().not().isEmpty().withMessage('Should have a valid search'),
@@ -61,7 +62,7 @@ const userSubscriptionGetValidator = [
61 62
62 if (!subscription || !subscription.ActorFollowing.VideoChannel) { 63 if (!subscription || !subscription.ActorFollowing.VideoChannel) {
63 return res 64 return res
64 .status(404) 65 .status(HttpStatusCode.NOT_FOUND_404)
65 .json({ 66 .json({
66 error: `Subscription ${req.params.uri} not found.` 67 error: `Subscription ${req.params.uri} not found.`
67 }) 68 })
diff --git a/server/middlewares/validators/users.ts b/server/middlewares/validators/users.ts
index c91c378b3..c93895f2f 100644
--- a/server/middlewares/validators/users.ts
+++ b/server/middlewares/validators/users.ts
@@ -37,6 +37,7 @@ import { doesVideoExist } from '../../helpers/middlewares'
37import { UserRole } from '../../../shared/models/users' 37import { UserRole } from '../../../shared/models/users'
38import { MUserDefault } from '@server/types/models' 38import { MUserDefault } from '@server/types/models'
39import { Hooks } from '@server/lib/plugins/hooks' 39import { Hooks } from '@server/lib/plugins/hooks'
40import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes'
40 41
41const usersListValidator = [ 42const usersListValidator = [
42 query('blocked') 43 query('blocked')
@@ -73,19 +74,22 @@ const usersAddValidator = [
73 74
74 const authUser = res.locals.oauth.token.User 75 const authUser = res.locals.oauth.token.User
75 if (authUser.role !== UserRole.ADMINISTRATOR && req.body.role !== UserRole.USER) { 76 if (authUser.role !== UserRole.ADMINISTRATOR && req.body.role !== UserRole.USER) {
76 return res.status(403) 77 return res
78 .status(HttpStatusCode.FORBIDDEN_403)
77 .json({ error: 'You can only create users (and not administrators or moderators)' }) 79 .json({ error: 'You can only create users (and not administrators or moderators)' })
78 } 80 }
79 81
80 if (req.body.channelName) { 82 if (req.body.channelName) {
81 if (req.body.channelName === req.body.username) { 83 if (req.body.channelName === req.body.username) {
82 return res.status(400) 84 return res
85 .status(HttpStatusCode.BAD_REQUEST_400)
83 .json({ error: 'Channel name cannot be the same as user username.' }) 86 .json({ error: 'Channel name cannot be the same as user username.' })
84 } 87 }
85 88
86 const existing = await ActorModel.loadLocalByName(req.body.channelName) 89 const existing = await ActorModel.loadLocalByName(req.body.channelName)
87 if (existing) { 90 if (existing) {
88 return res.status(409) 91 return res
92 .status(HttpStatusCode.CONFLICT_409)
89 .json({ error: `Channel with name ${req.body.channelName} already exists.` }) 93 .json({ error: `Channel with name ${req.body.channelName} already exists.` })
90 } 94 }
91 } 95 }
@@ -118,18 +122,19 @@ const usersRegisterValidator = [
118 const body: UserRegister = req.body 122 const body: UserRegister = req.body
119 if (body.channel) { 123 if (body.channel) {
120 if (!body.channel.name || !body.channel.displayName) { 124 if (!body.channel.name || !body.channel.displayName) {
121 return res.status(400) 125 return res
126 .status(HttpStatusCode.BAD_REQUEST_400)
122 .json({ error: 'Channel is optional but if you specify it, channel.name and channel.displayName are required.' }) 127 .json({ error: 'Channel is optional but if you specify it, channel.name and channel.displayName are required.' })
123 } 128 }
124 129
125 if (body.channel.name === body.username) { 130 if (body.channel.name === body.username) {
126 return res.status(400) 131 return res.status(HttpStatusCode.BAD_REQUEST_400)
127 .json({ error: 'Channel name cannot be the same as user username.' }) 132 .json({ error: 'Channel name cannot be the same as user username.' })
128 } 133 }
129 134
130 const existing = await ActorModel.loadLocalByName(body.channel.name) 135 const existing = await ActorModel.loadLocalByName(body.channel.name)
131 if (existing) { 136 if (existing) {
132 return res.status(409) 137 return res.status(HttpStatusCode.CONFLICT_409)
133 .json({ error: `Channel with name ${body.channel.name} already exists.` }) 138 .json({ error: `Channel with name ${body.channel.name} already exists.` })
134 } 139 }
135 } 140 }
@@ -149,7 +154,7 @@ const usersRemoveValidator = [
149 154
150 const user = res.locals.user 155 const user = res.locals.user
151 if (user.username === 'root') { 156 if (user.username === 'root') {
152 return res.status(400) 157 return res.status(HttpStatusCode.BAD_REQUEST_400)
153 .json({ error: 'Cannot remove the root user' }) 158 .json({ error: 'Cannot remove the root user' })
154 } 159 }
155 160
@@ -169,7 +174,7 @@ const usersBlockingValidator = [
169 174
170 const user = res.locals.user 175 const user = res.locals.user
171 if (user.username === 'root') { 176 if (user.username === 'root') {
172 return res.status(400) 177 return res.status(HttpStatusCode.BAD_REQUEST_400)
173 .json({ error: 'Cannot block the root user' }) 178 .json({ error: 'Cannot block the root user' })
174 } 179 }
175 180
@@ -181,7 +186,7 @@ const deleteMeValidator = [
181 (req: express.Request, res: express.Response, next: express.NextFunction) => { 186 (req: express.Request, res: express.Response, next: express.NextFunction) => {
182 const user = res.locals.oauth.token.User 187 const user = res.locals.oauth.token.User
183 if (user.username === 'root') { 188 if (user.username === 'root') {
184 return res.status(400) 189 return res.status(HttpStatusCode.BAD_REQUEST_400)
185 .json({ error: 'You cannot delete your root account.' }) 190 .json({ error: 'You cannot delete your root account.' })
186 .end() 191 .end()
187 } 192 }
@@ -211,8 +216,8 @@ const usersUpdateValidator = [
211 216
212 const user = res.locals.user 217 const user = res.locals.user
213 if (user.username === 'root' && req.body.role !== undefined && user.role !== req.body.role) { 218 if (user.username === 'root' && req.body.role !== undefined && user.role !== req.body.role) {
214 return res.status(400) 219 return res.status(HttpStatusCode.BAD_REQUEST_400)
215 .json({ error: 'Cannot change root role.' }) 220 .json({ error: 'Cannot change root role.' })
216 } 221 }
217 222
218 return next() 223 return next()
@@ -267,17 +272,17 @@ const usersUpdateMeValidator = [
267 272
268 if (req.body.password || req.body.email) { 273 if (req.body.password || req.body.email) {
269 if (user.pluginAuth !== null) { 274 if (user.pluginAuth !== null) {
270 return res.status(400) 275 return res.status(HttpStatusCode.BAD_REQUEST_400)
271 .json({ error: 'You cannot update your email or password that is associated with an external auth system.' }) 276 .json({ error: 'You cannot update your email or password that is associated with an external auth system.' })
272 } 277 }
273 278
274 if (!req.body.currentPassword) { 279 if (!req.body.currentPassword) {
275 return res.status(400) 280 return res.status(HttpStatusCode.BAD_REQUEST_400)
276 .json({ error: 'currentPassword parameter is missing.' }) 281 .json({ error: 'currentPassword parameter is missing.' })
277 } 282 }
278 283
279 if (await user.isPasswordMatch(req.body.currentPassword) !== true) { 284 if (await user.isPasswordMatch(req.body.currentPassword) !== true) {
280 return res.status(401) 285 return res.status(HttpStatusCode.UNAUTHORIZED_401)
281 .json({ error: 'currentPassword is invalid.' }) 286 .json({ error: 'currentPassword is invalid.' })
282 } 287 }
283 } 288 }
@@ -329,7 +334,7 @@ const ensureUserRegistrationAllowed = [
329 ) 334 )
330 335
331 if (allowedResult.allowed === false) { 336 if (allowedResult.allowed === false) {
332 return res.status(403) 337 return res.status(HttpStatusCode.FORBIDDEN_403)
333 .json({ error: allowedResult.errorMessage || 'User registration is not enabled or user limit is reached.' }) 338 .json({ error: allowedResult.errorMessage || 'User registration is not enabled or user limit is reached.' })
334 } 339 }
335 340
@@ -342,7 +347,7 @@ const ensureUserRegistrationAllowedForIP = [
342 const allowed = isSignupAllowedForCurrentIP(req.ip) 347 const allowed = isSignupAllowedForCurrentIP(req.ip)
343 348
344 if (allowed === false) { 349 if (allowed === false) {
345 return res.status(403) 350 return res.status(HttpStatusCode.FORBIDDEN_403)
346 .json({ error: 'You are not on a network authorized for registration.' }) 351 .json({ error: 'You are not on a network authorized for registration.' })
347 } 352 }
348 353
@@ -362,7 +367,7 @@ const usersAskResetPasswordValidator = [
362 if (!exists) { 367 if (!exists) {
363 logger.debug('User with email %s does not exist (asking reset password).', req.body.email) 368 logger.debug('User with email %s does not exist (asking reset password).', req.body.email)
364 // Do not leak our emails 369 // Do not leak our emails
365 return res.status(204).end() 370 return res.status(HttpStatusCode.NO_CONTENT_204).end()
366 } 371 }
367 372
368 return next() 373 return next()
@@ -385,7 +390,7 @@ const usersResetPasswordValidator = [
385 390
386 if (redisVerificationString !== req.body.verificationString) { 391 if (redisVerificationString !== req.body.verificationString) {
387 return res 392 return res
388 .status(403) 393 .status(HttpStatusCode.FORBIDDEN_403)
389 .json({ error: 'Invalid verification string.' }) 394 .json({ error: 'Invalid verification string.' })
390 } 395 }
391 396
@@ -404,7 +409,7 @@ const usersAskSendVerifyEmailValidator = [
404 if (!exists) { 409 if (!exists) {
405 logger.debug('User with email %s does not exist (asking verify email).', req.body.email) 410 logger.debug('User with email %s does not exist (asking verify email).', req.body.email)
406 // Do not leak our emails 411 // Do not leak our emails
407 return res.status(204).end() 412 return res.status(HttpStatusCode.NO_CONTENT_204).end()
408 } 413 }
409 414
410 return next() 415 return next()
@@ -432,7 +437,7 @@ const usersVerifyEmailValidator = [
432 437
433 if (redisVerificationString !== req.body.verificationString) { 438 if (redisVerificationString !== req.body.verificationString) {
434 return res 439 return res
435 .status(403) 440 .status(HttpStatusCode.FORBIDDEN_403)
436 .json({ error: 'Invalid verification string.' }) 441 .json({ error: 'Invalid verification string.' })
437 } 442 }
438 443
@@ -449,7 +454,7 @@ const ensureAuthUserOwnsAccountValidator = [
449 const user = res.locals.oauth.token.User 454 const user = res.locals.oauth.token.User
450 455
451 if (res.locals.account.id !== user.Account.id) { 456 if (res.locals.account.id !== user.Account.id) {
452 return res.status(403) 457 return res.status(HttpStatusCode.FORBIDDEN_403)
453 .json({ error: 'Only owner can access ratings list.' }) 458 .json({ error: 'Only owner can access ratings list.' })
454 } 459 }
455 460
@@ -465,7 +470,7 @@ const ensureCanManageUser = [
465 if (authUser.role === UserRole.ADMINISTRATOR) return next() 470 if (authUser.role === UserRole.ADMINISTRATOR) return next()
466 if (authUser.role === UserRole.MODERATOR && onUser.role === UserRole.USER) return next() 471 if (authUser.role === UserRole.MODERATOR && onUser.role === UserRole.USER) return next()
467 472
468 return res.status(403) 473 return res.status(HttpStatusCode.FORBIDDEN_403)
469 .json({ error: 'A moderator can only manager users.' }) 474 .json({ error: 'A moderator can only manager users.' })
470 } 475 }
471] 476]
@@ -509,14 +514,14 @@ async function checkUserNameOrEmailDoesNotAlreadyExist (username: string, email:
509 const user = await UserModel.loadByUsernameOrEmail(username, email) 514 const user = await UserModel.loadByUsernameOrEmail(username, email)
510 515
511 if (user) { 516 if (user) {
512 res.status(409) 517 res.status(HttpStatusCode.CONFLICT_409)
513 .json({ error: 'User with this username or email already exists.' }) 518 .json({ error: 'User with this username or email already exists.' })
514 return false 519 return false
515 } 520 }
516 521
517 const actor = await ActorModel.loadLocalByName(username) 522 const actor = await ActorModel.loadLocalByName(username)
518 if (actor) { 523 if (actor) {
519 res.status(409) 524 res.status(HttpStatusCode.CONFLICT_409)
520 .json({ error: 'Another actor (account/channel) with this name on this instance already exists or has already existed.' }) 525 .json({ error: 'Another actor (account/channel) with this name on this instance already exists or has already existed.' })
521 return false 526 return false
522 } 527 }
@@ -529,7 +534,7 @@ async function checkUserExist (finder: () => Bluebird<MUserDefault>, res: expres
529 534
530 if (!user) { 535 if (!user) {
531 if (abortResponse === true) { 536 if (abortResponse === true) {
532 res.status(404) 537 res.status(HttpStatusCode.NOT_FOUND_404)
533 .json({ error: 'User not found' }) 538 .json({ error: 'User not found' })
534 } 539 }
535 540
diff --git a/server/middlewares/validators/utils.ts b/server/middlewares/validators/utils.ts
index 43e5652fa..2899bed6f 100644
--- a/server/middlewares/validators/utils.ts
+++ b/server/middlewares/validators/utils.ts
@@ -1,13 +1,15 @@
1import * as express from 'express' 1import * as express from 'express'
2import { query, validationResult } from 'express-validator' 2import { query, validationResult } from 'express-validator'
3import { logger } from '../../helpers/logger' 3import { logger } from '../../helpers/logger'
4import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes'
4 5
5function areValidationErrors (req: express.Request, res: express.Response) { 6function areValidationErrors (req: express.Request, res: express.Response) {
6 const errors = validationResult(req) 7 const errors = validationResult(req)
7 8
8 if (!errors.isEmpty()) { 9 if (!errors.isEmpty()) {
9 logger.warn('Incorrect request parameters', { path: req.originalUrl, err: errors.mapped() }) 10 logger.warn('Incorrect request parameters', { path: req.originalUrl, err: errors.mapped() })
10 res.status(400).json({ errors: errors.mapped() }) 11 res.status(HttpStatusCode.BAD_REQUEST_400)
12 .json({ errors: errors.mapped() })
11 13
12 return true 14 return true
13 } 15 }
diff --git a/server/middlewares/validators/videos/video-blacklist.ts b/server/middlewares/validators/videos/video-blacklist.ts
index 808fefc25..88c788a43 100644
--- a/server/middlewares/validators/videos/video-blacklist.ts
+++ b/server/middlewares/validators/videos/video-blacklist.ts
@@ -5,6 +5,7 @@ import { isVideoBlacklistReasonValid, isVideoBlacklistTypeValid } from '../../..
5import { logger } from '../../../helpers/logger' 5import { logger } from '../../../helpers/logger'
6import { doesVideoBlacklistExist, doesVideoExist } from '../../../helpers/middlewares' 6import { doesVideoBlacklistExist, doesVideoExist } from '../../../helpers/middlewares'
7import { areValidationErrors } from '../utils' 7import { areValidationErrors } from '../utils'
8import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
8 9
9const videosBlacklistRemoveValidator = [ 10const videosBlacklistRemoveValidator = [
10 param('videoId').custom(isIdOrUUIDValid).not().isEmpty().withMessage('Should have a valid videoId'), 11 param('videoId').custom(isIdOrUUIDValid).not().isEmpty().withMessage('Should have a valid videoId'),
@@ -39,7 +40,7 @@ const videosBlacklistAddValidator = [
39 const video = res.locals.videoAll 40 const video = res.locals.videoAll
40 if (req.body.unfederate === true && video.remote === true) { 41 if (req.body.unfederate === true && video.remote === true) {
41 return res 42 return res
42 .status(409) 43 .status(HttpStatusCode.CONFLICT_409)
43 .send({ error: 'You cannot unfederate a remote video.' }) 44 .send({ error: 'You cannot unfederate a remote video.' })
44 .end() 45 .end()
45 } 46 }
diff --git a/server/middlewares/validators/videos/video-channels.ts b/server/middlewares/validators/videos/video-channels.ts
index 2e4e755e7..57ac548b9 100644
--- a/server/middlewares/validators/videos/video-channels.ts
+++ b/server/middlewares/validators/videos/video-channels.ts
@@ -15,6 +15,7 @@ import { doesLocalVideoChannelNameExist, doesVideoChannelNameWithHostExist } fro
15import { ActorModel } from '../../../models/activitypub/actor' 15import { ActorModel } from '../../../models/activitypub/actor'
16import { VideoChannelModel } from '../../../models/video/video-channel' 16import { VideoChannelModel } from '../../../models/video/video-channel'
17import { areValidationErrors } from '../utils' 17import { areValidationErrors } from '../utils'
18import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
18 19
19const videoChannelsAddValidator = [ 20const videoChannelsAddValidator = [
20 body('name').custom(isActorPreferredUsernameValid).withMessage('Should have a valid channel name'), 21 body('name').custom(isActorPreferredUsernameValid).withMessage('Should have a valid channel name'),
@@ -29,7 +30,7 @@ const videoChannelsAddValidator = [
29 30
30 const actor = await ActorModel.loadLocalByName(req.body.name) 31 const actor = await ActorModel.loadLocalByName(req.body.name)
31 if (actor) { 32 if (actor) {
32 res.status(409) 33 res.status(HttpStatusCode.CONFLICT_409)
33 .send({ error: 'Another actor (account/channel) with this name on this instance already exists or has already existed.' }) 34 .send({ error: 'Another actor (account/channel) with this name on this instance already exists or has already existed.' })
34 .end() 35 .end()
35 return false 36 return false
@@ -37,7 +38,7 @@ const videoChannelsAddValidator = [
37 38
38 const count = await VideoChannelModel.countByAccount(res.locals.oauth.token.User.Account.id) 39 const count = await VideoChannelModel.countByAccount(res.locals.oauth.token.User.Account.id)
39 if (count >= VIDEO_CHANNELS.MAX_PER_USER) { 40 if (count >= VIDEO_CHANNELS.MAX_PER_USER) {
40 res.status(400) 41 res.status(HttpStatusCode.BAD_REQUEST_400)
41 .send({ error: `You cannot create more than ${VIDEO_CHANNELS.MAX_PER_USER} channels` }) 42 .send({ error: `You cannot create more than ${VIDEO_CHANNELS.MAX_PER_USER} channels` })
42 .end() 43 .end()
43 return false 44 return false
@@ -70,13 +71,13 @@ const videoChannelsUpdateValidator = [
70 71
71 // We need to make additional checks 72 // We need to make additional checks
72 if (res.locals.videoChannel.Actor.isOwned() === false) { 73 if (res.locals.videoChannel.Actor.isOwned() === false) {
73 return res.status(403) 74 return res.status(HttpStatusCode.FORBIDDEN_403)
74 .json({ error: 'Cannot update video channel of another server' }) 75 .json({ error: 'Cannot update video channel of another server' })
75 .end() 76 .end()
76 } 77 }
77 78
78 if (res.locals.videoChannel.Account.userId !== res.locals.oauth.token.User.id) { 79 if (res.locals.videoChannel.Account.userId !== res.locals.oauth.token.User.id) {
79 return res.status(403) 80 return res.status(HttpStatusCode.FORBIDDEN_403)
80 .json({ error: 'Cannot update video channel of another user' }) 81 .json({ error: 'Cannot update video channel of another user' })
81 .end() 82 .end()
82 } 83 }
@@ -155,7 +156,7 @@ export {
155 156
156function checkUserCanDeleteVideoChannel (user: MUser, videoChannel: MChannelAccountDefault, res: express.Response) { 157function checkUserCanDeleteVideoChannel (user: MUser, videoChannel: MChannelAccountDefault, res: express.Response) {
157 if (videoChannel.Actor.isOwned() === false) { 158 if (videoChannel.Actor.isOwned() === false) {
158 res.status(403) 159 res.status(HttpStatusCode.FORBIDDEN_403)
159 .json({ error: 'Cannot remove video channel of another server.' }) 160 .json({ error: 'Cannot remove video channel of another server.' })
160 .end() 161 .end()
161 162
@@ -166,7 +167,7 @@ function checkUserCanDeleteVideoChannel (user: MUser, videoChannel: MChannelAcco
166 // The user can delete it if s/he is an admin 167 // The user can delete it if s/he is an admin
167 // Or if s/he is the video channel's account 168 // Or if s/he is the video channel's account
168 if (user.hasRight(UserRight.REMOVE_ANY_VIDEO_CHANNEL) === false && videoChannel.Account.userId !== user.id) { 169 if (user.hasRight(UserRight.REMOVE_ANY_VIDEO_CHANNEL) === false && videoChannel.Account.userId !== user.id) {
169 res.status(403) 170 res.status(HttpStatusCode.FORBIDDEN_403)
170 .json({ error: 'Cannot remove video channel of another user' }) 171 .json({ error: 'Cannot remove video channel of another user' })
171 .end() 172 .end()
172 173
@@ -180,9 +181,9 @@ async function checkVideoChannelIsNotTheLastOne (res: express.Response) {
180 const count = await VideoChannelModel.countByAccount(res.locals.oauth.token.User.Account.id) 181 const count = await VideoChannelModel.countByAccount(res.locals.oauth.token.User.Account.id)
181 182
182 if (count <= 1) { 183 if (count <= 1) {
183 res.status(409) 184 res.status(HttpStatusCode.CONFLICT_409)
184 .json({ error: 'Cannot remove the last channel of this user' }) 185 .json({ error: 'Cannot remove the last channel of this user' })
185 .end() 186 .end()
186 187
187 return false 188 return false
188 } 189 }
diff --git a/server/middlewares/validators/videos/video-comments.ts b/server/middlewares/validators/videos/video-comments.ts
index a3c9febc4..226c9d436 100644
--- a/server/middlewares/validators/videos/video-comments.ts
+++ b/server/middlewares/validators/videos/video-comments.ts
@@ -14,6 +14,7 @@ import { AcceptResult, isLocalVideoCommentReplyAccepted, isLocalVideoThreadAccep
14import { Hooks } from '../../../lib/plugins/hooks' 14import { Hooks } from '../../../lib/plugins/hooks'
15import { MCommentOwnerVideoReply, MVideo, MVideoFullLight } from '../../../types/models/video' 15import { MCommentOwnerVideoReply, MVideo, MVideoFullLight } from '../../../types/models/video'
16import { areValidationErrors } from '../utils' 16import { areValidationErrors } from '../utils'
17import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
17 18
18const listVideoCommentsValidator = [ 19const listVideoCommentsValidator = [
19 query('isLocal') 20 query('isLocal')
@@ -154,8 +155,8 @@ export {
154 155
155function isVideoCommentsEnabled (video: MVideo, res: express.Response) { 156function isVideoCommentsEnabled (video: MVideo, res: express.Response) {
156 if (video.commentsEnabled !== true) { 157 if (video.commentsEnabled !== true) {
157 res.status(409) 158 res.status(HttpStatusCode.CONFLICT_409)
158 .json({ error: 'Video comments are disabled for this video.' }) 159 .json({ error: 'Video comments are disabled for this video.' })
159 160
160 return false 161 return false
161 } 162 }
@@ -165,8 +166,8 @@ function isVideoCommentsEnabled (video: MVideo, res: express.Response) {
165 166
166function checkUserCanDeleteVideoComment (user: MUserAccountUrl, videoComment: MCommentOwnerVideoReply, res: express.Response) { 167function checkUserCanDeleteVideoComment (user: MUserAccountUrl, videoComment: MCommentOwnerVideoReply, res: express.Response) {
167 if (videoComment.isDeleted()) { 168 if (videoComment.isDeleted()) {
168 res.status(409) 169 res.status(HttpStatusCode.CONFLICT_409)
169 .json({ error: 'This comment is already deleted' }) 170 .json({ error: 'This comment is already deleted' })
170 171
171 return false 172 return false
172 } 173 }
@@ -178,7 +179,7 @@ function checkUserCanDeleteVideoComment (user: MUserAccountUrl, videoComment: MC
178 videoComment.accountId !== userAccount.id && // Not the comment owner 179 videoComment.accountId !== userAccount.id && // Not the comment owner
179 videoComment.Video.VideoChannel.accountId !== userAccount.id // Not the video owner 180 videoComment.Video.VideoChannel.accountId !== userAccount.id // Not the video owner
180 ) { 181 ) {
181 res.status(403) 182 res.status(HttpStatusCode.FORBIDDEN_403)
182 .json({ error: 'Cannot remove video comment of another user' }) 183 .json({ error: 'Cannot remove video comment of another user' })
183 184
184 return false 185 return false
@@ -214,7 +215,7 @@ async function isVideoCommentAccepted (req: express.Request, res: express.Respon
214 215
215 if (!acceptedResult || acceptedResult.accepted !== true) { 216 if (!acceptedResult || acceptedResult.accepted !== true) {
216 logger.info('Refused local comment.', { acceptedResult, acceptParameters }) 217 logger.info('Refused local comment.', { acceptedResult, acceptParameters })
217 res.status(403) 218 res.status(HttpStatusCode.FORBIDDEN_403)
218 .json({ error: acceptedResult.errorMessage || 'Refused local comment' }) 219 .json({ error: acceptedResult.errorMessage || 'Refused local comment' })
219 220
220 return false 221 return false
diff --git a/server/middlewares/validators/videos/video-imports.ts b/server/middlewares/validators/videos/video-imports.ts
index d69aff118..0d41933a6 100644
--- a/server/middlewares/validators/videos/video-imports.ts
+++ b/server/middlewares/validators/videos/video-imports.ts
@@ -13,6 +13,7 @@ import { CONFIG } from '../../../initializers/config'
13import { CONSTRAINTS_FIELDS } from '../../../initializers/constants' 13import { CONSTRAINTS_FIELDS } from '../../../initializers/constants'
14import { areValidationErrors } from '../utils' 14import { areValidationErrors } from '../utils'
15import { getCommonVideoEditAttributes } from './videos' 15import { getCommonVideoEditAttributes } from './videos'
16import { HttpStatusCode } from '@shared/core-utils/miscs/http-error-codes'
16 17
17const videoImportAddValidator = getCommonVideoEditAttributes().concat([ 18const videoImportAddValidator = getCommonVideoEditAttributes().concat([
18 body('channelId') 19 body('channelId')
@@ -44,14 +45,14 @@ const videoImportAddValidator = getCommonVideoEditAttributes().concat([
44 45
45 if (req.body.targetUrl && CONFIG.IMPORT.VIDEOS.HTTP.ENABLED !== true) { 46 if (req.body.targetUrl && CONFIG.IMPORT.VIDEOS.HTTP.ENABLED !== true) {
46 cleanUpReqFiles(req) 47 cleanUpReqFiles(req)
47 return res.status(409) 48 return res.status(HttpStatusCode.CONFLICT_409)
48 .json({ error: 'HTTP import is not enabled on this instance.' }) 49 .json({ error: 'HTTP import is not enabled on this instance.' })
49 .end() 50 .end()
50 } 51 }
51 52
52 if (CONFIG.IMPORT.VIDEOS.TORRENT.ENABLED !== true && (req.body.magnetUri || torrentFile)) { 53 if (CONFIG.IMPORT.VIDEOS.TORRENT.ENABLED !== true && (req.body.magnetUri || torrentFile)) {
53 cleanUpReqFiles(req) 54 cleanUpReqFiles(req)
54 return res.status(409) 55 return res.status(HttpStatusCode.CONFLICT_409)
55 .json({ error: 'Torrent/magnet URI import is not enabled on this instance.' }) 56 .json({ error: 'Torrent/magnet URI import is not enabled on this instance.' })
56 .end() 57 .end()
57 } 58 }
@@ -62,7 +63,7 @@ const videoImportAddValidator = getCommonVideoEditAttributes().concat([
62 if (!req.body.targetUrl && !req.body.magnetUri && !torrentFile) { 63 if (!req.body.targetUrl && !req.body.magnetUri && !torrentFile) {
63 cleanUpReqFiles(req) 64 cleanUpReqFiles(req)
64 65
65 return res.status(400) 66 return res.status(HttpStatusCode.BAD_REQUEST_400)
66 .json({ error: 'Should have a magnetUri or a targetUrl or a torrent file.' }) 67 .json({ error: 'Should have a magnetUri or a targetUrl or a torrent file.' })
67 .end() 68 .end()
68 } 69 }
@@ -100,7 +101,7 @@ async function isImportAccepted (req: express.Request, res: express.Response) {
100 101
101 if (!acceptedResult || acceptedResult.accepted !== true) { 102 if (!acceptedResult || acceptedResult.accepted !== true) {
102 logger.info('Refused to import video.', { acceptedResult, acceptParameters }) 103 logger.info('Refused to import video.', { acceptedResult, acceptParameters })
103 res.status(403) 104 res.status(HttpStatusCode.FORBIDDEN_403)
104 .json({ error: acceptedResult.errorMessage || 'Refused to import video' }) 105 .json({ error: acceptedResult.errorMessage || 'Refused to import video' })
105 106
106 return false 107 return false
diff --git a/server/middlewares/validators/videos/video-live.ts b/server/middlewares/validators/videos/video-live.ts
index 69a14ccb1..3a73e1272 100644
--- a/server/middlewares/validators/videos/video-live.ts
+++ b/server/middlewares/validators/videos/video-live.ts
@@ -13,6 +13,7 @@ import { getCommonVideoEditAttributes } from './videos'
13import { VideoModel } from '@server/models/video/video' 13import { VideoModel } from '@server/models/video/video'
14import { Hooks } from '@server/lib/plugins/hooks' 14import { Hooks } from '@server/lib/plugins/hooks'
15import { isLocalLiveVideoAccepted } from '@server/lib/moderation' 15import { isLocalLiveVideoAccepted } from '@server/lib/moderation'
16import { HttpStatusCode } from '@shared/core-utils/miscs/http-error-codes'
16 17
17const videoLiveGetValidator = [ 18const videoLiveGetValidator = [
18 param('videoId').custom(isIdOrUUIDValid).not().isEmpty().withMessage('Should have a valid videoId'), 19 param('videoId').custom(isIdOrUUIDValid).not().isEmpty().withMessage('Should have a valid videoId'),
@@ -28,7 +29,7 @@ const videoLiveGetValidator = [
28 if (!checkUserCanManageVideo(user, res.locals.videoAll, UserRight.GET_ANY_LIVE, res, false)) return 29 if (!checkUserCanManageVideo(user, res.locals.videoAll, UserRight.GET_ANY_LIVE, res, false)) return
29 30
30 const videoLive = await VideoLiveModel.loadByVideoId(res.locals.videoAll.id) 31 const videoLive = await VideoLiveModel.loadByVideoId(res.locals.videoAll.id)
31 if (!videoLive) return res.sendStatus(404) 32 if (!videoLive) return res.sendStatus(HttpStatusCode.NOT_FOUND_404)
32 33
33 res.locals.videoLive = videoLive 34 res.locals.videoLive = videoLive
34 35
@@ -62,21 +63,21 @@ const videoLiveAddValidator = getCommonVideoEditAttributes().concat([
62 if (CONFIG.LIVE.ENABLED !== true) { 63 if (CONFIG.LIVE.ENABLED !== true) {
63 cleanUpReqFiles(req) 64 cleanUpReqFiles(req)
64 65
65 return res.status(403) 66 return res.status(HttpStatusCode.FORBIDDEN_403)
66 .json({ error: 'Live is not enabled on this instance' }) 67 .json({ error: 'Live is not enabled on this instance' })
67 } 68 }
68 69
69 if (CONFIG.LIVE.ALLOW_REPLAY !== true && req.body.saveReplay === true) { 70 if (CONFIG.LIVE.ALLOW_REPLAY !== true && req.body.saveReplay === true) {
70 cleanUpReqFiles(req) 71 cleanUpReqFiles(req)
71 72
72 return res.status(403) 73 return res.status(HttpStatusCode.FORBIDDEN_403)
73 .json({ error: 'Saving live replay is not allowed instance' }) 74 .json({ error: 'Saving live replay is not allowed instance' })
74 } 75 }
75 76
76 if (req.body.permanentLive && req.body.saveReplay) { 77 if (req.body.permanentLive && req.body.saveReplay) {
77 cleanUpReqFiles(req) 78 cleanUpReqFiles(req)
78 79
79 return res.status(400) 80 return res.status(HttpStatusCode.BAD_REQUEST_400)
80 .json({ error: 'Cannot set this live as permanent while saving its replay' }) 81 .json({ error: 'Cannot set this live as permanent while saving its replay' })
81 } 82 }
82 83
@@ -89,7 +90,7 @@ const videoLiveAddValidator = getCommonVideoEditAttributes().concat([
89 if (totalInstanceLives >= CONFIG.LIVE.MAX_INSTANCE_LIVES) { 90 if (totalInstanceLives >= CONFIG.LIVE.MAX_INSTANCE_LIVES) {
90 cleanUpReqFiles(req) 91 cleanUpReqFiles(req)
91 92
92 return res.status(403) 93 return res.status(HttpStatusCode.FORBIDDEN_403)
93 .json({ 94 .json({
94 code: ServerErrorCode.MAX_INSTANCE_LIVES_LIMIT_REACHED, 95 code: ServerErrorCode.MAX_INSTANCE_LIVES_LIMIT_REACHED,
95 error: 'Cannot create this live because the max instance lives limit is reached.' 96 error: 'Cannot create this live because the max instance lives limit is reached.'
@@ -103,7 +104,7 @@ const videoLiveAddValidator = getCommonVideoEditAttributes().concat([
103 if (totalUserLives >= CONFIG.LIVE.MAX_USER_LIVES) { 104 if (totalUserLives >= CONFIG.LIVE.MAX_USER_LIVES) {
104 cleanUpReqFiles(req) 105 cleanUpReqFiles(req)
105 106
106 return res.status(403) 107 return res.status(HttpStatusCode.FORBIDDEN_403)
107 .json({ 108 .json({
108 code: ServerErrorCode.MAX_USER_LIVES_LIMIT_REACHED, 109 code: ServerErrorCode.MAX_USER_LIVES_LIMIT_REACHED,
109 error: 'Cannot create this live because the max user lives limit is reached.' 110 error: 'Cannot create this live because the max user lives limit is reached.'
@@ -129,17 +130,17 @@ const videoLiveUpdateValidator = [
129 if (areValidationErrors(req, res)) return 130 if (areValidationErrors(req, res)) return
130 131
131 if (req.body.permanentLive && req.body.saveReplay) { 132 if (req.body.permanentLive && req.body.saveReplay) {
132 return res.status(400) 133 return res.status(HttpStatusCode.BAD_REQUEST_400)
133 .json({ error: 'Cannot set this live as permanent while saving its replay' }) 134 .json({ error: 'Cannot set this live as permanent while saving its replay' })
134 } 135 }
135 136
136 if (CONFIG.LIVE.ALLOW_REPLAY !== true && req.body.saveReplay === true) { 137 if (CONFIG.LIVE.ALLOW_REPLAY !== true && req.body.saveReplay === true) {
137 return res.status(403) 138 return res.status(HttpStatusCode.FORBIDDEN_403)
138 .json({ error: 'Saving live replay is not allowed instance' }) 139 .json({ error: 'Saving live replay is not allowed instance' })
139 } 140 }
140 141
141 if (res.locals.videoAll.state !== VideoState.WAITING_FOR_LIVE) { 142 if (res.locals.videoAll.state !== VideoState.WAITING_FOR_LIVE) {
142 return res.status(400) 143 return res.status(HttpStatusCode.BAD_REQUEST_400)
143 .json({ error: 'Cannot update a live that has already started' }) 144 .json({ error: 'Cannot update a live that has already started' })
144 } 145 }
145 146
@@ -176,7 +177,7 @@ async function isLiveVideoAccepted (req: express.Request, res: express.Response)
176 if (!acceptedResult || acceptedResult.accepted !== true) { 177 if (!acceptedResult || acceptedResult.accepted !== true) {
177 logger.info('Refused local live video.', { acceptedResult, acceptParameters }) 178 logger.info('Refused local live video.', { acceptedResult, acceptParameters })
178 179
179 res.status(403) 180 res.status(HttpStatusCode.FORBIDDEN_403)
180 .json({ error: acceptedResult.errorMessage || 'Refused local live video' }) 181 .json({ error: acceptedResult.errorMessage || 'Refused local live video' })
181 182
182 return false 183 return false
diff --git a/server/middlewares/validators/videos/video-playlists.ts b/server/middlewares/validators/videos/video-playlists.ts
index 4647eae44..c7a6f68e3 100644
--- a/server/middlewares/validators/videos/video-playlists.ts
+++ b/server/middlewares/validators/videos/video-playlists.ts
@@ -29,6 +29,7 @@ import { VideoPlaylistType } from '../../../../shared/models/videos/playlist/vid
29import { doesVideoChannelIdExist, doesVideoExist, doesVideoPlaylistExist, VideoPlaylistFetchType } from '../../../helpers/middlewares' 29import { doesVideoChannelIdExist, doesVideoExist, doesVideoPlaylistExist, VideoPlaylistFetchType } from '../../../helpers/middlewares'
30import { MVideoPlaylist } from '../../../types/models/video/video-playlist' 30import { MVideoPlaylist } from '../../../types/models/video/video-playlist'
31import { MUserAccountId } from '@server/types/models' 31import { MUserAccountId } from '@server/types/models'
32import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
32 33
33const videoPlaylistsAddValidator = getCommonPlaylistEditAttributes().concat([ 34const videoPlaylistsAddValidator = getCommonPlaylistEditAttributes().concat([
34 body('displayName') 35 body('displayName')
@@ -44,7 +45,7 @@ const videoPlaylistsAddValidator = getCommonPlaylistEditAttributes().concat([
44 45
45 if (body.privacy === VideoPlaylistPrivacy.PUBLIC && !body.videoChannelId) { 46 if (body.privacy === VideoPlaylistPrivacy.PUBLIC && !body.videoChannelId) {
46 cleanUpReqFiles(req) 47 cleanUpReqFiles(req)
47 return res.status(400) 48 return res.status(HttpStatusCode.BAD_REQUEST_400)
48 .json({ error: 'Cannot set "public" a playlist that is not assigned to a channel.' }) 49 .json({ error: 'Cannot set "public" a playlist that is not assigned to a channel.' })
49 } 50 }
50 51
@@ -83,13 +84,13 @@ const videoPlaylistsUpdateValidator = getCommonPlaylistEditAttributes().concat([
83 ) 84 )
84 ) { 85 ) {
85 cleanUpReqFiles(req) 86 cleanUpReqFiles(req)
86 return res.status(400) 87 return res.status(HttpStatusCode.BAD_REQUEST_400)
87 .json({ error: 'Cannot set "public" a playlist that is not assigned to a channel.' }) 88 .json({ error: 'Cannot set "public" a playlist that is not assigned to a channel.' })
88 } 89 }
89 90
90 if (videoPlaylist.type === VideoPlaylistType.WATCH_LATER) { 91 if (videoPlaylist.type === VideoPlaylistType.WATCH_LATER) {
91 cleanUpReqFiles(req) 92 cleanUpReqFiles(req)
92 return res.status(400) 93 return res.status(HttpStatusCode.BAD_REQUEST_400)
93 .json({ error: 'Cannot update a watch later playlist.' }) 94 .json({ error: 'Cannot update a watch later playlist.' })
94 } 95 }
95 96
@@ -112,7 +113,7 @@ const videoPlaylistsDeleteValidator = [
112 113
113 const videoPlaylist = getPlaylist(res) 114 const videoPlaylist = getPlaylist(res)
114 if (videoPlaylist.type === VideoPlaylistType.WATCH_LATER) { 115 if (videoPlaylist.type === VideoPlaylistType.WATCH_LATER) {
115 return res.status(400) 116 return res.status(HttpStatusCode.BAD_REQUEST_400)
116 .json({ error: 'Cannot delete a watch later playlist.' }) 117 .json({ error: 'Cannot delete a watch later playlist.' })
117 } 118 }
118 119
@@ -142,7 +143,7 @@ const videoPlaylistsGetValidator = (fetchType: VideoPlaylistFetchType) => {
142 if (videoPlaylist.privacy === VideoPlaylistPrivacy.UNLISTED) { 143 if (videoPlaylist.privacy === VideoPlaylistPrivacy.UNLISTED) {
143 if (isUUIDValid(req.params.playlistId)) return next() 144 if (isUUIDValid(req.params.playlistId)) return next()
144 145
145 return res.status(404).end() 146 return res.status(HttpStatusCode.NOT_FOUND_404).end()
146 } 147 }
147 148
148 if (videoPlaylist.privacy === VideoPlaylistPrivacy.PRIVATE) { 149 if (videoPlaylist.privacy === VideoPlaylistPrivacy.PRIVATE) {
@@ -154,7 +155,7 @@ const videoPlaylistsGetValidator = (fetchType: VideoPlaylistFetchType) => {
154 !user || 155 !user ||
155 (videoPlaylist.OwnerAccount.id !== user.Account.id && !user.hasRight(UserRight.UPDATE_ANY_VIDEO_PLAYLIST)) 156 (videoPlaylist.OwnerAccount.id !== user.Account.id && !user.hasRight(UserRight.UPDATE_ANY_VIDEO_PLAYLIST))
156 ) { 157 ) {
157 return res.status(403) 158 return res.status(HttpStatusCode.FORBIDDEN_403)
158 .json({ error: 'Cannot get this private video playlist.' }) 159 .json({ error: 'Cannot get this private video playlist.' })
159 } 160 }
160 161
@@ -231,7 +232,7 @@ const videoPlaylistsUpdateOrRemoveVideoValidator = [
231 232
232 const videoPlaylistElement = await VideoPlaylistElementModel.loadById(req.params.playlistElementId) 233 const videoPlaylistElement = await VideoPlaylistElementModel.loadById(req.params.playlistElementId)
233 if (!videoPlaylistElement) { 234 if (!videoPlaylistElement) {
234 res.status(404) 235 res.status(HttpStatusCode.NOT_FOUND_404)
235 .json({ error: 'Video playlist element not found' }) 236 .json({ error: 'Video playlist element not found' })
236 .end() 237 .end()
237 238
@@ -261,7 +262,7 @@ const videoPlaylistElementAPGetValidator = [
261 262
262 const videoPlaylistElement = await VideoPlaylistElementModel.loadByPlaylistAndElementIdForAP(playlistId, playlistElementId) 263 const videoPlaylistElement = await VideoPlaylistElementModel.loadByPlaylistAndElementIdForAP(playlistId, playlistElementId)
263 if (!videoPlaylistElement) { 264 if (!videoPlaylistElement) {
264 res.status(404) 265 res.status(HttpStatusCode.NOT_FOUND_404)
265 .json({ error: 'Video playlist element not found' }) 266 .json({ error: 'Video playlist element not found' })
266 .end() 267 .end()
267 268
@@ -269,7 +270,7 @@ const videoPlaylistElementAPGetValidator = [
269 } 270 }
270 271
271 if (videoPlaylistElement.VideoPlaylist.privacy === VideoPlaylistPrivacy.PRIVATE) { 272 if (videoPlaylistElement.VideoPlaylist.privacy === VideoPlaylistPrivacy.PRIVATE) {
272 return res.status(403).end() 273 return res.status(HttpStatusCode.FORBIDDEN_403).end()
273 } 274 }
274 275
275 res.locals.videoPlaylistElementAP = videoPlaylistElement 276 res.locals.videoPlaylistElementAP = videoPlaylistElement
@@ -305,7 +306,7 @@ const videoPlaylistsReorderVideosValidator = [
305 const reorderLength: number = req.body.reorderLength 306 const reorderLength: number = req.body.reorderLength
306 307
307 if (startPosition >= nextPosition || insertAfterPosition >= nextPosition) { 308 if (startPosition >= nextPosition || insertAfterPosition >= nextPosition) {
308 res.status(400) 309 res.status(HttpStatusCode.BAD_REQUEST_400)
309 .json({ error: `Start position or insert after position exceed the playlist limits (max: ${nextPosition - 1})` }) 310 .json({ error: `Start position or insert after position exceed the playlist limits (max: ${nextPosition - 1})` })
310 .end() 311 .end()
311 312
@@ -313,7 +314,7 @@ const videoPlaylistsReorderVideosValidator = [
313 } 314 }
314 315
315 if (reorderLength && reorderLength + startPosition > nextPosition) { 316 if (reorderLength && reorderLength + startPosition > nextPosition) {
316 res.status(400) 317 res.status(HttpStatusCode.BAD_REQUEST_400)
317 .json({ error: `Reorder length with this start position exceeds the playlist limits (max: ${nextPosition - startPosition})` }) 318 .json({ error: `Reorder length with this start position exceeds the playlist limits (max: ${nextPosition - startPosition})` })
318 .end() 319 .end()
319 320
@@ -399,7 +400,7 @@ function getCommonPlaylistEditAttributes () {
399 400
400function checkUserCanManageVideoPlaylist (user: MUserAccountId, videoPlaylist: MVideoPlaylist, right: UserRight, res: express.Response) { 401function checkUserCanManageVideoPlaylist (user: MUserAccountId, videoPlaylist: MVideoPlaylist, right: UserRight, res: express.Response) {
401 if (videoPlaylist.isOwned() === false) { 402 if (videoPlaylist.isOwned() === false) {
402 res.status(403) 403 res.status(HttpStatusCode.FORBIDDEN_403)
403 .json({ error: 'Cannot manage video playlist of another server.' }) 404 .json({ error: 'Cannot manage video playlist of another server.' })
404 .end() 405 .end()
405 406
@@ -410,7 +411,7 @@ function checkUserCanManageVideoPlaylist (user: MUserAccountId, videoPlaylist: M
410 // The user can delete it if s/he is an admin 411 // The user can delete it if s/he is an admin
411 // Or if s/he is the video playlist's owner 412 // Or if s/he is the video playlist's owner
412 if (user.hasRight(right) === false && videoPlaylist.ownerAccountId !== user.Account.id) { 413 if (user.hasRight(right) === false && videoPlaylist.ownerAccountId !== user.Account.id) {
413 res.status(403) 414 res.status(HttpStatusCode.FORBIDDEN_403)
414 .json({ error: 'Cannot manage video playlist of another user' }) 415 .json({ error: 'Cannot manage video playlist of another user' })
415 .end() 416 .end()
416 417
diff --git a/server/middlewares/validators/videos/video-rates.ts b/server/middlewares/validators/videos/video-rates.ts
index 15a8c7983..7dcba15f1 100644
--- a/server/middlewares/validators/videos/video-rates.ts
+++ b/server/middlewares/validators/videos/video-rates.ts
@@ -9,6 +9,7 @@ import { AccountVideoRateModel } from '../../../models/account/account-video-rat
9import { VideoRateType } from '../../../../shared/models/videos' 9import { VideoRateType } from '../../../../shared/models/videos'
10import { isAccountNameValid } from '../../../helpers/custom-validators/accounts' 10import { isAccountNameValid } from '../../../helpers/custom-validators/accounts'
11import { doesVideoExist } from '../../../helpers/middlewares' 11import { doesVideoExist } from '../../../helpers/middlewares'
12import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
12 13
13const videoUpdateRateValidator = [ 14const videoUpdateRateValidator = [
14 param('id').custom(isIdOrUUIDValid).not().isEmpty().withMessage('Should have a valid id'), 15 param('id').custom(isIdOrUUIDValid).not().isEmpty().withMessage('Should have a valid id'),
@@ -36,7 +37,7 @@ const getAccountVideoRateValidatorFactory = function (rateType: VideoRateType) {
36 37
37 const rate = await AccountVideoRateModel.loadLocalAndPopulateVideo(rateType, req.params.name, req.params.videoId) 38 const rate = await AccountVideoRateModel.loadLocalAndPopulateVideo(rateType, req.params.name, req.params.videoId)
38 if (!rate) { 39 if (!rate) {
39 return res.status(404) 40 return res.status(HttpStatusCode.NOT_FOUND_404)
40 .json({ error: 'Video rate not found' }) 41 .json({ error: 'Video rate not found' })
41 } 42 }
42 43
diff --git a/server/middlewares/validators/videos/video-shares.ts b/server/middlewares/validators/videos/video-shares.ts
index 20fc96243..f0d8e0c36 100644
--- a/server/middlewares/validators/videos/video-shares.ts
+++ b/server/middlewares/validators/videos/video-shares.ts
@@ -5,6 +5,7 @@ import { logger } from '../../../helpers/logger'
5import { VideoShareModel } from '../../../models/video/video-share' 5import { VideoShareModel } from '../../../models/video/video-share'
6import { areValidationErrors } from '../utils' 6import { areValidationErrors } from '../utils'
7import { doesVideoExist } from '../../../helpers/middlewares' 7import { doesVideoExist } from '../../../helpers/middlewares'
8import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
8 9
9const videosShareValidator = [ 10const videosShareValidator = [
10 param('id').custom(isIdOrUUIDValid).not().isEmpty().withMessage('Should have a valid id'), 11 param('id').custom(isIdOrUUIDValid).not().isEmpty().withMessage('Should have a valid id'),
@@ -20,7 +21,7 @@ const videosShareValidator = [
20 21
21 const share = await VideoShareModel.load(req.params.actorId, video.id) 22 const share = await VideoShareModel.load(req.params.actorId, video.id)
22 if (!share) { 23 if (!share) {
23 return res.status(404) 24 return res.status(HttpStatusCode.NOT_FOUND_404)
24 .end() 25 .end()
25 } 26 }
26 27
diff --git a/server/middlewares/validators/videos/video-watch.ts b/server/middlewares/validators/videos/video-watch.ts
index d6ca1d341..29ce0dab6 100644
--- a/server/middlewares/validators/videos/video-watch.ts
+++ b/server/middlewares/validators/videos/video-watch.ts
@@ -4,6 +4,7 @@ import { isIdOrUUIDValid, toIntOrNull } from '../../../helpers/custom-validators
4import { areValidationErrors } from '../utils' 4import { areValidationErrors } from '../utils'
5import { logger } from '../../../helpers/logger' 5import { logger } from '../../../helpers/logger'
6import { doesVideoExist } from '../../../helpers/middlewares' 6import { doesVideoExist } from '../../../helpers/middlewares'
7import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
7 8
8const videoWatchingValidator = [ 9const videoWatchingValidator = [
9 param('videoId').custom(isIdOrUUIDValid).not().isEmpty().withMessage('Should have a valid id'), 10 param('videoId').custom(isIdOrUUIDValid).not().isEmpty().withMessage('Should have a valid id'),
@@ -20,7 +21,7 @@ const videoWatchingValidator = [
20 const user = res.locals.oauth.token.User 21 const user = res.locals.oauth.token.User
21 if (user.videosHistoryEnabled === false) { 22 if (user.videosHistoryEnabled === false) {
22 logger.warn('Cannot set videos to watch by user %d: videos history is disabled.', user.id) 23 logger.warn('Cannot set videos to watch by user %d: videos history is disabled.', user.id)
23 return res.status(409).end() 24 return res.status(HttpStatusCode.CONFLICT_409).end()
24 } 25 }
25 26
26 return next() 27 return next()
diff --git a/server/middlewares/validators/videos/videos.ts b/server/middlewares/validators/videos/videos.ts
index af0072d73..9834f714b 100644
--- a/server/middlewares/validators/videos/videos.ts
+++ b/server/middlewares/validators/videos/videos.ts
@@ -51,6 +51,7 @@ import { AccountModel } from '../../../models/account/account'
51import { VideoModel } from '../../../models/video/video' 51import { VideoModel } from '../../../models/video/video'
52import { authenticatePromiseIfNeeded } from '../../oauth' 52import { authenticatePromiseIfNeeded } from '../../oauth'
53import { areValidationErrors } from '../utils' 53import { areValidationErrors } from '../utils'
54import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
54 55
55const videosAddValidator = getCommonVideoEditAttributes().concat([ 56const videosAddValidator = getCommonVideoEditAttributes().concat([
56 body('videofile') 57 body('videofile')
@@ -75,7 +76,7 @@ const videosAddValidator = getCommonVideoEditAttributes().concat([
75 if (!await doesVideoChannelOfAccountExist(req.body.channelId, user, res)) return cleanUpReqFiles(req) 76 if (!await doesVideoChannelOfAccountExist(req.body.channelId, user, res)) return cleanUpReqFiles(req)
76 77
77 if (await isAbleToUploadVideo(user.id, videoFile.size) === false) { 78 if (await isAbleToUploadVideo(user.id, videoFile.size) === false) {
78 res.status(403) 79 res.status(HttpStatusCode.FORBIDDEN_403)
79 .json({ error: 'The user video quota is exceeded with this video.' }) 80 .json({ error: 'The user video quota is exceeded with this video.' })
80 81
81 return cleanUpReqFiles(req) 82 return cleanUpReqFiles(req)
@@ -87,7 +88,7 @@ const videosAddValidator = getCommonVideoEditAttributes().concat([
87 duration = await getDurationFromVideoFile(videoFile.path) 88 duration = await getDurationFromVideoFile(videoFile.path)
88 } catch (err) { 89 } catch (err) {
89 logger.error('Invalid input file in videosAddValidator.', { err }) 90 logger.error('Invalid input file in videosAddValidator.', { err })
90 res.status(400) 91 res.status(HttpStatusCode.BAD_REQUEST_400)
91 .json({ error: 'Invalid input file.' }) 92 .json({ error: 'Invalid input file.' })
92 93
93 return cleanUpReqFiles(req) 94 return cleanUpReqFiles(req)
@@ -147,7 +148,7 @@ async function checkVideoFollowConstraints (req: express.Request, res: express.R
147 const serverActor = await getServerActor() 148 const serverActor = await getServerActor()
148 if (await VideoModel.checkVideoHasInstanceFollow(video.id, serverActor.id) === true) return next() 149 if (await VideoModel.checkVideoHasInstanceFollow(video.id, serverActor.id) === true) return next()
149 150
150 return res.status(403) 151 return res.status(HttpStatusCode.FORBIDDEN_403)
151 .json({ 152 .json({
152 errorCode: ServerErrorCode.DOES_NOT_RESPECT_FOLLOW_CONSTRAINTS, 153 errorCode: ServerErrorCode.DOES_NOT_RESPECT_FOLLOW_CONSTRAINTS,
153 error: 'Cannot get this video regarding follow constraints.', 154 error: 'Cannot get this video regarding follow constraints.',
@@ -182,7 +183,7 @@ const videosCustomGetValidator = (
182 183
183 // Only the owner or a user that have blacklist rights can see the video 184 // Only the owner or a user that have blacklist rights can see the video
184 if (!user || !user.canGetVideo(videoAll)) { 185 if (!user || !user.canGetVideo(videoAll)) {
185 return res.status(403) 186 return res.status(HttpStatusCode.FORBIDDEN_403)
186 .json({ error: 'Cannot get this private/internal or blacklisted video.' }) 187 .json({ error: 'Cannot get this private/internal or blacklisted video.' })
187 } 188 }
188 189
@@ -197,7 +198,7 @@ const videosCustomGetValidator = (
197 if (isUUIDValid(req.params.id)) return next() 198 if (isUUIDValid(req.params.id)) return next()
198 199
199 // Don't leak this unlisted video 200 // Don't leak this unlisted video
200 return res.status(404).end() 201 return res.status(HttpStatusCode.NOT_FOUND_404).end()
201 } 202 }
202 } 203 }
203 ] 204 ]
@@ -250,7 +251,7 @@ const videosChangeOwnershipValidator = [
250 251
251 const nextOwner = await AccountModel.loadLocalByName(req.body.username) 252 const nextOwner = await AccountModel.loadLocalByName(req.body.username)
252 if (!nextOwner) { 253 if (!nextOwner) {
253 res.status(400) 254 res.status(HttpStatusCode.BAD_REQUEST_400)
254 .json({ error: 'Changing video ownership to a remote account is not supported yet' }) 255 .json({ error: 'Changing video ownership to a remote account is not supported yet' })
255 256
256 return 257 return
@@ -276,7 +277,7 @@ const videosTerminateChangeOwnershipValidator = [
276 const videoChangeOwnership = res.locals.videoChangeOwnership 277 const videoChangeOwnership = res.locals.videoChangeOwnership
277 278
278 if (videoChangeOwnership.status !== VideoChangeOwnershipStatus.WAITING) { 279 if (videoChangeOwnership.status !== VideoChangeOwnershipStatus.WAITING) {
279 res.status(403) 280 res.status(HttpStatusCode.FORBIDDEN_403)
280 .json({ error: 'Ownership already accepted or refused' }) 281 .json({ error: 'Ownership already accepted or refused' })
281 return 282 return
282 } 283 }
@@ -294,7 +295,7 @@ const videosAcceptChangeOwnershipValidator = [
294 const videoChangeOwnership = res.locals.videoChangeOwnership 295 const videoChangeOwnership = res.locals.videoChangeOwnership
295 const isAble = await isAbleToUploadVideo(user.id, videoChangeOwnership.Video.getMaxQualityFile().size) 296 const isAble = await isAbleToUploadVideo(user.id, videoChangeOwnership.Video.getMaxQualityFile().size)
296 if (isAble === false) { 297 if (isAble === false) {
297 res.status(403) 298 res.status(HttpStatusCode.FORBIDDEN_403)
298 .json({ error: 'The user video quota is exceeded with this video.' }) 299 .json({ error: 'The user video quota is exceeded with this video.' })
299 300
300 return 301 return
@@ -433,7 +434,7 @@ const commonVideosFiltersValidator = [
433 (req.query.filter === 'all-local' || req.query.filter === 'all') && 434 (req.query.filter === 'all-local' || req.query.filter === 'all') &&
434 (!user || user.hasRight(UserRight.SEE_ALL_VIDEOS) === false) 435 (!user || user.hasRight(UserRight.SEE_ALL_VIDEOS) === false)
435 ) { 436 ) {
436 res.status(401) 437 res.status(HttpStatusCode.UNAUTHORIZED_401)
437 .json({ error: 'You are not allowed to see all local videos.' }) 438 .json({ error: 'You are not allowed to see all local videos.' })
438 439
439 return 440 return
@@ -473,7 +474,7 @@ function areErrorsInScheduleUpdate (req: express.Request, res: express.Response)
473 if (!req.body.scheduleUpdate.updateAt) { 474 if (!req.body.scheduleUpdate.updateAt) {
474 logger.warn('Invalid parameters: scheduleUpdate.updateAt is mandatory.') 475 logger.warn('Invalid parameters: scheduleUpdate.updateAt is mandatory.')
475 476
476 res.status(400) 477 res.status(HttpStatusCode.BAD_REQUEST_400)
477 .json({ error: 'Schedule update at is mandatory.' }) 478 .json({ error: 'Schedule update at is mandatory.' })
478 479
479 return true 480 return true
@@ -498,7 +499,7 @@ async function isVideoAccepted (req: express.Request, res: express.Response, vid
498 499
499 if (!acceptedResult || acceptedResult.accepted !== true) { 500 if (!acceptedResult || acceptedResult.accepted !== true) {
500 logger.info('Refused local video.', { acceptedResult, acceptParameters }) 501 logger.info('Refused local video.', { acceptedResult, acceptParameters })
501 res.status(403) 502 res.status(HttpStatusCode.FORBIDDEN_403)
502 .json({ error: acceptedResult.errorMessage || 'Refused local video' }) 503 .json({ error: acceptedResult.errorMessage || 'Refused local video' })
503 504
504 return false 505 return false
diff --git a/server/middlewares/validators/webfinger.ts b/server/middlewares/validators/webfinger.ts
index 5fe864f8b..a71422ed8 100644
--- a/server/middlewares/validators/webfinger.ts
+++ b/server/middlewares/validators/webfinger.ts
@@ -5,6 +5,7 @@ import { logger } from '../../helpers/logger'
5import { ActorModel } from '../../models/activitypub/actor' 5import { ActorModel } from '../../models/activitypub/actor'
6import { areValidationErrors } from './utils' 6import { areValidationErrors } from './utils'
7import { getHostWithPort } from '../../helpers/express-utils' 7import { getHostWithPort } from '../../helpers/express-utils'
8import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes'
8 9
9const webfingerValidator = [ 10const webfingerValidator = [
10 query('resource').custom(isWebfingerLocalResourceValid).withMessage('Should have a valid webfinger resource'), 11 query('resource').custom(isWebfingerLocalResourceValid).withMessage('Should have a valid webfinger resource'),
@@ -20,9 +21,9 @@ const webfingerValidator = [
20 21
21 const actor = await ActorModel.loadLocalUrlByName(name) 22 const actor = await ActorModel.loadLocalUrlByName(name)
22 if (!actor) { 23 if (!actor) {
23 return res.status(404) 24 return res.status(HttpStatusCode.NOT_FOUND_404)
24 .send({ error: 'Actor not found' }) 25 .send({ error: 'Actor not found' })
25 .end() 26 .end()
26 } 27 }
27 28
28 res.locals.actorUrl = actor 29 res.locals.actorUrl = actor
diff --git a/server/tests/api/activitypub/security.ts b/server/tests/api/activitypub/security.ts
index e6002b661..55dcced15 100644
--- a/server/tests/api/activitypub/security.ts
+++ b/server/tests/api/activitypub/security.ts
@@ -9,6 +9,7 @@ import * as chai from 'chai'
9import { activityPubContextify, buildSignedActivity } from '../../../helpers/activitypub' 9import { activityPubContextify, buildSignedActivity } from '../../../helpers/activitypub'
10import { makeFollowRequest, makePOSTAPRequest } from '../../../../shared/extra-utils/requests/activitypub' 10import { makeFollowRequest, makePOSTAPRequest } from '../../../../shared/extra-utils/requests/activitypub'
11import { buildDigest } from '@server/helpers/peertube-crypto' 11import { buildDigest } from '@server/helpers/peertube-crypto'
12import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
12 13
13const expect = chai.expect 14const expect = chai.expect
14 15
@@ -74,7 +75,7 @@ describe('Test ActivityPub security', function () {
74 75
75 const { response } = await makePOSTAPRequest(url, body, baseHttpSignature(), headers) 76 const { response } = await makePOSTAPRequest(url, body, baseHttpSignature(), headers)
76 77
77 expect(response.statusCode).to.equal(403) 78 expect(response.statusCode).to.equal(HttpStatusCode.FORBIDDEN_403)
78 }) 79 })
79 80
80 it('Should fail with an invalid date', async function () { 81 it('Should fail with an invalid date', async function () {
@@ -84,7 +85,7 @@ describe('Test ActivityPub security', function () {
84 85
85 const { response } = await makePOSTAPRequest(url, body, baseHttpSignature(), headers) 86 const { response } = await makePOSTAPRequest(url, body, baseHttpSignature(), headers)
86 87
87 expect(response.statusCode).to.equal(403) 88 expect(response.statusCode).to.equal(HttpStatusCode.FORBIDDEN_403)
88 }) 89 })
89 90
90 it('Should fail with bad keys', async function () { 91 it('Should fail with bad keys', async function () {
@@ -96,7 +97,7 @@ describe('Test ActivityPub security', function () {
96 97
97 const { response } = await makePOSTAPRequest(url, body, baseHttpSignature(), headers) 98 const { response } = await makePOSTAPRequest(url, body, baseHttpSignature(), headers)
98 99
99 expect(response.statusCode).to.equal(403) 100 expect(response.statusCode).to.equal(HttpStatusCode.FORBIDDEN_403)
100 }) 101 })
101 102
102 it('Should reject requests without appropriate signed headers', async function () { 103 it('Should reject requests without appropriate signed headers', async function () {
@@ -117,7 +118,7 @@ describe('Test ActivityPub security', function () {
117 signatureOptions.headers = badHeaders 118 signatureOptions.headers = badHeaders
118 119
119 const { response } = await makePOSTAPRequest(url, body, signatureOptions, headers) 120 const { response } = await makePOSTAPRequest(url, body, signatureOptions, headers)
120 expect(response.statusCode).to.equal(403) 121 expect(response.statusCode).to.equal(HttpStatusCode.FORBIDDEN_403)
121 } 122 }
122 }) 123 })
123 124
@@ -127,7 +128,7 @@ describe('Test ActivityPub security', function () {
127 128
128 const { response } = await makePOSTAPRequest(url, body, baseHttpSignature(), headers) 129 const { response } = await makePOSTAPRequest(url, body, baseHttpSignature(), headers)
129 130
130 expect(response.statusCode).to.equal(204) 131 expect(response.statusCode).to.equal(HttpStatusCode.NO_CONTENT_204)
131 }) 132 })
132 }) 133 })
133 134
@@ -156,7 +157,7 @@ describe('Test ActivityPub security', function () {
156 157
157 const { response } = await makePOSTAPRequest(url, signedBody, baseHttpSignature(), headers) 158 const { response } = await makePOSTAPRequest(url, signedBody, baseHttpSignature(), headers)
158 159
159 expect(response.statusCode).to.equal(403) 160 expect(response.statusCode).to.equal(HttpStatusCode.FORBIDDEN_403)
160 }) 161 })
161 162
162 it('Should fail with an altered body', async function () { 163 it('Should fail with an altered body', async function () {
@@ -177,7 +178,7 @@ describe('Test ActivityPub security', function () {
177 178
178 const { response } = await makePOSTAPRequest(url, signedBody, baseHttpSignature(), headers) 179 const { response } = await makePOSTAPRequest(url, signedBody, baseHttpSignature(), headers)
179 180
180 expect(response.statusCode).to.equal(403) 181 expect(response.statusCode).to.equal(HttpStatusCode.FORBIDDEN_403)
181 }) 182 })
182 183
183 it('Should succeed with a valid signature', async function () { 184 it('Should succeed with a valid signature', async function () {
@@ -193,7 +194,7 @@ describe('Test ActivityPub security', function () {
193 194
194 const { response } = await makePOSTAPRequest(url, signedBody, baseHttpSignature(), headers) 195 const { response } = await makePOSTAPRequest(url, signedBody, baseHttpSignature(), headers)
195 196
196 expect(response.statusCode).to.equal(204) 197 expect(response.statusCode).to.equal(HttpStatusCode.NO_CONTENT_204)
197 }) 198 })
198 }) 199 })
199 200
diff --git a/server/tests/api/check-params/abuses.ts b/server/tests/api/check-params/abuses.ts
index 8dadd9922..ef6c66b72 100644
--- a/server/tests/api/check-params/abuses.ts
+++ b/server/tests/api/check-params/abuses.ts
@@ -29,6 +29,7 @@ import {
29 checkBadSortPagination, 29 checkBadSortPagination,
30 checkBadStartPagination 30 checkBadStartPagination
31} from '../../../../shared/extra-utils/requests/check-api-params' 31} from '../../../../shared/extra-utils/requests/check-api-params'
32import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
32 33
33describe('Test abuses API validators', function () { 34describe('Test abuses API validators', function () {
34 const basePath = '/api/v1/abuses/' 35 const basePath = '/api/v1/abuses/'
@@ -81,7 +82,7 @@ describe('Test abuses API validators', function () {
81 await makeGetRequest({ 82 await makeGetRequest({
82 url: server.url, 83 url: server.url,
83 path, 84 path,
84 statusCodeExpected: 401 85 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401
85 }) 86 })
86 }) 87 })
87 88
@@ -90,7 +91,7 @@ describe('Test abuses API validators', function () {
90 url: server.url, 91 url: server.url,
91 path, 92 path,
92 token: userAccessToken, 93 token: userAccessToken,
93 statusCodeExpected: 403 94 statusCodeExpected: HttpStatusCode.FORBIDDEN_403
94 }) 95 })
95 }) 96 })
96 97
@@ -125,7 +126,7 @@ describe('Test abuses API validators', function () {
125 videoIs: 'deleted' 126 videoIs: 'deleted'
126 } 127 }
127 128
128 await makeGetRequest({ url: server.url, path, token: server.accessToken, query, statusCodeExpected: 200 }) 129 await makeGetRequest({ url: server.url, path, token: server.accessToken, query, statusCodeExpected: HttpStatusCode.OK_200 })
129 }) 130 })
130 }) 131 })
131 132
@@ -148,7 +149,7 @@ describe('Test abuses API validators', function () {
148 await makeGetRequest({ 149 await makeGetRequest({
149 url: server.url, 150 url: server.url,
150 path, 151 path,
151 statusCodeExpected: 401 152 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401
152 }) 153 })
153 }) 154 })
154 155
@@ -167,7 +168,7 @@ describe('Test abuses API validators', function () {
167 state: 2 168 state: 2
168 } 169 }
169 170
170 await makeGetRequest({ url: server.url, path, token: userAccessToken, query, statusCodeExpected: 200 }) 171 await makeGetRequest({ url: server.url, path, token: userAccessToken, query, statusCodeExpected: HttpStatusCode.OK_200 })
171 }) 172 })
172 }) 173 })
173 174
@@ -186,7 +187,13 @@ describe('Test abuses API validators', function () {
186 187
187 it('Should fail with an unknown video', async function () { 188 it('Should fail with an unknown video', async function () {
188 const fields = { video: { id: 42 }, reason: 'my super reason' } 189 const fields = { video: { id: 42 }, reason: 'my super reason' }
189 await makePostBodyRequest({ url: server.url, path: path, token: userAccessToken, fields, statusCodeExpected: 404 }) 190 await makePostBodyRequest({
191 url: server.url,
192 path,
193 token: userAccessToken,
194 fields,
195 statusCodeExpected: HttpStatusCode.NOT_FOUND_404
196 })
190 }) 197 })
191 198
192 it('Should fail with a wrong comment', async function () { 199 it('Should fail with a wrong comment', async function () {
@@ -196,7 +203,13 @@ describe('Test abuses API validators', function () {
196 203
197 it('Should fail with an unknown comment', async function () { 204 it('Should fail with an unknown comment', async function () {
198 const fields = { comment: { id: 42 }, reason: 'my super reason' } 205 const fields = { comment: { id: 42 }, reason: 'my super reason' }
199 await makePostBodyRequest({ url: server.url, path: path, token: userAccessToken, fields, statusCodeExpected: 404 }) 206 await makePostBodyRequest({
207 url: server.url,
208 path,
209 token: userAccessToken,
210 fields,
211 statusCodeExpected: HttpStatusCode.NOT_FOUND_404
212 })
200 }) 213 })
201 214
202 it('Should fail with a wrong account', async function () { 215 it('Should fail with a wrong account', async function () {
@@ -206,18 +219,30 @@ describe('Test abuses API validators', function () {
206 219
207 it('Should fail with an unknown account', async function () { 220 it('Should fail with an unknown account', async function () {
208 const fields = { account: { id: 42 }, reason: 'my super reason' } 221 const fields = { account: { id: 42 }, reason: 'my super reason' }
209 await makePostBodyRequest({ url: server.url, path: path, token: userAccessToken, fields, statusCodeExpected: 404 }) 222 await makePostBodyRequest({
223 url: server.url,
224 path,
225 token: userAccessToken,
226 fields,
227 statusCodeExpected: HttpStatusCode.NOT_FOUND_404
228 })
210 }) 229 })
211 230
212 it('Should fail with not account, comment or video', async function () { 231 it('Should fail with not account, comment or video', async function () {
213 const fields = { reason: 'my super reason' } 232 const fields = { reason: 'my super reason' }
214 await makePostBodyRequest({ url: server.url, path: path, token: userAccessToken, fields, statusCodeExpected: 400 }) 233 await makePostBodyRequest({
234 url: server.url,
235 path,
236 token: userAccessToken,
237 fields,
238 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400
239 })
215 }) 240 })
216 241
217 it('Should fail with a non authenticated user', async function () { 242 it('Should fail with a non authenticated user', async function () {
218 const fields = { video: { id: server.video.id }, reason: 'my super reason' } 243 const fields = { video: { id: server.video.id }, reason: 'my super reason' }
219 244
220 await makePostBodyRequest({ url: server.url, path, token: 'hello', fields, statusCodeExpected: 401 }) 245 await makePostBodyRequest({ url: server.url, path, token: 'hello', fields, statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 })
221 }) 246 })
222 247
223 it('Should fail with a reason too short', async function () { 248 it('Should fail with a reason too short', async function () {
@@ -235,7 +260,13 @@ describe('Test abuses API validators', function () {
235 it('Should succeed with the correct parameters (basic)', async function () { 260 it('Should succeed with the correct parameters (basic)', async function () {
236 const fields: AbuseCreate = { video: { id: server.video.id }, reason: 'my super reason' } 261 const fields: AbuseCreate = { video: { id: server.video.id }, reason: 'my super reason' }
237 262
238 const res = await makePostBodyRequest({ url: server.url, path, token: userAccessToken, fields, statusCodeExpected: 200 }) 263 const res = await makePostBodyRequest({
264 url: server.url,
265 path,
266 token: userAccessToken,
267 fields,
268 statusCodeExpected: HttpStatusCode.OK_200
269 })
239 abuseId = res.body.abuse.id 270 abuseId = res.body.abuse.id
240 }) 271 })
241 272
@@ -268,32 +299,32 @@ describe('Test abuses API validators', function () {
268 predefinedReasons: [ 'serverRules' ] 299 predefinedReasons: [ 'serverRules' ]
269 } 300 }
270 301
271 await makePostBodyRequest({ url: server.url, path, token: userAccessToken, fields, statusCodeExpected: 200 }) 302 await makePostBodyRequest({ url: server.url, path, token: userAccessToken, fields, statusCodeExpected: HttpStatusCode.OK_200 })
272 }) 303 })
273 }) 304 })
274 305
275 describe('When updating an abuse', function () { 306 describe('When updating an abuse', function () {
276 307
277 it('Should fail with a non authenticated user', async function () { 308 it('Should fail with a non authenticated user', async function () {
278 await updateAbuse(server.url, 'blabla', abuseId, {}, 401) 309 await updateAbuse(server.url, 'blabla', abuseId, {}, HttpStatusCode.UNAUTHORIZED_401)
279 }) 310 })
280 311
281 it('Should fail with a non admin user', async function () { 312 it('Should fail with a non admin user', async function () {
282 await updateAbuse(server.url, userAccessToken, abuseId, {}, 403) 313 await updateAbuse(server.url, userAccessToken, abuseId, {}, HttpStatusCode.FORBIDDEN_403)
283 }) 314 })
284 315
285 it('Should fail with a bad abuse id', async function () { 316 it('Should fail with a bad abuse id', async function () {
286 await updateAbuse(server.url, server.accessToken, 45, {}, 404) 317 await updateAbuse(server.url, server.accessToken, 45, {}, HttpStatusCode.NOT_FOUND_404)
287 }) 318 })
288 319
289 it('Should fail with a bad state', async function () { 320 it('Should fail with a bad state', async function () {
290 const body = { state: 5 } 321 const body = { state: 5 }
291 await updateAbuse(server.url, server.accessToken, abuseId, body, 400) 322 await updateAbuse(server.url, server.accessToken, abuseId, body, HttpStatusCode.BAD_REQUEST_400)
292 }) 323 })
293 324
294 it('Should fail with a bad moderation comment', async function () { 325 it('Should fail with a bad moderation comment', async function () {
295 const body = { moderationComment: 'b'.repeat(3001) } 326 const body = { moderationComment: 'b'.repeat(3001) }
296 await updateAbuse(server.url, server.accessToken, abuseId, body, 400) 327 await updateAbuse(server.url, server.accessToken, abuseId, body, HttpStatusCode.BAD_REQUEST_400)
297 }) 328 })
298 329
299 it('Should succeed with the correct params', async function () { 330 it('Should succeed with the correct params', async function () {
@@ -306,19 +337,19 @@ describe('Test abuses API validators', function () {
306 const message = 'my super message' 337 const message = 'my super message'
307 338
308 it('Should fail with an invalid abuse id', async function () { 339 it('Should fail with an invalid abuse id', async function () {
309 await addAbuseMessage(server.url, userAccessToken2, 888, message, 404) 340 await addAbuseMessage(server.url, userAccessToken2, 888, message, HttpStatusCode.NOT_FOUND_404)
310 }) 341 })
311 342
312 it('Should fail with a non authenticated user', async function () { 343 it('Should fail with a non authenticated user', async function () {
313 await addAbuseMessage(server.url, 'fake_token', abuseId, message, 401) 344 await addAbuseMessage(server.url, 'fake_token', abuseId, message, HttpStatusCode.UNAUTHORIZED_401)
314 }) 345 })
315 346
316 it('Should fail with an invalid logged in user', async function () { 347 it('Should fail with an invalid logged in user', async function () {
317 await addAbuseMessage(server.url, userAccessToken2, abuseId, message, 403) 348 await addAbuseMessage(server.url, userAccessToken2, abuseId, message, HttpStatusCode.FORBIDDEN_403)
318 }) 349 })
319 350
320 it('Should fail with an invalid message', async function () { 351 it('Should fail with an invalid message', async function () {
321 await addAbuseMessage(server.url, userAccessToken, abuseId, 'a'.repeat(5000), 400) 352 await addAbuseMessage(server.url, userAccessToken, abuseId, 'a'.repeat(5000), HttpStatusCode.BAD_REQUEST_400)
322 }) 353 })
323 354
324 it('Should suceed with the correct params', async function () { 355 it('Should suceed with the correct params', async function () {
@@ -330,15 +361,15 @@ describe('Test abuses API validators', function () {
330 describe('When listing abuse messages', function () { 361 describe('When listing abuse messages', function () {
331 362
332 it('Should fail with an invalid abuse id', async function () { 363 it('Should fail with an invalid abuse id', async function () {
333 await listAbuseMessages(server.url, userAccessToken, 888, 404) 364 await listAbuseMessages(server.url, userAccessToken, 888, HttpStatusCode.NOT_FOUND_404)
334 }) 365 })
335 366
336 it('Should fail with a non authenticated user', async function () { 367 it('Should fail with a non authenticated user', async function () {
337 await listAbuseMessages(server.url, 'fake_token', abuseId, 401) 368 await listAbuseMessages(server.url, 'fake_token', abuseId, HttpStatusCode.UNAUTHORIZED_401)
338 }) 369 })
339 370
340 it('Should fail with an invalid logged in user', async function () { 371 it('Should fail with an invalid logged in user', async function () {
341 await listAbuseMessages(server.url, userAccessToken2, abuseId, 403) 372 await listAbuseMessages(server.url, userAccessToken2, abuseId, HttpStatusCode.FORBIDDEN_403)
342 }) 373 })
343 374
344 it('Should succeed with the correct params', async function () { 375 it('Should succeed with the correct params', async function () {
@@ -349,19 +380,19 @@ describe('Test abuses API validators', function () {
349 describe('When deleting an abuse message', function () { 380 describe('When deleting an abuse message', function () {
350 381
351 it('Should fail with an invalid abuse id', async function () { 382 it('Should fail with an invalid abuse id', async function () {
352 await deleteAbuseMessage(server.url, userAccessToken, 888, messageId, 404) 383 await deleteAbuseMessage(server.url, userAccessToken, 888, messageId, HttpStatusCode.NOT_FOUND_404)
353 }) 384 })
354 385
355 it('Should fail with an invalid message id', async function () { 386 it('Should fail with an invalid message id', async function () {
356 await deleteAbuseMessage(server.url, userAccessToken, abuseId, 888, 404) 387 await deleteAbuseMessage(server.url, userAccessToken, abuseId, 888, HttpStatusCode.NOT_FOUND_404)
357 }) 388 })
358 389
359 it('Should fail with a non authenticated user', async function () { 390 it('Should fail with a non authenticated user', async function () {
360 await deleteAbuseMessage(server.url, 'fake_token', abuseId, messageId, 401) 391 await deleteAbuseMessage(server.url, 'fake_token', abuseId, messageId, HttpStatusCode.UNAUTHORIZED_401)
361 }) 392 })
362 393
363 it('Should fail with an invalid logged in user', async function () { 394 it('Should fail with an invalid logged in user', async function () {
364 await deleteAbuseMessage(server.url, userAccessToken2, abuseId, messageId, 403) 395 await deleteAbuseMessage(server.url, userAccessToken2, abuseId, messageId, HttpStatusCode.FORBIDDEN_403)
365 }) 396 })
366 397
367 it('Should succeed with the correct params', async function () { 398 it('Should succeed with the correct params', async function () {
@@ -372,15 +403,15 @@ describe('Test abuses API validators', function () {
372 describe('When deleting a video abuse', function () { 403 describe('When deleting a video abuse', function () {
373 404
374 it('Should fail with a non authenticated user', async function () { 405 it('Should fail with a non authenticated user', async function () {
375 await deleteAbuse(server.url, 'blabla', abuseId, 401) 406 await deleteAbuse(server.url, 'blabla', abuseId, HttpStatusCode.UNAUTHORIZED_401)
376 }) 407 })
377 408
378 it('Should fail with a non admin user', async function () { 409 it('Should fail with a non admin user', async function () {
379 await deleteAbuse(server.url, userAccessToken, abuseId, 403) 410 await deleteAbuse(server.url, userAccessToken, abuseId, HttpStatusCode.FORBIDDEN_403)
380 }) 411 })
381 412
382 it('Should fail with a bad abuse id', async function () { 413 it('Should fail with a bad abuse id', async function () {
383 await deleteAbuse(server.url, server.accessToken, 45, 404) 414 await deleteAbuse(server.url, server.accessToken, 45, HttpStatusCode.NOT_FOUND_404)
384 }) 415 })
385 416
386 it('Should succeed with the correct params', async function () { 417 it('Should succeed with the correct params', async function () {
@@ -415,11 +446,11 @@ describe('Test abuses API validators', function () {
415 }) 446 })
416 447
417 it('Should fail when listing abuse messages of a remote abuse', async function () { 448 it('Should fail when listing abuse messages of a remote abuse', async function () {
418 await listAbuseMessages(server.url, server.accessToken, remoteAbuseId, 400) 449 await listAbuseMessages(server.url, server.accessToken, remoteAbuseId, HttpStatusCode.BAD_REQUEST_400)
419 }) 450 })
420 451
421 it('Should fail when creating abuse message of a remote abuse', async function () { 452 it('Should fail when creating abuse message of a remote abuse', async function () {
422 await addAbuseMessage(server.url, server.accessToken, remoteAbuseId, 'message', 400) 453 await addAbuseMessage(server.url, server.accessToken, remoteAbuseId, 'message', HttpStatusCode.BAD_REQUEST_400)
423 }) 454 })
424 455
425 after(async function () { 456 after(async function () {
diff --git a/server/tests/api/check-params/blocklist.ts b/server/tests/api/check-params/blocklist.ts
index 1219ec9bd..5ed8810ce 100644
--- a/server/tests/api/check-params/blocklist.ts
+++ b/server/tests/api/check-params/blocklist.ts
@@ -19,6 +19,7 @@ import {
19 checkBadSortPagination, 19 checkBadSortPagination,
20 checkBadStartPagination 20 checkBadStartPagination
21} from '../../../../shared/extra-utils/requests/check-api-params' 21} from '../../../../shared/extra-utils/requests/check-api-params'
22import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
22 23
23describe('Test blocklist API validators', function () { 24describe('Test blocklist API validators', function () {
24 let servers: ServerInfo[] 25 let servers: ServerInfo[]
@@ -53,7 +54,7 @@ describe('Test blocklist API validators', function () {
53 await makeGetRequest({ 54 await makeGetRequest({
54 url: server.url, 55 url: server.url,
55 path, 56 path,
56 statusCodeExpected: 401 57 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401
57 }) 58 })
58 }) 59 })
59 60
@@ -76,7 +77,7 @@ describe('Test blocklist API validators', function () {
76 url: server.url, 77 url: server.url,
77 path, 78 path,
78 fields: { accountName: 'user1' }, 79 fields: { accountName: 'user1' },
79 statusCodeExpected: 401 80 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401
80 }) 81 })
81 }) 82 })
82 83
@@ -86,7 +87,7 @@ describe('Test blocklist API validators', function () {
86 token: server.accessToken, 87 token: server.accessToken,
87 path, 88 path,
88 fields: { accountName: 'user2' }, 89 fields: { accountName: 'user2' },
89 statusCodeExpected: 404 90 statusCodeExpected: HttpStatusCode.NOT_FOUND_404
90 }) 91 })
91 }) 92 })
92 93
@@ -96,7 +97,7 @@ describe('Test blocklist API validators', function () {
96 token: server.accessToken, 97 token: server.accessToken,
97 path, 98 path,
98 fields: { accountName: 'root' }, 99 fields: { accountName: 'root' },
99 statusCodeExpected: 409 100 statusCodeExpected: HttpStatusCode.CONFLICT_409
100 }) 101 })
101 }) 102 })
102 103
@@ -106,7 +107,7 @@ describe('Test blocklist API validators', function () {
106 token: server.accessToken, 107 token: server.accessToken,
107 path, 108 path,
108 fields: { accountName: 'user1' }, 109 fields: { accountName: 'user1' },
109 statusCodeExpected: 204 110 statusCodeExpected: HttpStatusCode.NO_CONTENT_204
110 }) 111 })
111 }) 112 })
112 }) 113 })
@@ -116,7 +117,7 @@ describe('Test blocklist API validators', function () {
116 await makeDeleteRequest({ 117 await makeDeleteRequest({
117 url: server.url, 118 url: server.url,
118 path: path + '/user1', 119 path: path + '/user1',
119 statusCodeExpected: 401 120 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401
120 }) 121 })
121 }) 122 })
122 123
@@ -125,7 +126,7 @@ describe('Test blocklist API validators', function () {
125 url: server.url, 126 url: server.url,
126 path: path + '/user2', 127 path: path + '/user2',
127 token: server.accessToken, 128 token: server.accessToken,
128 statusCodeExpected: 404 129 statusCodeExpected: HttpStatusCode.NOT_FOUND_404
129 }) 130 })
130 }) 131 })
131 132
@@ -134,7 +135,7 @@ describe('Test blocklist API validators', function () {
134 url: server.url, 135 url: server.url,
135 path: path + '/user1', 136 path: path + '/user1',
136 token: server.accessToken, 137 token: server.accessToken,
137 statusCodeExpected: 204 138 statusCodeExpected: HttpStatusCode.NO_CONTENT_204
138 }) 139 })
139 }) 140 })
140 }) 141 })
@@ -148,7 +149,7 @@ describe('Test blocklist API validators', function () {
148 await makeGetRequest({ 149 await makeGetRequest({
149 url: server.url, 150 url: server.url,
150 path, 151 path,
151 statusCodeExpected: 401 152 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401
152 }) 153 })
153 }) 154 })
154 155
@@ -171,7 +172,7 @@ describe('Test blocklist API validators', function () {
171 url: server.url, 172 url: server.url,
172 path, 173 path,
173 fields: { host: 'localhost:9002' }, 174 fields: { host: 'localhost:9002' },
174 statusCodeExpected: 401 175 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401
175 }) 176 })
176 }) 177 })
177 178
@@ -181,7 +182,7 @@ describe('Test blocklist API validators', function () {
181 token: server.accessToken, 182 token: server.accessToken,
182 path, 183 path,
183 fields: { host: 'localhost:9003' }, 184 fields: { host: 'localhost:9003' },
184 statusCodeExpected: 204 185 statusCodeExpected: HttpStatusCode.NO_CONTENT_204
185 }) 186 })
186 }) 187 })
187 188
@@ -191,7 +192,7 @@ describe('Test blocklist API validators', function () {
191 token: server.accessToken, 192 token: server.accessToken,
192 path, 193 path,
193 fields: { host: 'localhost:' + server.port }, 194 fields: { host: 'localhost:' + server.port },
194 statusCodeExpected: 409 195 statusCodeExpected: HttpStatusCode.CONFLICT_409
195 }) 196 })
196 }) 197 })
197 198
@@ -201,7 +202,7 @@ describe('Test blocklist API validators', function () {
201 token: server.accessToken, 202 token: server.accessToken,
202 path, 203 path,
203 fields: { host: 'localhost:' + servers[1].port }, 204 fields: { host: 'localhost:' + servers[1].port },
204 statusCodeExpected: 204 205 statusCodeExpected: HttpStatusCode.NO_CONTENT_204
205 }) 206 })
206 }) 207 })
207 }) 208 })
@@ -211,7 +212,7 @@ describe('Test blocklist API validators', function () {
211 await makeDeleteRequest({ 212 await makeDeleteRequest({
212 url: server.url, 213 url: server.url,
213 path: path + '/localhost:' + servers[1].port, 214 path: path + '/localhost:' + servers[1].port,
214 statusCodeExpected: 401 215 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401
215 }) 216 })
216 }) 217 })
217 218
@@ -220,7 +221,7 @@ describe('Test blocklist API validators', function () {
220 url: server.url, 221 url: server.url,
221 path: path + '/localhost:9004', 222 path: path + '/localhost:9004',
222 token: server.accessToken, 223 token: server.accessToken,
223 statusCodeExpected: 404 224 statusCodeExpected: HttpStatusCode.NOT_FOUND_404
224 }) 225 })
225 }) 226 })
226 227
@@ -229,7 +230,7 @@ describe('Test blocklist API validators', function () {
229 url: server.url, 230 url: server.url,
230 path: path + '/localhost:' + servers[1].port, 231 path: path + '/localhost:' + servers[1].port,
231 token: server.accessToken, 232 token: server.accessToken,
232 statusCodeExpected: 204 233 statusCodeExpected: HttpStatusCode.NO_CONTENT_204
233 }) 234 })
234 }) 235 })
235 }) 236 })
@@ -246,7 +247,7 @@ describe('Test blocklist API validators', function () {
246 await makeGetRequest({ 247 await makeGetRequest({
247 url: server.url, 248 url: server.url,
248 path, 249 path,
249 statusCodeExpected: 401 250 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401
250 }) 251 })
251 }) 252 })
252 253
@@ -255,7 +256,7 @@ describe('Test blocklist API validators', function () {
255 url: server.url, 256 url: server.url,
256 token: userAccessToken, 257 token: userAccessToken,
257 path, 258 path,
258 statusCodeExpected: 403 259 statusCodeExpected: HttpStatusCode.FORBIDDEN_403
259 }) 260 })
260 }) 261 })
261 262
@@ -278,7 +279,7 @@ describe('Test blocklist API validators', function () {
278 url: server.url, 279 url: server.url,
279 path, 280 path,
280 fields: { accountName: 'user1' }, 281 fields: { accountName: 'user1' },
281 statusCodeExpected: 401 282 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401
282 }) 283 })
283 }) 284 })
284 285
@@ -288,7 +289,7 @@ describe('Test blocklist API validators', function () {
288 token: userAccessToken, 289 token: userAccessToken,
289 path, 290 path,
290 fields: { accountName: 'user1' }, 291 fields: { accountName: 'user1' },
291 statusCodeExpected: 403 292 statusCodeExpected: HttpStatusCode.FORBIDDEN_403
292 }) 293 })
293 }) 294 })
294 295
@@ -298,7 +299,7 @@ describe('Test blocklist API validators', function () {
298 token: server.accessToken, 299 token: server.accessToken,
299 path, 300 path,
300 fields: { accountName: 'user2' }, 301 fields: { accountName: 'user2' },
301 statusCodeExpected: 404 302 statusCodeExpected: HttpStatusCode.NOT_FOUND_404
302 }) 303 })
303 }) 304 })
304 305
@@ -308,7 +309,7 @@ describe('Test blocklist API validators', function () {
308 token: server.accessToken, 309 token: server.accessToken,
309 path, 310 path,
310 fields: { accountName: 'root' }, 311 fields: { accountName: 'root' },
311 statusCodeExpected: 409 312 statusCodeExpected: HttpStatusCode.CONFLICT_409
312 }) 313 })
313 }) 314 })
314 315
@@ -318,7 +319,7 @@ describe('Test blocklist API validators', function () {
318 token: server.accessToken, 319 token: server.accessToken,
319 path, 320 path,
320 fields: { accountName: 'user1' }, 321 fields: { accountName: 'user1' },
321 statusCodeExpected: 204 322 statusCodeExpected: HttpStatusCode.NO_CONTENT_204
322 }) 323 })
323 }) 324 })
324 }) 325 })
@@ -328,7 +329,7 @@ describe('Test blocklist API validators', function () {
328 await makeDeleteRequest({ 329 await makeDeleteRequest({
329 url: server.url, 330 url: server.url,
330 path: path + '/user1', 331 path: path + '/user1',
331 statusCodeExpected: 401 332 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401
332 }) 333 })
333 }) 334 })
334 335
@@ -337,7 +338,7 @@ describe('Test blocklist API validators', function () {
337 url: server.url, 338 url: server.url,
338 path: path + '/user1', 339 path: path + '/user1',
339 token: userAccessToken, 340 token: userAccessToken,
340 statusCodeExpected: 403 341 statusCodeExpected: HttpStatusCode.FORBIDDEN_403
341 }) 342 })
342 }) 343 })
343 344
@@ -346,7 +347,7 @@ describe('Test blocklist API validators', function () {
346 url: server.url, 347 url: server.url,
347 path: path + '/user2', 348 path: path + '/user2',
348 token: server.accessToken, 349 token: server.accessToken,
349 statusCodeExpected: 404 350 statusCodeExpected: HttpStatusCode.NOT_FOUND_404
350 }) 351 })
351 }) 352 })
352 353
@@ -355,7 +356,7 @@ describe('Test blocklist API validators', function () {
355 url: server.url, 356 url: server.url,
356 path: path + '/user1', 357 path: path + '/user1',
357 token: server.accessToken, 358 token: server.accessToken,
358 statusCodeExpected: 204 359 statusCodeExpected: HttpStatusCode.NO_CONTENT_204
359 }) 360 })
360 }) 361 })
361 }) 362 })
@@ -369,7 +370,7 @@ describe('Test blocklist API validators', function () {
369 await makeGetRequest({ 370 await makeGetRequest({
370 url: server.url, 371 url: server.url,
371 path, 372 path,
372 statusCodeExpected: 401 373 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401
373 }) 374 })
374 }) 375 })
375 376
@@ -378,7 +379,7 @@ describe('Test blocklist API validators', function () {
378 url: server.url, 379 url: server.url,
379 token: userAccessToken, 380 token: userAccessToken,
380 path, 381 path,
381 statusCodeExpected: 403 382 statusCodeExpected: HttpStatusCode.FORBIDDEN_403
382 }) 383 })
383 }) 384 })
384 385
@@ -401,7 +402,7 @@ describe('Test blocklist API validators', function () {
401 url: server.url, 402 url: server.url,
402 path, 403 path,
403 fields: { host: 'localhost:' + servers[1].port }, 404 fields: { host: 'localhost:' + servers[1].port },
404 statusCodeExpected: 401 405 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401
405 }) 406 })
406 }) 407 })
407 408
@@ -411,7 +412,7 @@ describe('Test blocklist API validators', function () {
411 token: userAccessToken, 412 token: userAccessToken,
412 path, 413 path,
413 fields: { host: 'localhost:' + servers[1].port }, 414 fields: { host: 'localhost:' + servers[1].port },
414 statusCodeExpected: 403 415 statusCodeExpected: HttpStatusCode.FORBIDDEN_403
415 }) 416 })
416 }) 417 })
417 418
@@ -421,7 +422,7 @@ describe('Test blocklist API validators', function () {
421 token: server.accessToken, 422 token: server.accessToken,
422 path, 423 path,
423 fields: { host: 'localhost:9003' }, 424 fields: { host: 'localhost:9003' },
424 statusCodeExpected: 204 425 statusCodeExpected: HttpStatusCode.NO_CONTENT_204
425 }) 426 })
426 }) 427 })
427 428
@@ -431,7 +432,7 @@ describe('Test blocklist API validators', function () {
431 token: server.accessToken, 432 token: server.accessToken,
432 path, 433 path,
433 fields: { host: 'localhost:' + server.port }, 434 fields: { host: 'localhost:' + server.port },
434 statusCodeExpected: 409 435 statusCodeExpected: HttpStatusCode.CONFLICT_409
435 }) 436 })
436 }) 437 })
437 438
@@ -441,7 +442,7 @@ describe('Test blocklist API validators', function () {
441 token: server.accessToken, 442 token: server.accessToken,
442 path, 443 path,
443 fields: { host: 'localhost:' + servers[1].port }, 444 fields: { host: 'localhost:' + servers[1].port },
444 statusCodeExpected: 204 445 statusCodeExpected: HttpStatusCode.NO_CONTENT_204
445 }) 446 })
446 }) 447 })
447 }) 448 })
@@ -451,7 +452,7 @@ describe('Test blocklist API validators', function () {
451 await makeDeleteRequest({ 452 await makeDeleteRequest({
452 url: server.url, 453 url: server.url,
453 path: path + '/localhost:' + servers[1].port, 454 path: path + '/localhost:' + servers[1].port,
454 statusCodeExpected: 401 455 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401
455 }) 456 })
456 }) 457 })
457 458
@@ -460,7 +461,7 @@ describe('Test blocklist API validators', function () {
460 url: server.url, 461 url: server.url,
461 path: path + '/localhost:' + servers[1].port, 462 path: path + '/localhost:' + servers[1].port,
462 token: userAccessToken, 463 token: userAccessToken,
463 statusCodeExpected: 403 464 statusCodeExpected: HttpStatusCode.FORBIDDEN_403
464 }) 465 })
465 }) 466 })
466 467
@@ -469,7 +470,7 @@ describe('Test blocklist API validators', function () {
469 url: server.url, 470 url: server.url,
470 path: path + '/localhost:9004', 471 path: path + '/localhost:9004',
471 token: server.accessToken, 472 token: server.accessToken,
472 statusCodeExpected: 404 473 statusCodeExpected: HttpStatusCode.NOT_FOUND_404
473 }) 474 })
474 }) 475 })
475 476
@@ -478,7 +479,7 @@ describe('Test blocklist API validators', function () {
478 url: server.url, 479 url: server.url,
479 path: path + '/localhost:' + servers[1].port, 480 path: path + '/localhost:' + servers[1].port,
480 token: server.accessToken, 481 token: server.accessToken,
481 statusCodeExpected: 204 482 statusCodeExpected: HttpStatusCode.NO_CONTENT_204
482 }) 483 })
483 }) 484 })
484 }) 485 })
diff --git a/server/tests/api/check-params/bulk.ts b/server/tests/api/check-params/bulk.ts
index 432858b33..07b920ba7 100644
--- a/server/tests/api/check-params/bulk.ts
+++ b/server/tests/api/check-params/bulk.ts
@@ -10,6 +10,7 @@ import {
10 userLogin 10 userLogin
11} from '../../../../shared/extra-utils' 11} from '../../../../shared/extra-utils'
12import { makePostBodyRequest } from '../../../../shared/extra-utils/requests/requests' 12import { makePostBodyRequest } from '../../../../shared/extra-utils/requests/requests'
13import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
13 14
14describe('Test bulk API validators', function () { 15describe('Test bulk API validators', function () {
15 let server: ServerInfo 16 let server: ServerInfo
@@ -37,7 +38,7 @@ describe('Test bulk API validators', function () {
37 url: server.url, 38 url: server.url,
38 path, 39 path,
39 fields: { accountName: 'user1', scope: 'my-videos' }, 40 fields: { accountName: 'user1', scope: 'my-videos' },
40 statusCodeExpected: 401 41 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401
41 }) 42 })
42 }) 43 })
43 44
@@ -47,7 +48,7 @@ describe('Test bulk API validators', function () {
47 token: server.accessToken, 48 token: server.accessToken,
48 path, 49 path,
49 fields: { accountName: 'user2', scope: 'my-videos' }, 50 fields: { accountName: 'user2', scope: 'my-videos' },
50 statusCodeExpected: 404 51 statusCodeExpected: HttpStatusCode.NOT_FOUND_404
51 }) 52 })
52 }) 53 })
53 54
@@ -57,7 +58,7 @@ describe('Test bulk API validators', function () {
57 token: server.accessToken, 58 token: server.accessToken,
58 path, 59 path,
59 fields: { accountName: 'user1', scope: 'my-videoss' }, 60 fields: { accountName: 'user1', scope: 'my-videoss' },
60 statusCodeExpected: 400 61 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400
61 }) 62 })
62 }) 63 })
63 64
@@ -67,7 +68,7 @@ describe('Test bulk API validators', function () {
67 token: userAccessToken, 68 token: userAccessToken,
68 path, 69 path,
69 fields: { accountName: 'user1', scope: 'instance' }, 70 fields: { accountName: 'user1', scope: 'instance' },
70 statusCodeExpected: 403 71 statusCodeExpected: HttpStatusCode.FORBIDDEN_403
71 }) 72 })
72 }) 73 })
73 74
@@ -77,7 +78,7 @@ describe('Test bulk API validators', function () {
77 token: server.accessToken, 78 token: server.accessToken,
78 path, 79 path,
79 fields: { accountName: 'user1', scope: 'instance' }, 80 fields: { accountName: 'user1', scope: 'instance' },
80 statusCodeExpected: 204 81 statusCodeExpected: HttpStatusCode.NO_CONTENT_204
81 }) 82 })
82 }) 83 })
83 }) 84 })
diff --git a/server/tests/api/check-params/config.ts b/server/tests/api/check-params/config.ts
index 42ac5e1f9..08576c3ae 100644
--- a/server/tests/api/check-params/config.ts
+++ b/server/tests/api/check-params/config.ts
@@ -16,6 +16,7 @@ import {
16 setAccessTokensToServers, 16 setAccessTokensToServers,
17 userLogin 17 userLogin
18} from '../../../../shared/extra-utils' 18} from '../../../../shared/extra-utils'
19import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
19 20
20describe('Test config API validators', function () { 21describe('Test config API validators', function () {
21 const path = '/api/v1/config/custom' 22 const path = '/api/v1/config/custom'
@@ -197,7 +198,7 @@ describe('Test config API validators', function () {
197 await makeGetRequest({ 198 await makeGetRequest({
198 url: server.url, 199 url: server.url,
199 path, 200 path,
200 statusCodeExpected: 401 201 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401
201 }) 202 })
202 }) 203 })
203 204
@@ -206,7 +207,7 @@ describe('Test config API validators', function () {
206 url: server.url, 207 url: server.url,
207 path, 208 path,
208 token: userAccessToken, 209 token: userAccessToken,
209 statusCodeExpected: 403 210 statusCodeExpected: HttpStatusCode.FORBIDDEN_403
210 }) 211 })
211 }) 212 })
212 }) 213 })
@@ -217,7 +218,7 @@ describe('Test config API validators', function () {
217 url: server.url, 218 url: server.url,
218 path, 219 path,
219 fields: updateParams, 220 fields: updateParams,
220 statusCodeExpected: 401 221 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401
221 }) 222 })
222 }) 223 })
223 224
@@ -227,7 +228,7 @@ describe('Test config API validators', function () {
227 path, 228 path,
228 fields: updateParams, 229 fields: updateParams,
229 token: userAccessToken, 230 token: userAccessToken,
230 statusCodeExpected: 403 231 statusCodeExpected: HttpStatusCode.FORBIDDEN_403
231 }) 232 })
232 }) 233 })
233 234
@@ -239,7 +240,7 @@ describe('Test config API validators', function () {
239 path, 240 path,
240 fields: newUpdateParams, 241 fields: newUpdateParams,
241 token: server.accessToken, 242 token: server.accessToken,
242 statusCodeExpected: 400 243 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400
243 }) 244 })
244 }) 245 })
245 246
@@ -255,7 +256,7 @@ describe('Test config API validators', function () {
255 path, 256 path,
256 fields: newUpdateParams, 257 fields: newUpdateParams,
257 token: server.accessToken, 258 token: server.accessToken,
258 statusCodeExpected: 400 259 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400
259 }) 260 })
260 }) 261 })
261 262
@@ -274,7 +275,7 @@ describe('Test config API validators', function () {
274 path, 275 path,
275 fields: newUpdateParams, 276 fields: newUpdateParams,
276 token: server.accessToken, 277 token: server.accessToken,
277 statusCodeExpected: 400 278 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400
278 }) 279 })
279 }) 280 })
280 281
@@ -295,7 +296,7 @@ describe('Test config API validators', function () {
295 path, 296 path,
296 fields: newUpdateParams, 297 fields: newUpdateParams,
297 token: server.accessToken, 298 token: server.accessToken,
298 statusCodeExpected: 400 299 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400
299 }) 300 })
300 }) 301 })
301 302
@@ -305,7 +306,7 @@ describe('Test config API validators', function () {
305 path, 306 path,
306 fields: updateParams, 307 fields: updateParams,
307 token: server.accessToken, 308 token: server.accessToken,
308 statusCodeExpected: 200 309 statusCodeExpected: HttpStatusCode.OK_200
309 }) 310 })
310 }) 311 })
311 }) 312 })
@@ -315,7 +316,7 @@ describe('Test config API validators', function () {
315 await makeDeleteRequest({ 316 await makeDeleteRequest({
316 url: server.url, 317 url: server.url,
317 path, 318 path,
318 statusCodeExpected: 401 319 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401
319 }) 320 })
320 }) 321 })
321 322
@@ -324,7 +325,7 @@ describe('Test config API validators', function () {
324 url: server.url, 325 url: server.url,
325 path, 326 path,
326 token: userAccessToken, 327 token: userAccessToken,
327 statusCodeExpected: 403 328 statusCodeExpected: HttpStatusCode.FORBIDDEN_403
328 }) 329 })
329 }) 330 })
330 }) 331 })
diff --git a/server/tests/api/check-params/debug.ts b/server/tests/api/check-params/debug.ts
index 5fac73485..37bf0f99b 100644
--- a/server/tests/api/check-params/debug.ts
+++ b/server/tests/api/check-params/debug.ts
@@ -11,6 +11,7 @@ import {
11 userLogin 11 userLogin
12} from '../../../../shared/extra-utils' 12} from '../../../../shared/extra-utils'
13import { makeGetRequest } from '../../../../shared/extra-utils/requests/requests' 13import { makeGetRequest } from '../../../../shared/extra-utils/requests/requests'
14import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
14 15
15describe('Test debug API validators', function () { 16describe('Test debug API validators', function () {
16 const path = '/api/v1/server/debug' 17 const path = '/api/v1/server/debug'
@@ -40,7 +41,7 @@ describe('Test debug API validators', function () {
40 await makeGetRequest({ 41 await makeGetRequest({
41 url: server.url, 42 url: server.url,
42 path, 43 path,
43 statusCodeExpected: 401 44 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401
44 }) 45 })
45 }) 46 })
46 47
@@ -49,7 +50,7 @@ describe('Test debug API validators', function () {
49 url: server.url, 50 url: server.url,
50 path, 51 path,
51 token: userAccessToken, 52 token: userAccessToken,
52 statusCodeExpected: 403 53 statusCodeExpected: HttpStatusCode.FORBIDDEN_403
53 }) 54 })
54 }) 55 })
55 56
@@ -59,7 +60,7 @@ describe('Test debug API validators', function () {
59 path, 60 path,
60 token: server.accessToken, 61 token: server.accessToken,
61 query: { startDate: new Date().toISOString() }, 62 query: { startDate: new Date().toISOString() },
62 statusCodeExpected: 200 63 statusCodeExpected: HttpStatusCode.OK_200
63 }) 64 })
64 }) 65 })
65 }) 66 })
diff --git a/server/tests/api/check-params/follows.ts b/server/tests/api/check-params/follows.ts
index 2c2224a45..c03dd5c9c 100644
--- a/server/tests/api/check-params/follows.ts
+++ b/server/tests/api/check-params/follows.ts
@@ -17,6 +17,7 @@ import {
17 checkBadSortPagination, 17 checkBadSortPagination,
18 checkBadStartPagination 18 checkBadStartPagination
19} from '../../../../shared/extra-utils/requests/check-api-params' 19} from '../../../../shared/extra-utils/requests/check-api-params'
20import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
20 21
21describe('Test server follows API validators', function () { 22describe('Test server follows API validators', function () {
22 let server: ServerInfo 23 let server: ServerInfo
@@ -52,7 +53,7 @@ describe('Test server follows API validators', function () {
52 url: server.url, 53 url: server.url,
53 path, 54 path,
54 token: server.accessToken, 55 token: server.accessToken,
55 statusCodeExpected: 400 56 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400
56 }) 57 })
57 }) 58 })
58 59
@@ -62,7 +63,7 @@ describe('Test server follows API validators', function () {
62 path, 63 path,
63 token: server.accessToken, 64 token: server.accessToken,
64 fields: { hosts: 'localhost:9002' }, 65 fields: { hosts: 'localhost:9002' },
65 statusCodeExpected: 400 66 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400
66 }) 67 })
67 }) 68 })
68 69
@@ -72,7 +73,7 @@ describe('Test server follows API validators', function () {
72 path, 73 path,
73 fields: { hosts: [ 'localhost:9002', 'localhost:coucou' ] }, 74 fields: { hosts: [ 'localhost:9002', 'localhost:coucou' ] },
74 token: server.accessToken, 75 token: server.accessToken,
75 statusCodeExpected: 400 76 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400
76 }) 77 })
77 }) 78 })
78 79
@@ -82,7 +83,7 @@ describe('Test server follows API validators', function () {
82 path, 83 path,
83 fields: { hosts: [ 'localhost:9002', 'http://localhost:9003' ] }, 84 fields: { hosts: [ 'localhost:9002', 'http://localhost:9003' ] },
84 token: server.accessToken, 85 token: server.accessToken,
85 statusCodeExpected: 400 86 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400
86 }) 87 })
87 }) 88 })
88 89
@@ -92,7 +93,7 @@ describe('Test server follows API validators', function () {
92 path, 93 path,
93 fields: { urls: [ 'localhost:9002', 'localhost:9002' ] }, 94 fields: { urls: [ 'localhost:9002', 'localhost:9002' ] },
94 token: server.accessToken, 95 token: server.accessToken,
95 statusCodeExpected: 400 96 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400
96 }) 97 })
97 }) 98 })
98 99
@@ -102,7 +103,7 @@ describe('Test server follows API validators', function () {
102 path, 103 path,
103 fields: { hosts: [ 'localhost:9002' ] }, 104 fields: { hosts: [ 'localhost:9002' ] },
104 token: 'fake_token', 105 token: 'fake_token',
105 statusCodeExpected: 401 106 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401
106 }) 107 })
107 }) 108 })
108 109
@@ -112,7 +113,7 @@ describe('Test server follows API validators', function () {
112 path, 113 path,
113 fields: { hosts: [ 'localhost:9002' ] }, 114 fields: { hosts: [ 'localhost:9002' ] },
114 token: userAccessToken, 115 token: userAccessToken,
115 statusCodeExpected: 403 116 statusCodeExpected: HttpStatusCode.FORBIDDEN_403
116 }) 117 })
117 }) 118 })
118 }) 119 })
@@ -156,7 +157,7 @@ describe('Test server follows API validators', function () {
156 await makeGetRequest({ 157 await makeGetRequest({
157 url: server.url, 158 url: server.url,
158 path, 159 path,
159 statusCodeExpected: 200, 160 statusCodeExpected: HttpStatusCode.OK_200,
160 query: { 161 query: {
161 state: 'accepted', 162 state: 'accepted',
162 actorType: 'Application' 163 actorType: 'Application'
@@ -205,7 +206,7 @@ describe('Test server follows API validators', function () {
205 await makeGetRequest({ 206 await makeGetRequest({
206 url: server.url, 207 url: server.url,
207 path, 208 path,
208 statusCodeExpected: 200, 209 statusCodeExpected: HttpStatusCode.OK_200,
209 query: { 210 query: {
210 state: 'accepted' 211 state: 'accepted'
211 } 212 }
@@ -221,7 +222,7 @@ describe('Test server follows API validators', function () {
221 url: server.url, 222 url: server.url,
222 path: path + '/toto@localhost:9002', 223 path: path + '/toto@localhost:9002',
223 token: 'fake_token', 224 token: 'fake_token',
224 statusCodeExpected: 401 225 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401
225 }) 226 })
226 }) 227 })
227 228
@@ -230,7 +231,7 @@ describe('Test server follows API validators', function () {
230 url: server.url, 231 url: server.url,
231 path: path + '/toto@localhost:9002', 232 path: path + '/toto@localhost:9002',
232 token: userAccessToken, 233 token: userAccessToken,
233 statusCodeExpected: 403 234 statusCodeExpected: HttpStatusCode.FORBIDDEN_403
234 }) 235 })
235 }) 236 })
236 237
@@ -239,7 +240,7 @@ describe('Test server follows API validators', function () {
239 url: server.url, 240 url: server.url,
240 path: path + '/toto', 241 path: path + '/toto',
241 token: server.accessToken, 242 token: server.accessToken,
242 statusCodeExpected: 400 243 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400
243 }) 244 })
244 }) 245 })
245 246
@@ -248,7 +249,7 @@ describe('Test server follows API validators', function () {
248 url: server.url, 249 url: server.url,
249 path: path + '/toto@localhost:9003', 250 path: path + '/toto@localhost:9003',
250 token: server.accessToken, 251 token: server.accessToken,
251 statusCodeExpected: 404 252 statusCodeExpected: HttpStatusCode.NOT_FOUND_404
252 }) 253 })
253 }) 254 })
254 }) 255 })
@@ -261,7 +262,7 @@ describe('Test server follows API validators', function () {
261 url: server.url, 262 url: server.url,
262 path: path + '/toto@localhost:9002/accept', 263 path: path + '/toto@localhost:9002/accept',
263 token: 'fake_token', 264 token: 'fake_token',
264 statusCodeExpected: 401 265 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401
265 }) 266 })
266 }) 267 })
267 268
@@ -270,7 +271,7 @@ describe('Test server follows API validators', function () {
270 url: server.url, 271 url: server.url,
271 path: path + '/toto@localhost:9002/accept', 272 path: path + '/toto@localhost:9002/accept',
272 token: userAccessToken, 273 token: userAccessToken,
273 statusCodeExpected: 403 274 statusCodeExpected: HttpStatusCode.FORBIDDEN_403
274 }) 275 })
275 }) 276 })
276 277
@@ -279,7 +280,7 @@ describe('Test server follows API validators', function () {
279 url: server.url, 280 url: server.url,
280 path: path + '/toto/accept', 281 path: path + '/toto/accept',
281 token: server.accessToken, 282 token: server.accessToken,
282 statusCodeExpected: 400 283 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400
283 }) 284 })
284 }) 285 })
285 286
@@ -288,7 +289,7 @@ describe('Test server follows API validators', function () {
288 url: server.url, 289 url: server.url,
289 path: path + '/toto@localhost:9003/accept', 290 path: path + '/toto@localhost:9003/accept',
290 token: server.accessToken, 291 token: server.accessToken,
291 statusCodeExpected: 404 292 statusCodeExpected: HttpStatusCode.NOT_FOUND_404
292 }) 293 })
293 }) 294 })
294 }) 295 })
@@ -301,7 +302,7 @@ describe('Test server follows API validators', function () {
301 url: server.url, 302 url: server.url,
302 path: path + '/toto@localhost:9002/reject', 303 path: path + '/toto@localhost:9002/reject',
303 token: 'fake_token', 304 token: 'fake_token',
304 statusCodeExpected: 401 305 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401
305 }) 306 })
306 }) 307 })
307 308
@@ -310,7 +311,7 @@ describe('Test server follows API validators', function () {
310 url: server.url, 311 url: server.url,
311 path: path + '/toto@localhost:9002/reject', 312 path: path + '/toto@localhost:9002/reject',
312 token: userAccessToken, 313 token: userAccessToken,
313 statusCodeExpected: 403 314 statusCodeExpected: HttpStatusCode.FORBIDDEN_403
314 }) 315 })
315 }) 316 })
316 317
@@ -319,7 +320,7 @@ describe('Test server follows API validators', function () {
319 url: server.url, 320 url: server.url,
320 path: path + '/toto/reject', 321 path: path + '/toto/reject',
321 token: server.accessToken, 322 token: server.accessToken,
322 statusCodeExpected: 400 323 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400
323 }) 324 })
324 }) 325 })
325 326
@@ -328,7 +329,7 @@ describe('Test server follows API validators', function () {
328 url: server.url, 329 url: server.url,
329 path: path + '/toto@localhost:9003/reject', 330 path: path + '/toto@localhost:9003/reject',
330 token: server.accessToken, 331 token: server.accessToken,
331 statusCodeExpected: 404 332 statusCodeExpected: HttpStatusCode.NOT_FOUND_404
332 }) 333 })
333 }) 334 })
334 }) 335 })
@@ -341,7 +342,7 @@ describe('Test server follows API validators', function () {
341 url: server.url, 342 url: server.url,
342 path: path + '/localhost:9002', 343 path: path + '/localhost:9002',
343 token: 'fake_token', 344 token: 'fake_token',
344 statusCodeExpected: 401 345 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401
345 }) 346 })
346 }) 347 })
347 348
@@ -350,7 +351,7 @@ describe('Test server follows API validators', function () {
350 url: server.url, 351 url: server.url,
351 path: path + '/localhost:9002', 352 path: path + '/localhost:9002',
352 token: userAccessToken, 353 token: userAccessToken,
353 statusCodeExpected: 403 354 statusCodeExpected: HttpStatusCode.FORBIDDEN_403
354 }) 355 })
355 }) 356 })
356 357
@@ -359,7 +360,7 @@ describe('Test server follows API validators', function () {
359 url: server.url, 360 url: server.url,
360 path: path + '/example.com', 361 path: path + '/example.com',
361 token: server.accessToken, 362 token: server.accessToken,
362 statusCodeExpected: 404 363 statusCodeExpected: HttpStatusCode.NOT_FOUND_404
363 }) 364 })
364 }) 365 })
365 }) 366 })
diff --git a/server/tests/api/check-params/jobs.ts b/server/tests/api/check-params/jobs.ts
index 8f4af8d16..3c1d2049b 100644
--- a/server/tests/api/check-params/jobs.ts
+++ b/server/tests/api/check-params/jobs.ts
@@ -16,6 +16,7 @@ import {
16 checkBadStartPagination 16 checkBadStartPagination
17} from '../../../../shared/extra-utils/requests/check-api-params' 17} from '../../../../shared/extra-utils/requests/check-api-params'
18import { makeGetRequest } from '../../../../shared/extra-utils/requests/requests' 18import { makeGetRequest } from '../../../../shared/extra-utils/requests/requests'
19import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
19 20
20describe('Test jobs API validators', function () { 21describe('Test jobs API validators', function () {
21 const path = '/api/v1/jobs/failed' 22 const path = '/api/v1/jobs/failed'
@@ -76,7 +77,7 @@ describe('Test jobs API validators', function () {
76 await makeGetRequest({ 77 await makeGetRequest({
77 url: server.url, 78 url: server.url,
78 path, 79 path,
79 statusCodeExpected: 401 80 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401
80 }) 81 })
81 }) 82 })
82 83
@@ -85,7 +86,7 @@ describe('Test jobs API validators', function () {
85 url: server.url, 86 url: server.url,
86 path, 87 path,
87 token: userAccessToken, 88 token: userAccessToken,
88 statusCodeExpected: 403 89 statusCodeExpected: HttpStatusCode.FORBIDDEN_403
89 }) 90 })
90 }) 91 })
91 92
diff --git a/server/tests/api/check-params/live.ts b/server/tests/api/check-params/live.ts
index 055f2f295..40dca908b 100644
--- a/server/tests/api/check-params/live.ts
+++ b/server/tests/api/check-params/live.ts
@@ -24,6 +24,7 @@ import {
24 userLogin, 24 userLogin,
25 waitUntilLiveStarts 25 waitUntilLiveStarts
26} from '../../../../shared/extra-utils' 26} from '../../../../shared/extra-utils'
27import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
27 28
28describe('Test video lives API validator', function () { 29describe('Test video lives API validator', function () {
29 const path = '/api/v1/videos/live' 30 const path = '/api/v1/videos/live'
@@ -226,7 +227,7 @@ describe('Test video lives API validator', function () {
226 path, 227 path,
227 token: server.accessToken, 228 token: server.accessToken,
228 fields: baseCorrectParams, 229 fields: baseCorrectParams,
229 statusCodeExpected: 200 230 statusCodeExpected: HttpStatusCode.OK_200
230 }) 231 })
231 232
232 videoId = res.body.video.id 233 videoId = res.body.video.id
@@ -244,7 +245,7 @@ describe('Test video lives API validator', function () {
244 path, 245 path,
245 token: server.accessToken, 246 token: server.accessToken,
246 fields: baseCorrectParams, 247 fields: baseCorrectParams,
247 statusCodeExpected: 403 248 statusCodeExpected: HttpStatusCode.FORBIDDEN_403
248 }) 249 })
249 }) 250 })
250 251
@@ -263,7 +264,7 @@ describe('Test video lives API validator', function () {
263 path, 264 path,
264 token: server.accessToken, 265 token: server.accessToken,
265 fields, 266 fields,
266 statusCodeExpected: 403 267 statusCodeExpected: HttpStatusCode.FORBIDDEN_403
267 }) 268 })
268 }) 269 })
269 270
@@ -282,7 +283,7 @@ describe('Test video lives API validator', function () {
282 path, 283 path,
283 token: server.accessToken, 284 token: server.accessToken,
284 fields, 285 fields,
285 statusCodeExpected: 200 286 statusCodeExpected: HttpStatusCode.OK_200
286 }) 287 })
287 }) 288 })
288 289
@@ -299,7 +300,7 @@ describe('Test video lives API validator', function () {
299 path, 300 path,
300 token: server.accessToken, 301 token: server.accessToken,
301 fields: baseCorrectParams, 302 fields: baseCorrectParams,
302 statusCodeExpected: 403 303 statusCodeExpected: HttpStatusCode.FORBIDDEN_403
303 }) 304 })
304 }) 305 })
305 306
@@ -317,7 +318,7 @@ describe('Test video lives API validator', function () {
317 path, 318 path,
318 token: server.accessToken, 319 token: server.accessToken,
319 fields: baseCorrectParams, 320 fields: baseCorrectParams,
320 statusCodeExpected: 403 321 statusCodeExpected: HttpStatusCode.FORBIDDEN_403
321 }) 322 })
322 }) 323 })
323 }) 324 })
@@ -325,27 +326,27 @@ describe('Test video lives API validator', function () {
325 describe('When getting live information', function () { 326 describe('When getting live information', function () {
326 327
327 it('Should fail without access token', async function () { 328 it('Should fail without access token', async function () {
328 await getLive(server.url, '', videoId, 401) 329 await getLive(server.url, '', videoId, HttpStatusCode.UNAUTHORIZED_401)
329 }) 330 })
330 331
331 it('Should fail with a bad access token', async function () { 332 it('Should fail with a bad access token', async function () {
332 await getLive(server.url, 'toto', videoId, 401) 333 await getLive(server.url, 'toto', videoId, HttpStatusCode.UNAUTHORIZED_401)
333 }) 334 })
334 335
335 it('Should fail with access token of another user', async function () { 336 it('Should fail with access token of another user', async function () {
336 await getLive(server.url, userAccessToken, videoId, 403) 337 await getLive(server.url, userAccessToken, videoId, HttpStatusCode.FORBIDDEN_403)
337 }) 338 })
338 339
339 it('Should fail with a bad video id', async function () { 340 it('Should fail with a bad video id', async function () {
340 await getLive(server.url, server.accessToken, 'toto', 400) 341 await getLive(server.url, server.accessToken, 'toto', HttpStatusCode.BAD_REQUEST_400)
341 }) 342 })
342 343
343 it('Should fail with an unknown video id', async function () { 344 it('Should fail with an unknown video id', async function () {
344 await getLive(server.url, server.accessToken, 454555, 404) 345 await getLive(server.url, server.accessToken, 454555, HttpStatusCode.NOT_FOUND_404)
345 }) 346 })
346 347
347 it('Should fail with a non live video', async function () { 348 it('Should fail with a non live video', async function () {
348 await getLive(server.url, server.accessToken, videoIdNotLive, 404) 349 await getLive(server.url, server.accessToken, videoIdNotLive, HttpStatusCode.NOT_FOUND_404)
349 }) 350 })
350 351
351 it('Should succeed with the correct params', async function () { 352 it('Should succeed with the correct params', async function () {
@@ -356,33 +357,33 @@ describe('Test video lives API validator', function () {
356 describe('When updating live information', async function () { 357 describe('When updating live information', async function () {
357 358
358 it('Should fail without access token', async function () { 359 it('Should fail without access token', async function () {
359 await updateLive(server.url, '', videoId, {}, 401) 360 await updateLive(server.url, '', videoId, {}, HttpStatusCode.UNAUTHORIZED_401)
360 }) 361 })
361 362
362 it('Should fail with a bad access token', async function () { 363 it('Should fail with a bad access token', async function () {
363 await updateLive(server.url, 'toto', videoId, {}, 401) 364 await updateLive(server.url, 'toto', videoId, {}, HttpStatusCode.UNAUTHORIZED_401)
364 }) 365 })
365 366
366 it('Should fail with access token of another user', async function () { 367 it('Should fail with access token of another user', async function () {
367 await updateLive(server.url, userAccessToken, videoId, {}, 403) 368 await updateLive(server.url, userAccessToken, videoId, {}, HttpStatusCode.FORBIDDEN_403)
368 }) 369 })
369 370
370 it('Should fail with a bad video id', async function () { 371 it('Should fail with a bad video id', async function () {
371 await updateLive(server.url, server.accessToken, 'toto', {}, 400) 372 await updateLive(server.url, server.accessToken, 'toto', {}, HttpStatusCode.BAD_REQUEST_400)
372 }) 373 })
373 374
374 it('Should fail with an unknown video id', async function () { 375 it('Should fail with an unknown video id', async function () {
375 await updateLive(server.url, server.accessToken, 454555, {}, 404) 376 await updateLive(server.url, server.accessToken, 454555, {}, HttpStatusCode.NOT_FOUND_404)
376 }) 377 })
377 378
378 it('Should fail with a non live video', async function () { 379 it('Should fail with a non live video', async function () {
379 await updateLive(server.url, server.accessToken, videoIdNotLive, {}, 404) 380 await updateLive(server.url, server.accessToken, videoIdNotLive, {}, HttpStatusCode.NOT_FOUND_404)
380 }) 381 })
381 382
382 it('Should fail with save replay and permanent live set to true', async function () { 383 it('Should fail with save replay and permanent live set to true', async function () {
383 const fields = { saveReplay: true, permanentLive: true } 384 const fields = { saveReplay: true, permanentLive: true }
384 385
385 await updateLive(server.url, server.accessToken, videoId, fields, 400) 386 await updateLive(server.url, server.accessToken, videoId, fields, HttpStatusCode.BAD_REQUEST_400)
386 }) 387 })
387 388
388 it('Should succeed with the correct params', async function () { 389 it('Should succeed with the correct params', async function () {
@@ -397,7 +398,7 @@ describe('Test video lives API validator', function () {
397 } 398 }
398 }) 399 })
399 400
400 await updateLive(server.url, server.accessToken, videoId, { saveReplay: true }, 403) 401 await updateLive(server.url, server.accessToken, videoId, { saveReplay: true }, HttpStatusCode.FORBIDDEN_403)
401 }) 402 })
402 403
403 it('Should fail to update a live if it has already started', async function () { 404 it('Should fail to update a live if it has already started', async function () {
@@ -409,7 +410,7 @@ describe('Test video lives API validator', function () {
409 const command = sendRTMPStream(live.rtmpUrl, live.streamKey) 410 const command = sendRTMPStream(live.rtmpUrl, live.streamKey)
410 411
411 await waitUntilLiveStarts(server.url, server.accessToken, videoId) 412 await waitUntilLiveStarts(server.url, server.accessToken, videoId)
412 await updateLive(server.url, server.accessToken, videoId, {}, 400) 413 await updateLive(server.url, server.accessToken, videoId, {}, HttpStatusCode.BAD_REQUEST_400)
413 414
414 await stopFfmpeg(command) 415 await stopFfmpeg(command)
415 }) 416 })
diff --git a/server/tests/api/check-params/logs.ts b/server/tests/api/check-params/logs.ts
index 719da54e6..dac1e6b98 100644
--- a/server/tests/api/check-params/logs.ts
+++ b/server/tests/api/check-params/logs.ts
@@ -11,6 +11,7 @@ import {
11 userLogin 11 userLogin
12} from '../../../../shared/extra-utils' 12} from '../../../../shared/extra-utils'
13import { makeGetRequest } from '../../../../shared/extra-utils/requests/requests' 13import { makeGetRequest } from '../../../../shared/extra-utils/requests/requests'
14import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
14 15
15describe('Test logs API validators', function () { 16describe('Test logs API validators', function () {
16 const path = '/api/v1/server/logs' 17 const path = '/api/v1/server/logs'
@@ -40,7 +41,7 @@ describe('Test logs API validators', function () {
40 await makeGetRequest({ 41 await makeGetRequest({
41 url: server.url, 42 url: server.url,
42 path, 43 path,
43 statusCodeExpected: 401 44 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401
44 }) 45 })
45 }) 46 })
46 47
@@ -49,7 +50,7 @@ describe('Test logs API validators', function () {
49 url: server.url, 50 url: server.url,
50 path, 51 path,
51 token: userAccessToken, 52 token: userAccessToken,
52 statusCodeExpected: 403 53 statusCodeExpected: HttpStatusCode.FORBIDDEN_403
53 }) 54 })
54 }) 55 })
55 56
@@ -58,7 +59,7 @@ describe('Test logs API validators', function () {
58 url: server.url, 59 url: server.url,
59 path, 60 path,
60 token: server.accessToken, 61 token: server.accessToken,
61 statusCodeExpected: 400 62 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400
62 }) 63 })
63 }) 64 })
64 65
@@ -68,7 +69,7 @@ describe('Test logs API validators', function () {
68 path, 69 path,
69 token: server.accessToken, 70 token: server.accessToken,
70 query: { startDate: 'toto' }, 71 query: { startDate: 'toto' },
71 statusCodeExpected: 400 72 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400
72 }) 73 })
73 }) 74 })
74 75
@@ -78,7 +79,7 @@ describe('Test logs API validators', function () {
78 path, 79 path,
79 token: server.accessToken, 80 token: server.accessToken,
80 query: { startDate: new Date().toISOString(), endDate: 'toto' }, 81 query: { startDate: new Date().toISOString(), endDate: 'toto' },
81 statusCodeExpected: 400 82 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400
82 }) 83 })
83 }) 84 })
84 85
@@ -88,7 +89,7 @@ describe('Test logs API validators', function () {
88 path, 89 path,
89 token: server.accessToken, 90 token: server.accessToken,
90 query: { startDate: new Date().toISOString(), level: 'toto' }, 91 query: { startDate: new Date().toISOString(), level: 'toto' },
91 statusCodeExpected: 400 92 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400
92 }) 93 })
93 }) 94 })
94 95
@@ -98,7 +99,7 @@ describe('Test logs API validators', function () {
98 path, 99 path,
99 token: server.accessToken, 100 token: server.accessToken,
100 query: { startDate: new Date().toISOString() }, 101 query: { startDate: new Date().toISOString() },
101 statusCodeExpected: 200 102 statusCodeExpected: HttpStatusCode.OK_200
102 }) 103 })
103 }) 104 })
104 }) 105 })
diff --git a/server/tests/api/check-params/plugins.ts b/server/tests/api/check-params/plugins.ts
index 07ded26ee..6e540bcbb 100644
--- a/server/tests/api/check-params/plugins.ts
+++ b/server/tests/api/check-params/plugins.ts
@@ -18,6 +18,7 @@ import {
18} from '../../../../shared/extra-utils' 18} from '../../../../shared/extra-utils'
19import { PluginType } from '../../../../shared/models/plugins/plugin.type' 19import { PluginType } from '../../../../shared/models/plugins/plugin.type'
20import { PeerTubePlugin } from '../../../../shared/models/plugins/peertube-plugin.model' 20import { PeerTubePlugin } from '../../../../shared/models/plugins/peertube-plugin.model'
21import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
21 22
22describe('Test server plugins API validators', function () { 23describe('Test server plugins API validators', function () {
23 let server: ServerInfo 24 let server: ServerInfo
@@ -73,7 +74,7 @@ describe('Test server plugins API validators', function () {
73 ] 74 ]
74 75
75 for (const p of paths) { 76 for (const p of paths) {
76 await makeGetRequest({ url: server.url, path: p, statusCodeExpected: 404 }) 77 await makeGetRequest({ url: server.url, path: p, statusCodeExpected: HttpStatusCode.NOT_FOUND_404 })
77 } 78 }
78 }) 79 })
79 80
@@ -81,7 +82,7 @@ describe('Test server plugins API validators', function () {
81 await makeGetRequest({ 82 await makeGetRequest({
82 url: server.url, 83 url: server.url,
83 path: '/themes/' + pluginName + '/' + npmVersion + '/static/images/chocobo.png', 84 path: '/themes/' + pluginName + '/' + npmVersion + '/static/images/chocobo.png',
84 statusCodeExpected: 404 85 statusCodeExpected: HttpStatusCode.NOT_FOUND_404
85 }) 86 })
86 }) 87 })
87 88
@@ -96,7 +97,7 @@ describe('Test server plugins API validators', function () {
96 ] 97 ]
97 98
98 for (const p of paths) { 99 for (const p of paths) {
99 await makeGetRequest({ url: server.url, path: p, statusCodeExpected: 400 }) 100 await makeGetRequest({ url: server.url, path: p, statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 })
100 } 101 }
101 }) 102 })
102 103
@@ -110,14 +111,14 @@ describe('Test server plugins API validators', function () {
110 ] 111 ]
111 112
112 for (const p of paths) { 113 for (const p of paths) {
113 await makeGetRequest({ url: server.url, path: p, statusCodeExpected: 400 }) 114 await makeGetRequest({ url: server.url, path: p, statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 })
114 } 115 }
115 }) 116 })
116 117
117 it('Should fail with an unknown auth name', async function () { 118 it('Should fail with an unknown auth name', async function () {
118 const path = '/plugins/' + pluginName + '/' + npmVersion + '/auth/bad-auth' 119 const path = '/plugins/' + pluginName + '/' + npmVersion + '/auth/bad-auth'
119 120
120 await makeGetRequest({ url: server.url, path, statusCodeExpected: 404 }) 121 await makeGetRequest({ url: server.url, path, statusCodeExpected: HttpStatusCode.NOT_FOUND_404 })
121 }) 122 })
122 123
123 it('Should fail with an unknown static file', async function () { 124 it('Should fail with an unknown static file', async function () {
@@ -129,7 +130,7 @@ describe('Test server plugins API validators', function () {
129 ] 130 ]
130 131
131 for (const p of paths) { 132 for (const p of paths) {
132 await makeGetRequest({ url: server.url, path: p, statusCodeExpected: 404 }) 133 await makeGetRequest({ url: server.url, path: p, statusCodeExpected: HttpStatusCode.NOT_FOUND_404 })
133 } 134 }
134 }) 135 })
135 136
@@ -137,7 +138,7 @@ describe('Test server plugins API validators', function () {
137 await makeGetRequest({ 138 await makeGetRequest({
138 url: server.url, 139 url: server.url,
139 path: '/themes/' + themeName + '/' + themeVersion + '/css/assets/fake.css', 140 path: '/themes/' + themeName + '/' + themeVersion + '/css/assets/fake.css',
140 statusCodeExpected: 404 141 statusCodeExpected: HttpStatusCode.NOT_FOUND_404
141 }) 142 })
142 }) 143 })
143 144
@@ -151,11 +152,11 @@ describe('Test server plugins API validators', function () {
151 ] 152 ]
152 153
153 for (const p of paths) { 154 for (const p of paths) {
154 await makeGetRequest({ url: server.url, path: p, statusCodeExpected: 200 }) 155 await makeGetRequest({ url: server.url, path: p, statusCodeExpected: HttpStatusCode.OK_200 })
155 } 156 }
156 157
157 const authPath = '/plugins/' + pluginName + '/' + npmVersion + '/auth/fake-auth' 158 const authPath = '/plugins/' + pluginName + '/' + npmVersion + '/auth/fake-auth'
158 await makeGetRequest({ url: server.url, path: authPath, statusCodeExpected: 302 }) 159 await makeGetRequest({ url: server.url, path: authPath, statusCodeExpected: HttpStatusCode.FOUND_302 })
159 }) 160 })
160 }) 161 })
161 162
@@ -173,7 +174,7 @@ describe('Test server plugins API validators', function () {
173 path, 174 path,
174 token: 'fake_token', 175 token: 'fake_token',
175 query: baseQuery, 176 query: baseQuery,
176 statusCodeExpected: 401 177 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401
177 }) 178 })
178 }) 179 })
179 180
@@ -183,7 +184,7 @@ describe('Test server plugins API validators', function () {
183 path, 184 path,
184 token: userAccessToken, 185 token: userAccessToken,
185 query: baseQuery, 186 query: baseQuery,
186 statusCodeExpected: 403 187 statusCodeExpected: HttpStatusCode.FORBIDDEN_403
187 }) 188 })
188 }) 189 })
189 190
@@ -227,7 +228,7 @@ describe('Test server plugins API validators', function () {
227 path, 228 path,
228 token: server.accessToken, 229 token: server.accessToken,
229 query: baseQuery, 230 query: baseQuery,
230 statusCodeExpected: 200 231 statusCodeExpected: HttpStatusCode.OK_200
231 }) 232 })
232 }) 233 })
233 }) 234 })
@@ -244,7 +245,7 @@ describe('Test server plugins API validators', function () {
244 path, 245 path,
245 token: 'fake_token', 246 token: 'fake_token',
246 query: baseQuery, 247 query: baseQuery,
247 statusCodeExpected: 401 248 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401
248 }) 249 })
249 }) 250 })
250 251
@@ -254,7 +255,7 @@ describe('Test server plugins API validators', function () {
254 path, 255 path,
255 token: userAccessToken, 256 token: userAccessToken,
256 query: baseQuery, 257 query: baseQuery,
257 statusCodeExpected: 403 258 statusCodeExpected: HttpStatusCode.FORBIDDEN_403
258 }) 259 })
259 }) 260 })
260 261
@@ -287,7 +288,7 @@ describe('Test server plugins API validators', function () {
287 path, 288 path,
288 token: server.accessToken, 289 token: server.accessToken,
289 query: baseQuery, 290 query: baseQuery,
290 statusCodeExpected: 200 291 statusCodeExpected: HttpStatusCode.OK_200
291 }) 292 })
292 }) 293 })
293 }) 294 })
@@ -301,7 +302,7 @@ describe('Test server plugins API validators', function () {
301 url: server.url, 302 url: server.url,
302 path: path + suffix, 303 path: path + suffix,
303 token: 'fake_token', 304 token: 'fake_token',
304 statusCodeExpected: 401 305 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401
305 }) 306 })
306 } 307 }
307 }) 308 })
@@ -312,7 +313,7 @@ describe('Test server plugins API validators', function () {
312 url: server.url, 313 url: server.url,
313 path: path + suffix, 314 path: path + suffix,
314 token: userAccessToken, 315 token: userAccessToken,
315 statusCodeExpected: 403 316 statusCodeExpected: HttpStatusCode.FORBIDDEN_403
316 }) 317 })
317 } 318 }
318 }) 319 })
@@ -323,7 +324,7 @@ describe('Test server plugins API validators', function () {
323 url: server.url, 324 url: server.url,
324 path: path + suffix, 325 path: path + suffix,
325 token: server.accessToken, 326 token: server.accessToken,
326 statusCodeExpected: 400 327 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400
327 }) 328 })
328 } 329 }
329 330
@@ -332,7 +333,7 @@ describe('Test server plugins API validators', function () {
332 url: server.url, 333 url: server.url,
333 path: path + suffix, 334 path: path + suffix,
334 token: server.accessToken, 335 token: server.accessToken,
335 statusCodeExpected: 400 336 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400
336 }) 337 })
337 } 338 }
338 }) 339 })
@@ -343,7 +344,7 @@ describe('Test server plugins API validators', function () {
343 url: server.url, 344 url: server.url,
344 path: path + suffix, 345 path: path + suffix,
345 token: server.accessToken, 346 token: server.accessToken,
346 statusCodeExpected: 404 347 statusCodeExpected: HttpStatusCode.NOT_FOUND_404
347 }) 348 })
348 } 349 }
349 }) 350 })
@@ -354,7 +355,7 @@ describe('Test server plugins API validators', function () {
354 url: server.url, 355 url: server.url,
355 path: path + suffix, 356 path: path + suffix,
356 token: server.accessToken, 357 token: server.accessToken,
357 statusCodeExpected: 200 358 statusCodeExpected: HttpStatusCode.OK_200
358 }) 359 })
359 } 360 }
360 }) 361 })
@@ -370,7 +371,7 @@ describe('Test server plugins API validators', function () {
370 path: path + npmPlugin + '/settings', 371 path: path + npmPlugin + '/settings',
371 fields: { settings }, 372 fields: { settings },
372 token: 'fake_token', 373 token: 'fake_token',
373 statusCodeExpected: 401 374 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401
374 }) 375 })
375 }) 376 })
376 377
@@ -380,7 +381,7 @@ describe('Test server plugins API validators', function () {
380 path: path + npmPlugin + '/settings', 381 path: path + npmPlugin + '/settings',
381 fields: { settings }, 382 fields: { settings },
382 token: userAccessToken, 383 token: userAccessToken,
383 statusCodeExpected: 403 384 statusCodeExpected: HttpStatusCode.FORBIDDEN_403
384 }) 385 })
385 }) 386 })
386 387
@@ -390,7 +391,7 @@ describe('Test server plugins API validators', function () {
390 path: path + 'toto/settings', 391 path: path + 'toto/settings',
391 fields: { settings }, 392 fields: { settings },
392 token: server.accessToken, 393 token: server.accessToken,
393 statusCodeExpected: 400 394 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400
394 }) 395 })
395 396
396 await makePutBodyRequest({ 397 await makePutBodyRequest({
@@ -398,7 +399,7 @@ describe('Test server plugins API validators', function () {
398 path: path + 'peertube-plugin-TOTO/settings', 399 path: path + 'peertube-plugin-TOTO/settings',
399 fields: { settings }, 400 fields: { settings },
400 token: server.accessToken, 401 token: server.accessToken,
401 statusCodeExpected: 400 402 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400
402 }) 403 })
403 }) 404 })
404 405
@@ -408,7 +409,7 @@ describe('Test server plugins API validators', function () {
408 path: path + 'peertube-plugin-toto/settings', 409 path: path + 'peertube-plugin-toto/settings',
409 fields: { settings }, 410 fields: { settings },
410 token: server.accessToken, 411 token: server.accessToken,
411 statusCodeExpected: 404 412 statusCodeExpected: HttpStatusCode.NOT_FOUND_404
412 }) 413 })
413 }) 414 })
414 415
@@ -418,7 +419,7 @@ describe('Test server plugins API validators', function () {
418 path: path + npmPlugin + '/settings', 419 path: path + npmPlugin + '/settings',
419 fields: { settings }, 420 fields: { settings },
420 token: server.accessToken, 421 token: server.accessToken,
421 statusCodeExpected: 204 422 statusCodeExpected: HttpStatusCode.NO_CONTENT_204
422 }) 423 })
423 }) 424 })
424 }) 425 })
@@ -433,7 +434,7 @@ describe('Test server plugins API validators', function () {
433 path: path + suffix, 434 path: path + suffix,
434 fields: { npmName: npmPlugin }, 435 fields: { npmName: npmPlugin },
435 token: 'fake_token', 436 token: 'fake_token',
436 statusCodeExpected: 401 437 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401
437 }) 438 })
438 } 439 }
439 }) 440 })
@@ -445,7 +446,7 @@ describe('Test server plugins API validators', function () {
445 path: path + suffix, 446 path: path + suffix,
446 fields: { npmName: npmPlugin }, 447 fields: { npmName: npmPlugin },
447 token: userAccessToken, 448 token: userAccessToken,
448 statusCodeExpected: 403 449 statusCodeExpected: HttpStatusCode.FORBIDDEN_403
449 }) 450 })
450 } 451 }
451 }) 452 })
@@ -457,7 +458,7 @@ describe('Test server plugins API validators', function () {
457 path: path + suffix, 458 path: path + suffix,
458 fields: { npmName: 'toto' }, 459 fields: { npmName: 'toto' },
459 token: server.accessToken, 460 token: server.accessToken,
460 statusCodeExpected: 400 461 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400
461 }) 462 })
462 } 463 }
463 464
@@ -467,7 +468,7 @@ describe('Test server plugins API validators', function () {
467 path: path + suffix, 468 path: path + suffix,
468 fields: { npmName: 'peertube-plugin-TOTO' }, 469 fields: { npmName: 'peertube-plugin-TOTO' },
469 token: server.accessToken, 470 token: server.accessToken,
470 statusCodeExpected: 400 471 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400
471 }) 472 })
472 } 473 }
473 }) 474 })
@@ -476,9 +477,9 @@ describe('Test server plugins API validators', function () {
476 this.timeout(10000) 477 this.timeout(10000)
477 478
478 const it = [ 479 const it = [
479 { suffix: 'install', status: 200 }, 480 { suffix: 'install', status: HttpStatusCode.OK_200 },
480 { suffix: 'update', status: 200 }, 481 { suffix: 'update', status: HttpStatusCode.OK_200 },
481 { suffix: 'uninstall', status: 204 } 482 { suffix: 'uninstall', status: HttpStatusCode.NO_CONTENT_204 }
482 ] 483 ]
483 484
484 for (const obj of it) { 485 for (const obj of it) {
diff --git a/server/tests/api/check-params/redundancy.ts b/server/tests/api/check-params/redundancy.ts
index cb0cc0854..3e04865ee 100644
--- a/server/tests/api/check-params/redundancy.ts
+++ b/server/tests/api/check-params/redundancy.ts
@@ -16,6 +16,7 @@ import {
16 setAccessTokensToServers, uploadVideoAndGetId, 16 setAccessTokensToServers, uploadVideoAndGetId,
17 userLogin, waitJobs, getVideoIdFromUUID 17 userLogin, waitJobs, getVideoIdFromUUID
18} from '../../../../shared/extra-utils' 18} from '../../../../shared/extra-utils'
19import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
19 20
20describe('Test server redundancy API validators', function () { 21describe('Test server redundancy API validators', function () {
21 let servers: ServerInfo[] 22 let servers: ServerInfo[]
@@ -62,11 +63,11 @@ describe('Test server redundancy API validators', function () {
62 }) 63 })
63 64
64 it('Should fail with an invalid token', async function () { 65 it('Should fail with an invalid token', async function () {
65 await makeGetRequest({ url, path, token: 'fake_token', statusCodeExpected: 401 }) 66 await makeGetRequest({ url, path, token: 'fake_token', statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 })
66 }) 67 })
67 68
68 it('Should fail if the user is not an administrator', async function () { 69 it('Should fail if the user is not an administrator', async function () {
69 await makeGetRequest({ url, path, token: userAccessToken, statusCodeExpected: 403 }) 70 await makeGetRequest({ url, path, token: userAccessToken, statusCodeExpected: HttpStatusCode.FORBIDDEN_403 })
70 }) 71 })
71 72
72 it('Should fail with a bad start pagination', async function () { 73 it('Should fail with a bad start pagination', async function () {
@@ -90,7 +91,7 @@ describe('Test server redundancy API validators', function () {
90 }) 91 })
91 92
92 it('Should succeed with the correct params', async function () { 93 it('Should succeed with the correct params', async function () {
93 await makeGetRequest({ url, path, token, query: { target: 'my-videos' }, statusCodeExpected: 200 }) 94 await makeGetRequest({ url, path, token, query: { target: 'my-videos' }, statusCodeExpected: HttpStatusCode.OK_200 })
94 }) 95 })
95 }) 96 })
96 97
@@ -106,11 +107,11 @@ describe('Test server redundancy API validators', function () {
106 }) 107 })
107 108
108 it('Should fail with an invalid token', async function () { 109 it('Should fail with an invalid token', async function () {
109 await makePostBodyRequest({ url, path, token: 'fake_token', statusCodeExpected: 401 }) 110 await makePostBodyRequest({ url, path, token: 'fake_token', statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 })
110 }) 111 })
111 112
112 it('Should fail if the user is not an administrator', async function () { 113 it('Should fail if the user is not an administrator', async function () {
113 await makePostBodyRequest({ url, path, token: userAccessToken, statusCodeExpected: 403 }) 114 await makePostBodyRequest({ url, path, token: userAccessToken, statusCodeExpected: HttpStatusCode.FORBIDDEN_403 })
114 }) 115 })
115 116
116 it('Should fail without a video id', async function () { 117 it('Should fail without a video id', async function () {
@@ -122,7 +123,7 @@ describe('Test server redundancy API validators', function () {
122 }) 123 })
123 124
124 it('Should fail with a not found video id', async function () { 125 it('Should fail with a not found video id', async function () {
125 await makePostBodyRequest({ url, path, token, fields: { videoId: 6565 }, statusCodeExpected: 404 }) 126 await makePostBodyRequest({ url, path, token, fields: { videoId: 6565 }, statusCodeExpected: HttpStatusCode.NOT_FOUND_404 })
126 }) 127 })
127 128
128 it('Should fail with a local a video id', async function () { 129 it('Should fail with a local a video id', async function () {
@@ -130,7 +131,7 @@ describe('Test server redundancy API validators', function () {
130 }) 131 })
131 132
132 it('Should succeed with the correct params', async function () { 133 it('Should succeed with the correct params', async function () {
133 await makePostBodyRequest({ url, path, token, fields: { videoId: videoIdRemote }, statusCodeExpected: 204 }) 134 await makePostBodyRequest({ url, path, token, fields: { videoId: videoIdRemote }, statusCodeExpected: HttpStatusCode.NO_CONTENT_204 })
134 }) 135 })
135 136
136 it('Should fail if the video is already duplicated', async function () { 137 it('Should fail if the video is already duplicated', async function () {
@@ -138,7 +139,7 @@ describe('Test server redundancy API validators', function () {
138 139
139 await waitJobs(servers) 140 await waitJobs(servers)
140 141
141 await makePostBodyRequest({ url, path, token, fields: { videoId: videoIdRemote }, statusCodeExpected: 409 }) 142 await makePostBodyRequest({ url, path, token, fields: { videoId: videoIdRemote }, statusCodeExpected: HttpStatusCode.CONFLICT_409 })
142 }) 143 })
143 }) 144 })
144 145
@@ -154,11 +155,11 @@ describe('Test server redundancy API validators', function () {
154 }) 155 })
155 156
156 it('Should fail with an invalid token', async function () { 157 it('Should fail with an invalid token', async function () {
157 await makeDeleteRequest({ url, path: path + '1', token: 'fake_token', statusCodeExpected: 401 }) 158 await makeDeleteRequest({ url, path: path + '1', token: 'fake_token', statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 })
158 }) 159 })
159 160
160 it('Should fail if the user is not an administrator', async function () { 161 it('Should fail if the user is not an administrator', async function () {
161 await makeDeleteRequest({ url, path: path + '1', token: userAccessToken, statusCodeExpected: 403 }) 162 await makeDeleteRequest({ url, path: path + '1', token: userAccessToken, statusCodeExpected: HttpStatusCode.FORBIDDEN_403 })
162 }) 163 })
163 164
164 it('Should fail with an incorrect video id', async function () { 165 it('Should fail with an incorrect video id', async function () {
@@ -166,7 +167,7 @@ describe('Test server redundancy API validators', function () {
166 }) 167 })
167 168
168 it('Should fail with a not found video redundancy', async function () { 169 it('Should fail with a not found video redundancy', async function () {
169 await makeDeleteRequest({ url, path: path + '454545', token, statusCodeExpected: 404 }) 170 await makeDeleteRequest({ url, path: path + '454545', token, statusCodeExpected: HttpStatusCode.NOT_FOUND_404 })
170 }) 171 })
171 }) 172 })
172 173
@@ -179,7 +180,7 @@ describe('Test server redundancy API validators', function () {
179 path: path + '/localhost:' + servers[1].port, 180 path: path + '/localhost:' + servers[1].port,
180 fields: { redundancyAllowed: true }, 181 fields: { redundancyAllowed: true },
181 token: 'fake_token', 182 token: 'fake_token',
182 statusCodeExpected: 401 183 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401
183 }) 184 })
184 }) 185 })
185 186
@@ -189,7 +190,7 @@ describe('Test server redundancy API validators', function () {
189 path: path + '/localhost:' + servers[1].port, 190 path: path + '/localhost:' + servers[1].port,
190 fields: { redundancyAllowed: true }, 191 fields: { redundancyAllowed: true },
191 token: userAccessToken, 192 token: userAccessToken,
192 statusCodeExpected: 403 193 statusCodeExpected: HttpStatusCode.FORBIDDEN_403
193 }) 194 })
194 }) 195 })
195 196
@@ -199,7 +200,7 @@ describe('Test server redundancy API validators', function () {
199 path: path + '/example.com', 200 path: path + '/example.com',
200 fields: { redundancyAllowed: true }, 201 fields: { redundancyAllowed: true },
201 token: servers[0].accessToken, 202 token: servers[0].accessToken,
202 statusCodeExpected: 404 203 statusCodeExpected: HttpStatusCode.NOT_FOUND_404
203 }) 204 })
204 }) 205 })
205 206
@@ -209,7 +210,7 @@ describe('Test server redundancy API validators', function () {
209 path: path + '/localhost:' + servers[1].port, 210 path: path + '/localhost:' + servers[1].port,
210 fields: { blabla: true }, 211 fields: { blabla: true },
211 token: servers[0].accessToken, 212 token: servers[0].accessToken,
212 statusCodeExpected: 400 213 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400
213 }) 214 })
214 }) 215 })
215 216
@@ -219,7 +220,7 @@ describe('Test server redundancy API validators', function () {
219 path: path + '/localhost:' + servers[1].port, 220 path: path + '/localhost:' + servers[1].port,
220 fields: { redundancyAllowed: true }, 221 fields: { redundancyAllowed: true },
221 token: servers[0].accessToken, 222 token: servers[0].accessToken,
222 statusCodeExpected: 204 223 statusCodeExpected: HttpStatusCode.NO_CONTENT_204
223 }) 224 })
224 }) 225 })
225 }) 226 })
diff --git a/server/tests/api/check-params/search.ts b/server/tests/api/check-params/search.ts
index 1a8a7235e..8378c3a89 100644
--- a/server/tests/api/check-params/search.ts
+++ b/server/tests/api/check-params/search.ts
@@ -15,6 +15,7 @@ import {
15 checkBadSortPagination, 15 checkBadSortPagination,
16 checkBadStartPagination 16 checkBadStartPagination
17} from '../../../../shared/extra-utils/requests/check-api-params' 17} from '../../../../shared/extra-utils/requests/check-api-params'
18import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
18 19
19function updateSearchIndex (server: ServerInfo, enabled: boolean, disableLocalSearch = false) { 20function updateSearchIndex (server: ServerInfo, enabled: boolean, disableLocalSearch = false) {
20 return updateCustomSubConfig(server.url, server.accessToken, { 21 return updateCustomSubConfig(server.url, server.accessToken, {
@@ -59,83 +60,83 @@ describe('Test videos API validator', function () {
59 }) 60 })
60 61
61 it('Should success with the correct parameters', async function () { 62 it('Should success with the correct parameters', async function () {
62 await makeGetRequest({ url: server.url, path, query, statusCodeExpected: 200 }) 63 await makeGetRequest({ url: server.url, path, query, statusCodeExpected: HttpStatusCode.OK_200 })
63 }) 64 })
64 65
65 it('Should fail with an invalid category', async function () { 66 it('Should fail with an invalid category', async function () {
66 const customQuery1 = immutableAssign(query, { categoryOneOf: [ 'aa', 'b' ] }) 67 const customQuery1 = immutableAssign(query, { categoryOneOf: [ 'aa', 'b' ] })
67 await makeGetRequest({ url: server.url, path, query: customQuery1, statusCodeExpected: 400 }) 68 await makeGetRequest({ url: server.url, path, query: customQuery1, statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 })
68 69
69 const customQuery2 = immutableAssign(query, { categoryOneOf: 'a' }) 70 const customQuery2 = immutableAssign(query, { categoryOneOf: 'a' })
70 await makeGetRequest({ url: server.url, path, query: customQuery2, statusCodeExpected: 400 }) 71 await makeGetRequest({ url: server.url, path, query: customQuery2, statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 })
71 }) 72 })
72 73
73 it('Should succeed with a valid category', async function () { 74 it('Should succeed with a valid category', async function () {
74 const customQuery1 = immutableAssign(query, { categoryOneOf: [ 1, 7 ] }) 75 const customQuery1 = immutableAssign(query, { categoryOneOf: [ 1, 7 ] })
75 await makeGetRequest({ url: server.url, path, query: customQuery1, statusCodeExpected: 200 }) 76 await makeGetRequest({ url: server.url, path, query: customQuery1, statusCodeExpected: HttpStatusCode.OK_200 })
76 77
77 const customQuery2 = immutableAssign(query, { categoryOneOf: 1 }) 78 const customQuery2 = immutableAssign(query, { categoryOneOf: 1 })
78 await makeGetRequest({ url: server.url, path, query: customQuery2, statusCodeExpected: 200 }) 79 await makeGetRequest({ url: server.url, path, query: customQuery2, statusCodeExpected: HttpStatusCode.OK_200 })
79 }) 80 })
80 81
81 it('Should fail with an invalid licence', async function () { 82 it('Should fail with an invalid licence', async function () {
82 const customQuery1 = immutableAssign(query, { licenceOneOf: [ 'aa', 'b' ] }) 83 const customQuery1 = immutableAssign(query, { licenceOneOf: [ 'aa', 'b' ] })
83 await makeGetRequest({ url: server.url, path, query: customQuery1, statusCodeExpected: 400 }) 84 await makeGetRequest({ url: server.url, path, query: customQuery1, statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 })
84 85
85 const customQuery2 = immutableAssign(query, { licenceOneOf: 'a' }) 86 const customQuery2 = immutableAssign(query, { licenceOneOf: 'a' })
86 await makeGetRequest({ url: server.url, path, query: customQuery2, statusCodeExpected: 400 }) 87 await makeGetRequest({ url: server.url, path, query: customQuery2, statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 })
87 }) 88 })
88 89
89 it('Should succeed with a valid licence', async function () { 90 it('Should succeed with a valid licence', async function () {
90 const customQuery1 = immutableAssign(query, { licenceOneOf: [ 1, 2 ] }) 91 const customQuery1 = immutableAssign(query, { licenceOneOf: [ 1, 2 ] })
91 await makeGetRequest({ url: server.url, path, query: customQuery1, statusCodeExpected: 200 }) 92 await makeGetRequest({ url: server.url, path, query: customQuery1, statusCodeExpected: HttpStatusCode.OK_200 })
92 93
93 const customQuery2 = immutableAssign(query, { licenceOneOf: 1 }) 94 const customQuery2 = immutableAssign(query, { licenceOneOf: 1 })
94 await makeGetRequest({ url: server.url, path, query: customQuery2, statusCodeExpected: 200 }) 95 await makeGetRequest({ url: server.url, path, query: customQuery2, statusCodeExpected: HttpStatusCode.OK_200 })
95 }) 96 })
96 97
97 it('Should succeed with a valid language', async function () { 98 it('Should succeed with a valid language', async function () {
98 const customQuery1 = immutableAssign(query, { languageOneOf: [ 'fr', 'en' ] }) 99 const customQuery1 = immutableAssign(query, { languageOneOf: [ 'fr', 'en' ] })
99 await makeGetRequest({ url: server.url, path, query: customQuery1, statusCodeExpected: 200 }) 100 await makeGetRequest({ url: server.url, path, query: customQuery1, statusCodeExpected: HttpStatusCode.OK_200 })
100 101
101 const customQuery2 = immutableAssign(query, { languageOneOf: 'fr' }) 102 const customQuery2 = immutableAssign(query, { languageOneOf: 'fr' })
102 await makeGetRequest({ url: server.url, path, query: customQuery2, statusCodeExpected: 200 }) 103 await makeGetRequest({ url: server.url, path, query: customQuery2, statusCodeExpected: HttpStatusCode.OK_200 })
103 }) 104 })
104 105
105 it('Should succeed with valid tags', async function () { 106 it('Should succeed with valid tags', async function () {
106 const customQuery1 = immutableAssign(query, { tagsOneOf: [ 'tag1', 'tag2' ] }) 107 const customQuery1 = immutableAssign(query, { tagsOneOf: [ 'tag1', 'tag2' ] })
107 await makeGetRequest({ url: server.url, path, query: customQuery1, statusCodeExpected: 200 }) 108 await makeGetRequest({ url: server.url, path, query: customQuery1, statusCodeExpected: HttpStatusCode.OK_200 })
108 109
109 const customQuery2 = immutableAssign(query, { tagsOneOf: 'tag1' }) 110 const customQuery2 = immutableAssign(query, { tagsOneOf: 'tag1' })
110 await makeGetRequest({ url: server.url, path, query: customQuery2, statusCodeExpected: 200 }) 111 await makeGetRequest({ url: server.url, path, query: customQuery2, statusCodeExpected: HttpStatusCode.OK_200 })
111 112
112 const customQuery3 = immutableAssign(query, { tagsAllOf: [ 'tag1', 'tag2' ] }) 113 const customQuery3 = immutableAssign(query, { tagsAllOf: [ 'tag1', 'tag2' ] })
113 await makeGetRequest({ url: server.url, path, query: customQuery3, statusCodeExpected: 200 }) 114 await makeGetRequest({ url: server.url, path, query: customQuery3, statusCodeExpected: HttpStatusCode.OK_200 })
114 115
115 const customQuery4 = immutableAssign(query, { tagsAllOf: 'tag1' }) 116 const customQuery4 = immutableAssign(query, { tagsAllOf: 'tag1' })
116 await makeGetRequest({ url: server.url, path, query: customQuery4, statusCodeExpected: 200 }) 117 await makeGetRequest({ url: server.url, path, query: customQuery4, statusCodeExpected: HttpStatusCode.OK_200 })
117 }) 118 })
118 119
119 it('Should fail with invalid durations', async function () { 120 it('Should fail with invalid durations', async function () {
120 const customQuery1 = immutableAssign(query, { durationMin: 'hello' }) 121 const customQuery1 = immutableAssign(query, { durationMin: 'hello' })
121 await makeGetRequest({ url: server.url, path, query: customQuery1, statusCodeExpected: 400 }) 122 await makeGetRequest({ url: server.url, path, query: customQuery1, statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 })
122 123
123 const customQuery2 = immutableAssign(query, { durationMax: 'hello' }) 124 const customQuery2 = immutableAssign(query, { durationMax: 'hello' })
124 await makeGetRequest({ url: server.url, path, query: customQuery2, statusCodeExpected: 400 }) 125 await makeGetRequest({ url: server.url, path, query: customQuery2, statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 })
125 }) 126 })
126 127
127 it('Should fail with invalid dates', async function () { 128 it('Should fail with invalid dates', async function () {
128 const customQuery1 = immutableAssign(query, { startDate: 'hello' }) 129 const customQuery1 = immutableAssign(query, { startDate: 'hello' })
129 await makeGetRequest({ url: server.url, path, query: customQuery1, statusCodeExpected: 400 }) 130 await makeGetRequest({ url: server.url, path, query: customQuery1, statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 })
130 131
131 const customQuery2 = immutableAssign(query, { endDate: 'hello' }) 132 const customQuery2 = immutableAssign(query, { endDate: 'hello' })
132 await makeGetRequest({ url: server.url, path, query: customQuery2, statusCodeExpected: 400 }) 133 await makeGetRequest({ url: server.url, path, query: customQuery2, statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 })
133 134
134 const customQuery3 = immutableAssign(query, { originallyPublishedStartDate: 'hello' }) 135 const customQuery3 = immutableAssign(query, { originallyPublishedStartDate: 'hello' })
135 await makeGetRequest({ url: server.url, path, query: customQuery3, statusCodeExpected: 400 }) 136 await makeGetRequest({ url: server.url, path, query: customQuery3, statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 })
136 137
137 const customQuery4 = immutableAssign(query, { originallyPublishedEndDate: 'hello' }) 138 const customQuery4 = immutableAssign(query, { originallyPublishedEndDate: 'hello' })
138 await makeGetRequest({ url: server.url, path, query: customQuery4, statusCodeExpected: 400 }) 139 await makeGetRequest({ url: server.url, path, query: customQuery4, statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 })
139 }) 140 })
140 }) 141 })
141 142
@@ -159,7 +160,7 @@ describe('Test videos API validator', function () {
159 }) 160 })
160 161
161 it('Should success with the correct parameters', async function () { 162 it('Should success with the correct parameters', async function () {
162 await makeGetRequest({ url: server.url, path, query, statusCodeExpected: 200 }) 163 await makeGetRequest({ url: server.url, path, query, statusCodeExpected: HttpStatusCode.OK_200 })
163 }) 164 })
164 }) 165 })
165 166
@@ -177,41 +178,41 @@ describe('Test videos API validator', function () {
177 for (const path of paths) { 178 for (const path of paths) {
178 { 179 {
179 const customQuery = immutableAssign(query, { searchTarget: 'hello' }) 180 const customQuery = immutableAssign(query, { searchTarget: 'hello' })
180 await makeGetRequest({ url: server.url, path, query: customQuery, statusCodeExpected: 400 }) 181 await makeGetRequest({ url: server.url, path, query: customQuery, statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 })
181 } 182 }
182 183
183 { 184 {
184 const customQuery = immutableAssign(query, { searchTarget: undefined }) 185 const customQuery = immutableAssign(query, { searchTarget: undefined })
185 await makeGetRequest({ url: server.url, path, query: customQuery, statusCodeExpected: 200 }) 186 await makeGetRequest({ url: server.url, path, query: customQuery, statusCodeExpected: HttpStatusCode.OK_200 })
186 } 187 }
187 188
188 { 189 {
189 const customQuery = immutableAssign(query, { searchTarget: 'local' }) 190 const customQuery = immutableAssign(query, { searchTarget: 'local' })
190 await makeGetRequest({ url: server.url, path, query: customQuery, statusCodeExpected: 200 }) 191 await makeGetRequest({ url: server.url, path, query: customQuery, statusCodeExpected: HttpStatusCode.OK_200 })
191 } 192 }
192 193
193 { 194 {
194 const customQuery = immutableAssign(query, { searchTarget: 'search-index' }) 195 const customQuery = immutableAssign(query, { searchTarget: 'search-index' })
195 await makeGetRequest({ url: server.url, path, query: customQuery, statusCodeExpected: 400 }) 196 await makeGetRequest({ url: server.url, path, query: customQuery, statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 })
196 } 197 }
197 198
198 await updateSearchIndex(server, true, true) 199 await updateSearchIndex(server, true, true)
199 200
200 { 201 {
201 const customQuery = immutableAssign(query, { searchTarget: 'local' }) 202 const customQuery = immutableAssign(query, { searchTarget: 'local' })
202 await makeGetRequest({ url: server.url, path, query: customQuery, statusCodeExpected: 400 }) 203 await makeGetRequest({ url: server.url, path, query: customQuery, statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 })
203 } 204 }
204 205
205 { 206 {
206 const customQuery = immutableAssign(query, { searchTarget: 'search-index' }) 207 const customQuery = immutableAssign(query, { searchTarget: 'search-index' })
207 await makeGetRequest({ url: server.url, path, query: customQuery, statusCodeExpected: 200 }) 208 await makeGetRequest({ url: server.url, path, query: customQuery, statusCodeExpected: HttpStatusCode.OK_200 })
208 } 209 }
209 210
210 await updateSearchIndex(server, true, false) 211 await updateSearchIndex(server, true, false)
211 212
212 { 213 {
213 const customQuery = immutableAssign(query, { searchTarget: 'local' }) 214 const customQuery = immutableAssign(query, { searchTarget: 'local' })
214 await makeGetRequest({ url: server.url, path, query: customQuery, statusCodeExpected: 200 }) 215 await makeGetRequest({ url: server.url, path, query: customQuery, statusCodeExpected: HttpStatusCode.OK_200 })
215 } 216 }
216 217
217 await updateSearchIndex(server, false, false) 218 await updateSearchIndex(server, false, false)
diff --git a/server/tests/api/check-params/services.ts b/server/tests/api/check-params/services.ts
index e57edd9e4..514e3da70 100644
--- a/server/tests/api/check-params/services.ts
+++ b/server/tests/api/check-params/services.ts
@@ -13,6 +13,7 @@ import {
13 setDefaultVideoChannel 13 setDefaultVideoChannel
14} from '../../../../shared/extra-utils' 14} from '../../../../shared/extra-utils'
15import { VideoPlaylistPrivacy } from '@shared/models' 15import { VideoPlaylistPrivacy } from '@shared/models'
16import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
16 17
17describe('Test services API validators', function () { 18describe('Test services API validators', function () {
18 let server: ServerInfo 19 let server: ServerInfo
@@ -66,7 +67,7 @@ describe('Test services API validators', function () {
66 67
67 it('Should fail with an unknown element', async function () { 68 it('Should fail with an unknown element', async function () {
68 const embedUrl = `http://localhost:${server.port}/videos/watch/88fc0165-d1f0-4a35-a51a-3b47f668689c` 69 const embedUrl = `http://localhost:${server.port}/videos/watch/88fc0165-d1f0-4a35-a51a-3b47f668689c`
69 await checkParamEmbed(server, embedUrl, 404) 70 await checkParamEmbed(server, embedUrl, HttpStatusCode.NOT_FOUND_404)
70 }) 71 })
71 72
72 it('Should fail with an invalid path', async function () { 73 it('Should fail with an invalid path', async function () {
@@ -78,25 +79,25 @@ describe('Test services API validators', function () {
78 it('Should fail with an invalid max height', async function () { 79 it('Should fail with an invalid max height', async function () {
79 const embedUrl = `http://localhost:${server.port}/videos/watch/${server.video.uuid}` 80 const embedUrl = `http://localhost:${server.port}/videos/watch/${server.video.uuid}`
80 81
81 await checkParamEmbed(server, embedUrl, 400, { maxheight: 'hello' }) 82 await checkParamEmbed(server, embedUrl, HttpStatusCode.BAD_REQUEST_400, { maxheight: 'hello' })
82 }) 83 })
83 84
84 it('Should fail with an invalid max width', async function () { 85 it('Should fail with an invalid max width', async function () {
85 const embedUrl = `http://localhost:${server.port}/videos/watch/${server.video.uuid}` 86 const embedUrl = `http://localhost:${server.port}/videos/watch/${server.video.uuid}`
86 87
87 await checkParamEmbed(server, embedUrl, 400, { maxwidth: 'hello' }) 88 await checkParamEmbed(server, embedUrl, HttpStatusCode.BAD_REQUEST_400, { maxwidth: 'hello' })
88 }) 89 })
89 90
90 it('Should fail with an invalid format', async function () { 91 it('Should fail with an invalid format', async function () {
91 const embedUrl = `http://localhost:${server.port}/videos/watch/${server.video.uuid}` 92 const embedUrl = `http://localhost:${server.port}/videos/watch/${server.video.uuid}`
92 93
93 await checkParamEmbed(server, embedUrl, 400, { format: 'blabla' }) 94 await checkParamEmbed(server, embedUrl, HttpStatusCode.BAD_REQUEST_400, { format: 'blabla' })
94 }) 95 })
95 96
96 it('Should fail with a non supported format', async function () { 97 it('Should fail with a non supported format', async function () {
97 const embedUrl = `http://localhost:${server.port}/videos/watch/${server.video.uuid}` 98 const embedUrl = `http://localhost:${server.port}/videos/watch/${server.video.uuid}`
98 99
99 await checkParamEmbed(server, embedUrl, 501, { format: 'xml' }) 100 await checkParamEmbed(server, embedUrl, HttpStatusCode.NOT_IMPLEMENTED_501, { format: 'xml' })
100 }) 101 })
101 102
102 it('Should succeed with the correct params with a video', async function () { 103 it('Should succeed with the correct params with a video', async function () {
@@ -107,7 +108,7 @@ describe('Test services API validators', function () {
107 maxwidth: 400 108 maxwidth: 400
108 } 109 }
109 110
110 await checkParamEmbed(server, embedUrl, 200, query) 111 await checkParamEmbed(server, embedUrl, HttpStatusCode.OK_200, query)
111 }) 112 })
112 113
113 it('Should succeed with the correct params with a playlist', async function () { 114 it('Should succeed with the correct params with a playlist', async function () {
@@ -118,7 +119,7 @@ describe('Test services API validators', function () {
118 maxwidth: 400 119 maxwidth: 400
119 } 120 }
120 121
121 await checkParamEmbed(server, embedUrl, 200, query) 122 await checkParamEmbed(server, embedUrl, HttpStatusCode.OK_200, query)
122 }) 123 })
123 }) 124 })
124 125
@@ -127,7 +128,7 @@ describe('Test services API validators', function () {
127 }) 128 })
128}) 129})
129 130
130function checkParamEmbed (server: ServerInfo, embedUrl: string, statusCodeExpected = 400, query = {}) { 131function checkParamEmbed (server: ServerInfo, embedUrl: string, statusCodeExpected = HttpStatusCode.BAD_REQUEST_400, query = {}) {
131 const path = '/services/oembed' 132 const path = '/services/oembed'
132 133
133 return makeGetRequest({ 134 return makeGetRequest({
diff --git a/server/tests/api/check-params/user-notifications.ts b/server/tests/api/check-params/user-notifications.ts
index 6fa0502be..05a78b0ad 100644
--- a/server/tests/api/check-params/user-notifications.ts
+++ b/server/tests/api/check-params/user-notifications.ts
@@ -20,6 +20,7 @@ import {
20 checkBadStartPagination 20 checkBadStartPagination
21} from '../../../../shared/extra-utils/requests/check-api-params' 21} from '../../../../shared/extra-utils/requests/check-api-params'
22import { UserNotificationSetting, UserNotificationSettingValue } from '../../../../shared/models/users' 22import { UserNotificationSetting, UserNotificationSettingValue } from '../../../../shared/models/users'
23import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
23 24
24describe('Test user notifications API validators', function () { 25describe('Test user notifications API validators', function () {
25 let server: ServerInfo 26 let server: ServerInfo
@@ -57,7 +58,7 @@ describe('Test user notifications API validators', function () {
57 unread: 'toto' 58 unread: 'toto'
58 }, 59 },
59 token: server.accessToken, 60 token: server.accessToken,
60 statusCodeExpected: 200 61 statusCodeExpected: HttpStatusCode.OK_200
61 }) 62 })
62 }) 63 })
63 64
@@ -65,7 +66,7 @@ describe('Test user notifications API validators', function () {
65 await makeGetRequest({ 66 await makeGetRequest({
66 url: server.url, 67 url: server.url,
67 path, 68 path,
68 statusCodeExpected: 401 69 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401
69 }) 70 })
70 }) 71 })
71 72
@@ -74,7 +75,7 @@ describe('Test user notifications API validators', function () {
74 url: server.url, 75 url: server.url,
75 path, 76 path,
76 token: server.accessToken, 77 token: server.accessToken,
77 statusCodeExpected: 200 78 statusCodeExpected: HttpStatusCode.OK_200
78 }) 79 })
79 }) 80 })
80 }) 81 })
@@ -90,7 +91,7 @@ describe('Test user notifications API validators', function () {
90 ids: [ 'hello' ] 91 ids: [ 'hello' ]
91 }, 92 },
92 token: server.accessToken, 93 token: server.accessToken,
93 statusCodeExpected: 400 94 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400
94 }) 95 })
95 96
96 await makePostBodyRequest({ 97 await makePostBodyRequest({
@@ -100,7 +101,7 @@ describe('Test user notifications API validators', function () {
100 ids: [ ] 101 ids: [ ]
101 }, 102 },
102 token: server.accessToken, 103 token: server.accessToken,
103 statusCodeExpected: 400 104 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400
104 }) 105 })
105 106
106 await makePostBodyRequest({ 107 await makePostBodyRequest({
@@ -110,7 +111,7 @@ describe('Test user notifications API validators', function () {
110 ids: 5 111 ids: 5
111 }, 112 },
112 token: server.accessToken, 113 token: server.accessToken,
113 statusCodeExpected: 400 114 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400
114 }) 115 })
115 }) 116 })
116 117
@@ -121,7 +122,7 @@ describe('Test user notifications API validators', function () {
121 fields: { 122 fields: {
122 ids: [ 5 ] 123 ids: [ 5 ]
123 }, 124 },
124 statusCodeExpected: 401 125 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401
125 }) 126 })
126 }) 127 })
127 128
@@ -133,7 +134,7 @@ describe('Test user notifications API validators', function () {
133 ids: [ 5 ] 134 ids: [ 5 ]
134 }, 135 },
135 token: server.accessToken, 136 token: server.accessToken,
136 statusCodeExpected: 204 137 statusCodeExpected: HttpStatusCode.NO_CONTENT_204
137 }) 138 })
138 }) 139 })
139 }) 140 })
@@ -145,7 +146,7 @@ describe('Test user notifications API validators', function () {
145 await makePostBodyRequest({ 146 await makePostBodyRequest({
146 url: server.url, 147 url: server.url,
147 path, 148 path,
148 statusCodeExpected: 401 149 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401
149 }) 150 })
150 }) 151 })
151 152
@@ -154,7 +155,7 @@ describe('Test user notifications API validators', function () {
154 url: server.url, 155 url: server.url,
155 path, 156 path,
156 token: server.accessToken, 157 token: server.accessToken,
157 statusCodeExpected: 204 158 statusCodeExpected: HttpStatusCode.NO_CONTENT_204
158 }) 159 })
159 }) 160 })
160 }) 161 })
@@ -184,7 +185,7 @@ describe('Test user notifications API validators', function () {
184 path, 185 path,
185 token: server.accessToken, 186 token: server.accessToken,
186 fields: { newVideoFromSubscription: UserNotificationSettingValue.WEB }, 187 fields: { newVideoFromSubscription: UserNotificationSettingValue.WEB },
187 statusCodeExpected: 400 188 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400
188 }) 189 })
189 }) 190 })
190 191
@@ -197,7 +198,7 @@ describe('Test user notifications API validators', function () {
197 path, 198 path,
198 token: server.accessToken, 199 token: server.accessToken,
199 fields, 200 fields,
200 statusCodeExpected: 400 201 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400
201 }) 202 })
202 } 203 }
203 204
@@ -209,7 +210,7 @@ describe('Test user notifications API validators', function () {
209 path, 210 path,
210 fields, 211 fields,
211 token: server.accessToken, 212 token: server.accessToken,
212 statusCodeExpected: 400 213 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400
213 }) 214 })
214 } 215 }
215 }) 216 })
@@ -219,7 +220,7 @@ describe('Test user notifications API validators', function () {
219 url: server.url, 220 url: server.url,
220 path, 221 path,
221 fields: correctFields, 222 fields: correctFields,
222 statusCodeExpected: 401 223 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401
223 }) 224 })
224 }) 225 })
225 226
@@ -229,7 +230,7 @@ describe('Test user notifications API validators', function () {
229 path, 230 path,
230 token: server.accessToken, 231 token: server.accessToken,
231 fields: correctFields, 232 fields: correctFields,
232 statusCodeExpected: 204 233 statusCodeExpected: HttpStatusCode.NO_CONTENT_204
233 }) 234 })
234 }) 235 })
235 }) 236 })
diff --git a/server/tests/api/check-params/user-subscriptions.ts b/server/tests/api/check-params/user-subscriptions.ts
index 1edba4d64..538201647 100644
--- a/server/tests/api/check-params/user-subscriptions.ts
+++ b/server/tests/api/check-params/user-subscriptions.ts
@@ -20,6 +20,7 @@ import {
20 checkBadStartPagination 20 checkBadStartPagination
21} from '../../../../shared/extra-utils/requests/check-api-params' 21} from '../../../../shared/extra-utils/requests/check-api-params'
22import { waitJobs } from '../../../../shared/extra-utils/server/jobs' 22import { waitJobs } from '../../../../shared/extra-utils/server/jobs'
23import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
23 24
24describe('Test user subscriptions API validators', function () { 25describe('Test user subscriptions API validators', function () {
25 const path = '/api/v1/users/me/subscriptions' 26 const path = '/api/v1/users/me/subscriptions'
@@ -60,7 +61,7 @@ describe('Test user subscriptions API validators', function () {
60 await makeGetRequest({ 61 await makeGetRequest({
61 url: server.url, 62 url: server.url,
62 path, 63 path,
63 statusCodeExpected: 401 64 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401
64 }) 65 })
65 }) 66 })
66 67
@@ -69,7 +70,7 @@ describe('Test user subscriptions API validators', function () {
69 url: server.url, 70 url: server.url,
70 path, 71 path,
71 token: userAccessToken, 72 token: userAccessToken,
72 statusCodeExpected: 200 73 statusCodeExpected: HttpStatusCode.OK_200
73 }) 74 })
74 }) 75 })
75 }) 76 })
@@ -93,7 +94,7 @@ describe('Test user subscriptions API validators', function () {
93 await makeGetRequest({ 94 await makeGetRequest({
94 url: server.url, 95 url: server.url,
95 path, 96 path,
96 statusCodeExpected: 401 97 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401
97 }) 98 })
98 }) 99 })
99 100
@@ -102,7 +103,7 @@ describe('Test user subscriptions API validators', function () {
102 url: server.url, 103 url: server.url,
103 path, 104 path,
104 token: userAccessToken, 105 token: userAccessToken,
105 statusCodeExpected: 200 106 statusCodeExpected: HttpStatusCode.OK_200
106 }) 107 })
107 }) 108 })
108 }) 109 })
@@ -113,7 +114,7 @@ describe('Test user subscriptions API validators', function () {
113 url: server.url, 114 url: server.url,
114 path, 115 path,
115 fields: { uri: 'user1_channel@localhost:' + server.port }, 116 fields: { uri: 'user1_channel@localhost:' + server.port },
116 statusCodeExpected: 401 117 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401
117 }) 118 })
118 }) 119 })
119 120
@@ -123,7 +124,7 @@ describe('Test user subscriptions API validators', function () {
123 path, 124 path,
124 token: server.accessToken, 125 token: server.accessToken,
125 fields: { uri: 'root' }, 126 fields: { uri: 'root' },
126 statusCodeExpected: 400 127 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400
127 }) 128 })
128 129
129 await makePostBodyRequest({ 130 await makePostBodyRequest({
@@ -131,7 +132,7 @@ describe('Test user subscriptions API validators', function () {
131 path, 132 path,
132 token: server.accessToken, 133 token: server.accessToken,
133 fields: { uri: 'root@' }, 134 fields: { uri: 'root@' },
134 statusCodeExpected: 400 135 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400
135 }) 136 })
136 137
137 await makePostBodyRequest({ 138 await makePostBodyRequest({
@@ -139,7 +140,7 @@ describe('Test user subscriptions API validators', function () {
139 path, 140 path,
140 token: server.accessToken, 141 token: server.accessToken,
141 fields: { uri: 'root@hello@' }, 142 fields: { uri: 'root@hello@' },
142 statusCodeExpected: 400 143 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400
143 }) 144 })
144 }) 145 })
145 146
@@ -151,7 +152,7 @@ describe('Test user subscriptions API validators', function () {
151 path, 152 path,
152 token: server.accessToken, 153 token: server.accessToken,
153 fields: { uri: 'user1_channel@localhost:' + server.port }, 154 fields: { uri: 'user1_channel@localhost:' + server.port },
154 statusCodeExpected: 204 155 statusCodeExpected: HttpStatusCode.NO_CONTENT_204
155 }) 156 })
156 157
157 await waitJobs([ server ]) 158 await waitJobs([ server ])
@@ -163,7 +164,7 @@ describe('Test user subscriptions API validators', function () {
163 await makeGetRequest({ 164 await makeGetRequest({
164 url: server.url, 165 url: server.url,
165 path: path + '/user1_channel@localhost:' + server.port, 166 path: path + '/user1_channel@localhost:' + server.port,
166 statusCodeExpected: 401 167 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401
167 }) 168 })
168 }) 169 })
169 170
@@ -172,21 +173,21 @@ describe('Test user subscriptions API validators', function () {
172 url: server.url, 173 url: server.url,
173 path: path + '/root', 174 path: path + '/root',
174 token: server.accessToken, 175 token: server.accessToken,
175 statusCodeExpected: 400 176 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400
176 }) 177 })
177 178
178 await makeGetRequest({ 179 await makeGetRequest({
179 url: server.url, 180 url: server.url,
180 path: path + '/root@', 181 path: path + '/root@',
181 token: server.accessToken, 182 token: server.accessToken,
182 statusCodeExpected: 400 183 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400
183 }) 184 })
184 185
185 await makeGetRequest({ 186 await makeGetRequest({
186 url: server.url, 187 url: server.url,
187 path: path + '/root@hello@', 188 path: path + '/root@hello@',
188 token: server.accessToken, 189 token: server.accessToken,
189 statusCodeExpected: 400 190 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400
190 }) 191 })
191 }) 192 })
192 193
@@ -195,7 +196,7 @@ describe('Test user subscriptions API validators', function () {
195 url: server.url, 196 url: server.url,
196 path: path + '/root1@localhost:' + server.port, 197 path: path + '/root1@localhost:' + server.port,
197 token: server.accessToken, 198 token: server.accessToken,
198 statusCodeExpected: 404 199 statusCodeExpected: HttpStatusCode.NOT_FOUND_404
199 }) 200 })
200 }) 201 })
201 202
@@ -204,7 +205,7 @@ describe('Test user subscriptions API validators', function () {
204 url: server.url, 205 url: server.url,
205 path: path + '/user1_channel@localhost:' + server.port, 206 path: path + '/user1_channel@localhost:' + server.port,
206 token: server.accessToken, 207 token: server.accessToken,
207 statusCodeExpected: 200 208 statusCodeExpected: HttpStatusCode.OK_200
208 }) 209 })
209 }) 210 })
210 }) 211 })
@@ -216,7 +217,7 @@ describe('Test user subscriptions API validators', function () {
216 await makeGetRequest({ 217 await makeGetRequest({
217 url: server.url, 218 url: server.url,
218 path: existPath, 219 path: existPath,
219 statusCodeExpected: 401 220 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401
220 }) 221 })
221 }) 222 })
222 223
@@ -226,7 +227,7 @@ describe('Test user subscriptions API validators', function () {
226 path: existPath, 227 path: existPath,
227 query: { uris: 'toto' }, 228 query: { uris: 'toto' },
228 token: server.accessToken, 229 token: server.accessToken,
229 statusCodeExpected: 400 230 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400
230 }) 231 })
231 232
232 await makeGetRequest({ 233 await makeGetRequest({
@@ -234,7 +235,7 @@ describe('Test user subscriptions API validators', function () {
234 path: existPath, 235 path: existPath,
235 query: { 'uris[]': 1 }, 236 query: { 'uris[]': 1 },
236 token: server.accessToken, 237 token: server.accessToken,
237 statusCodeExpected: 400 238 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400
238 }) 239 })
239 }) 240 })
240 241
@@ -244,7 +245,7 @@ describe('Test user subscriptions API validators', function () {
244 path: existPath, 245 path: existPath,
245 query: { 'uris[]': 'coucou@localhost:' + server.port }, 246 query: { 'uris[]': 'coucou@localhost:' + server.port },
246 token: server.accessToken, 247 token: server.accessToken,
247 statusCodeExpected: 200 248 statusCodeExpected: HttpStatusCode.OK_200
248 }) 249 })
249 }) 250 })
250 }) 251 })
@@ -254,7 +255,7 @@ describe('Test user subscriptions API validators', function () {
254 await makeDeleteRequest({ 255 await makeDeleteRequest({
255 url: server.url, 256 url: server.url,
256 path: path + '/user1_channel@localhost:' + server.port, 257 path: path + '/user1_channel@localhost:' + server.port,
257 statusCodeExpected: 401 258 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401
258 }) 259 })
259 }) 260 })
260 261
@@ -263,21 +264,21 @@ describe('Test user subscriptions API validators', function () {
263 url: server.url, 264 url: server.url,
264 path: path + '/root', 265 path: path + '/root',
265 token: server.accessToken, 266 token: server.accessToken,
266 statusCodeExpected: 400 267 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400
267 }) 268 })
268 269
269 await makeDeleteRequest({ 270 await makeDeleteRequest({
270 url: server.url, 271 url: server.url,
271 path: path + '/root@', 272 path: path + '/root@',
272 token: server.accessToken, 273 token: server.accessToken,
273 statusCodeExpected: 400 274 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400
274 }) 275 })
275 276
276 await makeDeleteRequest({ 277 await makeDeleteRequest({
277 url: server.url, 278 url: server.url,
278 path: path + '/root@hello@', 279 path: path + '/root@hello@',
279 token: server.accessToken, 280 token: server.accessToken,
280 statusCodeExpected: 400 281 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400
281 }) 282 })
282 }) 283 })
283 284
@@ -286,7 +287,7 @@ describe('Test user subscriptions API validators', function () {
286 url: server.url, 287 url: server.url,
287 path: path + '/root1@localhost:' + server.port, 288 path: path + '/root1@localhost:' + server.port,
288 token: server.accessToken, 289 token: server.accessToken,
289 statusCodeExpected: 404 290 statusCodeExpected: HttpStatusCode.NOT_FOUND_404
290 }) 291 })
291 }) 292 })
292 293
@@ -295,7 +296,7 @@ describe('Test user subscriptions API validators', function () {
295 url: server.url, 296 url: server.url,
296 path: path + '/user1_channel@localhost:' + server.port, 297 path: path + '/user1_channel@localhost:' + server.port,
297 token: server.accessToken, 298 token: server.accessToken,
298 statusCodeExpected: 204 299 statusCodeExpected: HttpStatusCode.NO_CONTENT_204
299 }) 300 })
300 }) 301 })
301 }) 302 })
diff --git a/server/tests/api/check-params/users.ts b/server/tests/api/check-params/users.ts
index da7dc9704..21ace36aa 100644
--- a/server/tests/api/check-params/users.ts
+++ b/server/tests/api/check-params/users.ts
@@ -43,6 +43,7 @@ import { waitJobs } from '../../../../shared/extra-utils/server/jobs'
43import { getGoodVideoUrl, getMagnetURI, getMyVideoImports, importVideo } from '../../../../shared/extra-utils/videos/video-imports' 43import { getGoodVideoUrl, getMagnetURI, getMyVideoImports, importVideo } from '../../../../shared/extra-utils/videos/video-imports'
44import { UserAdminFlag } from '../../../../shared/models/users/user-flag.model' 44import { UserAdminFlag } from '../../../../shared/models/users/user-flag.model'
45import { VideoPrivacy } from '../../../../shared/models/videos' 45import { VideoPrivacy } from '../../../../shared/models/videos'
46import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
46 47
47describe('Test users API validators', function () { 48describe('Test users API validators', function () {
48 const path = '/api/v1/users/' 49 const path = '/api/v1/users/'
@@ -160,7 +161,7 @@ describe('Test users API validators', function () {
160 await makeGetRequest({ 161 await makeGetRequest({
161 url: server.url, 162 url: server.url,
162 path, 163 path,
163 statusCodeExpected: 401 164 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401
164 }) 165 })
165 }) 166 })
166 167
@@ -169,7 +170,7 @@ describe('Test users API validators', function () {
169 url: server.url, 170 url: server.url,
170 path, 171 path,
171 token: userAccessToken, 172 token: userAccessToken,
172 statusCodeExpected: 403 173 statusCodeExpected: HttpStatusCode.FORBIDDEN_403
173 }) 174 })
174 }) 175 })
175 }) 176 })
@@ -263,7 +264,7 @@ describe('Test users API validators', function () {
263 path: path, 264 path: path,
264 token: server.accessToken, 265 token: server.accessToken,
265 fields, 266 fields,
266 statusCodeExpected: 200 267 statusCodeExpected: HttpStatusCode.OK_200
267 }) 268 })
268 }) 269 })
269 270
@@ -279,20 +280,32 @@ describe('Test users API validators', function () {
279 path, 280 path,
280 token: 'super token', 281 token: 'super token',
281 fields: baseCorrectParams, 282 fields: baseCorrectParams,
282 statusCodeExpected: 401 283 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401
283 }) 284 })
284 }) 285 })
285 286
286 it('Should fail if we add a user with the same username', async function () { 287 it('Should fail if we add a user with the same username', async function () {
287 const fields = immutableAssign(baseCorrectParams, { username: 'user1' }) 288 const fields = immutableAssign(baseCorrectParams, { username: 'user1' })
288 289
289 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields, statusCodeExpected: 409 }) 290 await makePostBodyRequest({
291 url: server.url,
292 path,
293 token: server.accessToken,
294 fields,
295 statusCodeExpected: HttpStatusCode.CONFLICT_409
296 })
290 }) 297 })
291 298
292 it('Should fail if we add a user with the same email', async function () { 299 it('Should fail if we add a user with the same email', async function () {
293 const fields = immutableAssign(baseCorrectParams, { email: 'user1@example.com' }) 300 const fields = immutableAssign(baseCorrectParams, { email: 'user1@example.com' })
294 301
295 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields, statusCodeExpected: 409 }) 302 await makePostBodyRequest({
303 url: server.url,
304 path,
305 token: server.accessToken,
306 fields,
307 statusCodeExpected: HttpStatusCode.CONFLICT_409
308 })
296 }) 309 })
297 310
298 it('Should fail without a videoQuota', async function () { 311 it('Should fail without a videoQuota', async function () {
@@ -339,7 +352,7 @@ describe('Test users API validators', function () {
339 path, 352 path,
340 token: server.accessToken, 353 token: server.accessToken,
341 fields, 354 fields,
342 statusCodeExpected: 409 355 statusCodeExpected: HttpStatusCode.CONFLICT_409
343 }) 356 })
344 }) 357 })
345 358
@@ -352,7 +365,7 @@ describe('Test users API validators', function () {
352 path, 365 path,
353 token: moderatorAccessToken, 366 token: moderatorAccessToken,
354 fields, 367 fields,
355 statusCodeExpected: 403 368 statusCodeExpected: HttpStatusCode.FORBIDDEN_403
356 }) 369 })
357 } 370 }
358 }) 371 })
@@ -365,7 +378,7 @@ describe('Test users API validators', function () {
365 path, 378 path,
366 token: moderatorAccessToken, 379 token: moderatorAccessToken,
367 fields, 380 fields,
368 statusCodeExpected: 200 381 statusCodeExpected: HttpStatusCode.OK_200
369 }) 382 })
370 }) 383 })
371 384
@@ -375,7 +388,7 @@ describe('Test users API validators', function () {
375 path, 388 path,
376 token: server.accessToken, 389 token: server.accessToken,
377 fields: baseCorrectParams, 390 fields: baseCorrectParams,
378 statusCodeExpected: 200 391 statusCodeExpected: HttpStatusCode.OK_200
379 }) 392 })
380 }) 393 })
381 394
@@ -392,7 +405,7 @@ describe('Test users API validators', function () {
392 password: 'my super password', 405 password: 'my super password',
393 videoQuota: 42000000 406 videoQuota: 42000000
394 } 407 }
395 await makePostBodyRequest({ url: server.url, path, token: userAccessToken, fields, statusCodeExpected: 403 }) 408 await makePostBodyRequest({ url: server.url, path, token: userAccessToken, fields, statusCodeExpected: HttpStatusCode.FORBIDDEN_403 })
396 }) 409 })
397 }) 410 })
398 411
@@ -438,7 +451,13 @@ describe('Test users API validators', function () {
438 password: 'super'.repeat(61) 451 password: 'super'.repeat(61)
439 } 452 }
440 453
441 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields, statusCodeExpected: 401 }) 454 await makePutBodyRequest({
455 url: server.url,
456 path: path + 'me',
457 token: userAccessToken,
458 fields,
459 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401
460 })
442 }) 461 })
443 462
444 it('Should fail with an invalid NSFW policy attribute', async function () { 463 it('Should fail with an invalid NSFW policy attribute', async function () {
@@ -479,7 +498,13 @@ describe('Test users API validators', function () {
479 password: 'my super password' 498 password: 'my super password'
480 } 499 }
481 500
482 await makePutBodyRequest({ url: server.url, path: path + 'me', token: 'super token', fields, statusCodeExpected: 401 }) 501 await makePutBodyRequest({
502 url: server.url,
503 path: path + 'me',
504 token: 'super token',
505 fields,
506 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401
507 })
483 }) 508 })
484 509
485 it('Should fail with a too long description', async function () { 510 it('Should fail with a too long description', async function () {
@@ -551,7 +576,13 @@ describe('Test users API validators', function () {
551 noWelcomeModal: true 576 noWelcomeModal: true
552 } 577 }
553 578
554 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields, statusCodeExpected: 204 }) 579 await makePutBodyRequest({
580 url: server.url,
581 path: path + 'me',
582 token: userAccessToken,
583 fields,
584 statusCodeExpected: HttpStatusCode.NO_CONTENT_204
585 })
555 }) 586 })
556 587
557 it('Should succeed without password change with the correct params', async function () { 588 it('Should succeed without password change with the correct params', async function () {
@@ -560,7 +591,13 @@ describe('Test users API validators', function () {
560 autoPlayVideo: false 591 autoPlayVideo: false
561 } 592 }
562 593
563 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields, statusCodeExpected: 204 }) 594 await makePutBodyRequest({
595 url: server.url,
596 path: path + 'me',
597 token: userAccessToken,
598 fields,
599 statusCodeExpected: HttpStatusCode.NO_CONTENT_204
600 })
564 }) 601 })
565 }) 602 })
566 603
@@ -591,7 +628,7 @@ describe('Test users API validators', function () {
591 path: path + '/me/avatar/pick', 628 path: path + '/me/avatar/pick',
592 fields, 629 fields,
593 attaches, 630 attaches,
594 statusCodeExpected: 401 631 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401
595 }) 632 })
596 }) 633 })
597 634
@@ -606,7 +643,7 @@ describe('Test users API validators', function () {
606 token: server.accessToken, 643 token: server.accessToken,
607 fields, 644 fields,
608 attaches, 645 attaches,
609 statusCodeExpected: 200 646 statusCodeExpected: HttpStatusCode.OK_200
610 }) 647 })
611 }) 648 })
612 }) 649 })
@@ -614,11 +651,11 @@ describe('Test users API validators', function () {
614 describe('When managing my scoped tokens', function () { 651 describe('When managing my scoped tokens', function () {
615 652
616 it('Should fail to get my scoped tokens with an non authenticated user', async function () { 653 it('Should fail to get my scoped tokens with an non authenticated user', async function () {
617 await getUserScopedTokens(server.url, null, 401) 654 await getUserScopedTokens(server.url, null, HttpStatusCode.UNAUTHORIZED_401)
618 }) 655 })
619 656
620 it('Should fail to get my scoped tokens with a bad token', async function () { 657 it('Should fail to get my scoped tokens with a bad token', async function () {
621 await getUserScopedTokens(server.url, 'bad', 401) 658 await getUserScopedTokens(server.url, 'bad', HttpStatusCode.UNAUTHORIZED_401)
622 659
623 }) 660 })
624 661
@@ -627,11 +664,11 @@ describe('Test users API validators', function () {
627 }) 664 })
628 665
629 it('Should fail to renew my scoped tokens with an non authenticated user', async function () { 666 it('Should fail to renew my scoped tokens with an non authenticated user', async function () {
630 await renewUserScopedTokens(server.url, null, 401) 667 await renewUserScopedTokens(server.url, null, HttpStatusCode.UNAUTHORIZED_401)
631 }) 668 })
632 669
633 it('Should fail to renew my scoped tokens with a bad token', async function () { 670 it('Should fail to renew my scoped tokens with a bad token', async function () {
634 await renewUserScopedTokens(server.url, 'bad', 401) 671 await renewUserScopedTokens(server.url, 'bad', HttpStatusCode.UNAUTHORIZED_401)
635 }) 672 })
636 673
637 it('Should succeed to renew my scoped tokens', async function () { 674 it('Should succeed to renew my scoped tokens', async function () {
@@ -642,15 +679,20 @@ describe('Test users API validators', function () {
642 describe('When getting a user', function () { 679 describe('When getting a user', function () {
643 680
644 it('Should fail with an non authenticated user', async function () { 681 it('Should fail with an non authenticated user', async function () {
645 await makeGetRequest({ url: server.url, path: path + userId, token: 'super token', statusCodeExpected: 401 }) 682 await makeGetRequest({
683 url: server.url,
684 path: path + userId,
685 token: 'super token',
686 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401
687 })
646 }) 688 })
647 689
648 it('Should fail with a non admin user', async function () { 690 it('Should fail with a non admin user', async function () {
649 await makeGetRequest({ url: server.url, path, token: userAccessToken, statusCodeExpected: 403 }) 691 await makeGetRequest({ url: server.url, path, token: userAccessToken, statusCodeExpected: HttpStatusCode.FORBIDDEN_403 })
650 }) 692 })
651 693
652 it('Should succeed with the correct params', async function () { 694 it('Should succeed with the correct params', async function () {
653 await makeGetRequest({ url: server.url, path: path + userId, token: server.accessToken, statusCodeExpected: 200 }) 695 await makeGetRequest({ url: server.url, path: path + userId, token: server.accessToken, statusCodeExpected: HttpStatusCode.OK_200 })
654 }) 696 })
655 }) 697 })
656 698
@@ -711,7 +753,13 @@ describe('Test users API validators', function () {
711 videoQuota: 42 753 videoQuota: 42
712 } 754 }
713 755
714 await makePutBodyRequest({ url: server.url, path: path + userId, token: 'super token', fields, statusCodeExpected: 401 }) 756 await makePutBodyRequest({
757 url: server.url,
758 path: path + userId,
759 token: 'super token',
760 fields,
761 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401
762 })
715 }) 763 })
716 764
717 it('Should fail when updating root role', async function () { 765 it('Should fail when updating root role', async function () {
@@ -738,7 +786,7 @@ describe('Test users API validators', function () {
738 path: path + moderatorId, 786 path: path + moderatorId,
739 token: moderatorAccessToken, 787 token: moderatorAccessToken,
740 fields, 788 fields,
741 statusCodeExpected: 403 789 statusCodeExpected: HttpStatusCode.FORBIDDEN_403
742 }) 790 })
743 }) 791 })
744 792
@@ -752,7 +800,7 @@ describe('Test users API validators', function () {
752 path: path + userId, 800 path: path + userId,
753 token: moderatorAccessToken, 801 token: moderatorAccessToken,
754 fields, 802 fields,
755 statusCodeExpected: 204 803 statusCodeExpected: HttpStatusCode.NO_CONTENT_204
756 }) 804 })
757 }) 805 })
758 806
@@ -764,13 +812,19 @@ describe('Test users API validators', function () {
764 role: UserRole.USER 812 role: UserRole.USER
765 } 813 }
766 814
767 await makePutBodyRequest({ url: server.url, path: path + userId, token: server.accessToken, fields, statusCodeExpected: 204 }) 815 await makePutBodyRequest({
816 url: server.url,
817 path: path + userId,
818 token: server.accessToken,
819 fields,
820 statusCodeExpected: HttpStatusCode.NO_CONTENT_204
821 })
768 }) 822 })
769 }) 823 })
770 824
771 describe('When getting my information', function () { 825 describe('When getting my information', function () {
772 it('Should fail with a non authenticated user', async function () { 826 it('Should fail with a non authenticated user', async function () {
773 await getMyUserInformation(server.url, 'fake_token', 401) 827 await getMyUserInformation(server.url, 'fake_token', HttpStatusCode.UNAUTHORIZED_401)
774 }) 828 })
775 829
776 it('Should success with the correct parameters', async function () { 830 it('Should success with the correct parameters', async function () {
@@ -780,15 +834,15 @@ describe('Test users API validators', function () {
780 834
781 describe('When getting my video rating', function () { 835 describe('When getting my video rating', function () {
782 it('Should fail with a non authenticated user', async function () { 836 it('Should fail with a non authenticated user', async function () {
783 await getMyUserVideoRating(server.url, 'fake_token', videoId, 401) 837 await getMyUserVideoRating(server.url, 'fake_token', videoId, HttpStatusCode.UNAUTHORIZED_401)
784 }) 838 })
785 839
786 it('Should fail with an incorrect video uuid', async function () { 840 it('Should fail with an incorrect video uuid', async function () {
787 await getMyUserVideoRating(server.url, server.accessToken, 'blabla', 400) 841 await getMyUserVideoRating(server.url, server.accessToken, 'blabla', HttpStatusCode.BAD_REQUEST_400)
788 }) 842 })
789 843
790 it('Should fail with an unknown video', async function () { 844 it('Should fail with an unknown video', async function () {
791 await getMyUserVideoRating(server.url, server.accessToken, '4da6fde3-88f7-4d16-b119-108df5630b06', 404) 845 await getMyUserVideoRating(server.url, server.accessToken, '4da6fde3-88f7-4d16-b119-108df5630b06', HttpStatusCode.NOT_FOUND_404)
792 }) 846 })
793 847
794 it('Should succeed with the correct parameters', async function () { 848 it('Should succeed with the correct parameters', async function () {
@@ -812,51 +866,57 @@ describe('Test users API validators', function () {
812 }) 866 })
813 867
814 it('Should fail with a unauthenticated user', async function () { 868 it('Should fail with a unauthenticated user', async function () {
815 await makeGetRequest({ url: server.url, path, statusCodeExpected: 401 }) 869 await makeGetRequest({ url: server.url, path, statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 })
816 }) 870 })
817 871
818 it('Should fail with a another user', async function () { 872 it('Should fail with a another user', async function () {
819 await makeGetRequest({ url: server.url, path, token: server.accessToken, statusCodeExpected: 403 }) 873 await makeGetRequest({ url: server.url, path, token: server.accessToken, statusCodeExpected: HttpStatusCode.FORBIDDEN_403 })
820 }) 874 })
821 875
822 it('Should fail with a bad type', async function () { 876 it('Should fail with a bad type', async function () {
823 await makeGetRequest({ url: server.url, path, token: userAccessToken, query: { rating: 'toto ' }, statusCodeExpected: 400 }) 877 await makeGetRequest({
878 url: server.url,
879 path,
880 token: userAccessToken,
881 query: { rating: 'toto ' },
882 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400
883 })
824 }) 884 })
825 885
826 it('Should succeed with the correct params', async function () { 886 it('Should succeed with the correct params', async function () {
827 await makeGetRequest({ url: server.url, path, token: userAccessToken, statusCodeExpected: 200 }) 887 await makeGetRequest({ url: server.url, path, token: userAccessToken, statusCodeExpected: HttpStatusCode.OK_200 })
828 }) 888 })
829 }) 889 })
830 890
831 describe('When blocking/unblocking/removing user', function () { 891 describe('When blocking/unblocking/removing user', function () {
832 it('Should fail with an incorrect id', async function () { 892 it('Should fail with an incorrect id', async function () {
833 await removeUser(server.url, 'blabla', server.accessToken, 400) 893 await removeUser(server.url, 'blabla', server.accessToken, HttpStatusCode.BAD_REQUEST_400)
834 await blockUser(server.url, 'blabla', server.accessToken, 400) 894 await blockUser(server.url, 'blabla', server.accessToken, HttpStatusCode.BAD_REQUEST_400)
835 await unblockUser(server.url, 'blabla', server.accessToken, 400) 895 await unblockUser(server.url, 'blabla', server.accessToken, HttpStatusCode.BAD_REQUEST_400)
836 }) 896 })
837 897
838 it('Should fail with the root user', async function () { 898 it('Should fail with the root user', async function () {
839 await removeUser(server.url, rootId, server.accessToken, 400) 899 await removeUser(server.url, rootId, server.accessToken, HttpStatusCode.BAD_REQUEST_400)
840 await blockUser(server.url, rootId, server.accessToken, 400) 900 await blockUser(server.url, rootId, server.accessToken, HttpStatusCode.BAD_REQUEST_400)
841 await unblockUser(server.url, rootId, server.accessToken, 400) 901 await unblockUser(server.url, rootId, server.accessToken, HttpStatusCode.BAD_REQUEST_400)
842 }) 902 })
843 903
844 it('Should return 404 with a non existing id', async function () { 904 it('Should return 404 with a non existing id', async function () {
845 await removeUser(server.url, 4545454, server.accessToken, 404) 905 await removeUser(server.url, 4545454, server.accessToken, HttpStatusCode.NOT_FOUND_404)
846 await blockUser(server.url, 4545454, server.accessToken, 404) 906 await blockUser(server.url, 4545454, server.accessToken, HttpStatusCode.NOT_FOUND_404)
847 await unblockUser(server.url, 4545454, server.accessToken, 404) 907 await unblockUser(server.url, 4545454, server.accessToken, HttpStatusCode.NOT_FOUND_404)
848 }) 908 })
849 909
850 it('Should fail with a non admin user', async function () { 910 it('Should fail with a non admin user', async function () {
851 await removeUser(server.url, userId, userAccessToken, 403) 911 await removeUser(server.url, userId, userAccessToken, HttpStatusCode.FORBIDDEN_403)
852 await blockUser(server.url, userId, userAccessToken, 403) 912 await blockUser(server.url, userId, userAccessToken, HttpStatusCode.FORBIDDEN_403)
853 await unblockUser(server.url, userId, userAccessToken, 403) 913 await unblockUser(server.url, userId, userAccessToken, HttpStatusCode.FORBIDDEN_403)
854 }) 914 })
855 915
856 it('Should fail on a moderator with a moderator', async function () { 916 it('Should fail on a moderator with a moderator', async function () {
857 await removeUser(server.url, moderatorId, moderatorAccessToken, 403) 917 await removeUser(server.url, moderatorId, moderatorAccessToken, HttpStatusCode.FORBIDDEN_403)
858 await blockUser(server.url, moderatorId, moderatorAccessToken, 403) 918 await blockUser(server.url, moderatorId, moderatorAccessToken, HttpStatusCode.FORBIDDEN_403)
859 await unblockUser(server.url, moderatorId, moderatorAccessToken, 403) 919 await unblockUser(server.url, moderatorId, moderatorAccessToken, HttpStatusCode.FORBIDDEN_403)
860 }) 920 })
861 921
862 it('Should succeed on a user with a moderator', async function () { 922 it('Should succeed on a user with a moderator', async function () {
@@ -867,7 +927,7 @@ describe('Test users API validators', function () {
867 927
868 describe('When deleting our account', function () { 928 describe('When deleting our account', function () {
869 it('Should fail with with the root account', async function () { 929 it('Should fail with with the root account', async function () {
870 await deleteMe(server.url, server.accessToken, 400) 930 await deleteMe(server.url, server.accessToken, HttpStatusCode.BAD_REQUEST_400)
871 }) 931 })
872 }) 932 })
873 933
@@ -930,7 +990,7 @@ describe('Test users API validators', function () {
930 path: registrationPath, 990 path: registrationPath,
931 token: server.accessToken, 991 token: server.accessToken,
932 fields, 992 fields,
933 statusCodeExpected: 409 993 statusCodeExpected: HttpStatusCode.CONFLICT_409
934 }) 994 })
935 }) 995 })
936 996
@@ -942,7 +1002,7 @@ describe('Test users API validators', function () {
942 path: registrationPath, 1002 path: registrationPath,
943 token: server.accessToken, 1003 token: server.accessToken,
944 fields, 1004 fields,
945 statusCodeExpected: 409 1005 statusCodeExpected: HttpStatusCode.CONFLICT_409
946 }) 1006 })
947 }) 1007 })
948 1008
@@ -954,7 +1014,7 @@ describe('Test users API validators', function () {
954 path: registrationPath, 1014 path: registrationPath,
955 token: server.accessToken, 1015 token: server.accessToken,
956 fields, 1016 fields,
957 statusCodeExpected: 409 1017 statusCodeExpected: HttpStatusCode.CONFLICT_409
958 }) 1018 })
959 }) 1019 })
960 1020
@@ -989,7 +1049,13 @@ describe('Test users API validators', function () {
989 1049
990 const fields = immutableAssign(baseCorrectParams, { channel: { name: 'existing_channel', displayName: 'toto' } }) 1050 const fields = immutableAssign(baseCorrectParams, { channel: { name: 'existing_channel', displayName: 'toto' } })
991 1051
992 await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields, statusCodeExpected: 409 }) 1052 await makePostBodyRequest({
1053 url: server.url,
1054 path: registrationPath,
1055 token: server.accessToken,
1056 fields,
1057 statusCodeExpected: HttpStatusCode.CONFLICT_409
1058 })
993 }) 1059 })
994 1060
995 it('Should succeed with the correct params', async function () { 1061 it('Should succeed with the correct params', async function () {
@@ -1000,7 +1066,7 @@ describe('Test users API validators', function () {
1000 path: registrationPath, 1066 path: registrationPath,
1001 token: server.accessToken, 1067 token: server.accessToken,
1002 fields: fields, 1068 fields: fields,
1003 statusCodeExpected: 204 1069 statusCodeExpected: HttpStatusCode.NO_CONTENT_204
1004 }) 1070 })
1005 }) 1071 })
1006 1072
@@ -1016,14 +1082,14 @@ describe('Test users API validators', function () {
1016 path: registrationPath, 1082 path: registrationPath,
1017 token: serverWithRegistrationDisabled.accessToken, 1083 token: serverWithRegistrationDisabled.accessToken,
1018 fields, 1084 fields,
1019 statusCodeExpected: 403 1085 statusCodeExpected: HttpStatusCode.FORBIDDEN_403
1020 }) 1086 })
1021 }) 1087 })
1022 }) 1088 })
1023 1089
1024 describe('When registering multiple users on a server with users limit', function () { 1090 describe('When registering multiple users on a server with users limit', function () {
1025 it('Should fail when after 3 registrations', async function () { 1091 it('Should fail when after 3 registrations', async function () {
1026 await registerUser(server.url, 'user42', 'super password', 403) 1092 await registerUser(server.url, 'user42', 'super password', HttpStatusCode.FORBIDDEN_403)
1027 }) 1093 })
1028 }) 1094 })
1029 1095
@@ -1036,7 +1102,7 @@ describe('Test users API validators', function () {
1036 videoQuota: 42 1102 videoQuota: 42
1037 }) 1103 })
1038 1104
1039 await uploadVideo(server.url, server.accessToken, {}, 403) 1105 await uploadVideo(server.url, server.accessToken, {}, HttpStatusCode.FORBIDDEN_403)
1040 }) 1106 })
1041 1107
1042 it('Should fail with a registered user having too many videos', async function () { 1108 it('Should fail with a registered user having too many videos', async function () {
@@ -1054,7 +1120,7 @@ describe('Test users API validators', function () {
1054 await uploadVideo(server.url, userAccessToken, videoAttributes) 1120 await uploadVideo(server.url, userAccessToken, videoAttributes)
1055 await uploadVideo(server.url, userAccessToken, videoAttributes) 1121 await uploadVideo(server.url, userAccessToken, videoAttributes)
1056 await uploadVideo(server.url, userAccessToken, videoAttributes) 1122 await uploadVideo(server.url, userAccessToken, videoAttributes)
1057 await uploadVideo(server.url, userAccessToken, videoAttributes, 403) 1123 await uploadVideo(server.url, userAccessToken, videoAttributes, HttpStatusCode.FORBIDDEN_403)
1058 }) 1124 })
1059 1125
1060 it('Should fail to import with HTTP/Torrent/magnet', async function () { 1126 it('Should fail to import with HTTP/Torrent/magnet', async function () {
@@ -1093,7 +1159,7 @@ describe('Test users API validators', function () {
1093 videoQuotaDaily: 42 1159 videoQuotaDaily: 42
1094 }) 1160 })
1095 1161
1096 await uploadVideo(server.url, server.accessToken, {}, 403) 1162 await uploadVideo(server.url, server.accessToken, {}, HttpStatusCode.FORBIDDEN_403)
1097 }) 1163 })
1098 }) 1164 })
1099 1165
@@ -1107,7 +1173,7 @@ describe('Test users API validators', function () {
1107 videoQuotaDaily: 1024 * 1024 * 1024 1173 videoQuotaDaily: 1024 * 1024 * 1024
1108 }) 1174 })
1109 1175
1110 await uploadVideo(server.url, server.accessToken, {}, 403) 1176 await uploadVideo(server.url, server.accessToken, {}, HttpStatusCode.FORBIDDEN_403)
1111 }) 1177 })
1112 1178
1113 it('Should fail if exceeding daily quota', async function () { 1179 it('Should fail if exceeding daily quota', async function () {
@@ -1119,7 +1185,7 @@ describe('Test users API validators', function () {
1119 videoQuotaDaily: 42 1185 videoQuotaDaily: 42
1120 }) 1186 })
1121 1187
1122 await uploadVideo(server.url, server.accessToken, {}, 403) 1188 await uploadVideo(server.url, server.accessToken, {}, HttpStatusCode.FORBIDDEN_403)
1123 }) 1189 })
1124 }) 1190 })
1125 1191
@@ -1141,7 +1207,13 @@ describe('Test users API validators', function () {
1141 it('Should success with the correct params', async function () { 1207 it('Should success with the correct params', async function () {
1142 const fields = { email: 'admin@example.com' } 1208 const fields = { email: 'admin@example.com' }
1143 1209
1144 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields, statusCodeExpected: 204 }) 1210 await makePostBodyRequest({
1211 url: server.url,
1212 path,
1213 token: server.accessToken,
1214 fields,
1215 statusCodeExpected: HttpStatusCode.NO_CONTENT_204
1216 })
1145 }) 1217 })
1146 }) 1218 })
1147 1219
@@ -1163,7 +1235,13 @@ describe('Test users API validators', function () {
1163 it('Should succeed with the correct params', async function () { 1235 it('Should succeed with the correct params', async function () {
1164 const fields = { email: 'admin@example.com' } 1236 const fields = { email: 'admin@example.com' }
1165 1237
1166 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields, statusCodeExpected: 204 }) 1238 await makePostBodyRequest({
1239 url: server.url,
1240 path,
1241 token: server.accessToken,
1242 fields,
1243 statusCodeExpected: HttpStatusCode.NO_CONTENT_204
1244 })
1167 }) 1245 })
1168 }) 1246 })
1169 1247
diff --git a/server/tests/api/check-params/video-blacklist.ts b/server/tests/api/check-params/video-blacklist.ts
index 145f43980..3d4837d58 100644
--- a/server/tests/api/check-params/video-blacklist.ts
+++ b/server/tests/api/check-params/video-blacklist.ts
@@ -26,6 +26,7 @@ import {
26} from '../../../../shared/extra-utils/requests/check-api-params' 26} from '../../../../shared/extra-utils/requests/check-api-params'
27import { VideoBlacklistType, VideoDetails } from '../../../../shared/models/videos' 27import { VideoBlacklistType, VideoDetails } from '../../../../shared/models/videos'
28import { expect } from 'chai' 28import { expect } from 'chai'
29import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
29 30
30describe('Test video blacklist API validators', function () { 31describe('Test video blacklist API validators', function () {
31 let servers: ServerInfo[] 32 let servers: ServerInfo[]
@@ -94,13 +95,19 @@ describe('Test video blacklist API validators', function () {
94 it('Should fail with a non authenticated user', async function () { 95 it('Should fail with a non authenticated user', async function () {
95 const path = basePath + servers[0].video + '/blacklist' 96 const path = basePath + servers[0].video + '/blacklist'
96 const fields = {} 97 const fields = {}
97 await makePostBodyRequest({ url: servers[0].url, path, token: 'hello', fields, statusCodeExpected: 401 }) 98 await makePostBodyRequest({ url: servers[0].url, path, token: 'hello', fields, statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 })
98 }) 99 })
99 100
100 it('Should fail with a non admin user', async function () { 101 it('Should fail with a non admin user', async function () {
101 const path = basePath + servers[0].video + '/blacklist' 102 const path = basePath + servers[0].video + '/blacklist'
102 const fields = {} 103 const fields = {}
103 await makePostBodyRequest({ url: servers[0].url, path, token: userAccessToken2, fields, statusCodeExpected: 403 }) 104 await makePostBodyRequest({
105 url: servers[0].url,
106 path,
107 token: userAccessToken2,
108 fields,
109 statusCodeExpected: HttpStatusCode.FORBIDDEN_403
110 })
104 }) 111 })
105 112
106 it('Should fail with an invalid reason', async function () { 113 it('Should fail with an invalid reason', async function () {
@@ -114,14 +121,26 @@ describe('Test video blacklist API validators', function () {
114 const path = basePath + remoteVideoUUID + '/blacklist' 121 const path = basePath + remoteVideoUUID + '/blacklist'
115 const fields = { unfederate: true } 122 const fields = { unfederate: true }
116 123
117 await makePostBodyRequest({ url: servers[0].url, path, token: servers[0].accessToken, fields, statusCodeExpected: 409 }) 124 await makePostBodyRequest({
125 url: servers[0].url,
126 path,
127 token: servers[0].accessToken,
128 fields,
129 statusCodeExpected: HttpStatusCode.CONFLICT_409
130 })
118 }) 131 })
119 132
120 it('Should succeed with the correct params', async function () { 133 it('Should succeed with the correct params', async function () {
121 const path = basePath + servers[0].video.uuid + '/blacklist' 134 const path = basePath + servers[0].video.uuid + '/blacklist'
122 const fields = {} 135 const fields = {}
123 136
124 await makePostBodyRequest({ url: servers[0].url, path, token: servers[0].accessToken, fields, statusCodeExpected: 204 }) 137 await makePostBodyRequest({
138 url: servers[0].url,
139 path,
140 token: servers[0].accessToken,
141 fields,
142 statusCodeExpected: HttpStatusCode.NO_CONTENT_204
143 })
125 }) 144 })
126 }) 145 })
127 146
@@ -137,19 +156,31 @@ describe('Test video blacklist API validators', function () {
137 it('Should fail with a video not blacklisted', async function () { 156 it('Should fail with a video not blacklisted', async function () {
138 const path = '/api/v1/videos/' + notBlacklistedVideoId + '/blacklist' 157 const path = '/api/v1/videos/' + notBlacklistedVideoId + '/blacklist'
139 const fields = {} 158 const fields = {}
140 await makePutBodyRequest({ url: servers[0].url, path, token: servers[0].accessToken, fields, statusCodeExpected: 404 }) 159 await makePutBodyRequest({
160 url: servers[0].url,
161 path,
162 token: servers[0].accessToken,
163 fields,
164 statusCodeExpected: HttpStatusCode.NOT_FOUND_404
165 })
141 }) 166 })
142 167
143 it('Should fail with a non authenticated user', async function () { 168 it('Should fail with a non authenticated user', async function () {
144 const path = basePath + servers[0].video + '/blacklist' 169 const path = basePath + servers[0].video + '/blacklist'
145 const fields = {} 170 const fields = {}
146 await makePutBodyRequest({ url: servers[0].url, path, token: 'hello', fields, statusCodeExpected: 401 }) 171 await makePutBodyRequest({ url: servers[0].url, path, token: 'hello', fields, statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 })
147 }) 172 })
148 173
149 it('Should fail with a non admin user', async function () { 174 it('Should fail with a non admin user', async function () {
150 const path = basePath + servers[0].video + '/blacklist' 175 const path = basePath + servers[0].video + '/blacklist'
151 const fields = {} 176 const fields = {}
152 await makePutBodyRequest({ url: servers[0].url, path, token: userAccessToken2, fields, statusCodeExpected: 403 }) 177 await makePutBodyRequest({
178 url: servers[0].url,
179 path,
180 token: userAccessToken2,
181 fields,
182 statusCodeExpected: HttpStatusCode.FORBIDDEN_403
183 })
153 }) 184 })
154 185
155 it('Should fail with an invalid reason', async function () { 186 it('Should fail with an invalid reason', async function () {
@@ -163,29 +194,35 @@ describe('Test video blacklist API validators', function () {
163 const path = basePath + servers[0].video.uuid + '/blacklist' 194 const path = basePath + servers[0].video.uuid + '/blacklist'
164 const fields = { reason: 'hello' } 195 const fields = { reason: 'hello' }
165 196
166 await makePutBodyRequest({ url: servers[0].url, path, token: servers[0].accessToken, fields, statusCodeExpected: 204 }) 197 await makePutBodyRequest({
198 url: servers[0].url,
199 path,
200 token: servers[0].accessToken,
201 fields,
202 statusCodeExpected: HttpStatusCode.NO_CONTENT_204
203 })
167 }) 204 })
168 }) 205 })
169 206
170 describe('When getting blacklisted video', function () { 207 describe('When getting blacklisted video', function () {
171 208
172 it('Should fail with a non authenticated user', async function () { 209 it('Should fail with a non authenticated user', async function () {
173 await getVideo(servers[0].url, servers[0].video.uuid, 401) 210 await getVideo(servers[0].url, servers[0].video.uuid, HttpStatusCode.UNAUTHORIZED_401)
174 }) 211 })
175 212
176 it('Should fail with another user', async function () { 213 it('Should fail with another user', async function () {
177 await getVideoWithToken(servers[0].url, userAccessToken2, servers[0].video.uuid, 403) 214 await getVideoWithToken(servers[0].url, userAccessToken2, servers[0].video.uuid, HttpStatusCode.FORBIDDEN_403)
178 }) 215 })
179 216
180 it('Should succeed with the owner authenticated user', async function () { 217 it('Should succeed with the owner authenticated user', async function () {
181 const res = await getVideoWithToken(servers[0].url, userAccessToken1, servers[0].video.uuid, 200) 218 const res = await getVideoWithToken(servers[0].url, userAccessToken1, servers[0].video.uuid, HttpStatusCode.OK_200)
182 const video: VideoDetails = res.body 219 const video: VideoDetails = res.body
183 220
184 expect(video.blacklisted).to.be.true 221 expect(video.blacklisted).to.be.true
185 }) 222 })
186 223
187 it('Should succeed with an admin', async function () { 224 it('Should succeed with an admin', async function () {
188 const res = await getVideoWithToken(servers[0].url, servers[0].accessToken, servers[0].video.uuid, 200) 225 const res = await getVideoWithToken(servers[0].url, servers[0].accessToken, servers[0].video.uuid, HttpStatusCode.OK_200)
189 const video: VideoDetails = res.body 226 const video: VideoDetails = res.body
190 227
191 expect(video.blacklisted).to.be.true 228 expect(video.blacklisted).to.be.true
@@ -194,24 +231,24 @@ describe('Test video blacklist API validators', function () {
194 231
195 describe('When removing a video in blacklist', function () { 232 describe('When removing a video in blacklist', function () {
196 it('Should fail with a non authenticated user', async function () { 233 it('Should fail with a non authenticated user', async function () {
197 await removeVideoFromBlacklist(servers[0].url, 'fake token', servers[0].video.uuid, 401) 234 await removeVideoFromBlacklist(servers[0].url, 'fake token', servers[0].video.uuid, HttpStatusCode.UNAUTHORIZED_401)
198 }) 235 })
199 236
200 it('Should fail with a non admin user', async function () { 237 it('Should fail with a non admin user', async function () {
201 await removeVideoFromBlacklist(servers[0].url, userAccessToken2, servers[0].video.uuid, 403) 238 await removeVideoFromBlacklist(servers[0].url, userAccessToken2, servers[0].video.uuid, HttpStatusCode.FORBIDDEN_403)
202 }) 239 })
203 240
204 it('Should fail with an incorrect id', async function () { 241 it('Should fail with an incorrect id', async function () {
205 await removeVideoFromBlacklist(servers[0].url, servers[0].accessToken, 'hello', 400) 242 await removeVideoFromBlacklist(servers[0].url, servers[0].accessToken, 'hello', HttpStatusCode.BAD_REQUEST_400)
206 }) 243 })
207 244
208 it('Should fail with a not blacklisted video', async function () { 245 it('Should fail with a not blacklisted video', async function () {
209 // The video was not added to the blacklist so it should fail 246 // The video was not added to the blacklist so it should fail
210 await removeVideoFromBlacklist(servers[0].url, servers[0].accessToken, notBlacklistedVideoId, 404) 247 await removeVideoFromBlacklist(servers[0].url, servers[0].accessToken, notBlacklistedVideoId, HttpStatusCode.NOT_FOUND_404)
211 }) 248 })
212 249
213 it('Should succeed with the correct params', async function () { 250 it('Should succeed with the correct params', async function () {
214 await removeVideoFromBlacklist(servers[0].url, servers[0].accessToken, servers[0].video.uuid, 204) 251 await removeVideoFromBlacklist(servers[0].url, servers[0].accessToken, servers[0].video.uuid, HttpStatusCode.NO_CONTENT_204)
215 }) 252 })
216 }) 253 })
217 254
@@ -219,11 +256,11 @@ describe('Test video blacklist API validators', function () {
219 const basePath = '/api/v1/videos/blacklist/' 256 const basePath = '/api/v1/videos/blacklist/'
220 257
221 it('Should fail with a non authenticated user', async function () { 258 it('Should fail with a non authenticated user', async function () {
222 await getBlacklistedVideosList({ url: servers[0].url, token: 'fake token', specialStatus: 401 }) 259 await getBlacklistedVideosList({ url: servers[0].url, token: 'fake token', specialStatus: HttpStatusCode.UNAUTHORIZED_401 })
223 }) 260 })
224 261
225 it('Should fail with a non admin user', async function () { 262 it('Should fail with a non admin user', async function () {
226 await getBlacklistedVideosList({ url: servers[0].url, token: userAccessToken2, specialStatus: 403 }) 263 await getBlacklistedVideosList({ url: servers[0].url, token: userAccessToken2, specialStatus: HttpStatusCode.FORBIDDEN_403 })
227 }) 264 })
228 265
229 it('Should fail with a bad start pagination', async function () { 266 it('Should fail with a bad start pagination', async function () {
@@ -239,7 +276,12 @@ describe('Test video blacklist API validators', function () {
239 }) 276 })
240 277
241 it('Should fail with an invalid type', async function () { 278 it('Should fail with an invalid type', async function () {
242 await getBlacklistedVideosList({ url: servers[0].url, token: servers[0].accessToken, type: 0, specialStatus: 400 }) 279 await getBlacklistedVideosList({
280 url: servers[0].url,
281 token: servers[0].accessToken,
282 type: 0,
283 specialStatus: HttpStatusCode.BAD_REQUEST_400
284 })
243 }) 285 })
244 286
245 it('Should succeed with the correct parameters', async function () { 287 it('Should succeed with the correct parameters', async function () {
diff --git a/server/tests/api/check-params/video-captions.ts b/server/tests/api/check-params/video-captions.ts
index a5f5c3322..e42e8db81 100644
--- a/server/tests/api/check-params/video-captions.ts
+++ b/server/tests/api/check-params/video-captions.ts
@@ -15,6 +15,7 @@ import {
15} from '../../../../shared/extra-utils' 15} from '../../../../shared/extra-utils'
16import { join } from 'path' 16import { join } from 'path'
17import { createVideoCaption } from '../../../../shared/extra-utils/videos/video-captions' 17import { createVideoCaption } from '../../../../shared/extra-utils/videos/video-captions'
18import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
18 19
19describe('Test video captions API validator', function () { 20describe('Test video captions API validator', function () {
20 const path = '/api/v1/videos/' 21 const path = '/api/v1/videos/'
@@ -107,7 +108,7 @@ describe('Test video captions API validator', function () {
107 path: captionPath, 108 path: captionPath,
108 fields, 109 fields,
109 attaches, 110 attaches,
110 statusCodeExpected: 401 111 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401
111 }) 112 })
112 }) 113 })
113 114
@@ -120,7 +121,7 @@ describe('Test video captions API validator', function () {
120 token: 'blabla', 121 token: 'blabla',
121 fields, 122 fields,
122 attaches, 123 attaches,
123 statusCodeExpected: 401 124 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401
124 }) 125 })
125 }) 126 })
126 127
@@ -138,7 +139,7 @@ describe('Test video captions API validator', function () {
138 // token: server.accessToken, 139 // token: server.accessToken,
139 // fields, 140 // fields,
140 // attaches, 141 // attaches,
141 // statusCodeExpected: 400 142 // statusCodeExpected: HttpStatusCode.BAD_REQUEST_400
142 // }) 143 // })
143 // }) 144 // })
144 145
@@ -151,7 +152,7 @@ describe('Test video captions API validator', function () {
151 // videoId: videoUUID, 152 // videoId: videoUUID,
152 // fixture: 'subtitle-bad.txt', 153 // fixture: 'subtitle-bad.txt',
153 // mimeType: 'application/octet-stream', 154 // mimeType: 'application/octet-stream',
154 // statusCodeExpected: 400 155 // statusCodeExpected: HttpStatusCode.BAD_REQUEST_400
155 // }) 156 // })
156 // }) 157 // })
157 158
@@ -180,7 +181,7 @@ describe('Test video captions API validator', function () {
180 // token: server.accessToken, 181 // token: server.accessToken,
181 // fields, 182 // fields,
182 // attaches, 183 // attaches,
183 // statusCodeExpected: 500 184 // statusCodeExpected: HttpStatusCode.INTERNAL_SERVER_ERROR_500
184 // }) 185 // })
185 // }) 186 // })
186 187
@@ -193,7 +194,7 @@ describe('Test video captions API validator', function () {
193 token: server.accessToken, 194 token: server.accessToken,
194 fields, 195 fields,
195 attaches, 196 attaches,
196 statusCodeExpected: 204 197 statusCodeExpected: HttpStatusCode.NO_CONTENT_204
197 }) 198 })
198 }) 199 })
199 }) 200 })
@@ -204,11 +205,15 @@ describe('Test video captions API validator', function () {
204 }) 205 })
205 206
206 it('Should fail with an unknown id', async function () { 207 it('Should fail with an unknown id', async function () {
207 await makeGetRequest({ url: server.url, path: path + '4da6fde3-88f7-4d16-b119-108df5630b06/captions', statusCodeExpected: 404 }) 208 await makeGetRequest({
209 url: server.url,
210 path: path + '4da6fde3-88f7-4d16-b119-108df5630b06/captions',
211 statusCodeExpected: HttpStatusCode.NOT_FOUND_404
212 })
208 }) 213 })
209 214
210 it('Should success with the correct parameters', async function () { 215 it('Should success with the correct parameters', async function () {
211 await makeGetRequest({ url: server.url, path: path + videoUUID + '/captions', statusCodeExpected: 200 }) 216 await makeGetRequest({ url: server.url, path: path + videoUUID + '/captions', statusCodeExpected: HttpStatusCode.OK_200 })
212 }) 217 })
213 }) 218 })
214 219
@@ -226,7 +231,7 @@ describe('Test video captions API validator', function () {
226 url: server.url, 231 url: server.url,
227 path: path + '4da6fde3-88f7-4d16-b119-108df5630b06/captions/fr', 232 path: path + '4da6fde3-88f7-4d16-b119-108df5630b06/captions/fr',
228 token: server.accessToken, 233 token: server.accessToken,
229 statusCodeExpected: 404 234 statusCodeExpected: HttpStatusCode.NOT_FOUND_404
230 }) 235 })
231 }) 236 })
232 237
@@ -250,22 +255,32 @@ describe('Test video captions API validator', function () {
250 255
251 it('Should fail without access token', async function () { 256 it('Should fail without access token', async function () {
252 const captionPath = path + videoUUID + '/captions/fr' 257 const captionPath = path + videoUUID + '/captions/fr'
253 await makeDeleteRequest({ url: server.url, path: captionPath, statusCodeExpected: 401 }) 258 await makeDeleteRequest({ url: server.url, path: captionPath, statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 })
254 }) 259 })
255 260
256 it('Should fail with a bad access token', async function () { 261 it('Should fail with a bad access token', async function () {
257 const captionPath = path + videoUUID + '/captions/fr' 262 const captionPath = path + videoUUID + '/captions/fr'
258 await makeDeleteRequest({ url: server.url, path: captionPath, token: 'coucou', statusCodeExpected: 401 }) 263 await makeDeleteRequest({ url: server.url, path: captionPath, token: 'coucou', statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 })
259 }) 264 })
260 265
261 it('Should fail with another user', async function () { 266 it('Should fail with another user', async function () {
262 const captionPath = path + videoUUID + '/captions/fr' 267 const captionPath = path + videoUUID + '/captions/fr'
263 await makeDeleteRequest({ url: server.url, path: captionPath, token: userAccessToken, statusCodeExpected: 403 }) 268 await makeDeleteRequest({
269 url: server.url,
270 path: captionPath,
271 token: userAccessToken,
272 statusCodeExpected: HttpStatusCode.FORBIDDEN_403
273 })
264 }) 274 })
265 275
266 it('Should success with the correct parameters', async function () { 276 it('Should success with the correct parameters', async function () {
267 const captionPath = path + videoUUID + '/captions/fr' 277 const captionPath = path + videoUUID + '/captions/fr'
268 await makeDeleteRequest({ url: server.url, path: captionPath, token: server.accessToken, statusCodeExpected: 204 }) 278 await makeDeleteRequest({
279 url: server.url,
280 path: captionPath,
281 token: server.accessToken,
282 statusCodeExpected: HttpStatusCode.NO_CONTENT_204
283 })
269 }) 284 })
270 }) 285 })
271 286
diff --git a/server/tests/api/check-params/video-channels.ts b/server/tests/api/check-params/video-channels.ts
index 2795ad7d5..0dd436426 100644
--- a/server/tests/api/check-params/video-channels.ts
+++ b/server/tests/api/check-params/video-channels.ts
@@ -25,6 +25,7 @@ import {
25} from '../../../../shared/extra-utils/requests/check-api-params' 25} from '../../../../shared/extra-utils/requests/check-api-params'
26import { join } from 'path' 26import { join } from 'path'
27import { VideoChannelUpdate } from '../../../../shared/models/videos' 27import { VideoChannelUpdate } from '../../../../shared/models/videos'
28import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
28 29
29const expect = chai.expect 30const expect = chai.expect
30 31
@@ -83,14 +84,14 @@ describe('Test video channels API validator', function () {
83 }) 84 })
84 85
85 it('Should fail with a unknown account', async function () { 86 it('Should fail with a unknown account', async function () {
86 await getAccountVideoChannelsList({ url: server.url, accountName: 'unknown', specialStatus: 404 }) 87 await getAccountVideoChannelsList({ url: server.url, accountName: 'unknown', specialStatus: HttpStatusCode.NOT_FOUND_404 })
87 }) 88 })
88 89
89 it('Should succeed with the correct parameters', async function () { 90 it('Should succeed with the correct parameters', async function () {
90 await makeGetRequest({ 91 await makeGetRequest({
91 url: server.url, 92 url: server.url,
92 path: accountChannelPath, 93 path: accountChannelPath,
93 statusCodeExpected: 200 94 statusCodeExpected: HttpStatusCode.OK_200
94 }) 95 })
95 }) 96 })
96 }) 97 })
@@ -109,7 +110,7 @@ describe('Test video channels API validator', function () {
109 path: videoChannelPath, 110 path: videoChannelPath,
110 token: 'none', 111 token: 'none',
111 fields: baseCorrectParams, 112 fields: baseCorrectParams,
112 statusCodeExpected: 401 113 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401
113 }) 114 })
114 }) 115 })
115 116
@@ -154,7 +155,7 @@ describe('Test video channels API validator', function () {
154 path: videoChannelPath, 155 path: videoChannelPath,
155 token: server.accessToken, 156 token: server.accessToken,
156 fields: baseCorrectParams, 157 fields: baseCorrectParams,
157 statusCodeExpected: 200 158 statusCodeExpected: HttpStatusCode.OK_200
158 }) 159 })
159 }) 160 })
160 161
@@ -164,7 +165,7 @@ describe('Test video channels API validator', function () {
164 path: videoChannelPath, 165 path: videoChannelPath,
165 token: server.accessToken, 166 token: server.accessToken,
166 fields: baseCorrectParams, 167 fields: baseCorrectParams,
167 statusCodeExpected: 409 168 statusCodeExpected: HttpStatusCode.CONFLICT_409
168 }) 169 })
169 }) 170 })
170 }) 171 })
@@ -188,7 +189,7 @@ describe('Test video channels API validator', function () {
188 path, 189 path,
189 token: 'hi', 190 token: 'hi',
190 fields: baseCorrectParams, 191 fields: baseCorrectParams,
191 statusCodeExpected: 401 192 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401
192 }) 193 })
193 }) 194 })
194 195
@@ -198,7 +199,7 @@ describe('Test video channels API validator', function () {
198 path, 199 path,
199 token: accessTokenUser, 200 token: accessTokenUser,
200 fields: baseCorrectParams, 201 fields: baseCorrectParams,
201 statusCodeExpected: 403 202 statusCodeExpected: HttpStatusCode.FORBIDDEN_403
202 }) 203 })
203 }) 204 })
204 205
@@ -228,7 +229,7 @@ describe('Test video channels API validator', function () {
228 path, 229 path,
229 token: server.accessToken, 230 token: server.accessToken,
230 fields: baseCorrectParams, 231 fields: baseCorrectParams,
231 statusCodeExpected: 204 232 statusCodeExpected: HttpStatusCode.NO_CONTENT_204
232 }) 233 })
233 }) 234 })
234 }) 235 })
@@ -266,7 +267,7 @@ describe('Test video channels API validator', function () {
266 path: path + '/avatar/pick', 267 path: path + '/avatar/pick',
267 fields, 268 fields,
268 attaches, 269 attaches,
269 statusCodeExpected: 401 270 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401
270 }) 271 })
271 }) 272 })
272 273
@@ -281,7 +282,7 @@ describe('Test video channels API validator', function () {
281 token: server.accessToken, 282 token: server.accessToken,
282 fields, 283 fields,
283 attaches, 284 attaches,
284 statusCodeExpected: 200 285 statusCodeExpected: HttpStatusCode.OK_200
285 }) 286 })
286 }) 287 })
287 }) 288 })
@@ -291,7 +292,7 @@ describe('Test video channels API validator', function () {
291 const res = await makeGetRequest({ 292 const res = await makeGetRequest({
292 url: server.url, 293 url: server.url,
293 path: videoChannelPath, 294 path: videoChannelPath,
294 statusCodeExpected: 200 295 statusCodeExpected: HttpStatusCode.OK_200
295 }) 296 })
296 297
297 expect(res.body.data).to.be.an('array') 298 expect(res.body.data).to.be.an('array')
@@ -301,7 +302,7 @@ describe('Test video channels API validator', function () {
301 await makeGetRequest({ 302 await makeGetRequest({
302 url: server.url, 303 url: server.url,
303 path: videoChannelPath + '/super_channel2', 304 path: videoChannelPath + '/super_channel2',
304 statusCodeExpected: 404 305 statusCodeExpected: HttpStatusCode.NOT_FOUND_404
305 }) 306 })
306 }) 307 })
307 308
@@ -309,22 +310,22 @@ describe('Test video channels API validator', function () {
309 await makeGetRequest({ 310 await makeGetRequest({
310 url: server.url, 311 url: server.url,
311 path: videoChannelPath + '/super_channel', 312 path: videoChannelPath + '/super_channel',
312 statusCodeExpected: 200 313 statusCodeExpected: HttpStatusCode.OK_200
313 }) 314 })
314 }) 315 })
315 }) 316 })
316 317
317 describe('When deleting a video channel', function () { 318 describe('When deleting a video channel', function () {
318 it('Should fail with a non authenticated user', async function () { 319 it('Should fail with a non authenticated user', async function () {
319 await deleteVideoChannel(server.url, 'coucou', 'super_channel', 401) 320 await deleteVideoChannel(server.url, 'coucou', 'super_channel', HttpStatusCode.UNAUTHORIZED_401)
320 }) 321 })
321 322
322 it('Should fail with another authenticated user', async function () { 323 it('Should fail with another authenticated user', async function () {
323 await deleteVideoChannel(server.url, accessTokenUser, 'super_channel', 403) 324 await deleteVideoChannel(server.url, accessTokenUser, 'super_channel', HttpStatusCode.FORBIDDEN_403)
324 }) 325 })
325 326
326 it('Should fail with an unknown video channel id', async function () { 327 it('Should fail with an unknown video channel id', async function () {
327 await deleteVideoChannel(server.url, server.accessToken, 'super_channel2', 404) 328 await deleteVideoChannel(server.url, server.accessToken, 'super_channel2', HttpStatusCode.NOT_FOUND_404)
328 }) 329 })
329 330
330 it('Should succeed with the correct parameters', async function () { 331 it('Should succeed with the correct parameters', async function () {
@@ -332,7 +333,7 @@ describe('Test video channels API validator', function () {
332 }) 333 })
333 334
334 it('Should fail to delete the last user video channel', async function () { 335 it('Should fail to delete the last user video channel', async function () {
335 await deleteVideoChannel(server.url, server.accessToken, 'root_channel', 409) 336 await deleteVideoChannel(server.url, server.accessToken, 'root_channel', HttpStatusCode.CONFLICT_409)
336 }) 337 })
337 }) 338 })
338 339
diff --git a/server/tests/api/check-params/video-comments.ts b/server/tests/api/check-params/video-comments.ts
index 662d4a70d..659a10c41 100644
--- a/server/tests/api/check-params/video-comments.ts
+++ b/server/tests/api/check-params/video-comments.ts
@@ -20,6 +20,7 @@ import {
20 checkBadStartPagination 20 checkBadStartPagination
21} from '../../../../shared/extra-utils/requests/check-api-params' 21} from '../../../../shared/extra-utils/requests/check-api-params'
22import { addVideoCommentThread } from '../../../../shared/extra-utils/videos/video-comments' 22import { addVideoCommentThread } from '../../../../shared/extra-utils/videos/video-comments'
23import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
23 24
24const expect = chai.expect 25const expect = chai.expect
25 26
@@ -83,7 +84,7 @@ describe('Test video comments API validator', function () {
83 await makeGetRequest({ 84 await makeGetRequest({
84 url: server.url, 85 url: server.url,
85 path: '/api/v1/videos/ba708d62-e3d7-45d9-9d73-41b9097cc02d/comment-threads', 86 path: '/api/v1/videos/ba708d62-e3d7-45d9-9d73-41b9097cc02d/comment-threads',
86 statusCodeExpected: 404 87 statusCodeExpected: HttpStatusCode.NOT_FOUND_404
87 }) 88 })
88 }) 89 })
89 }) 90 })
@@ -93,7 +94,7 @@ describe('Test video comments API validator', function () {
93 await makeGetRequest({ 94 await makeGetRequest({
94 url: server.url, 95 url: server.url,
95 path: '/api/v1/videos/ba708d62-e3d7-45d9-9d73-41b9097cc02d/comment-threads/' + commentId, 96 path: '/api/v1/videos/ba708d62-e3d7-45d9-9d73-41b9097cc02d/comment-threads/' + commentId,
96 statusCodeExpected: 404 97 statusCodeExpected: HttpStatusCode.NOT_FOUND_404
97 }) 98 })
98 }) 99 })
99 100
@@ -101,7 +102,7 @@ describe('Test video comments API validator', function () {
101 await makeGetRequest({ 102 await makeGetRequest({
102 url: server.url, 103 url: server.url,
103 path: '/api/v1/videos/' + videoUUID + '/comment-threads/156', 104 path: '/api/v1/videos/' + videoUUID + '/comment-threads/156',
104 statusCodeExpected: 404 105 statusCodeExpected: HttpStatusCode.NOT_FOUND_404
105 }) 106 })
106 }) 107 })
107 108
@@ -109,7 +110,7 @@ describe('Test video comments API validator', function () {
109 await makeGetRequest({ 110 await makeGetRequest({
110 url: server.url, 111 url: server.url,
111 path: '/api/v1/videos/' + videoUUID + '/comment-threads/' + commentId, 112 path: '/api/v1/videos/' + videoUUID + '/comment-threads/' + commentId,
112 statusCodeExpected: 200 113 statusCodeExpected: HttpStatusCode.OK_200
113 }) 114 })
114 }) 115 })
115 }) 116 })
@@ -120,7 +121,13 @@ describe('Test video comments API validator', function () {
120 const fields = { 121 const fields = {
121 text: 'text' 122 text: 'text'
122 } 123 }
123 await makePostBodyRequest({ url: server.url, path: pathThread, token: 'none', fields, statusCodeExpected: 401 }) 124 await makePostBodyRequest({
125 url: server.url,
126 path: pathThread,
127 token: 'none',
128 fields,
129 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401
130 })
124 }) 131 })
125 132
126 it('Should fail with nothing', async function () { 133 it('Should fail with nothing', async function () {
@@ -147,14 +154,26 @@ describe('Test video comments API validator', function () {
147 const fields = { 154 const fields = {
148 text: 'super comment' 155 text: 'super comment'
149 } 156 }
150 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields, statusCodeExpected: 404 }) 157 await makePostBodyRequest({
158 url: server.url,
159 path,
160 token: server.accessToken,
161 fields,
162 statusCodeExpected: HttpStatusCode.NOT_FOUND_404
163 })
151 }) 164 })
152 165
153 it('Should succeed with the correct parameters', async function () { 166 it('Should succeed with the correct parameters', async function () {
154 const fields = { 167 const fields = {
155 text: 'super comment' 168 text: 'super comment'
156 } 169 }
157 await makePostBodyRequest({ url: server.url, path: pathThread, token: server.accessToken, fields, statusCodeExpected: 200 }) 170 await makePostBodyRequest({
171 url: server.url,
172 path: pathThread,
173 token: server.accessToken,
174 fields,
175 statusCodeExpected: HttpStatusCode.OK_200
176 })
158 }) 177 })
159 }) 178 })
160 179
@@ -163,7 +182,13 @@ describe('Test video comments API validator', function () {
163 const fields = { 182 const fields = {
164 text: 'text' 183 text: 'text'
165 } 184 }
166 await makePostBodyRequest({ url: server.url, path: pathComment, token: 'none', fields, statusCodeExpected: 401 }) 185 await makePostBodyRequest({
186 url: server.url,
187 path: pathComment,
188 token: 'none',
189 fields,
190 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401
191 })
167 }) 192 })
168 193
169 it('Should fail with nothing', async function () { 194 it('Should fail with nothing', async function () {
@@ -190,7 +215,13 @@ describe('Test video comments API validator', function () {
190 const fields = { 215 const fields = {
191 text: 'super comment' 216 text: 'super comment'
192 } 217 }
193 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields, statusCodeExpected: 404 }) 218 await makePostBodyRequest({
219 url: server.url,
220 path,
221 token: server.accessToken,
222 fields,
223 statusCodeExpected: HttpStatusCode.NOT_FOUND_404
224 })
194 }) 225 })
195 226
196 it('Should fail with an incorrect comment', async function () { 227 it('Should fail with an incorrect comment', async function () {
@@ -198,34 +229,51 @@ describe('Test video comments API validator', function () {
198 const fields = { 229 const fields = {
199 text: 'super comment' 230 text: 'super comment'
200 } 231 }
201 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields, statusCodeExpected: 404 }) 232 await makePostBodyRequest({
233 url: server.url,
234 path,
235 token: server.accessToken,
236 fields,
237 statusCodeExpected: HttpStatusCode.NOT_FOUND_404
238 })
202 }) 239 })
203 240
204 it('Should succeed with the correct parameters', async function () { 241 it('Should succeed with the correct parameters', async function () {
205 const fields = { 242 const fields = {
206 text: 'super comment' 243 text: 'super comment'
207 } 244 }
208 await makePostBodyRequest({ url: server.url, path: pathComment, token: server.accessToken, fields, statusCodeExpected: 200 }) 245 await makePostBodyRequest({
246 url: server.url,
247 path: pathComment,
248 token: server.accessToken,
249 fields,
250 statusCodeExpected: HttpStatusCode.OK_200
251 })
209 }) 252 })
210 }) 253 })
211 254
212 describe('When removing video comments', function () { 255 describe('When removing video comments', function () {
213 it('Should fail with a non authenticated user', async function () { 256 it('Should fail with a non authenticated user', async function () {
214 await makeDeleteRequest({ url: server.url, path: pathComment, token: 'none', statusCodeExpected: 401 }) 257 await makeDeleteRequest({ url: server.url, path: pathComment, token: 'none', statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 })
215 }) 258 })
216 259
217 it('Should fail with another user', async function () { 260 it('Should fail with another user', async function () {
218 await makeDeleteRequest({ url: server.url, path: pathComment, token: userAccessToken, statusCodeExpected: 403 }) 261 await makeDeleteRequest({
262 url: server.url,
263 path: pathComment,
264 token: userAccessToken,
265 statusCodeExpected: HttpStatusCode.FORBIDDEN_403
266 })
219 }) 267 })
220 268
221 it('Should fail with an incorrect video', async function () { 269 it('Should fail with an incorrect video', async function () {
222 const path = '/api/v1/videos/ba708d62-e3d7-45d9-9d73-41b9097cc02d/comments/' + commentId 270 const path = '/api/v1/videos/ba708d62-e3d7-45d9-9d73-41b9097cc02d/comments/' + commentId
223 await makeDeleteRequest({ url: server.url, path, token: server.accessToken, statusCodeExpected: 404 }) 271 await makeDeleteRequest({ url: server.url, path, token: server.accessToken, statusCodeExpected: HttpStatusCode.NOT_FOUND_404 })
224 }) 272 })
225 273
226 it('Should fail with an incorrect comment', async function () { 274 it('Should fail with an incorrect comment', async function () {
227 const path = '/api/v1/videos/' + videoUUID + '/comments/124' 275 const path = '/api/v1/videos/' + videoUUID + '/comments/124'
228 await makeDeleteRequest({ url: server.url, path, token: server.accessToken, statusCodeExpected: 404 }) 276 await makeDeleteRequest({ url: server.url, path, token: server.accessToken, statusCodeExpected: HttpStatusCode.NOT_FOUND_404 })
229 }) 277 })
230 278
231 it('Should succeed with the same user', async function () { 279 it('Should succeed with the same user', async function () {
@@ -238,8 +286,8 @@ describe('Test video comments API validator', function () {
238 286
239 const path = '/api/v1/videos/' + videoUUID + '/comments/' + commentToDelete 287 const path = '/api/v1/videos/' + videoUUID + '/comments/' + commentToDelete
240 288
241 await makeDeleteRequest({ url: server.url, path, token: userAccessToken2, statusCodeExpected: 403 }) 289 await makeDeleteRequest({ url: server.url, path, token: userAccessToken2, statusCodeExpected: HttpStatusCode.FORBIDDEN_403 })
242 await makeDeleteRequest({ url: server.url, path, token: userAccessToken, statusCodeExpected: 204 }) 290 await makeDeleteRequest({ url: server.url, path, token: userAccessToken, statusCodeExpected: HttpStatusCode.NO_CONTENT_204 })
243 }) 291 })
244 292
245 it('Should succeed with the owner of the video', async function () { 293 it('Should succeed with the owner of the video', async function () {
@@ -258,12 +306,17 @@ describe('Test video comments API validator', function () {
258 306
259 const path = '/api/v1/videos/' + anotherVideoUUID + '/comments/' + commentToDelete 307 const path = '/api/v1/videos/' + anotherVideoUUID + '/comments/' + commentToDelete
260 308
261 await makeDeleteRequest({ url: server.url, path, token: userAccessToken2, statusCodeExpected: 403 }) 309 await makeDeleteRequest({ url: server.url, path, token: userAccessToken2, statusCodeExpected: HttpStatusCode.FORBIDDEN_403 })
262 await makeDeleteRequest({ url: server.url, path, token: userAccessToken, statusCodeExpected: 204 }) 310 await makeDeleteRequest({ url: server.url, path, token: userAccessToken, statusCodeExpected: HttpStatusCode.NO_CONTENT_204 })
263 }) 311 })
264 312
265 it('Should succeed with the correct parameters', async function () { 313 it('Should succeed with the correct parameters', async function () {
266 await makeDeleteRequest({ url: server.url, path: pathComment, token: server.accessToken, statusCodeExpected: 204 }) 314 await makeDeleteRequest({
315 url: server.url,
316 path: pathComment,
317 token: server.accessToken,
318 statusCodeExpected: HttpStatusCode.NO_CONTENT_204
319 })
267 }) 320 })
268 }) 321 })
269 322
@@ -278,7 +331,7 @@ describe('Test video comments API validator', function () {
278 const res = await makeGetRequest({ 331 const res = await makeGetRequest({
279 url: server.url, 332 url: server.url,
280 path: pathThread, 333 path: pathThread,
281 statusCodeExpected: 200 334 statusCodeExpected: HttpStatusCode.OK_200
282 }) 335 })
283 expect(res.body.total).to.equal(0) 336 expect(res.body.total).to.equal(0)
284 expect(res.body.data).to.have.lengthOf(0) 337 expect(res.body.data).to.have.lengthOf(0)
@@ -290,7 +343,13 @@ describe('Test video comments API validator', function () {
290 const fields = { 343 const fields = {
291 text: 'super comment' 344 text: 'super comment'
292 } 345 }
293 await makePostBodyRequest({ url: server.url, path: pathThread, token: server.accessToken, fields, statusCodeExpected: 409 }) 346 await makePostBodyRequest({
347 url: server.url,
348 path: pathThread,
349 token: server.accessToken,
350 fields,
351 statusCodeExpected: HttpStatusCode.CONFLICT_409
352 })
294 }) 353 })
295 354
296 it('Should return conflict on comment thread add') 355 it('Should return conflict on comment thread add')
@@ -315,7 +374,7 @@ describe('Test video comments API validator', function () {
315 await makeGetRequest({ 374 await makeGetRequest({
316 url: server.url, 375 url: server.url,
317 path, 376 path,
318 statusCodeExpected: 401 377 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401
319 }) 378 })
320 }) 379 })
321 380
@@ -324,7 +383,7 @@ describe('Test video comments API validator', function () {
324 url: server.url, 383 url: server.url,
325 path, 384 path,
326 token: userAccessToken, 385 token: userAccessToken,
327 statusCodeExpected: 403 386 statusCodeExpected: HttpStatusCode.FORBIDDEN_403
328 }) 387 })
329 }) 388 })
330 389
@@ -339,7 +398,7 @@ describe('Test video comments API validator', function () {
339 searchAccount: 'toto', 398 searchAccount: 'toto',
340 searchVideo: 'toto' 399 searchVideo: 'toto'
341 }, 400 },
342 statusCodeExpected: 200 401 statusCodeExpected: HttpStatusCode.OK_200
343 }) 402 })
344 }) 403 })
345 }) 404 })
diff --git a/server/tests/api/check-params/video-imports.ts b/server/tests/api/check-params/video-imports.ts
index f954ba089..49ff96117 100644
--- a/server/tests/api/check-params/video-imports.ts
+++ b/server/tests/api/check-params/video-imports.ts
@@ -24,6 +24,7 @@ import {
24} from '../../../../shared/extra-utils/requests/check-api-params' 24} from '../../../../shared/extra-utils/requests/check-api-params'
25import { getMagnetURI, getGoodVideoUrl } from '../../../../shared/extra-utils/videos/video-imports' 25import { getMagnetURI, getGoodVideoUrl } from '../../../../shared/extra-utils/videos/video-imports'
26import { VideoPrivacy } from '../../../../shared/models/videos/video-privacy.enum' 26import { VideoPrivacy } from '../../../../shared/models/videos/video-privacy.enum'
27import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
27 28
28describe('Test video imports API validator', function () { 29describe('Test video imports API validator', function () {
29 const path = '/api/v1/videos/imports' 30 const path = '/api/v1/videos/imports'
@@ -67,7 +68,7 @@ describe('Test video imports API validator', function () {
67 }) 68 })
68 69
69 it('Should success with the correct parameters', async function () { 70 it('Should success with the correct parameters', async function () {
70 await makeGetRequest({ url: server.url, path: myPath, statusCodeExpected: 200, token: server.accessToken }) 71 await makeGetRequest({ url: server.url, path: myPath, statusCodeExpected: HttpStatusCode.OK_200, token: server.accessToken })
71 }) 72 })
72 }) 73 })
73 74
@@ -100,7 +101,13 @@ describe('Test video imports API validator', function () {
100 101
101 it('Should fail without a target url', async function () { 102 it('Should fail without a target url', async function () {
102 const fields = omit(baseCorrectParams, 'targetUrl') 103 const fields = omit(baseCorrectParams, 'targetUrl')
103 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields, statusCodeExpected: 400 }) 104 await makePostBodyRequest({
105 url: server.url,
106 path,
107 token: server.accessToken,
108 fields,
109 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400
110 })
104 }) 111 })
105 112
106 it('Should fail with a bad target url', async function () { 113 it('Should fail with a bad target url', async function () {
@@ -251,7 +258,7 @@ describe('Test video imports API validator', function () {
251 path, 258 path,
252 token: server.accessToken, 259 token: server.accessToken,
253 fields: baseCorrectParams, 260 fields: baseCorrectParams,
254 statusCodeExpected: 200 261 statusCodeExpected: HttpStatusCode.OK_200
255 }) 262 })
256 }) 263 })
257 264
@@ -274,7 +281,7 @@ describe('Test video imports API validator', function () {
274 path, 281 path,
275 token: server.accessToken, 282 token: server.accessToken,
276 fields: baseCorrectParams, 283 fields: baseCorrectParams,
277 statusCodeExpected: 409 284 statusCodeExpected: HttpStatusCode.CONFLICT_409
278 }) 285 })
279 }) 286 })
280 287
@@ -295,14 +302,27 @@ describe('Test video imports API validator', function () {
295 let fields = omit(baseCorrectParams, 'targetUrl') 302 let fields = omit(baseCorrectParams, 'targetUrl')
296 fields = immutableAssign(fields, { magnetUri: getMagnetURI() }) 303 fields = immutableAssign(fields, { magnetUri: getMagnetURI() })
297 304
298 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields, statusCodeExpected: 409 }) 305 await makePostBodyRequest({
306 url: server.url,
307 path,
308 token: server.accessToken,
309 fields,
310 statusCodeExpected: HttpStatusCode.CONFLICT_409
311 })
299 312
300 fields = omit(fields, 'magnetUri') 313 fields = omit(fields, 'magnetUri')
301 const attaches = { 314 const attaches = {
302 torrentfile: join(__dirname, '..', '..', 'fixtures', 'video-720p.torrent') 315 torrentfile: join(__dirname, '..', '..', 'fixtures', 'video-720p.torrent')
303 } 316 }
304 317
305 await makeUploadRequest({ url: server.url, path, token: server.accessToken, fields, attaches, statusCodeExpected: 409 }) 318 await makeUploadRequest({
319 url: server.url,
320 path,
321 token: server.accessToken,
322 fields,
323 attaches,
324 statusCodeExpected: HttpStatusCode.CONFLICT_409
325 })
306 }) 326 })
307 }) 327 })
308 328
diff --git a/server/tests/api/check-params/video-playlists.ts b/server/tests/api/check-params/video-playlists.ts
index 179ae9201..418af05d1 100644
--- a/server/tests/api/check-params/video-playlists.ts
+++ b/server/tests/api/check-params/video-playlists.ts
@@ -28,6 +28,7 @@ import {
28} from '../../../../shared/extra-utils/requests/check-api-params' 28} from '../../../../shared/extra-utils/requests/check-api-params'
29import { VideoPlaylistPrivacy } from '../../../../shared/models/videos/playlist/video-playlist-privacy.model' 29import { VideoPlaylistPrivacy } from '../../../../shared/models/videos/playlist/video-playlist-privacy.model'
30import { VideoPlaylistType } from '../../../../shared/models/videos/playlist/video-playlist-type.model' 30import { VideoPlaylistType } from '../../../../shared/models/videos/playlist/video-playlist-type.model'
31import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
31 32
32describe('Test video playlists API validator', function () { 33describe('Test video playlists API validator', function () {
33 let server: ServerInfo 34 let server: ServerInfo
@@ -114,19 +115,34 @@ describe('Test video playlists API validator', function () {
114 it('Should fail with a bad account parameter', async function () { 115 it('Should fail with a bad account parameter', async function () {
115 const accountPath = '/api/v1/accounts/root2/video-playlists' 116 const accountPath = '/api/v1/accounts/root2/video-playlists'
116 117
117 await makeGetRequest({ url: server.url, path: accountPath, statusCodeExpected: 404, token: server.accessToken }) 118 await makeGetRequest({
119 url: server.url,
120 path: accountPath,
121 statusCodeExpected: HttpStatusCode.NOT_FOUND_404,
122 token: server.accessToken
123 })
118 }) 124 })
119 125
120 it('Should fail with a bad video channel parameter', async function () { 126 it('Should fail with a bad video channel parameter', async function () {
121 const accountPath = '/api/v1/video-channels/bad_channel/video-playlists' 127 const accountPath = '/api/v1/video-channels/bad_channel/video-playlists'
122 128
123 await makeGetRequest({ url: server.url, path: accountPath, statusCodeExpected: 404, token: server.accessToken }) 129 await makeGetRequest({
130 url: server.url,
131 path: accountPath,
132 statusCodeExpected: HttpStatusCode.NOT_FOUND_404,
133 token: server.accessToken
134 })
124 }) 135 })
125 136
126 it('Should success with the correct parameters', async function () { 137 it('Should success with the correct parameters', async function () {
127 await makeGetRequest({ url: server.url, path: globalPath, statusCodeExpected: 200, token: server.accessToken }) 138 await makeGetRequest({ url: server.url, path: globalPath, statusCodeExpected: HttpStatusCode.OK_200, token: server.accessToken })
128 await makeGetRequest({ url: server.url, path: accountPath, statusCodeExpected: 200, token: server.accessToken }) 139 await makeGetRequest({ url: server.url, path: accountPath, statusCodeExpected: HttpStatusCode.OK_200, token: server.accessToken })
129 await makeGetRequest({ url: server.url, path: videoChannelPath, statusCodeExpected: 200, token: server.accessToken }) 140 await makeGetRequest({
141 url: server.url,
142 path: videoChannelPath,
143 statusCodeExpected: HttpStatusCode.OK_200,
144 token: server.accessToken
145 })
130 }) 146 })
131 }) 147 })
132 148
@@ -142,17 +158,17 @@ describe('Test video playlists API validator', function () {
142 }) 158 })
143 159
144 it('Should success with the correct parameters', async function () { 160 it('Should success with the correct parameters', async function () {
145 await makeGetRequest({ url: server.url, path: path + playlistUUID + '/videos', statusCodeExpected: 200 }) 161 await makeGetRequest({ url: server.url, path: path + playlistUUID + '/videos', statusCodeExpected: HttpStatusCode.OK_200 })
146 }) 162 })
147 }) 163 })
148 164
149 describe('When getting a video playlist', function () { 165 describe('When getting a video playlist', function () {
150 it('Should fail with a bad id or uuid', async function () { 166 it('Should fail with a bad id or uuid', async function () {
151 await getVideoPlaylist(server.url, 'toto', 400) 167 await getVideoPlaylist(server.url, 'toto', HttpStatusCode.BAD_REQUEST_400)
152 }) 168 })
153 169
154 it('Should fail with an unknown playlist', async function () { 170 it('Should fail with an unknown playlist', async function () {
155 await getVideoPlaylist(server.url, 42, 404) 171 await getVideoPlaylist(server.url, 42, HttpStatusCode.NOT_FOUND_404)
156 }) 172 })
157 173
158 it('Should fail to get an unlisted playlist with the number id', async function () { 174 it('Should fail to get an unlisted playlist with the number id', async function () {
@@ -166,19 +182,19 @@ describe('Test video playlists API validator', function () {
166 }) 182 })
167 const playlist = res.body.videoPlaylist 183 const playlist = res.body.videoPlaylist
168 184
169 await getVideoPlaylist(server.url, playlist.id, 404) 185 await getVideoPlaylist(server.url, playlist.id, HttpStatusCode.NOT_FOUND_404)
170 await getVideoPlaylist(server.url, playlist.uuid, 200) 186 await getVideoPlaylist(server.url, playlist.uuid, HttpStatusCode.OK_200)
171 }) 187 })
172 188
173 it('Should succeed with the correct params', async function () { 189 it('Should succeed with the correct params', async function () {
174 await getVideoPlaylist(server.url, playlistUUID, 200) 190 await getVideoPlaylist(server.url, playlistUUID, HttpStatusCode.OK_200)
175 }) 191 })
176 }) 192 })
177 193
178 describe('When creating/updating a video playlist', function () { 194 describe('When creating/updating a video playlist', function () {
179 const getBase = (playlistAttrs: any = {}, wrapper: any = {}) => { 195 const getBase = (playlistAttrs: any = {}, wrapper: any = {}) => {
180 return Object.assign({ 196 return Object.assign({
181 expectedStatus: 400, 197 expectedStatus: HttpStatusCode.BAD_REQUEST_400,
182 url: server.url, 198 url: server.url,
183 token: server.accessToken, 199 token: server.accessToken,
184 playlistAttrs: Object.assign({ 200 playlistAttrs: Object.assign({
@@ -194,7 +210,7 @@ describe('Test video playlists API validator', function () {
194 } 210 }
195 211
196 it('Should fail with an unauthenticated user', async function () { 212 it('Should fail with an unauthenticated user', async function () {
197 const params = getBase({}, { token: null, expectedStatus: 401 }) 213 const params = getBase({}, { token: null, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 })
198 214
199 await createVideoPlaylist(params) 215 await createVideoPlaylist(params)
200 await updateVideoPlaylist(getUpdate(params, playlistUUID)) 216 await updateVideoPlaylist(getUpdate(params, playlistUUID))
@@ -228,7 +244,7 @@ describe('Test video playlists API validator', function () {
228 }) 244 })
229 245
230 it('Should fail with an unknown video channel id', async function () { 246 it('Should fail with an unknown video channel id', async function () {
231 const params = getBase({ videoChannelId: 42 }, { expectedStatus: 404 }) 247 const params = getBase({ videoChannelId: 42 }, { expectedStatus: HttpStatusCode.NOT_FOUND_404 })
232 248
233 await createVideoPlaylist(params) 249 await createVideoPlaylist(params)
234 await updateVideoPlaylist(getUpdate(params, playlistUUID)) 250 await updateVideoPlaylist(getUpdate(params, playlistUUID))
@@ -255,33 +271,33 @@ describe('Test video playlists API validator', function () {
255 271
256 it('Should fail with an unknown playlist to update', async function () { 272 it('Should fail with an unknown playlist to update', async function () {
257 await updateVideoPlaylist(getUpdate( 273 await updateVideoPlaylist(getUpdate(
258 getBase({}, { expectedStatus: 404 }), 274 getBase({}, { expectedStatus: HttpStatusCode.NOT_FOUND_404 }),
259 42 275 42
260 )) 276 ))
261 }) 277 })
262 278
263 it('Should fail to update a playlist of another user', async function () { 279 it('Should fail to update a playlist of another user', async function () {
264 await updateVideoPlaylist(getUpdate( 280 await updateVideoPlaylist(getUpdate(
265 getBase({}, { token: userAccessToken, expectedStatus: 403 }), 281 getBase({}, { token: userAccessToken, expectedStatus: HttpStatusCode.FORBIDDEN_403 }),
266 playlistUUID 282 playlistUUID
267 )) 283 ))
268 }) 284 })
269 285
270 it('Should fail to update the watch later playlist', async function () { 286 it('Should fail to update the watch later playlist', async function () {
271 await updateVideoPlaylist(getUpdate( 287 await updateVideoPlaylist(getUpdate(
272 getBase({}, { expectedStatus: 400 }), 288 getBase({}, { expectedStatus: HttpStatusCode.BAD_REQUEST_400 }),
273 watchLaterPlaylistId 289 watchLaterPlaylistId
274 )) 290 ))
275 }) 291 })
276 292
277 it('Should succeed with the correct params', async function () { 293 it('Should succeed with the correct params', async function () {
278 { 294 {
279 const params = getBase({}, { expectedStatus: 200 }) 295 const params = getBase({}, { expectedStatus: HttpStatusCode.OK_200 })
280 await createVideoPlaylist(params) 296 await createVideoPlaylist(params)
281 } 297 }
282 298
283 { 299 {
284 const params = getBase({}, { expectedStatus: 204 }) 300 const params = getBase({}, { expectedStatus: HttpStatusCode.NO_CONTENT_204 })
285 await updateVideoPlaylist(getUpdate(params, playlistUUID)) 301 await updateVideoPlaylist(getUpdate(params, playlistUUID))
286 } 302 }
287 }) 303 })
@@ -290,7 +306,7 @@ describe('Test video playlists API validator', function () {
290 describe('When adding an element in a playlist', function () { 306 describe('When adding an element in a playlist', function () {
291 const getBase = (elementAttrs: any = {}, wrapper: any = {}) => { 307 const getBase = (elementAttrs: any = {}, wrapper: any = {}) => {
292 return Object.assign({ 308 return Object.assign({
293 expectedStatus: 400, 309 expectedStatus: HttpStatusCode.BAD_REQUEST_400,
294 url: server.url, 310 url: server.url,
295 token: server.accessToken, 311 token: server.accessToken,
296 playlistId: playlistUUID, 312 playlistId: playlistUUID,
@@ -303,12 +319,12 @@ describe('Test video playlists API validator', function () {
303 } 319 }
304 320
305 it('Should fail with an unauthenticated user', async function () { 321 it('Should fail with an unauthenticated user', async function () {
306 const params = getBase({}, { token: null, expectedStatus: 401 }) 322 const params = getBase({}, { token: null, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 })
307 await addVideoInPlaylist(params) 323 await addVideoInPlaylist(params)
308 }) 324 })
309 325
310 it('Should fail with the playlist of another user', async function () { 326 it('Should fail with the playlist of another user', async function () {
311 const params = getBase({}, { token: userAccessToken, expectedStatus: 403 }) 327 const params = getBase({}, { token: userAccessToken, expectedStatus: HttpStatusCode.FORBIDDEN_403 })
312 await addVideoInPlaylist(params) 328 await addVideoInPlaylist(params)
313 }) 329 })
314 330
@@ -319,13 +335,13 @@ describe('Test video playlists API validator', function () {
319 } 335 }
320 336
321 { 337 {
322 const params = getBase({}, { playlistId: 42, expectedStatus: 404 }) 338 const params = getBase({}, { playlistId: 42, expectedStatus: HttpStatusCode.NOT_FOUND_404 })
323 await addVideoInPlaylist(params) 339 await addVideoInPlaylist(params)
324 } 340 }
325 }) 341 })
326 342
327 it('Should fail with an unknown or incorrect video id', async function () { 343 it('Should fail with an unknown or incorrect video id', async function () {
328 const params = getBase({ videoId: 42 }, { expectedStatus: 404 }) 344 const params = getBase({ videoId: 42 }, { expectedStatus: HttpStatusCode.NOT_FOUND_404 })
329 await addVideoInPlaylist(params) 345 await addVideoInPlaylist(params)
330 }) 346 })
331 347
@@ -342,7 +358,7 @@ describe('Test video playlists API validator', function () {
342 }) 358 })
343 359
344 it('Succeed with the correct params', async function () { 360 it('Succeed with the correct params', async function () {
345 const params = getBase({}, { expectedStatus: 200 }) 361 const params = getBase({}, { expectedStatus: HttpStatusCode.OK_200 })
346 const res = await addVideoInPlaylist(params) 362 const res = await addVideoInPlaylist(params)
347 playlistElementId = res.body.videoPlaylistElement.id 363 playlistElementId = res.body.videoPlaylistElement.id
348 }) 364 })
@@ -359,17 +375,17 @@ describe('Test video playlists API validator', function () {
359 }, elementAttrs), 375 }, elementAttrs),
360 playlistElementId, 376 playlistElementId,
361 playlistId: playlistUUID, 377 playlistId: playlistUUID,
362 expectedStatus: 400 378 expectedStatus: HttpStatusCode.BAD_REQUEST_400
363 }, wrapper) 379 }, wrapper)
364 } 380 }
365 381
366 it('Should fail with an unauthenticated user', async function () { 382 it('Should fail with an unauthenticated user', async function () {
367 const params = getBase({}, { token: null, expectedStatus: 401 }) 383 const params = getBase({}, { token: null, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 })
368 await updateVideoPlaylistElement(params) 384 await updateVideoPlaylistElement(params)
369 }) 385 })
370 386
371 it('Should fail with the playlist of another user', async function () { 387 it('Should fail with the playlist of another user', async function () {
372 const params = getBase({}, { token: userAccessToken, expectedStatus: 403 }) 388 const params = getBase({}, { token: userAccessToken, expectedStatus: HttpStatusCode.FORBIDDEN_403 })
373 await updateVideoPlaylistElement(params) 389 await updateVideoPlaylistElement(params)
374 }) 390 })
375 391
@@ -380,7 +396,7 @@ describe('Test video playlists API validator', function () {
380 } 396 }
381 397
382 { 398 {
383 const params = getBase({}, { playlistId: 42, expectedStatus: 404 }) 399 const params = getBase({}, { playlistId: 42, expectedStatus: HttpStatusCode.NOT_FOUND_404 })
384 await updateVideoPlaylistElement(params) 400 await updateVideoPlaylistElement(params)
385 } 401 }
386 }) 402 })
@@ -392,7 +408,7 @@ describe('Test video playlists API validator', function () {
392 } 408 }
393 409
394 { 410 {
395 const params = getBase({}, { playlistElementId: 42, expectedStatus: 404 }) 411 const params = getBase({}, { playlistElementId: 42, expectedStatus: HttpStatusCode.NOT_FOUND_404 })
396 await updateVideoPlaylistElement(params) 412 await updateVideoPlaylistElement(params)
397 } 413 }
398 }) 414 })
@@ -410,12 +426,12 @@ describe('Test video playlists API validator', function () {
410 }) 426 })
411 427
412 it('Should fail with an unknown element', async function () { 428 it('Should fail with an unknown element', async function () {
413 const params = getBase({}, { playlistElementId: 888, expectedStatus: 404 }) 429 const params = getBase({}, { playlistElementId: 888, expectedStatus: HttpStatusCode.NOT_FOUND_404 })
414 await updateVideoPlaylistElement(params) 430 await updateVideoPlaylistElement(params)
415 }) 431 })
416 432
417 it('Succeed with the correct params', async function () { 433 it('Succeed with the correct params', async function () {
418 const params = getBase({}, { expectedStatus: 204 }) 434 const params = getBase({}, { expectedStatus: HttpStatusCode.NO_CONTENT_204 })
419 await updateVideoPlaylistElement(params) 435 await updateVideoPlaylistElement(params)
420 }) 436 })
421 }) 437 })
@@ -434,7 +450,7 @@ describe('Test video playlists API validator', function () {
434 insertAfterPosition: 2, 450 insertAfterPosition: 2,
435 reorderLength: 3 451 reorderLength: 3
436 }, elementAttrs), 452 }, elementAttrs),
437 expectedStatus: 400 453 expectedStatus: HttpStatusCode.BAD_REQUEST_400
438 }, wrapper) 454 }, wrapper)
439 } 455 }
440 456
@@ -453,12 +469,12 @@ describe('Test video playlists API validator', function () {
453 }) 469 })
454 470
455 it('Should fail with an unauthenticated user', async function () { 471 it('Should fail with an unauthenticated user', async function () {
456 const params = getBase({}, { token: null, expectedStatus: 401 }) 472 const params = getBase({}, { token: null, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 })
457 await reorderVideosPlaylist(params) 473 await reorderVideosPlaylist(params)
458 }) 474 })
459 475
460 it('Should fail with the playlist of another user', async function () { 476 it('Should fail with the playlist of another user', async function () {
461 const params = getBase({}, { token: userAccessToken, expectedStatus: 403 }) 477 const params = getBase({}, { token: userAccessToken, expectedStatus: HttpStatusCode.FORBIDDEN_403 })
462 await reorderVideosPlaylist(params) 478 await reorderVideosPlaylist(params)
463 }) 479 })
464 480
@@ -469,7 +485,7 @@ describe('Test video playlists API validator', function () {
469 } 485 }
470 486
471 { 487 {
472 const params = getBase({}, { playlistId: 42, expectedStatus: 404 }) 488 const params = getBase({}, { playlistId: 42, expectedStatus: HttpStatusCode.NOT_FOUND_404 })
473 await reorderVideosPlaylist(params) 489 await reorderVideosPlaylist(params)
474 } 490 }
475 }) 491 })
@@ -526,7 +542,7 @@ describe('Test video playlists API validator', function () {
526 }) 542 })
527 543
528 it('Succeed with the correct params', async function () { 544 it('Succeed with the correct params', async function () {
529 const params = getBase({}, { expectedStatus: 204 }) 545 const params = getBase({}, { expectedStatus: HttpStatusCode.NO_CONTENT_204 })
530 await reorderVideosPlaylist(params) 546 await reorderVideosPlaylist(params)
531 }) 547 })
532 }) 548 })
@@ -539,7 +555,7 @@ describe('Test video playlists API validator', function () {
539 url: server.url, 555 url: server.url,
540 path, 556 path,
541 query: { videoIds: [ 1, 2 ] }, 557 query: { videoIds: [ 1, 2 ] },
542 statusCodeExpected: 401 558 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401
543 }) 559 })
544 }) 560 })
545 561
@@ -572,7 +588,7 @@ describe('Test video playlists API validator', function () {
572 token: server.accessToken, 588 token: server.accessToken,
573 path, 589 path,
574 query: { videoIds: [ 1, 2 ] }, 590 query: { videoIds: [ 1, 2 ] },
575 statusCodeExpected: 200 591 statusCodeExpected: HttpStatusCode.OK_200
576 }) 592 })
577 }) 593 })
578 }) 594 })
@@ -584,17 +600,17 @@ describe('Test video playlists API validator', function () {
584 token: server.accessToken, 600 token: server.accessToken,
585 playlistElementId, 601 playlistElementId,
586 playlistId: playlistUUID, 602 playlistId: playlistUUID,
587 expectedStatus: 400 603 expectedStatus: HttpStatusCode.BAD_REQUEST_400
588 }, wrapper) 604 }, wrapper)
589 } 605 }
590 606
591 it('Should fail with an unauthenticated user', async function () { 607 it('Should fail with an unauthenticated user', async function () {
592 const params = getBase({ token: null, expectedStatus: 401 }) 608 const params = getBase({ token: null, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 })
593 await removeVideoFromPlaylist(params) 609 await removeVideoFromPlaylist(params)
594 }) 610 })
595 611
596 it('Should fail with the playlist of another user', async function () { 612 it('Should fail with the playlist of another user', async function () {
597 const params = getBase({ token: userAccessToken, expectedStatus: 403 }) 613 const params = getBase({ token: userAccessToken, expectedStatus: HttpStatusCode.FORBIDDEN_403 })
598 await removeVideoFromPlaylist(params) 614 await removeVideoFromPlaylist(params)
599 }) 615 })
600 616
@@ -605,7 +621,7 @@ describe('Test video playlists API validator', function () {
605 } 621 }
606 622
607 { 623 {
608 const params = getBase({ playlistId: 42, expectedStatus: 404 }) 624 const params = getBase({ playlistId: 42, expectedStatus: HttpStatusCode.NOT_FOUND_404 })
609 await removeVideoFromPlaylist(params) 625 await removeVideoFromPlaylist(params)
610 } 626 }
611 }) 627 })
@@ -617,33 +633,33 @@ describe('Test video playlists API validator', function () {
617 } 633 }
618 634
619 { 635 {
620 const params = getBase({ playlistElementId: 42, expectedStatus: 404 }) 636 const params = getBase({ playlistElementId: 42, expectedStatus: HttpStatusCode.NOT_FOUND_404 })
621 await removeVideoFromPlaylist(params) 637 await removeVideoFromPlaylist(params)
622 } 638 }
623 }) 639 })
624 640
625 it('Should fail with an unknown element', async function () { 641 it('Should fail with an unknown element', async function () {
626 const params = getBase({ playlistElementId: 888, expectedStatus: 404 }) 642 const params = getBase({ playlistElementId: 888, expectedStatus: HttpStatusCode.NOT_FOUND_404 })
627 await removeVideoFromPlaylist(params) 643 await removeVideoFromPlaylist(params)
628 }) 644 })
629 645
630 it('Succeed with the correct params', async function () { 646 it('Succeed with the correct params', async function () {
631 const params = getBase({ expectedStatus: 204 }) 647 const params = getBase({ expectedStatus: HttpStatusCode.NO_CONTENT_204 })
632 await removeVideoFromPlaylist(params) 648 await removeVideoFromPlaylist(params)
633 }) 649 })
634 }) 650 })
635 651
636 describe('When deleting a playlist', function () { 652 describe('When deleting a playlist', function () {
637 it('Should fail with an unknown playlist', async function () { 653 it('Should fail with an unknown playlist', async function () {
638 await deleteVideoPlaylist(server.url, server.accessToken, 42, 404) 654 await deleteVideoPlaylist(server.url, server.accessToken, 42, HttpStatusCode.NOT_FOUND_404)
639 }) 655 })
640 656
641 it('Should fail with a playlist of another user', async function () { 657 it('Should fail with a playlist of another user', async function () {
642 await deleteVideoPlaylist(server.url, userAccessToken, playlistUUID, 403) 658 await deleteVideoPlaylist(server.url, userAccessToken, playlistUUID, HttpStatusCode.FORBIDDEN_403)
643 }) 659 })
644 660
645 it('Should fail with the watch later playlist', async function () { 661 it('Should fail with the watch later playlist', async function () {
646 await deleteVideoPlaylist(server.url, server.accessToken, watchLaterPlaylistId, 400) 662 await deleteVideoPlaylist(server.url, server.accessToken, watchLaterPlaylistId, HttpStatusCode.BAD_REQUEST_400)
647 }) 663 })
648 664
649 it('Should succeed with the correct params', async function () { 665 it('Should succeed with the correct params', async function () {
diff --git a/server/tests/api/check-params/videos-filter.ts b/server/tests/api/check-params/videos-filter.ts
index bf8248b0e..2391584a7 100644
--- a/server/tests/api/check-params/videos-filter.ts
+++ b/server/tests/api/check-params/videos-filter.ts
@@ -12,8 +12,9 @@ import {
12 userLogin 12 userLogin
13} from '../../../../shared/extra-utils' 13} from '../../../../shared/extra-utils'
14import { UserRole } from '../../../../shared/models/users' 14import { UserRole } from '../../../../shared/models/users'
15import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
15 16
16async function testEndpoints (server: ServerInfo, token: string, filter: string, statusCodeExpected: number) { 17async function testEndpoints (server: ServerInfo, token: string, filter: string, statusCodeExpected: HttpStatusCode) {
17 const paths = [ 18 const paths = [
18 '/api/v1/video-channels/root_channel/videos', 19 '/api/v1/video-channels/root_channel/videos',
19 '/api/v1/accounts/root/videos', 20 '/api/v1/accounts/root/videos',
@@ -71,26 +72,26 @@ describe('Test videos filters', function () {
71 describe('When setting a video filter', function () { 72 describe('When setting a video filter', function () {
72 73
73 it('Should fail with a bad filter', async function () { 74 it('Should fail with a bad filter', async function () {
74 await testEndpoints(server, server.accessToken, 'bad-filter', 400) 75 await testEndpoints(server, server.accessToken, 'bad-filter', HttpStatusCode.BAD_REQUEST_400)
75 }) 76 })
76 77
77 it('Should succeed with a good filter', async function () { 78 it('Should succeed with a good filter', async function () {
78 await testEndpoints(server, server.accessToken, 'local', 200) 79 await testEndpoints(server, server.accessToken, 'local', HttpStatusCode.OK_200)
79 }) 80 })
80 81
81 it('Should fail to list all-local/all with a simple user', async function () { 82 it('Should fail to list all-local/all with a simple user', async function () {
82 await testEndpoints(server, userAccessToken, 'all-local', 401) 83 await testEndpoints(server, userAccessToken, 'all-local', HttpStatusCode.UNAUTHORIZED_401)
83 await testEndpoints(server, userAccessToken, 'all', 401) 84 await testEndpoints(server, userAccessToken, 'all', HttpStatusCode.UNAUTHORIZED_401)
84 }) 85 })
85 86
86 it('Should succeed to list all-local/all with a moderator', async function () { 87 it('Should succeed to list all-local/all with a moderator', async function () {
87 await testEndpoints(server, moderatorAccessToken, 'all-local', 200) 88 await testEndpoints(server, moderatorAccessToken, 'all-local', HttpStatusCode.OK_200)
88 await testEndpoints(server, moderatorAccessToken, 'all', 200) 89 await testEndpoints(server, moderatorAccessToken, 'all', HttpStatusCode.OK_200)
89 }) 90 })
90 91
91 it('Should succeed to list all-local/all with an admin', async function () { 92 it('Should succeed to list all-local/all with an admin', async function () {
92 await testEndpoints(server, server.accessToken, 'all-local', 200) 93 await testEndpoints(server, server.accessToken, 'all-local', HttpStatusCode.OK_200)
93 await testEndpoints(server, server.accessToken, 'all', 200) 94 await testEndpoints(server, server.accessToken, 'all', HttpStatusCode.OK_200)
94 }) 95 })
95 96
96 // Because we cannot authenticate the user on the RSS endpoint 97 // Because we cannot authenticate the user on the RSS endpoint
@@ -99,7 +100,7 @@ describe('Test videos filters', function () {
99 await makeGetRequest({ 100 await makeGetRequest({
100 url: server.url, 101 url: server.url,
101 path: '/feeds/videos.json', 102 path: '/feeds/videos.json',
102 statusCodeExpected: 401, 103 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401,
103 query: { 104 query: {
104 filter 105 filter
105 } 106 }
@@ -111,7 +112,7 @@ describe('Test videos filters', function () {
111 await makeGetRequest({ 112 await makeGetRequest({
112 url: server.url, 113 url: server.url,
113 path: '/feeds/videos.json', 114 path: '/feeds/videos.json',
114 statusCodeExpected: 200, 115 statusCodeExpected: HttpStatusCode.OK_200,
115 query: { 116 query: {
116 filter: 'local' 117 filter: 'local'
117 } 118 }
diff --git a/server/tests/api/check-params/videos-history.ts b/server/tests/api/check-params/videos-history.ts
index 941f62654..0e91fe0a8 100644
--- a/server/tests/api/check-params/videos-history.ts
+++ b/server/tests/api/check-params/videos-history.ts
@@ -13,6 +13,7 @@ import {
13 setAccessTokensToServers, 13 setAccessTokensToServers,
14 uploadVideo 14 uploadVideo
15} from '../../../../shared/extra-utils' 15} from '../../../../shared/extra-utils'
16import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
16 17
17describe('Test videos history API validator', function () { 18describe('Test videos history API validator', function () {
18 const myHistoryPath = '/api/v1/users/me/history/videos' 19 const myHistoryPath = '/api/v1/users/me/history/videos'
@@ -39,31 +40,55 @@ describe('Test videos history API validator', function () {
39 40
40 it('Should fail with an unauthenticated user', async function () { 41 it('Should fail with an unauthenticated user', async function () {
41 const fields = { currentTime: 5 } 42 const fields = { currentTime: 5 }
42 await makePutBodyRequest({ url: server.url, path: watchingPath, fields, statusCodeExpected: 401 }) 43 await makePutBodyRequest({ url: server.url, path: watchingPath, fields, statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 })
43 }) 44 })
44 45
45 it('Should fail with an incorrect video id', async function () { 46 it('Should fail with an incorrect video id', async function () {
46 const fields = { currentTime: 5 } 47 const fields = { currentTime: 5 }
47 const path = '/api/v1/videos/blabla/watching' 48 const path = '/api/v1/videos/blabla/watching'
48 await makePutBodyRequest({ url: server.url, path, fields, token: server.accessToken, statusCodeExpected: 400 }) 49 await makePutBodyRequest({
50 url: server.url,
51 path,
52 fields,
53 token: server.accessToken,
54 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400
55 })
49 }) 56 })
50 57
51 it('Should fail with an unknown video', async function () { 58 it('Should fail with an unknown video', async function () {
52 const fields = { currentTime: 5 } 59 const fields = { currentTime: 5 }
53 const path = '/api/v1/videos/d91fff41-c24d-4508-8e13-3bd5902c3b02/watching' 60 const path = '/api/v1/videos/d91fff41-c24d-4508-8e13-3bd5902c3b02/watching'
54 61
55 await makePutBodyRequest({ url: server.url, path, fields, token: server.accessToken, statusCodeExpected: 404 }) 62 await makePutBodyRequest({
63 url: server.url,
64 path,
65 fields,
66 token: server.accessToken,
67 statusCodeExpected: HttpStatusCode.NOT_FOUND_404
68 })
56 }) 69 })
57 70
58 it('Should fail with a bad current time', async function () { 71 it('Should fail with a bad current time', async function () {
59 const fields = { currentTime: 'hello' } 72 const fields = { currentTime: 'hello' }
60 await makePutBodyRequest({ url: server.url, path: watchingPath, fields, token: server.accessToken, statusCodeExpected: 400 }) 73 await makePutBodyRequest({
74 url: server.url,
75 path: watchingPath,
76 fields,
77 token: server.accessToken,
78 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400
79 })
61 }) 80 })
62 81
63 it('Should succeed with the correct parameters', async function () { 82 it('Should succeed with the correct parameters', async function () {
64 const fields = { currentTime: 5 } 83 const fields = { currentTime: 5 }
65 84
66 await makePutBodyRequest({ url: server.url, path: watchingPath, fields, token: server.accessToken, statusCodeExpected: 204 }) 85 await makePutBodyRequest({
86 url: server.url,
87 path: watchingPath,
88 fields,
89 token: server.accessToken,
90 statusCodeExpected: HttpStatusCode.NO_CONTENT_204
91 })
67 }) 92 })
68 }) 93 })
69 94
@@ -77,17 +102,17 @@ describe('Test videos history API validator', function () {
77 }) 102 })
78 103
79 it('Should fail with an unauthenticated user', async function () { 104 it('Should fail with an unauthenticated user', async function () {
80 await makeGetRequest({ url: server.url, path: myHistoryPath, statusCodeExpected: 401 }) 105 await makeGetRequest({ url: server.url, path: myHistoryPath, statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 })
81 }) 106 })
82 107
83 it('Should succeed with the correct params', async function () { 108 it('Should succeed with the correct params', async function () {
84 await makeGetRequest({ url: server.url, token: server.accessToken, path: myHistoryPath, statusCodeExpected: 200 }) 109 await makeGetRequest({ url: server.url, token: server.accessToken, path: myHistoryPath, statusCodeExpected: HttpStatusCode.OK_200 })
85 }) 110 })
86 }) 111 })
87 112
88 describe('When removing user videos history', function () { 113 describe('When removing user videos history', function () {
89 it('Should fail with an unauthenticated user', async function () { 114 it('Should fail with an unauthenticated user', async function () {
90 await makePostBodyRequest({ url: server.url, path: myHistoryPath + '/remove', statusCodeExpected: 401 }) 115 await makePostBodyRequest({ url: server.url, path: myHistoryPath + '/remove', statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 })
91 }) 116 })
92 117
93 it('Should fail with a bad beforeDate parameter', async function () { 118 it('Should fail with a bad beforeDate parameter', async function () {
@@ -97,7 +122,7 @@ describe('Test videos history API validator', function () {
97 token: server.accessToken, 122 token: server.accessToken,
98 path: myHistoryRemove, 123 path: myHistoryRemove,
99 fields: body, 124 fields: body,
100 statusCodeExpected: 400 125 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400
101 }) 126 })
102 }) 127 })
103 128
@@ -108,7 +133,7 @@ describe('Test videos history API validator', function () {
108 token: server.accessToken, 133 token: server.accessToken,
109 path: myHistoryRemove, 134 path: myHistoryRemove,
110 fields: body, 135 fields: body,
111 statusCodeExpected: 204 136 statusCodeExpected: HttpStatusCode.NO_CONTENT_204
112 }) 137 })
113 }) 138 })
114 139
@@ -117,7 +142,7 @@ describe('Test videos history API validator', function () {
117 url: server.url, 142 url: server.url,
118 token: server.accessToken, 143 token: server.accessToken,
119 path: myHistoryRemove, 144 path: myHistoryRemove,
120 statusCodeExpected: 204 145 statusCodeExpected: HttpStatusCode.NO_CONTENT_204
121 }) 146 })
122 }) 147 })
123 }) 148 })
diff --git a/server/tests/api/check-params/videos.ts b/server/tests/api/check-params/videos.ts
index 0d4665954..d60546917 100644
--- a/server/tests/api/check-params/videos.ts
+++ b/server/tests/api/check-params/videos.ts
@@ -28,6 +28,7 @@ import {
28 checkBadSortPagination, 28 checkBadSortPagination,
29 checkBadStartPagination 29 checkBadStartPagination
30} from '../../../../shared/extra-utils/requests/check-api-params' 30} from '../../../../shared/extra-utils/requests/check-api-params'
31import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
31 32
32const expect = chai.expect 33const expect = chai.expect
33 34
@@ -76,11 +77,11 @@ describe('Test videos API validator', function () {
76 }) 77 })
77 78
78 it('Should fail with a bad skipVideos query', async function () { 79 it('Should fail with a bad skipVideos query', async function () {
79 await makeGetRequest({ url: server.url, path, statusCodeExpected: 200, query: { skipCount: 'toto' } }) 80 await makeGetRequest({ url: server.url, path, statusCodeExpected: HttpStatusCode.OK_200, query: { skipCount: 'toto' } })
80 }) 81 })
81 82
82 it('Should success with the correct parameters', async function () { 83 it('Should success with the correct parameters', async function () {
83 await makeGetRequest({ url: server.url, path, statusCodeExpected: 200, query: { skipCount: false } }) 84 await makeGetRequest({ url: server.url, path, statusCodeExpected: HttpStatusCode.OK_200, query: { skipCount: false } })
84 }) 85 })
85 }) 86 })
86 87
@@ -90,7 +91,7 @@ describe('Test videos API validator', function () {
90 await makeGetRequest({ 91 await makeGetRequest({
91 url: server.url, 92 url: server.url,
92 path: join(path, 'search'), 93 path: join(path, 'search'),
93 statusCodeExpected: 400 94 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400
94 }) 95 })
95 }) 96 })
96 97
@@ -107,7 +108,7 @@ describe('Test videos API validator', function () {
107 }) 108 })
108 109
109 it('Should success with the correct parameters', async function () { 110 it('Should success with the correct parameters', async function () {
110 await makeGetRequest({ url: server.url, path, statusCodeExpected: 200 }) 111 await makeGetRequest({ url: server.url, path, statusCodeExpected: HttpStatusCode.OK_200 })
111 }) 112 })
112 }) 113 })
113 114
@@ -127,7 +128,7 @@ describe('Test videos API validator', function () {
127 }) 128 })
128 129
129 it('Should success with the correct parameters', async function () { 130 it('Should success with the correct parameters', async function () {
130 await makeGetRequest({ url: server.url, token: server.accessToken, path, statusCodeExpected: 200 }) 131 await makeGetRequest({ url: server.url, token: server.accessToken, path, statusCodeExpected: HttpStatusCode.OK_200 })
131 }) 132 })
132 }) 133 })
133 134
@@ -151,7 +152,7 @@ describe('Test videos API validator', function () {
151 }) 152 })
152 153
153 it('Should success with the correct parameters', async function () { 154 it('Should success with the correct parameters', async function () {
154 await makeGetRequest({ url: server.url, path, statusCodeExpected: 200 }) 155 await makeGetRequest({ url: server.url, path, statusCodeExpected: HttpStatusCode.OK_200 })
155 }) 156 })
156 }) 157 })
157 158
@@ -175,7 +176,7 @@ describe('Test videos API validator', function () {
175 }) 176 })
176 177
177 it('Should success with the correct parameters', async function () { 178 it('Should success with the correct parameters', async function () {
178 await makeGetRequest({ url: server.url, path, statusCodeExpected: 200 }) 179 await makeGetRequest({ url: server.url, path, statusCodeExpected: HttpStatusCode.OK_200 })
179 }) 180 })
180 }) 181 })
181 182
@@ -408,7 +409,7 @@ describe('Test videos API validator', function () {
408 token: server.accessToken, 409 token: server.accessToken,
409 fields, 410 fields,
410 attaches, 411 attaches,
411 statusCodeExpected: 200 412 statusCodeExpected: HttpStatusCode.OK_200
412 }) 413 })
413 } 414 }
414 415
@@ -423,7 +424,7 @@ describe('Test videos API validator', function () {
423 token: server.accessToken, 424 token: server.accessToken,
424 fields, 425 fields,
425 attaches, 426 attaches,
426 statusCodeExpected: 200 427 statusCodeExpected: HttpStatusCode.OK_200
427 }) 428 })
428 } 429 }
429 430
@@ -438,7 +439,7 @@ describe('Test videos API validator', function () {
438 token: server.accessToken, 439 token: server.accessToken,
439 fields, 440 fields,
440 attaches, 441 attaches,
441 statusCodeExpected: 200 442 statusCodeExpected: HttpStatusCode.OK_200
442 }) 443 })
443 } 444 }
444 }) 445 })
@@ -481,7 +482,7 @@ describe('Test videos API validator', function () {
481 path: path + '4da6fde3-88f7-4d16-b119-108df5630b06', 482 path: path + '4da6fde3-88f7-4d16-b119-108df5630b06',
482 token: server.accessToken, 483 token: server.accessToken,
483 fields, 484 fields,
484 statusCodeExpected: 404 485 statusCodeExpected: HttpStatusCode.NOT_FOUND_404
485 }) 486 })
486 }) 487 })
487 488
@@ -630,7 +631,13 @@ describe('Test videos API validator', function () {
630 it('Should fail with a video of another user without the appropriate right', async function () { 631 it('Should fail with a video of another user without the appropriate right', async function () {
631 const fields = baseCorrectParams 632 const fields = baseCorrectParams
632 633
633 await makePutBodyRequest({ url: server.url, path: path + videoId, token: userAccessToken, fields, statusCodeExpected: 403 }) 634 await makePutBodyRequest({
635 url: server.url,
636 path: path + videoId,
637 token: userAccessToken,
638 fields,
639 statusCodeExpected: HttpStatusCode.FORBIDDEN_403
640 })
634 }) 641 })
635 642
636 it('Should fail with a video of another server') 643 it('Should fail with a video of another server')
@@ -638,7 +645,13 @@ describe('Test videos API validator', function () {
638 it('Should succeed with the correct parameters', async function () { 645 it('Should succeed with the correct parameters', async function () {
639 const fields = baseCorrectParams 646 const fields = baseCorrectParams
640 647
641 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields, statusCodeExpected: 204 }) 648 await makePutBodyRequest({
649 url: server.url,
650 path: path + videoId,
651 token: server.accessToken,
652 fields,
653 statusCodeExpected: HttpStatusCode.NO_CONTENT_204
654 })
642 }) 655 })
643 }) 656 })
644 657
@@ -647,7 +660,7 @@ describe('Test videos API validator', function () {
647 const res = await makeGetRequest({ 660 const res = await makeGetRequest({
648 url: server.url, 661 url: server.url,
649 path, 662 path,
650 statusCodeExpected: 200 663 statusCodeExpected: HttpStatusCode.OK_200
651 }) 664 })
652 665
653 expect(res.body.data).to.be.an('array') 666 expect(res.body.data).to.be.an('array')
@@ -655,11 +668,11 @@ describe('Test videos API validator', function () {
655 }) 668 })
656 669
657 it('Should fail without a correct uuid', async function () { 670 it('Should fail without a correct uuid', async function () {
658 await getVideo(server.url, 'coucou', 400) 671 await getVideo(server.url, 'coucou', HttpStatusCode.BAD_REQUEST_400)
659 }) 672 })
660 673
661 it('Should return 404 with an incorrect video', async function () { 674 it('Should return 404 with an incorrect video', async function () {
662 await getVideo(server.url, '4da6fde3-88f7-4d16-b119-108df5630b06', 404) 675 await getVideo(server.url, '4da6fde3-88f7-4d16-b119-108df5630b06', HttpStatusCode.NOT_FOUND_404)
663 }) 676 })
664 677
665 it('Should succeed with the correct parameters', async function () { 678 it('Should succeed with the correct parameters', async function () {
@@ -691,7 +704,7 @@ describe('Test videos API validator', function () {
691 path: path + '4da6fde3-88f7-4d16-b119-108df5630b06/rate', 704 path: path + '4da6fde3-88f7-4d16-b119-108df5630b06/rate',
692 token: server.accessToken, 705 token: server.accessToken,
693 fields, 706 fields,
694 statusCodeExpected: 404 707 statusCodeExpected: HttpStatusCode.NOT_FOUND_404
695 }) 708 })
696 }) 709 })
697 710
@@ -711,7 +724,7 @@ describe('Test videos API validator', function () {
711 path: path + videoId + '/rate', 724 path: path + videoId + '/rate',
712 token: server.accessToken, 725 token: server.accessToken,
713 fields, 726 fields,
714 statusCodeExpected: 204 727 statusCodeExpected: HttpStatusCode.NO_CONTENT_204
715 }) 728 })
716 }) 729 })
717 }) 730 })
@@ -721,20 +734,20 @@ describe('Test videos API validator', function () {
721 await makeDeleteRequest({ 734 await makeDeleteRequest({
722 url: server.url, 735 url: server.url,
723 path, 736 path,
724 statusCodeExpected: 400 737 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400
725 }) 738 })
726 }) 739 })
727 740
728 it('Should fail without a correct uuid', async function () { 741 it('Should fail without a correct uuid', async function () {
729 await removeVideo(server.url, server.accessToken, 'hello', 400) 742 await removeVideo(server.url, server.accessToken, 'hello', HttpStatusCode.BAD_REQUEST_400)
730 }) 743 })
731 744
732 it('Should fail with a video which does not exist', async function () { 745 it('Should fail with a video which does not exist', async function () {
733 await removeVideo(server.url, server.accessToken, '4da6fde3-88f7-4d16-b119-108df5630b06', 404) 746 await removeVideo(server.url, server.accessToken, '4da6fde3-88f7-4d16-b119-108df5630b06', HttpStatusCode.NOT_FOUND_404)
734 }) 747 })
735 748
736 it('Should fail with a video of another user without the appropriate right', async function () { 749 it('Should fail with a video of another user without the appropriate right', async function () {
737 await removeVideo(server.url, userAccessToken, videoId, 403) 750 await removeVideo(server.url, userAccessToken, videoId, HttpStatusCode.FORBIDDEN_403)
738 }) 751 })
739 752
740 it('Should fail with a video of another server') 753 it('Should fail with a video of another server')
diff --git a/server/tests/api/redundancy/redundancy.ts b/server/tests/api/redundancy/redundancy.ts
index c5037a541..7cfcf70e1 100644
--- a/server/tests/api/redundancy/redundancy.ts
+++ b/server/tests/api/redundancy/redundancy.ts
@@ -41,6 +41,7 @@ import { join } from 'path'
41import { VideoRedundancy, VideoRedundancyStrategy, VideoRedundancyStrategyWithManual } from '../../../../shared/models/redundancy' 41import { VideoRedundancy, VideoRedundancyStrategy, VideoRedundancyStrategyWithManual } from '../../../../shared/models/redundancy'
42import { getStats } from '../../../../shared/extra-utils/server/stats' 42import { getStats } from '../../../../shared/extra-utils/server/stats'
43import { ServerStats } from '../../../../shared/models/server/server-stats.model' 43import { ServerStats } from '../../../../shared/models/server/server-stats.model'
44import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
44 45
45const expect = chai.expect 46const expect = chai.expect
46 47
@@ -147,13 +148,13 @@ async function check2Webseeds (videoUUID?: string) {
147 148
148 await makeGetRequest({ 149 await makeGetRequest({
149 url: servers[0].url, 150 url: servers[0].url,
150 statusCodeExpected: 200, 151 statusCodeExpected: HttpStatusCode.OK_200,
151 path: '/static/redundancy/' + `${videoUUID}-${file.resolution.id}.mp4`, 152 path: '/static/redundancy/' + `${videoUUID}-${file.resolution.id}.mp4`,
152 contentType: null 153 contentType: null
153 }) 154 })
154 await makeGetRequest({ 155 await makeGetRequest({
155 url: servers[1].url, 156 url: servers[1].url,
156 statusCodeExpected: 200, 157 statusCodeExpected: HttpStatusCode.OK_200,
157 path: `/static/webseed/${videoUUID}-${file.resolution.id}.mp4`, 158 path: `/static/webseed/${videoUUID}-${file.resolution.id}.mp4`,
158 contentType: null 159 contentType: null
159 }) 160 })
diff --git a/server/tests/api/users/users.ts b/server/tests/api/users/users.ts
index fe83ca041..cd928b980 100644
--- a/server/tests/api/users/users.ts
+++ b/server/tests/api/users/users.ts
@@ -47,6 +47,7 @@ import { follow } from '../../../../shared/extra-utils/server/follows'
47import { logout, serverLogin, setAccessTokensToServers } from '../../../../shared/extra-utils/users/login' 47import { logout, serverLogin, setAccessTokensToServers } from '../../../../shared/extra-utils/users/login'
48import { getMyVideos } from '../../../../shared/extra-utils/videos/videos' 48import { getMyVideos } from '../../../../shared/extra-utils/videos/videos'
49import { UserAdminFlag } from '../../../../shared/models/users/user-flag.model' 49import { UserAdminFlag } from '../../../../shared/models/users/user-flag.model'
50import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
50 51
51const expect = chai.expect 52const expect = chai.expect
52 53
@@ -86,14 +87,14 @@ describe('Test users', function () {
86 87
87 it('Should not login with an invalid client id', async function () { 88 it('Should not login with an invalid client id', async function () {
88 const client = { id: 'client', secret: server.client.secret } 89 const client = { id: 'client', secret: server.client.secret }
89 const res = await login(server.url, client, server.user, 400) 90 const res = await login(server.url, client, server.user, HttpStatusCode.BAD_REQUEST_400)
90 91
91 expect(res.body.error).to.contain('client is invalid') 92 expect(res.body.error).to.contain('client is invalid')
92 }) 93 })
93 94
94 it('Should not login with an invalid client secret', async function () { 95 it('Should not login with an invalid client secret', async function () {
95 const client = { id: server.client.id, secret: 'coucou' } 96 const client = { id: server.client.id, secret: 'coucou' }
96 const res = await login(server.url, client, server.user, 400) 97 const res = await login(server.url, client, server.user, HttpStatusCode.BAD_REQUEST_400)
97 98
98 expect(res.body.error).to.contain('client is invalid') 99 expect(res.body.error).to.contain('client is invalid')
99 }) 100 })
@@ -103,14 +104,14 @@ describe('Test users', function () {
103 104
104 it('Should not login with an invalid username', async function () { 105 it('Should not login with an invalid username', async function () {
105 const user = { username: 'captain crochet', password: server.user.password } 106 const user = { username: 'captain crochet', password: server.user.password }
106 const res = await login(server.url, server.client, user, 400) 107 const res = await login(server.url, server.client, user, HttpStatusCode.BAD_REQUEST_400)
107 108
108 expect(res.body.error).to.contain('credentials are invalid') 109 expect(res.body.error).to.contain('credentials are invalid')
109 }) 110 })
110 111
111 it('Should not login with an invalid password', async function () { 112 it('Should not login with an invalid password', async function () {
112 const user = { username: server.user.username, password: 'mew_three' } 113 const user = { username: server.user.username, password: 'mew_three' }
113 const res = await login(server.url, server.client, user, 400) 114 const res = await login(server.url, server.client, user, HttpStatusCode.BAD_REQUEST_400)
114 115
115 expect(res.body.error).to.contain('credentials are invalid') 116 expect(res.body.error).to.contain('credentials are invalid')
116 }) 117 })
@@ -119,31 +120,31 @@ describe('Test users', function () {
119 accessToken = 'my_super_token' 120 accessToken = 'my_super_token'
120 121
121 const videoAttributes = {} 122 const videoAttributes = {}
122 await uploadVideo(server.url, accessToken, videoAttributes, 401) 123 await uploadVideo(server.url, accessToken, videoAttributes, HttpStatusCode.UNAUTHORIZED_401)
123 }) 124 })
124 125
125 it('Should not be able to follow', async function () { 126 it('Should not be able to follow', async function () {
126 accessToken = 'my_super_token' 127 accessToken = 'my_super_token'
127 await follow(server.url, [ 'http://example.com' ], accessToken, 401) 128 await follow(server.url, [ 'http://example.com' ], accessToken, HttpStatusCode.UNAUTHORIZED_401)
128 }) 129 })
129 130
130 it('Should not be able to unfollow') 131 it('Should not be able to unfollow')
131 132
132 it('Should be able to login', async function () { 133 it('Should be able to login', async function () {
133 const res = await login(server.url, server.client, server.user, 200) 134 const res = await login(server.url, server.client, server.user, HttpStatusCode.OK_200)
134 135
135 accessToken = res.body.access_token 136 accessToken = res.body.access_token
136 }) 137 })
137 138
138 it('Should be able to login with an insensitive username', async function () { 139 it('Should be able to login with an insensitive username', async function () {
139 const user = { username: 'RoOt', password: server.user.password } 140 const user = { username: 'RoOt', password: server.user.password }
140 await login(server.url, server.client, user, 200) 141 await login(server.url, server.client, user, HttpStatusCode.OK_200)
141 142
142 const user2 = { username: 'rOoT', password: server.user.password } 143 const user2 = { username: 'rOoT', password: server.user.password }
143 await login(server.url, server.client, user2, 200) 144 await login(server.url, server.client, user2, HttpStatusCode.OK_200)
144 145
145 const user3 = { username: 'ROOt', password: server.user.password } 146 const user3 = { username: 'ROOt', password: server.user.password }
146 await login(server.url, server.client, user3, 200) 147 await login(server.url, server.client, user3, HttpStatusCode.OK_200)
147 }) 148 })
148 }) 149 })
149 150
@@ -179,7 +180,7 @@ describe('Test users', function () {
179 it('Should retrieve ratings list', async function () { 180 it('Should retrieve ratings list', async function () {
180 await rateVideo(server.url, accessToken, videoId, 'like') 181 await rateVideo(server.url, accessToken, videoId, 'like')
181 182
182 const res = await getAccountRatings(server.url, server.user.username, server.accessToken, null, 200) 183 const res = await getAccountRatings(server.url, server.user.username, server.accessToken, null, HttpStatusCode.OK_200)
183 const ratings = res.body 184 const ratings = res.body
184 185
185 expect(ratings.total).to.equal(1) 186 expect(ratings.total).to.equal(1)
@@ -204,7 +205,7 @@ describe('Test users', function () {
204 205
205 describe('Remove video', function () { 206 describe('Remove video', function () {
206 it('Should not be able to remove the video with an incorrect token', async function () { 207 it('Should not be able to remove the video with an incorrect token', async function () {
207 await removeVideo(server.url, 'bad_token', videoId, 401) 208 await removeVideo(server.url, 'bad_token', videoId, HttpStatusCode.UNAUTHORIZED_401)
208 }) 209 })
209 210
210 it('Should not be able to remove the video with the token of another account') 211 it('Should not be able to remove the video with the token of another account')
@@ -220,11 +221,11 @@ describe('Test users', function () {
220 }) 221 })
221 222
222 it('Should not be able to get the user information', async function () { 223 it('Should not be able to get the user information', async function () {
223 await getMyUserInformation(server.url, server.accessToken, 401) 224 await getMyUserInformation(server.url, server.accessToken, HttpStatusCode.UNAUTHORIZED_401)
224 }) 225 })
225 226
226 it('Should not be able to upload a video', async function () { 227 it('Should not be able to upload a video', async function () {
227 await uploadVideo(server.url, server.accessToken, { name: 'video' }, 401) 228 await uploadVideo(server.url, server.accessToken, { name: 'video' }, HttpStatusCode.UNAUTHORIZED_401)
228 }) 229 })
229 230
230 it('Should not be able to rate a video', async function () { 231 it('Should not be able to rate a video', async function () {
@@ -238,7 +239,7 @@ describe('Test users', function () {
238 path: path + videoId, 239 path: path + videoId,
239 token: 'wrong token', 240 token: 'wrong token',
240 fields: data, 241 fields: data,
241 statusCodeExpected: 401 242 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401
242 } 243 }
243 await makePutBodyRequest(options) 244 await makePutBodyRequest(options)
244 }) 245 })
@@ -534,7 +535,7 @@ describe('Test users', function () {
534 }) 535 })
535 user.password = 'new password' 536 user.password = 'new password'
536 537
537 await userLogin(server, user, 200) 538 await userLogin(server, user, HttpStatusCode.OK_200)
538 }) 539 })
539 540
540 it('Should be able to change the NSFW display attribute', async function () { 541 it('Should be able to change the NSFW display attribute', async function () {
@@ -732,7 +733,7 @@ describe('Test users', function () {
732 }) 733 })
733 734
734 it('Should have removed the user token', async function () { 735 it('Should have removed the user token', async function () {
735 await getMyUserVideoQuotaUsed(server.url, accessTokenUser, 401) 736 await getMyUserVideoQuotaUsed(server.url, accessTokenUser, HttpStatusCode.UNAUTHORIZED_401)
736 737
737 accessTokenUser = await userLogin(server, user) 738 accessTokenUser = await userLogin(server, user)
738 }) 739 })
@@ -745,9 +746,9 @@ describe('Test users', function () {
745 password: 'password updated' 746 password: 'password updated'
746 }) 747 })
747 748
748 await getMyUserVideoQuotaUsed(server.url, accessTokenUser, 401) 749 await getMyUserVideoQuotaUsed(server.url, accessTokenUser, HttpStatusCode.UNAUTHORIZED_401)
749 750
750 await userLogin(server, user, 400) 751 await userLogin(server, user, HttpStatusCode.BAD_REQUEST_400)
751 752
752 user.password = 'password updated' 753 user.password = 'password updated'
753 accessTokenUser = await userLogin(server, user) 754 accessTokenUser = await userLogin(server, user)
@@ -766,7 +767,7 @@ describe('Test users', function () {
766 }) 767 })
767 768
768 it('Should not be able to login with this user', async function () { 769 it('Should not be able to login with this user', async function () {
769 await userLogin(server, user, 400) 770 await userLogin(server, user, HttpStatusCode.BAD_REQUEST_400)
770 }) 771 })
771 772
772 it('Should not have videos of this user', async function () { 773 it('Should not have videos of this user', async function () {
@@ -852,11 +853,11 @@ describe('Test users', function () {
852 853
853 user16AccessToken = await userLogin(server, user16) 854 user16AccessToken = await userLogin(server, user16)
854 855
855 await getMyUserInformation(server.url, user16AccessToken, 200) 856 await getMyUserInformation(server.url, user16AccessToken, HttpStatusCode.OK_200)
856 await blockUser(server.url, user16Id, server.accessToken) 857 await blockUser(server.url, user16Id, server.accessToken)
857 858
858 await getMyUserInformation(server.url, user16AccessToken, 401) 859 await getMyUserInformation(server.url, user16AccessToken, HttpStatusCode.UNAUTHORIZED_401)
859 await userLogin(server, user16, 400) 860 await userLogin(server, user16, HttpStatusCode.BAD_REQUEST_400)
860 }) 861 })
861 862
862 it('Should search user by banned status', async function () { 863 it('Should search user by banned status', async function () {
@@ -884,7 +885,7 @@ describe('Test users', function () {
884 it('Should unblock a user', async function () { 885 it('Should unblock a user', async function () {
885 await unblockUser(server.url, user16Id, server.accessToken) 886 await unblockUser(server.url, user16Id, server.accessToken)
886 user16AccessToken = await userLogin(server, user16) 887 user16AccessToken = await userLogin(server, user16)
887 await getMyUserInformation(server.url, user16AccessToken, 200) 888 await getMyUserInformation(server.url, user16AccessToken, HttpStatusCode.OK_200)
888 }) 889 })
889 }) 890 })
890 891
diff --git a/server/tests/api/videos/video-transcoder.ts b/server/tests/api/videos/video-transcoder.ts
index f9500d617..f88c59f0d 100644
--- a/server/tests/api/videos/video-transcoder.ts
+++ b/server/tests/api/videos/video-transcoder.ts
@@ -37,6 +37,7 @@ import {
37 getVideoFileFPS, 37 getVideoFileFPS,
38 getVideoFileResolution 38 getVideoFileResolution
39} from '../../../helpers/ffprobe-utils' 39} from '../../../helpers/ffprobe-utils'
40import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
40 41
41const expect = chai.expect 42const expect = chai.expect
42 43
@@ -280,7 +281,7 @@ describe('Test video transcoding', function () {
280 expect(videoToFindInList).to.be.undefined 281 expect(videoToFindInList).to.be.undefined
281 282
282 // Server 1 should not have the video yet 283 // Server 1 should not have the video yet
283 await getVideo(servers[0].url, videoId, 404) 284 await getVideo(servers[0].url, videoId, HttpStatusCode.NOT_FOUND_404)
284 } 285 }
285 286
286 await waitJobs(servers) 287 await waitJobs(servers)
@@ -400,8 +401,8 @@ describe('Test video transcoding', function () {
400 401
401 expect(videoDetails.files).to.have.lengthOf(1) 402 expect(videoDetails.files).to.have.lengthOf(1)
402 403
403 await makeGetRequest({ url: server.url, path: videoDetails.thumbnailPath, statusCodeExpected: 200 }) 404 await makeGetRequest({ url: server.url, path: videoDetails.thumbnailPath, statusCodeExpected: HttpStatusCode.OK_200 })
404 await makeGetRequest({ url: server.url, path: videoDetails.previewPath, statusCodeExpected: 200 }) 405 await makeGetRequest({ url: server.url, path: videoDetails.previewPath, statusCodeExpected: HttpStatusCode.OK_200 })
405 406
406 const magnetUri = videoDetails.files[0].magnetUri 407 const magnetUri = videoDetails.files[0].magnetUri
407 expect(magnetUri).to.contain('.mp4') 408 expect(magnetUri).to.contain('.mp4')
@@ -425,8 +426,8 @@ describe('Test video transcoding', function () {
425 426
426 expect(videoDetails.files).to.have.lengthOf(1) 427 expect(videoDetails.files).to.have.lengthOf(1)
427 428
428 await makeGetRequest({ url: server.url, path: videoDetails.thumbnailPath, statusCodeExpected: 200 }) 429 await makeGetRequest({ url: server.url, path: videoDetails.thumbnailPath, statusCodeExpected: HttpStatusCode.OK_200 })
429 await makeGetRequest({ url: server.url, path: videoDetails.previewPath, statusCodeExpected: 200 }) 430 await makeGetRequest({ url: server.url, path: videoDetails.previewPath, statusCodeExpected: HttpStatusCode.OK_200 })
430 431
431 const magnetUri = videoDetails.files[0].magnetUri 432 const magnetUri = videoDetails.files[0].magnetUri
432 expect(magnetUri).to.contain('.mp4') 433 expect(magnetUri).to.contain('.mp4')
diff --git a/server/tests/api/videos/videos-filter.ts b/server/tests/api/videos/videos-filter.ts
index 6b9a4b6d4..2961c8e78 100644
--- a/server/tests/api/videos/videos-filter.ts
+++ b/server/tests/api/videos/videos-filter.ts
@@ -15,10 +15,11 @@ import {
15} from '../../../../shared/extra-utils' 15} from '../../../../shared/extra-utils'
16import { Video, VideoPrivacy } from '../../../../shared/models/videos' 16import { Video, VideoPrivacy } from '../../../../shared/models/videos'
17import { UserRole } from '../../../../shared/models/users' 17import { UserRole } from '../../../../shared/models/users'
18import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
18 19
19const expect = chai.expect 20const expect = chai.expect
20 21
21async function getVideosNames (server: ServerInfo, token: string, filter: string, statusCodeExpected = 200) { 22async function getVideosNames (server: ServerInfo, token: string, filter: string, statusCodeExpected = HttpStatusCode.OK_200) {
22 const paths = [ 23 const paths = [
23 '/api/v1/video-channels/root_channel/videos', 24 '/api/v1/video-channels/root_channel/videos',
24 '/api/v1/accounts/root/videos', 25 '/api/v1/accounts/root/videos',
diff --git a/server/tests/cli/prune-storage.ts b/server/tests/cli/prune-storage.ts
index 052a5f91e..591ed217f 100644
--- a/server/tests/cli/prune-storage.ts
+++ b/server/tests/cli/prune-storage.ts
@@ -24,6 +24,7 @@ import { Account, VideoPlaylistPrivacy } from '../../../shared/models'
24import { createFile, readdir } from 'fs-extra' 24import { createFile, readdir } from 'fs-extra'
25import { v4 as uuidv4 } from 'uuid' 25import { v4 as uuidv4 } from 'uuid'
26import { join } from 'path' 26import { join } from 'path'
27import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes'
27 28
28const expect = chai.expect 29const expect = chai.expect
29 30
@@ -98,7 +99,7 @@ describe('Test prune storage scripts', function () {
98 await makeGetRequest({ 99 await makeGetRequest({
99 url: servers[0].url, 100 url: servers[0].url,
100 path: account.avatar.path, 101 path: account.avatar.path,
101 statusCodeExpected: 200 102 statusCodeExpected: HttpStatusCode.OK_200
102 }) 103 })
103 } 104 }
104 105
@@ -108,7 +109,7 @@ describe('Test prune storage scripts', function () {
108 await makeGetRequest({ 109 await makeGetRequest({
109 url: servers[1].url, 110 url: servers[1].url,
110 path: account.avatar.path, 111 path: account.avatar.path,
111 statusCodeExpected: 200 112 statusCodeExpected: HttpStatusCode.OK_200
112 }) 113 })
113 } 114 }
114 115
diff --git a/server/tests/client.ts b/server/tests/client.ts
index 96821eb6f..6dd4b7cf6 100644
--- a/server/tests/client.ts
+++ b/server/tests/client.ts
@@ -22,6 +22,7 @@ import {
22 updateMyUser, 22 updateMyUser,
23 updateVideoChannel 23 updateVideoChannel
24} from '../../shared/extra-utils' 24} from '../../shared/extra-utils'
25import { HttpStatusCode } from '@shared/core-utils/miscs/http-error-codes'
25 26
26const expect = chai.expect 27const expect = chai.expect
27 28
@@ -100,7 +101,7 @@ describe('Test a client controllers', function () {
100 const res = await request(server.url) 101 const res = await request(server.url)
101 .get(path) 102 .get(path)
102 .set('Accept', 'text/html') 103 .set('Accept', 'text/html')
103 .expect(200) 104 .expect(HttpStatusCode.OK_200)
104 105
105 const port = server.port 106 const port = server.port
106 107
@@ -115,7 +116,7 @@ describe('Test a client controllers', function () {
115 const res = await request(server.url) 116 const res = await request(server.url)
116 .get('/videos/watch/playlist/' + playlistUUID) 117 .get('/videos/watch/playlist/' + playlistUUID)
117 .set('Accept', 'text/html') 118 .set('Accept', 'text/html')
118 .expect(200) 119 .expect(HttpStatusCode.OK_200)
119 120
120 const port = server.port 121 const port = server.port
121 122
@@ -133,7 +134,7 @@ describe('Test a client controllers', function () {
133 const res = await request(server.url) 134 const res = await request(server.url)
134 .get('/accounts/' + server.user.username) 135 .get('/accounts/' + server.user.username)
135 .set('Accept', 'text/html') 136 .set('Accept', 'text/html')
136 .expect(200) 137 .expect(HttpStatusCode.OK_200)
137 138
138 expect(res.text).to.contain(`<meta property="og:title" content="${account.displayName}" />`) 139 expect(res.text).to.contain(`<meta property="og:title" content="${account.displayName}" />`)
139 expect(res.text).to.contain(`<meta property="og:description" content="${account.description}" />`) 140 expect(res.text).to.contain(`<meta property="og:description" content="${account.description}" />`)
@@ -145,7 +146,7 @@ describe('Test a client controllers', function () {
145 const res = await request(server.url) 146 const res = await request(server.url)
146 .get('/video-channels/' + server.videoChannel.name) 147 .get('/video-channels/' + server.videoChannel.name)
147 .set('Accept', 'text/html') 148 .set('Accept', 'text/html')
148 .expect(200) 149 .expect(HttpStatusCode.OK_200)
149 150
150 expect(res.text).to.contain(`<meta property="og:title" content="${server.videoChannel.displayName}" />`) 151 expect(res.text).to.contain(`<meta property="og:title" content="${server.videoChannel.displayName}" />`)
151 expect(res.text).to.contain(`<meta property="og:description" content="${channelDescription}" />`) 152 expect(res.text).to.contain(`<meta property="og:description" content="${channelDescription}" />`)
@@ -157,7 +158,7 @@ describe('Test a client controllers', function () {
157 const res = await request(server.url) 158 const res = await request(server.url)
158 .get('/videos/watch/' + server.video.id) 159 .get('/videos/watch/' + server.video.id)
159 .set('Accept', 'text/html') 160 .set('Accept', 'text/html')
160 .expect(200) 161 .expect(HttpStatusCode.OK_200)
161 162
162 expect(res.text).to.contain(`<meta property="og:title" content="${videoName}" />`) 163 expect(res.text).to.contain(`<meta property="og:title" content="${videoName}" />`)
163 expect(res.text).to.contain(`<meta property="og:description" content="${videoDescription}" />`) 164 expect(res.text).to.contain(`<meta property="og:description" content="${videoDescription}" />`)
@@ -169,7 +170,7 @@ describe('Test a client controllers', function () {
169 const res = await request(server.url) 170 const res = await request(server.url)
170 .get('/videos/watch/' + server.video.uuid) 171 .get('/videos/watch/' + server.video.uuid)
171 .set('Accept', 'text/html') 172 .set('Accept', 'text/html')
172 .expect(200) 173 .expect(HttpStatusCode.OK_200)
173 174
174 expect(res.text).to.contain(`<meta property="og:title" content="${videoName}" />`) 175 expect(res.text).to.contain(`<meta property="og:title" content="${videoName}" />`)
175 expect(res.text).to.contain(`<meta property="og:description" content="${videoDescription}" />`) 176 expect(res.text).to.contain(`<meta property="og:description" content="${videoDescription}" />`)
@@ -181,7 +182,7 @@ describe('Test a client controllers', function () {
181 const res = await request(server.url) 182 const res = await request(server.url)
182 .get('/videos/watch/playlist/' + playlistUUID) 183 .get('/videos/watch/playlist/' + playlistUUID)
183 .set('Accept', 'text/html') 184 .set('Accept', 'text/html')
184 .expect(200) 185 .expect(HttpStatusCode.OK_200)
185 186
186 expect(res.text).to.contain(`<meta property="og:title" content="${playlistName}" />`) 187 expect(res.text).to.contain(`<meta property="og:title" content="${playlistName}" />`)
187 expect(res.text).to.contain(`<meta property="og:description" content="${playlistDescription}" />`) 188 expect(res.text).to.contain(`<meta property="og:description" content="${playlistDescription}" />`)
@@ -196,7 +197,7 @@ describe('Test a client controllers', function () {
196 const res = await request(server.url) 197 const res = await request(server.url)
197 .get('/videos/watch/' + server.video.uuid) 198 .get('/videos/watch/' + server.video.uuid)
198 .set('Accept', 'text/html') 199 .set('Accept', 'text/html')
199 .expect(200) 200 .expect(HttpStatusCode.OK_200)
200 201
201 expect(res.text).to.contain('<meta property="twitter:card" content="summary_large_image" />') 202 expect(res.text).to.contain('<meta property="twitter:card" content="summary_large_image" />')
202 expect(res.text).to.contain('<meta property="twitter:site" content="@Chocobozzz" />') 203 expect(res.text).to.contain('<meta property="twitter:site" content="@Chocobozzz" />')
@@ -208,7 +209,7 @@ describe('Test a client controllers', function () {
208 const res = await request(server.url) 209 const res = await request(server.url)
209 .get('/videos/watch/playlist/' + playlistUUID) 210 .get('/videos/watch/playlist/' + playlistUUID)
210 .set('Accept', 'text/html') 211 .set('Accept', 'text/html')
211 .expect(200) 212 .expect(HttpStatusCode.OK_200)
212 213
213 expect(res.text).to.contain('<meta property="twitter:card" content="summary" />') 214 expect(res.text).to.contain('<meta property="twitter:card" content="summary" />')
214 expect(res.text).to.contain('<meta property="twitter:site" content="@Chocobozzz" />') 215 expect(res.text).to.contain('<meta property="twitter:site" content="@Chocobozzz" />')
@@ -220,7 +221,7 @@ describe('Test a client controllers', function () {
220 const res = await request(server.url) 221 const res = await request(server.url)
221 .get('/accounts/' + account.name) 222 .get('/accounts/' + account.name)
222 .set('Accept', 'text/html') 223 .set('Accept', 'text/html')
223 .expect(200) 224 .expect(HttpStatusCode.OK_200)
224 225
225 expect(res.text).to.contain('<meta property="twitter:card" content="summary" />') 226 expect(res.text).to.contain('<meta property="twitter:card" content="summary" />')
226 expect(res.text).to.contain('<meta property="twitter:site" content="@Chocobozzz" />') 227 expect(res.text).to.contain('<meta property="twitter:site" content="@Chocobozzz" />')
@@ -232,7 +233,7 @@ describe('Test a client controllers', function () {
232 const res = await request(server.url) 233 const res = await request(server.url)
233 .get('/video-channels/' + server.videoChannel.name) 234 .get('/video-channels/' + server.videoChannel.name)
234 .set('Accept', 'text/html') 235 .set('Accept', 'text/html')
235 .expect(200) 236 .expect(HttpStatusCode.OK_200)
236 237
237 expect(res.text).to.contain('<meta property="twitter:card" content="summary" />') 238 expect(res.text).to.contain('<meta property="twitter:card" content="summary" />')
238 expect(res.text).to.contain('<meta property="twitter:site" content="@Chocobozzz" />') 239 expect(res.text).to.contain('<meta property="twitter:site" content="@Chocobozzz" />')
@@ -252,7 +253,7 @@ describe('Test a client controllers', function () {
252 const resVideoRequest = await request(server.url) 253 const resVideoRequest = await request(server.url)
253 .get('/videos/watch/' + server.video.uuid) 254 .get('/videos/watch/' + server.video.uuid)
254 .set('Accept', 'text/html') 255 .set('Accept', 'text/html')
255 .expect(200) 256 .expect(HttpStatusCode.OK_200)
256 257
257 expect(resVideoRequest.text).to.contain('<meta property="twitter:card" content="player" />') 258 expect(resVideoRequest.text).to.contain('<meta property="twitter:card" content="player" />')
258 expect(resVideoRequest.text).to.contain('<meta property="twitter:site" content="@Kuja" />') 259 expect(resVideoRequest.text).to.contain('<meta property="twitter:site" content="@Kuja" />')
@@ -260,7 +261,7 @@ describe('Test a client controllers', function () {
260 const resVideoPlaylistRequest = await request(server.url) 261 const resVideoPlaylistRequest = await request(server.url)
261 .get('/videos/watch/playlist/' + playlistUUID) 262 .get('/videos/watch/playlist/' + playlistUUID)
262 .set('Accept', 'text/html') 263 .set('Accept', 'text/html')
263 .expect(200) 264 .expect(HttpStatusCode.OK_200)
264 265
265 expect(resVideoPlaylistRequest.text).to.contain('<meta property="twitter:card" content="player" />') 266 expect(resVideoPlaylistRequest.text).to.contain('<meta property="twitter:card" content="player" />')
266 expect(resVideoPlaylistRequest.text).to.contain('<meta property="twitter:site" content="@Kuja" />') 267 expect(resVideoPlaylistRequest.text).to.contain('<meta property="twitter:site" content="@Kuja" />')
@@ -268,7 +269,7 @@ describe('Test a client controllers', function () {
268 const resAccountRequest = await request(server.url) 269 const resAccountRequest = await request(server.url)
269 .get('/accounts/' + account.name) 270 .get('/accounts/' + account.name)
270 .set('Accept', 'text/html') 271 .set('Accept', 'text/html')
271 .expect(200) 272 .expect(HttpStatusCode.OK_200)
272 273
273 expect(resAccountRequest.text).to.contain('<meta property="twitter:card" content="summary" />') 274 expect(resAccountRequest.text).to.contain('<meta property="twitter:card" content="summary" />')
274 expect(resAccountRequest.text).to.contain('<meta property="twitter:site" content="@Kuja" />') 275 expect(resAccountRequest.text).to.contain('<meta property="twitter:site" content="@Kuja" />')
@@ -276,7 +277,7 @@ describe('Test a client controllers', function () {
276 const resChannelRequest = await request(server.url) 277 const resChannelRequest = await request(server.url)
277 .get('/video-channels/' + server.videoChannel.name) 278 .get('/video-channels/' + server.videoChannel.name)
278 .set('Accept', 'text/html') 279 .set('Accept', 'text/html')
279 .expect(200) 280 .expect(HttpStatusCode.OK_200)
280 281
281 expect(resChannelRequest.text).to.contain('<meta property="twitter:card" content="summary" />') 282 expect(resChannelRequest.text).to.contain('<meta property="twitter:card" content="summary" />')
282 expect(resChannelRequest.text).to.contain('<meta property="twitter:site" content="@Kuja" />') 283 expect(resChannelRequest.text).to.contain('<meta property="twitter:site" content="@Kuja" />')
diff --git a/server/tests/external-plugins/auto-mute.ts b/server/tests/external-plugins/auto-mute.ts
index 8ead34a2b..687f56e98 100644
--- a/server/tests/external-plugins/auto-mute.ts
+++ b/server/tests/external-plugins/auto-mute.ts
@@ -25,6 +25,7 @@ import {
25 reRunServer, 25 reRunServer,
26 ServerInfo 26 ServerInfo
27} from '../../../shared/extra-utils/server/servers' 27} from '../../../shared/extra-utils/server/servers'
28import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes'
28 29
29describe('Official plugin auto-mute', function () { 30describe('Official plugin auto-mute', function () {
30 const autoMuteListPath = '/plugins/auto-mute/router/api/v1/mute-list' 31 const autoMuteListPath = '/plugins/auto-mute/router/api/v1/mute-list'
@@ -178,7 +179,7 @@ describe('Official plugin auto-mute', function () {
178 await makeGetRequest({ 179 await makeGetRequest({
179 url: servers[0].url, 180 url: servers[0].url,
180 path: '/plugins/auto-mute/router/api/v1/mute-list', 181 path: '/plugins/auto-mute/router/api/v1/mute-list',
181 statusCodeExpected: 403 182 statusCodeExpected: HttpStatusCode.FORBIDDEN_403
182 }) 183 })
183 }) 184 })
184 185
@@ -197,7 +198,7 @@ describe('Official plugin auto-mute', function () {
197 await makeGetRequest({ 198 await makeGetRequest({
198 url: servers[0].url, 199 url: servers[0].url,
199 path: '/plugins/auto-mute/router/api/v1/mute-list', 200 path: '/plugins/auto-mute/router/api/v1/mute-list',
200 statusCodeExpected: 200 201 statusCodeExpected: HttpStatusCode.OK_200
201 }) 202 })
202 }) 203 })
203 204
@@ -221,7 +222,7 @@ describe('Official plugin auto-mute', function () {
221 const res = await makeGetRequest({ 222 const res = await makeGetRequest({
222 url: servers[0].url, 223 url: servers[0].url,
223 path: '/plugins/auto-mute/router/api/v1/mute-list', 224 path: '/plugins/auto-mute/router/api/v1/mute-list',
224 statusCodeExpected: 200 225 statusCodeExpected: HttpStatusCode.OK_200
225 }) 226 })
226 227
227 const data = res.body.data 228 const data = res.body.data
diff --git a/server/tests/misc-endpoints.ts b/server/tests/misc-endpoints.ts
index 3d0224323..698d83328 100644
--- a/server/tests/misc-endpoints.ts
+++ b/server/tests/misc-endpoints.ts
@@ -13,6 +13,7 @@ import {
13 uploadVideo 13 uploadVideo
14} from '../../shared/extra-utils' 14} from '../../shared/extra-utils'
15import { VideoPrivacy } from '../../shared/models/videos' 15import { VideoPrivacy } from '../../shared/models/videos'
16import { HttpStatusCode } from '@shared/core-utils'
16 17
17const expect = chai.expect 18const expect = chai.expect
18 19
@@ -32,7 +33,7 @@ describe('Test misc endpoints', function () {
32 const res = await makeGetRequest({ 33 const res = await makeGetRequest({
33 url: server.url, 34 url: server.url,
34 path: '/.well-known/security.txt', 35 path: '/.well-known/security.txt',
35 statusCodeExpected: 200 36 statusCodeExpected: HttpStatusCode.OK_200
36 }) 37 })
37 38
38 expect(res.text).to.contain('security issue') 39 expect(res.text).to.contain('security issue')
@@ -42,7 +43,7 @@ describe('Test misc endpoints', function () {
42 const res = await makeGetRequest({ 43 const res = await makeGetRequest({
43 url: server.url, 44 url: server.url,
44 path: '/.well-known/nodeinfo', 45 path: '/.well-known/nodeinfo',
45 statusCodeExpected: 200 46 statusCodeExpected: HttpStatusCode.OK_200
46 }) 47 })
47 48
48 expect(res.body.links).to.be.an('array') 49 expect(res.body.links).to.be.an('array')
@@ -54,7 +55,7 @@ describe('Test misc endpoints', function () {
54 const res = await makeGetRequest({ 55 const res = await makeGetRequest({
55 url: server.url, 56 url: server.url,
56 path: '/.well-known/dnt-policy.txt', 57 path: '/.well-known/dnt-policy.txt',
57 statusCodeExpected: 200 58 statusCodeExpected: HttpStatusCode.OK_200
58 }) 59 })
59 60
60 expect(res.text).to.contain('http://www.w3.org/TR/tracking-dnt') 61 expect(res.text).to.contain('http://www.w3.org/TR/tracking-dnt')
@@ -64,7 +65,7 @@ describe('Test misc endpoints', function () {
64 const res = await makeGetRequest({ 65 const res = await makeGetRequest({
65 url: server.url, 66 url: server.url,
66 path: '/.well-known/dnt', 67 path: '/.well-known/dnt',
67 statusCodeExpected: 200 68 statusCodeExpected: HttpStatusCode.OK_200
68 }) 69 })
69 70
70 expect(res.body.tracking).to.equal('N') 71 expect(res.body.tracking).to.equal('N')
@@ -74,7 +75,7 @@ describe('Test misc endpoints', function () {
74 const res = await makeGetRequest({ 75 const res = await makeGetRequest({
75 url: server.url, 76 url: server.url,
76 path: '/.well-known/change-password', 77 path: '/.well-known/change-password',
77 statusCodeExpected: 302 78 statusCodeExpected: HttpStatusCode.FOUND_302
78 }) 79 })
79 80
80 expect(res.header.location).to.equal('/my-account/settings') 81 expect(res.header.location).to.equal('/my-account/settings')
@@ -87,7 +88,7 @@ describe('Test misc endpoints', function () {
87 const res = await makeGetRequest({ 88 const res = await makeGetRequest({
88 url: server.url, 89 url: server.url,
89 path: '/robots.txt', 90 path: '/robots.txt',
90 statusCodeExpected: 200 91 statusCodeExpected: HttpStatusCode.OK_200
91 }) 92 })
92 93
93 expect(res.text).to.contain('User-agent') 94 expect(res.text).to.contain('User-agent')
@@ -97,7 +98,7 @@ describe('Test misc endpoints', function () {
97 await makeGetRequest({ 98 await makeGetRequest({
98 url: server.url, 99 url: server.url,
99 path: '/security.txt', 100 path: '/security.txt',
100 statusCodeExpected: 301 101 statusCodeExpected: HttpStatusCode.MOVED_PERMANENTLY_301
101 }) 102 })
102 }) 103 })
103 104
@@ -105,7 +106,7 @@ describe('Test misc endpoints', function () {
105 const res = await makeGetRequest({ 106 const res = await makeGetRequest({
106 url: server.url, 107 url: server.url,
107 path: '/nodeinfo/2.0.json', 108 path: '/nodeinfo/2.0.json',
108 statusCodeExpected: 200 109 statusCodeExpected: HttpStatusCode.OK_200
109 }) 110 })
110 111
111 expect(res.body.software.name).to.equal('peertube') 112 expect(res.body.software.name).to.equal('peertube')
@@ -118,7 +119,7 @@ describe('Test misc endpoints', function () {
118 const res = await makeGetRequest({ 119 const res = await makeGetRequest({
119 url: server.url, 120 url: server.url,
120 path: '/sitemap.xml', 121 path: '/sitemap.xml',
121 statusCodeExpected: 200 122 statusCodeExpected: HttpStatusCode.OK_200
122 }) 123 })
123 124
124 expect(res.text).to.contain('xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"') 125 expect(res.text).to.contain('xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"')
@@ -129,7 +130,7 @@ describe('Test misc endpoints', function () {
129 const res = await makeGetRequest({ 130 const res = await makeGetRequest({
130 url: server.url, 131 url: server.url,
131 path: '/sitemap.xml', 132 path: '/sitemap.xml',
132 statusCodeExpected: 200 133 statusCodeExpected: HttpStatusCode.OK_200
133 }) 134 })
134 135
135 expect(res.text).to.contain('xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"') 136 expect(res.text).to.contain('xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"')
@@ -152,7 +153,7 @@ describe('Test misc endpoints', function () {
152 const res = await makeGetRequest({ 153 const res = await makeGetRequest({
153 url: server.url, 154 url: server.url,
154 path: '/sitemap.xml?t=1', // avoid using cache 155 path: '/sitemap.xml?t=1', // avoid using cache
155 statusCodeExpected: 200 156 statusCodeExpected: HttpStatusCode.OK_200
156 }) 157 })
157 158
158 expect(res.text).to.contain('xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"') 159 expect(res.text).to.contain('xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"')
diff --git a/server/tests/plugins/external-auth.ts b/server/tests/plugins/external-auth.ts
index 6d907cc51..a1b5e8f5d 100644
--- a/server/tests/plugins/external-auth.ts
+++ b/server/tests/plugins/external-auth.ts
@@ -22,6 +22,7 @@ import {
22 createUser 22 createUser
23} from '../../../shared/extra-utils' 23} from '../../../shared/extra-utils'
24import { cleanupTests, flushAndRunServer, ServerInfo, waitUntilLog } from '../../../shared/extra-utils/server/servers' 24import { cleanupTests, flushAndRunServer, ServerInfo, waitUntilLog } from '../../../shared/extra-utils/server/servers'
25import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes'
25 26
26async function loginExternal (options: { 27async function loginExternal (options: {
27 server: ServerInfo 28 server: ServerInfo
@@ -29,8 +30,8 @@ async function loginExternal (options: {
29 authName: string 30 authName: string
30 username: string 31 username: string
31 query?: any 32 query?: any
32 statusCodeExpected?: number 33 statusCodeExpected?: HttpStatusCode
33 statusCodeExpectedStep2?: number 34 statusCodeExpectedStep2?: HttpStatusCode
34}) { 35}) {
35 const res = await getExternalAuth({ 36 const res = await getExternalAuth({
36 url: options.server.url, 37 url: options.server.url,
@@ -38,10 +39,10 @@ async function loginExternal (options: {
38 npmVersion: '0.0.1', 39 npmVersion: '0.0.1',
39 authName: options.authName, 40 authName: options.authName,
40 query: options.query, 41 query: options.query,
41 statusCodeExpected: options.statusCodeExpected || 302 42 statusCodeExpected: options.statusCodeExpected || HttpStatusCode.FOUND_302
42 }) 43 })
43 44
44 if (res.status !== 302) return 45 if (res.status !== HttpStatusCode.FOUND_302) return
45 46
46 const location = res.header.location 47 const location = res.header.location
47 const { externalAuthToken } = decodeQueryString(location) 48 const { externalAuthToken } = decodeQueryString(location)
@@ -105,7 +106,7 @@ describe('Test external auth plugins', function () {
105 query: { 106 query: {
106 username: 'cyan' 107 username: 'cyan'
107 }, 108 },
108 statusCodeExpected: 302 109 statusCodeExpected: HttpStatusCode.FOUND_302
109 }) 110 })
110 111
111 const location = res.header.location 112 const location = res.header.location
@@ -120,13 +121,13 @@ describe('Test external auth plugins', function () {
120 }) 121 })
121 122
122 it('Should reject auto external login with a missing or invalid token', async function () { 123 it('Should reject auto external login with a missing or invalid token', async function () {
123 await loginUsingExternalToken(server, 'cyan', '', 400) 124 await loginUsingExternalToken(server, 'cyan', '', HttpStatusCode.BAD_REQUEST_400)
124 await loginUsingExternalToken(server, 'cyan', 'blabla', 400) 125 await loginUsingExternalToken(server, 'cyan', 'blabla', HttpStatusCode.BAD_REQUEST_400)
125 }) 126 })
126 127
127 it('Should reject auto external login with a missing or invalid username', async function () { 128 it('Should reject auto external login with a missing or invalid username', async function () {
128 await loginUsingExternalToken(server, '', externalAuthToken, 400) 129 await loginUsingExternalToken(server, '', externalAuthToken, HttpStatusCode.BAD_REQUEST_400)
129 await loginUsingExternalToken(server, '', externalAuthToken, 400) 130 await loginUsingExternalToken(server, '', externalAuthToken, HttpStatusCode.BAD_REQUEST_400)
130 }) 131 })
131 132
132 it('Should reject auto external login with an expired token', async function () { 133 it('Should reject auto external login with an expired token', async function () {
@@ -134,7 +135,7 @@ describe('Test external auth plugins', function () {
134 135
135 await wait(5000) 136 await wait(5000)
136 137
137 await loginUsingExternalToken(server, 'cyan', externalAuthToken, 400) 138 await loginUsingExternalToken(server, 'cyan', externalAuthToken, HttpStatusCode.BAD_REQUEST_400)
138 139
139 await waitUntilLog(server, 'expired external auth token') 140 await waitUntilLog(server, 'expired external auth token')
140 }) 141 })
@@ -202,7 +203,7 @@ describe('Test external auth plugins', function () {
202 } 203 }
203 204
204 { 205 {
205 await refreshToken(server, kefkaRefreshToken, 400) 206 await refreshToken(server, kefkaRefreshToken, HttpStatusCode.BAD_REQUEST_400)
206 } 207 }
207 }) 208 })
208 209
@@ -228,7 +229,7 @@ describe('Test external auth plugins', function () {
228 it('Should have logged out Cyan', async function () { 229 it('Should have logged out Cyan', async function () {
229 await waitUntilLog(server, 'On logout cyan') 230 await waitUntilLog(server, 'On logout cyan')
230 231
231 await getMyUserInformation(server.url, cyanAccessToken, 401) 232 await getMyUserInformation(server.url, cyanAccessToken, HttpStatusCode.UNAUTHORIZED_401)
232 }) 233 })
233 234
234 it('Should login Cyan and keep the old existing profile', async function () { 235 it('Should login Cyan and keep the old existing profile', async function () {
@@ -261,7 +262,7 @@ describe('Test external auth plugins', function () {
261 accessToken: cyanAccessToken, 262 accessToken: cyanAccessToken,
262 email: 'toto@example.com', 263 email: 'toto@example.com',
263 currentPassword: 'toto', 264 currentPassword: 'toto',
264 statusCodeExpected: 400 265 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400
265 }) 266 })
266 }) 267 })
267 268
@@ -270,7 +271,7 @@ describe('Test external auth plugins', function () {
270 271
271 await wait(5000) 272 await wait(5000)
272 273
273 await getMyUserInformation(server.url, kefkaAccessToken, 401) 274 await getMyUserInformation(server.url, kefkaAccessToken, HttpStatusCode.UNAUTHORIZED_401)
274 }) 275 })
275 276
276 it('Should unregister external-auth-2 and do not login existing Kefka', async function () { 277 it('Should unregister external-auth-2 and do not login existing Kefka', async function () {
@@ -281,7 +282,7 @@ describe('Test external auth plugins', function () {
281 settings: { disableKefka: true } 282 settings: { disableKefka: true }
282 }) 283 })
283 284
284 await userLogin(server, { username: 'kefka', password: 'fake' }, 400) 285 await userLogin(server, { username: 'kefka', password: 'fake' }, HttpStatusCode.BAD_REQUEST_400)
285 286
286 await loginExternal({ 287 await loginExternal({
287 server, 288 server,
@@ -291,7 +292,7 @@ describe('Test external auth plugins', function () {
291 username: 'kefka' 292 username: 'kefka'
292 }, 293 },
293 username: 'kefka', 294 username: 'kefka',
294 statusCodeExpected: 404 295 statusCodeExpected: HttpStatusCode.NOT_FOUND_404
295 }) 296 })
296 }) 297 })
297 298
@@ -322,12 +323,12 @@ describe('Test external auth plugins', function () {
322 username: 'cyan' 323 username: 'cyan'
323 }, 324 },
324 username: 'cyan', 325 username: 'cyan',
325 statusCodeExpected: 404 326 statusCodeExpected: HttpStatusCode.NOT_FOUND_404
326 }) 327 })
327 328
328 await userLogin(server, { username: 'cyan', password: null }, 400) 329 await userLogin(server, { username: 'cyan', password: null }, HttpStatusCode.BAD_REQUEST_400)
329 await userLogin(server, { username: 'cyan', password: '' }, 400) 330 await userLogin(server, { username: 'cyan', password: '' }, HttpStatusCode.BAD_REQUEST_400)
330 await userLogin(server, { username: 'cyan', password: 'fake' }, 400) 331 await userLogin(server, { username: 'cyan', password: 'fake' }, HttpStatusCode.BAD_REQUEST_400)
331 }) 332 })
332 333
333 it('Should not login kefka with another plugin', async function () { 334 it('Should not login kefka with another plugin', async function () {
@@ -336,7 +337,7 @@ describe('Test external auth plugins', function () {
336 npmName: 'test-external-auth-two', 337 npmName: 'test-external-auth-two',
337 authName: 'external-auth-4', 338 authName: 'external-auth-4',
338 username: 'kefka2', 339 username: 'kefka2',
339 statusCodeExpectedStep2: 400 340 statusCodeExpectedStep2: HttpStatusCode.BAD_REQUEST_400
340 }) 341 })
341 342
342 await loginExternal({ 343 await loginExternal({
@@ -344,7 +345,7 @@ describe('Test external auth plugins', function () {
344 npmName: 'test-external-auth-two', 345 npmName: 'test-external-auth-two',
345 authName: 'external-auth-4', 346 authName: 'external-auth-4',
346 username: 'kefka', 347 username: 'kefka',
347 statusCodeExpectedStep2: 400 348 statusCodeExpectedStep2: HttpStatusCode.BAD_REQUEST_400
348 }) 349 })
349 }) 350 })
350 351
@@ -361,7 +362,7 @@ describe('Test external auth plugins', function () {
361 npmName: 'test-external-auth-two', 362 npmName: 'test-external-auth-two',
362 authName: 'external-auth-6', 363 authName: 'external-auth-6',
363 username: 'existing_user', 364 username: 'existing_user',
364 statusCodeExpectedStep2: 400 365 statusCodeExpectedStep2: HttpStatusCode.BAD_REQUEST_400
365 }) 366 })
366 }) 367 })
367 368
diff --git a/server/tests/plugins/plugin-helpers.ts b/server/tests/plugins/plugin-helpers.ts
index e76d7917a..c0d95e1e0 100644
--- a/server/tests/plugins/plugin-helpers.ts
+++ b/server/tests/plugins/plugin-helpers.ts
@@ -16,6 +16,7 @@ import {
16} from '../../../shared/extra-utils' 16} from '../../../shared/extra-utils'
17import { cleanupTests, flushAndRunMultipleServers, ServerInfo, waitUntilLog } from '../../../shared/extra-utils/server/servers' 17import { cleanupTests, flushAndRunMultipleServers, ServerInfo, waitUntilLog } from '../../../shared/extra-utils/server/servers'
18import { expect } from 'chai' 18import { expect } from 'chai'
19import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes'
19 20
20function postCommand (server: ServerInfo, command: string, bodyArg?: object) { 21function postCommand (server: ServerInfo, command: string, bodyArg?: object) {
21 const body = { command } 22 const body = { command }
@@ -25,7 +26,7 @@ function postCommand (server: ServerInfo, command: string, bodyArg?: object) {
25 url: server.url, 26 url: server.url,
26 path: '/plugins/test-four/router/commander', 27 path: '/plugins/test-four/router/commander',
27 fields: body, 28 fields: body,
28 statusCodeExpected: 204 29 statusCodeExpected: HttpStatusCode.NO_CONTENT_204
29 }) 30 })
30} 31}
31 32
diff --git a/server/tests/plugins/plugin-router.ts b/server/tests/plugins/plugin-router.ts
index cf4130f4b..9e78568cd 100644
--- a/server/tests/plugins/plugin-router.ts
+++ b/server/tests/plugins/plugin-router.ts
@@ -10,6 +10,7 @@ import {
10 setAccessTokensToServers, uninstallPlugin 10 setAccessTokensToServers, uninstallPlugin
11} from '../../../shared/extra-utils' 11} from '../../../shared/extra-utils'
12import { expect } from 'chai' 12import { expect } from 'chai'
13import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes'
13 14
14describe('Test plugin helpers', function () { 15describe('Test plugin helpers', function () {
15 let server: ServerInfo 16 let server: ServerInfo
@@ -36,7 +37,7 @@ describe('Test plugin helpers', function () {
36 const res = await makeGetRequest({ 37 const res = await makeGetRequest({
37 url: server.url, 38 url: server.url,
38 path: path + 'ping', 39 path: path + 'ping',
39 statusCodeExpected: 200 40 statusCodeExpected: HttpStatusCode.OK_200
40 }) 41 })
41 42
42 expect(res.body.message).to.equal('pong') 43 expect(res.body.message).to.equal('pong')
@@ -55,7 +56,7 @@ describe('Test plugin helpers', function () {
55 url: server.url, 56 url: server.url,
56 path: path + 'form/post/mirror', 57 path: path + 'form/post/mirror',
57 fields: body, 58 fields: body,
58 statusCodeExpected: 200 59 statusCodeExpected: HttpStatusCode.OK_200
59 }) 60 })
60 61
61 expect(res.body).to.deep.equal(body) 62 expect(res.body).to.deep.equal(body)
@@ -73,14 +74,14 @@ describe('Test plugin helpers', function () {
73 await makeGetRequest({ 74 await makeGetRequest({
74 url: server.url, 75 url: server.url,
75 path: path + 'ping', 76 path: path + 'ping',
76 statusCodeExpected: 404 77 statusCodeExpected: HttpStatusCode.NOT_FOUND_404
77 }) 78 })
78 79
79 await makePostBodyRequest({ 80 await makePostBodyRequest({
80 url: server.url, 81 url: server.url,
81 path: path + 'ping', 82 path: path + 'ping',
82 fields: {}, 83 fields: {},
83 statusCodeExpected: 404 84 statusCodeExpected: HttpStatusCode.NOT_FOUND_404
84 }) 85 })
85 } 86 }
86 }) 87 })