aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/api/check-params
diff options
context:
space:
mode:
Diffstat (limited to 'server/tests/api/check-params')
-rw-r--r--server/tests/api/check-params/abuses.ts20
-rw-r--r--server/tests/api/check-params/services.ts16
-rw-r--r--server/tests/api/check-params/video-blacklist.ts42
3 files changed, 43 insertions, 35 deletions
diff --git a/server/tests/api/check-params/abuses.ts b/server/tests/api/check-params/abuses.ts
index 72f2cbd8f..fb9a5fd8b 100644
--- a/server/tests/api/check-params/abuses.ts
+++ b/server/tests/api/check-params/abuses.ts
@@ -41,7 +41,7 @@ describe('Test abuses API validators', function () {
41 userToken = await server.users.generateUserAndToken('user_1') 41 userToken = await server.users.generateUserAndToken('user_1')
42 userToken2 = await server.users.generateUserAndToken('user_2') 42 userToken2 = await server.users.generateUserAndToken('user_2')
43 43
44 server.store.video = await server.videos.upload() 44 server.store.videoCreated = await server.videos.upload()
45 45
46 command = server.abuses 46 command = server.abuses
47 }) 47 })
@@ -223,25 +223,25 @@ describe('Test abuses API validators', function () {
223 }) 223 })
224 224
225 it('Should fail with a non authenticated user', async function () { 225 it('Should fail with a non authenticated user', async function () {
226 const fields = { video: { id: server.store.video.id }, reason: 'my super reason' } 226 const fields = { video: { id: server.store.videoCreated.id }, reason: 'my super reason' }
227 227
228 await makePostBodyRequest({ url: server.url, path, token: 'hello', fields, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) 228 await makePostBodyRequest({ url: server.url, path, token: 'hello', fields, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 })
229 }) 229 })
230 230
231 it('Should fail with a reason too short', async function () { 231 it('Should fail with a reason too short', async function () {
232 const fields = { video: { id: server.store.video.id }, reason: 'h' } 232 const fields = { video: { id: server.store.videoCreated.id }, reason: 'h' }
233 233
234 await makePostBodyRequest({ url: server.url, path, token: userToken, fields }) 234 await makePostBodyRequest({ url: server.url, path, token: userToken, fields })
235 }) 235 })
236 236
237 it('Should fail with a too big reason', async function () { 237 it('Should fail with a too big reason', async function () {
238 const fields = { video: { id: server.store.video.id }, reason: 'super'.repeat(605) } 238 const fields = { video: { id: server.store.videoCreated.id }, reason: 'super'.repeat(605) }
239 239
240 await makePostBodyRequest({ url: server.url, path, token: userToken, fields }) 240 await makePostBodyRequest({ url: server.url, path, token: userToken, fields })
241 }) 241 })
242 242
243 it('Should succeed with the correct parameters (basic)', async function () { 243 it('Should succeed with the correct parameters (basic)', async function () {
244 const fields: AbuseCreate = { video: { id: server.store.video.shortUUID }, reason: 'my super reason' } 244 const fields: AbuseCreate = { video: { id: server.store.videoCreated.shortUUID }, reason: 'my super reason' }
245 245
246 const res = await makePostBodyRequest({ 246 const res = await makePostBodyRequest({
247 url: server.url, 247 url: server.url,
@@ -254,19 +254,19 @@ describe('Test abuses API validators', function () {
254 }) 254 })
255 255
256 it('Should fail with a wrong predefined reason', async function () { 256 it('Should fail with a wrong predefined reason', async function () {
257 const fields = { video: { id: server.store.video.id }, reason: 'my super reason', predefinedReasons: [ 'wrongPredefinedReason' ] } 257 const fields = { video: server.store.videoCreated, reason: 'my super reason', predefinedReasons: [ 'wrongPredefinedReason' ] }
258 258
259 await makePostBodyRequest({ url: server.url, path, token: userToken, fields }) 259 await makePostBodyRequest({ url: server.url, path, token: userToken, fields })
260 }) 260 })
261 261
262 it('Should fail with negative timestamps', async function () { 262 it('Should fail with negative timestamps', async function () {
263 const fields = { video: { id: server.store.video.id, startAt: -1 }, reason: 'my super reason' } 263 const fields = { video: { id: server.store.videoCreated.id, startAt: -1 }, reason: 'my super reason' }
264 264
265 await makePostBodyRequest({ url: server.url, path, token: userToken, fields }) 265 await makePostBodyRequest({ url: server.url, path, token: userToken, fields })
266 }) 266 })
267 267
268 it('Should fail mith misordered startAt/endAt', async function () { 268 it('Should fail mith misordered startAt/endAt', async function () {
269 const fields = { video: { id: server.store.video.id, startAt: 5, endAt: 1 }, reason: 'my super reason' } 269 const fields = { video: { id: server.store.videoCreated.id, startAt: 5, endAt: 1 }, reason: 'my super reason' }
270 270
271 await makePostBodyRequest({ url: server.url, path, token: userToken, fields }) 271 await makePostBodyRequest({ url: server.url, path, token: userToken, fields })
272 }) 272 })
@@ -274,7 +274,7 @@ describe('Test abuses API validators', function () {
274 it('Should succeed with the corret parameters (advanced)', async function () { 274 it('Should succeed with the corret parameters (advanced)', async function () {
275 const fields: AbuseCreate = { 275 const fields: AbuseCreate = {
276 video: { 276 video: {
277 id: server.store.video.id, 277 id: server.store.videoCreated.id,
278 startAt: 1, 278 startAt: 1,
279 endAt: 5 279 endAt: 5
280 }, 280 },
@@ -413,7 +413,7 @@ describe('Test abuses API validators', function () {
413 413
414 await doubleFollow(anotherServer, server) 414 await doubleFollow(anotherServer, server)
415 415
416 const server2VideoId = await anotherServer.videos.getId({ uuid: server.store.video.uuid }) 416 const server2VideoId = await anotherServer.videos.getId({ uuid: server.store.videoCreated.uuid })
417 await anotherServer.abuses.report({ reason: 'remote server', videoId: server2VideoId }) 417 await anotherServer.abuses.report({ reason: 'remote server', videoId: server2VideoId })
418 418
419 await waitJobs([ server, anotherServer ]) 419 await waitJobs([ server, anotherServer ])
diff --git a/server/tests/api/check-params/services.ts b/server/tests/api/check-params/services.ts
index 4c4a5cade..8d795fabc 100644
--- a/server/tests/api/check-params/services.ts
+++ b/server/tests/api/check-params/services.ts
@@ -24,7 +24,7 @@ describe('Test services API validators', function () {
24 await setAccessTokensToServers([ server ]) 24 await setAccessTokensToServers([ server ])
25 await setDefaultVideoChannel([ server ]) 25 await setDefaultVideoChannel([ server ])
26 26
27 server.store.video = await server.videos.upload({ attributes: { name: 'my super name' } }) 27 server.store.videoCreated = await server.videos.upload({ attributes: { name: 'my super name' } })
28 28
29 { 29 {
30 const created = await server.playlists.create({ 30 const created = await server.playlists.create({
@@ -47,7 +47,7 @@ describe('Test services API validators', function () {
47 }) 47 })
48 48
49 it('Should fail with an invalid host', async function () { 49 it('Should fail with an invalid host', async function () {
50 const embedUrl = 'http://hello.com/videos/watch/' + server.store.video.uuid 50 const embedUrl = 'http://hello.com/videos/watch/' + server.store.videoCreated.uuid
51 await checkParamEmbed(server, embedUrl) 51 await checkParamEmbed(server, embedUrl)
52 }) 52 })
53 53
@@ -62,37 +62,37 @@ describe('Test services API validators', function () {
62 }) 62 })
63 63
64 it('Should fail with an invalid path', async function () { 64 it('Should fail with an invalid path', async function () {
65 const embedUrl = `http://localhost:${server.port}/videos/watchs/${server.store.video.uuid}` 65 const embedUrl = `http://localhost:${server.port}/videos/watchs/${server.store.videoCreated.uuid}`
66 66
67 await checkParamEmbed(server, embedUrl) 67 await checkParamEmbed(server, embedUrl)
68 }) 68 })
69 69
70 it('Should fail with an invalid max height', async function () { 70 it('Should fail with an invalid max height', async function () {
71 const embedUrl = `http://localhost:${server.port}/videos/watch/${server.store.video.uuid}` 71 const embedUrl = `http://localhost:${server.port}/videos/watch/${server.store.videoCreated.uuid}`
72 72
73 await checkParamEmbed(server, embedUrl, HttpStatusCode.BAD_REQUEST_400, { maxheight: 'hello' }) 73 await checkParamEmbed(server, embedUrl, HttpStatusCode.BAD_REQUEST_400, { maxheight: 'hello' })
74 }) 74 })
75 75
76 it('Should fail with an invalid max width', async function () { 76 it('Should fail with an invalid max width', async function () {
77 const embedUrl = `http://localhost:${server.port}/videos/watch/${server.store.video.uuid}` 77 const embedUrl = `http://localhost:${server.port}/videos/watch/${server.store.videoCreated.uuid}`
78 78
79 await checkParamEmbed(server, embedUrl, HttpStatusCode.BAD_REQUEST_400, { maxwidth: 'hello' }) 79 await checkParamEmbed(server, embedUrl, HttpStatusCode.BAD_REQUEST_400, { maxwidth: 'hello' })
80 }) 80 })
81 81
82 it('Should fail with an invalid format', async function () { 82 it('Should fail with an invalid format', async function () {
83 const embedUrl = `http://localhost:${server.port}/videos/watch/${server.store.video.uuid}` 83 const embedUrl = `http://localhost:${server.port}/videos/watch/${server.store.videoCreated.uuid}`
84 84
85 await checkParamEmbed(server, embedUrl, HttpStatusCode.BAD_REQUEST_400, { format: 'blabla' }) 85 await checkParamEmbed(server, embedUrl, HttpStatusCode.BAD_REQUEST_400, { format: 'blabla' })
86 }) 86 })
87 87
88 it('Should fail with a non supported format', async function () { 88 it('Should fail with a non supported format', async function () {
89 const embedUrl = `http://localhost:${server.port}/videos/watch/${server.store.video.uuid}` 89 const embedUrl = `http://localhost:${server.port}/videos/watch/${server.store.videoCreated.uuid}`
90 90
91 await checkParamEmbed(server, embedUrl, HttpStatusCode.NOT_IMPLEMENTED_501, { format: 'xml' }) 91 await checkParamEmbed(server, embedUrl, HttpStatusCode.NOT_IMPLEMENTED_501, { format: 'xml' })
92 }) 92 })
93 93
94 it('Should succeed with the correct params with a video', async function () { 94 it('Should succeed with the correct params with a video', async function () {
95 const embedUrl = `http://localhost:${server.port}/videos/watch/${server.store.video.uuid}` 95 const embedUrl = `http://localhost:${server.port}/videos/watch/${server.store.videoCreated.uuid}`
96 const query = { 96 const query = {
97 format: 'json', 97 format: 'json',
98 maxheight: 400, 98 maxheight: 400,
diff --git a/server/tests/api/check-params/video-blacklist.ts b/server/tests/api/check-params/video-blacklist.ts
index d28c6a952..1f926d227 100644
--- a/server/tests/api/check-params/video-blacklist.ts
+++ b/server/tests/api/check-params/video-blacklist.ts
@@ -51,7 +51,7 @@ describe('Test video blacklist API validators', function () {
51 } 51 }
52 52
53 { 53 {
54 servers[0].store.video = await servers[0].videos.upload({ token: userAccessToken1 }) 54 servers[0].store.videoCreated = await servers[0].videos.upload({ token: userAccessToken1 })
55 } 55 }
56 56
57 { 57 {
@@ -73,7 +73,7 @@ describe('Test video blacklist API validators', function () {
73 const basePath = '/api/v1/videos/' 73 const basePath = '/api/v1/videos/'
74 74
75 it('Should fail with nothing', async function () { 75 it('Should fail with nothing', async function () {
76 const path = basePath + servers[0].store.video + '/blacklist' 76 const path = basePath + servers[0].store.videoCreated + '/blacklist'
77 const fields = {} 77 const fields = {}
78 await makePostBodyRequest({ url: servers[0].url, path, token: servers[0].accessToken, fields }) 78 await makePostBodyRequest({ url: servers[0].url, path, token: servers[0].accessToken, fields })
79 }) 79 })
@@ -85,13 +85,13 @@ describe('Test video blacklist API validators', function () {
85 }) 85 })
86 86
87 it('Should fail with a non authenticated user', async function () { 87 it('Should fail with a non authenticated user', async function () {
88 const path = basePath + servers[0].store.video + '/blacklist' 88 const path = basePath + servers[0].store.videoCreated + '/blacklist'
89 const fields = {} 89 const fields = {}
90 await makePostBodyRequest({ url: servers[0].url, path, token: 'hello', fields, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) 90 await makePostBodyRequest({ url: servers[0].url, path, token: 'hello', fields, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 })
91 }) 91 })
92 92
93 it('Should fail with a non admin user', async function () { 93 it('Should fail with a non admin user', async function () {
94 const path = basePath + servers[0].store.video + '/blacklist' 94 const path = basePath + servers[0].store.videoCreated + '/blacklist'
95 const fields = {} 95 const fields = {}
96 await makePostBodyRequest({ 96 await makePostBodyRequest({
97 url: servers[0].url, 97 url: servers[0].url,
@@ -103,7 +103,7 @@ describe('Test video blacklist API validators', function () {
103 }) 103 })
104 104
105 it('Should fail with an invalid reason', async function () { 105 it('Should fail with an invalid reason', async function () {
106 const path = basePath + servers[0].store.video.uuid + '/blacklist' 106 const path = basePath + servers[0].store.videoCreated.uuid + '/blacklist'
107 const fields = { reason: 'a'.repeat(305) } 107 const fields = { reason: 'a'.repeat(305) }
108 108
109 await makePostBodyRequest({ url: servers[0].url, path, token: servers[0].accessToken, fields }) 109 await makePostBodyRequest({ url: servers[0].url, path, token: servers[0].accessToken, fields })
@@ -123,7 +123,7 @@ describe('Test video blacklist API validators', function () {
123 }) 123 })
124 124
125 it('Should succeed with the correct params', async function () { 125 it('Should succeed with the correct params', async function () {
126 const path = basePath + servers[0].store.video.uuid + '/blacklist' 126 const path = basePath + servers[0].store.videoCreated.uuid + '/blacklist'
127 const fields = {} 127 const fields = {}
128 128
129 await makePostBodyRequest({ 129 await makePostBodyRequest({
@@ -158,13 +158,13 @@ describe('Test video blacklist API validators', function () {
158 }) 158 })
159 159
160 it('Should fail with a non authenticated user', async function () { 160 it('Should fail with a non authenticated user', async function () {
161 const path = basePath + servers[0].store.video + '/blacklist' 161 const path = basePath + servers[0].store.videoCreated + '/blacklist'
162 const fields = {} 162 const fields = {}
163 await makePutBodyRequest({ url: servers[0].url, path, token: 'hello', fields, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) 163 await makePutBodyRequest({ url: servers[0].url, path, token: 'hello', fields, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 })
164 }) 164 })
165 165
166 it('Should fail with a non admin user', async function () { 166 it('Should fail with a non admin user', async function () {
167 const path = basePath + servers[0].store.video + '/blacklist' 167 const path = basePath + servers[0].store.videoCreated + '/blacklist'
168 const fields = {} 168 const fields = {}
169 await makePutBodyRequest({ 169 await makePutBodyRequest({
170 url: servers[0].url, 170 url: servers[0].url,
@@ -176,14 +176,14 @@ describe('Test video blacklist API validators', function () {
176 }) 176 })
177 177
178 it('Should fail with an invalid reason', async function () { 178 it('Should fail with an invalid reason', async function () {
179 const path = basePath + servers[0].store.video.uuid + '/blacklist' 179 const path = basePath + servers[0].store.videoCreated.uuid + '/blacklist'
180 const fields = { reason: 'a'.repeat(305) } 180 const fields = { reason: 'a'.repeat(305) }
181 181
182 await makePutBodyRequest({ url: servers[0].url, path, token: servers[0].accessToken, fields }) 182 await makePutBodyRequest({ url: servers[0].url, path, token: servers[0].accessToken, fields })
183 }) 183 })
184 184
185 it('Should succeed with the correct params', async function () { 185 it('Should succeed with the correct params', async function () {
186 const path = basePath + servers[0].store.video.shortUUID + '/blacklist' 186 const path = basePath + servers[0].store.videoCreated.shortUUID + '/blacklist'
187 const fields = { reason: 'hello' } 187 const fields = { reason: 'hello' }
188 188
189 await makePutBodyRequest({ 189 await makePutBodyRequest({
@@ -199,24 +199,24 @@ describe('Test video blacklist API validators', function () {
199 describe('When getting blacklisted video', function () { 199 describe('When getting blacklisted video', function () {
200 200
201 it('Should fail with a non authenticated user', async function () { 201 it('Should fail with a non authenticated user', async function () {
202 await servers[0].videos.get({ id: servers[0].store.video.uuid, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) 202 await servers[0].videos.get({ id: servers[0].store.videoCreated.uuid, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 })
203 }) 203 })
204 204
205 it('Should fail with another user', async function () { 205 it('Should fail with another user', async function () {
206 await servers[0].videos.getWithToken({ 206 await servers[0].videos.getWithToken({
207 token: userAccessToken2, 207 token: userAccessToken2,
208 id: servers[0].store.video.uuid, 208 id: servers[0].store.videoCreated.uuid,
209 expectedStatus: HttpStatusCode.FORBIDDEN_403 209 expectedStatus: HttpStatusCode.FORBIDDEN_403
210 }) 210 })
211 }) 211 })
212 212
213 it('Should succeed with the owner authenticated user', async function () { 213 it('Should succeed with the owner authenticated user', async function () {
214 const video = await servers[0].videos.getWithToken({ token: userAccessToken1, id: servers[0].store.video.uuid }) 214 const video = await servers[0].videos.getWithToken({ token: userAccessToken1, id: servers[0].store.videoCreated.uuid })
215 expect(video.blacklisted).to.be.true 215 expect(video.blacklisted).to.be.true
216 }) 216 })
217 217
218 it('Should succeed with an admin', async function () { 218 it('Should succeed with an admin', async function () {
219 const video = servers[0].store.video 219 const video = servers[0].store.videoCreated
220 220
221 for (const id of [ video.id, video.uuid, video.shortUUID ]) { 221 for (const id of [ video.id, video.uuid, video.shortUUID ]) {
222 const video = await servers[0].videos.getWithToken({ id, expectedStatus: HttpStatusCode.OK_200 }) 222 const video = await servers[0].videos.getWithToken({ id, expectedStatus: HttpStatusCode.OK_200 })
@@ -228,11 +228,19 @@ describe('Test video blacklist API validators', function () {
228 describe('When removing a video in blacklist', function () { 228 describe('When removing a video in blacklist', function () {
229 229
230 it('Should fail with a non authenticated user', async function () { 230 it('Should fail with a non authenticated user', async function () {
231 await command.remove({ token: 'fake token', videoId: servers[0].store.video.uuid, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) 231 await command.remove({
232 token: 'fake token',
233 videoId: servers[0].store.videoCreated.uuid,
234 expectedStatus: HttpStatusCode.UNAUTHORIZED_401
235 })
232 }) 236 })
233 237
234 it('Should fail with a non admin user', async function () { 238 it('Should fail with a non admin user', async function () {
235 await command.remove({ token: userAccessToken2, videoId: servers[0].store.video.uuid, expectedStatus: HttpStatusCode.FORBIDDEN_403 }) 239 await command.remove({
240 token: userAccessToken2,
241 videoId: servers[0].store.videoCreated.uuid,
242 expectedStatus: HttpStatusCode.FORBIDDEN_403
243 })
236 }) 244 })
237 245
238 it('Should fail with an incorrect id', async function () { 246 it('Should fail with an incorrect id', async function () {
@@ -245,7 +253,7 @@ describe('Test video blacklist API validators', function () {
245 }) 253 })
246 254
247 it('Should succeed with the correct params', async function () { 255 it('Should succeed with the correct params', async function () {
248 await command.remove({ videoId: servers[0].store.video.uuid, expectedStatus: HttpStatusCode.NO_CONTENT_204 }) 256 await command.remove({ videoId: servers[0].store.videoCreated.uuid, expectedStatus: HttpStatusCode.NO_CONTENT_204 })
249 }) 257 })
250 }) 258 })
251 259