aboutsummaryrefslogtreecommitdiffhomepage
path: root/server
diff options
context:
space:
mode:
Diffstat (limited to 'server')
-rw-r--r--server/controllers/api/videos/import.ts2
-rw-r--r--server/helpers/express-utils.ts18
-rw-r--r--server/middlewares/validators/activitypub/activity.ts6
-rw-r--r--server/middlewares/validators/videos/video-live.ts4
-rw-r--r--server/middlewares/validators/videos/videos.ts2
-rw-r--r--server/tests/api/users/users.ts24
6 files changed, 31 insertions, 25 deletions
diff --git a/server/controllers/api/videos/import.ts b/server/controllers/api/videos/import.ts
index 6ee109a8f..42ca59975 100644
--- a/server/controllers/api/videos/import.ts
+++ b/server/controllers/api/videos/import.ts
@@ -335,7 +335,7 @@ async function processTorrentOrAbortRequest (req: express.Request, res: express.
335 cleanUpReqFiles(req) 335 cleanUpReqFiles(req)
336 336
337 res.fail({ 337 res.fail({
338 type: ServerErrorCode.INCORRECT_FILES_IN_TORRENT.toString(), 338 type: ServerErrorCode.INCORRECT_FILES_IN_TORRENT,
339 message: 'Torrents with only 1 file are supported.' 339 message: 'Torrents with only 1 file are supported.'
340 }) 340 })
341 return undefined 341 return undefined
diff --git a/server/helpers/express-utils.ts b/server/helpers/express-utils.ts
index bca59a83c..10a860787 100644
--- a/server/helpers/express-utils.ts
+++ b/server/helpers/express-utils.ts
@@ -129,15 +129,14 @@ function getCountVideos (req: express.Request) {
129// helpers added in server.ts and used in subsequent controllers used 129// helpers added in server.ts and used in subsequent controllers used
130const apiResponseHelpers = (req, res: express.Response, next = null) => { 130const apiResponseHelpers = (req, res: express.Response, next = null) => {
131 res.fail = (options) => { 131 res.fail = (options) => {
132 const { data, status, message, title, type, docs, instance } = { 132 const { data, status = HttpStatusCode.BAD_REQUEST_400, message, title, type, docs = res.docs, instance } = options
133 data: null,
134 ...options,
135 status: options.status || HttpStatusCode.BAD_REQUEST_400
136 }
137 133
138 const extension = new ProblemDocumentExtension({ 134 const extension = new ProblemDocumentExtension({
139 ...data, 135 ...data,
140 docs: docs || res.docs 136 docs,
137 // fields for <= 3.2 compatibility, deprecated
138 error: message,
139 code: type
141 }) 140 })
142 141
143 res.status(status) 142 res.status(status)
@@ -146,12 +145,13 @@ const apiResponseHelpers = (req, res: express.Response, next = null) => {
146 status, 145 status,
147 title, 146 title,
148 instance, 147 instance,
149 type: type && '' + type, 148 // fields intended to replace 'error' and 'code' respectively
150 detail: message 149 detail: message,
150 type: type && 'https://docs.joinpeertube.org/api-rest-reference.html#section/Errors/' + type
151 }, extension)) 151 }, extension))
152 } 152 }
153 153
154 if (next !== null) next() 154 if (next) next()
155} 155}
156 156
157// --------------------------------------------------------------------------- 157// ---------------------------------------------------------------------------
diff --git a/server/middlewares/validators/activitypub/activity.ts b/server/middlewares/validators/activitypub/activity.ts
index 59355e855..cc6acd4b1 100644
--- a/server/middlewares/validators/activitypub/activity.ts
+++ b/server/middlewares/validators/activitypub/activity.ts
@@ -9,16 +9,14 @@ async function activityPubValidator (req: express.Request, res: express.Response
9 9
10 if (!isRootActivityValid(req.body)) { 10 if (!isRootActivityValid(req.body)) {
11 logger.warn('Incorrect activity parameters.', { activity: req.body }) 11 logger.warn('Incorrect activity parameters.', { activity: req.body })
12 return res.status(HttpStatusCode.BAD_REQUEST_400) 12 return res.fail({ message: 'Incorrect activity' })
13 .end()
14 } 13 }
15 14
16 const serverActor = await getServerActor() 15 const serverActor = await getServerActor()
17 const remoteActor = res.locals.signature.actor 16 const remoteActor = res.locals.signature.actor
18 if (serverActor.id === remoteActor.id || remoteActor.serverId === null) { 17 if (serverActor.id === remoteActor.id || remoteActor.serverId === null) {
19 logger.error('Receiving request in INBOX by ourselves!', req.body) 18 logger.error('Receiving request in INBOX by ourselves!', req.body)
20 return res.status(HttpStatusCode.CONFLICT_409) 19 return res.status(HttpStatusCode.CONFLICT_409).end()
21 .end()
22 } 20 }
23 21
24 return next() 22 return next()
diff --git a/server/middlewares/validators/videos/video-live.ts b/server/middlewares/validators/videos/video-live.ts
index 9544fa4f5..0fb864098 100644
--- a/server/middlewares/validators/videos/video-live.ts
+++ b/server/middlewares/validators/videos/video-live.ts
@@ -104,7 +104,7 @@ const videoLiveAddValidator = getCommonVideoEditAttributes().concat([
104 return res.fail({ 104 return res.fail({
105 status: HttpStatusCode.FORBIDDEN_403, 105 status: HttpStatusCode.FORBIDDEN_403,
106 message: 'Cannot create this live because the max instance lives limit is reached.', 106 message: 'Cannot create this live because the max instance lives limit is reached.',
107 type: ServerErrorCode.MAX_INSTANCE_LIVES_LIMIT_REACHED.toString() 107 type: ServerErrorCode.MAX_INSTANCE_LIVES_LIMIT_REACHED
108 }) 108 })
109 } 109 }
110 } 110 }
@@ -117,7 +117,7 @@ const videoLiveAddValidator = getCommonVideoEditAttributes().concat([
117 117
118 return res.fail({ 118 return res.fail({
119 status: HttpStatusCode.FORBIDDEN_403, 119 status: HttpStatusCode.FORBIDDEN_403,
120 type: ServerErrorCode.MAX_USER_LIVES_LIMIT_REACHED.toString(), 120 type: ServerErrorCode.MAX_USER_LIVES_LIMIT_REACHED,
121 message: 'Cannot create this live because the max user lives limit is reached.' 121 message: 'Cannot create this live because the max user lives limit is reached.'
122 }) 122 })
123 } 123 }
diff --git a/server/middlewares/validators/videos/videos.ts b/server/middlewares/validators/videos/videos.ts
index dfd472400..fd0e543f1 100644
--- a/server/middlewares/validators/videos/videos.ts
+++ b/server/middlewares/validators/videos/videos.ts
@@ -253,7 +253,7 @@ async function checkVideoFollowConstraints (req: express.Request, res: express.R
253 return res.fail({ 253 return res.fail({
254 status: HttpStatusCode.FORBIDDEN_403, 254 status: HttpStatusCode.FORBIDDEN_403,
255 message: 'Cannot get this video regarding follow constraints.', 255 message: 'Cannot get this video regarding follow constraints.',
256 type: ServerErrorCode.DOES_NOT_RESPECT_FOLLOW_CONSTRAINTS.toString(), 256 type: ServerErrorCode.DOES_NOT_RESPECT_FOLLOW_CONSTRAINTS,
257 data: { 257 data: {
258 originUrl: video.url 258 originUrl: video.url
259 } 259 }
diff --git a/server/tests/api/users/users.ts b/server/tests/api/users/users.ts
index 363236b62..464c11d34 100644
--- a/server/tests/api/users/users.ts
+++ b/server/tests/api/users/users.ts
@@ -93,16 +93,20 @@ describe('Test users', function () {
93 const client = { id: 'client', secret: server.client.secret } 93 const client = { id: 'client', secret: server.client.secret }
94 const res = await login(server.url, client, server.user, HttpStatusCode.BAD_REQUEST_400) 94 const res = await login(server.url, client, server.user, HttpStatusCode.BAD_REQUEST_400)
95 95
96 expect(res.body.type).to.equal('invalid_client') 96 expect(res.body.code).to.equal('invalid_client')
97 expect(res.body.detail).to.contain('client is invalid') 97 expect(res.body.error).to.contain('client is invalid')
98 expect(res.body.type.startsWith('https://')).to.be.true
99 expect(res.body.type).to.contain('invalid_client')
98 }) 100 })
99 101
100 it('Should not login with an invalid client secret', async function () { 102 it('Should not login with an invalid client secret', async function () {
101 const client = { id: server.client.id, secret: 'coucou' } 103 const client = { id: server.client.id, secret: 'coucou' }
102 const res = await login(server.url, client, server.user, HttpStatusCode.BAD_REQUEST_400) 104 const res = await login(server.url, client, server.user, HttpStatusCode.BAD_REQUEST_400)
103 105
104 expect(res.body.type).to.equal('invalid_client') 106 expect(res.body.code).to.equal('invalid_client')
105 expect(res.body.detail).to.contain('client is invalid') 107 expect(res.body.error).to.contain('client is invalid')
108 expect(res.body.type.startsWith('https://')).to.be.true
109 expect(res.body.type).to.contain('invalid_client')
106 }) 110 })
107 }) 111 })
108 112
@@ -112,16 +116,20 @@ describe('Test users', function () {
112 const user = { username: 'captain crochet', password: server.user.password } 116 const user = { username: 'captain crochet', password: server.user.password }
113 const res = await login(server.url, server.client, user, HttpStatusCode.BAD_REQUEST_400) 117 const res = await login(server.url, server.client, user, HttpStatusCode.BAD_REQUEST_400)
114 118
115 expect(res.body.type).to.equal('invalid_grant') 119 expect(res.body.code).to.equal('invalid_grant')
116 expect(res.body.detail).to.contain('credentials are invalid') 120 expect(res.body.error).to.contain('credentials are invalid')
121 expect(res.body.type.startsWith('https://')).to.be.true
122 expect(res.body.type).to.contain('invalid_grant')
117 }) 123 })
118 124
119 it('Should not login with an invalid password', async function () { 125 it('Should not login with an invalid password', async function () {
120 const user = { username: server.user.username, password: 'mew_three' } 126 const user = { username: server.user.username, password: 'mew_three' }
121 const res = await login(server.url, server.client, user, HttpStatusCode.BAD_REQUEST_400) 127 const res = await login(server.url, server.client, user, HttpStatusCode.BAD_REQUEST_400)
122 128
123 expect(res.body.type).to.equal('invalid_grant') 129 expect(res.body.code).to.equal('invalid_grant')
124 expect(res.body.detail).to.contain('credentials are invalid') 130 expect(res.body.error).to.contain('credentials are invalid')
131 expect(res.body.type.startsWith('https://')).to.be.true
132 expect(res.body.type).to.contain('invalid_grant')
125 }) 133 })
126 134
127 it('Should not be able to upload a video', async function () { 135 it('Should not be able to upload a video', async function () {