aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2023-07-26 09:38:03 +0200
committerChocobozzz <me@florianbigard.com>2023-07-26 09:42:44 +0200
commit22e7ffc7810798a0aa34145f2e06e62d6004b253 (patch)
tree09c9f445e82f30683bae38ad185a461ac05e2989
parent93fd6f3b18e1c0009ff6ca9208966ae36af5dafa (diff)
downloadPeerTube-22e7ffc7810798a0aa34145f2e06e62d6004b253.tar.gz
PeerTube-22e7ffc7810798a0aa34145f2e06e62d6004b253.tar.zst
PeerTube-22e7ffc7810798a0aa34145f2e06e62d6004b253.zip
Fix check params tests
-rw-r--r--server/tests/api/check-params/video-passwords.ts4
-rw-r--r--server/tests/api/check-params/videos.ts103
-rw-r--r--server/tests/shared/videos.ts27
3 files changed, 83 insertions, 51 deletions
diff --git a/server/tests/api/check-params/video-passwords.ts b/server/tests/api/check-params/video-passwords.ts
index 4e936b5d2..50b0bacb3 100644
--- a/server/tests/api/check-params/video-passwords.ts
+++ b/server/tests/api/check-params/video-passwords.ts
@@ -106,12 +106,12 @@ describe('Test video passwords validator', function () {
106 } 106 }
107 if (mode === 'uploadLegacy') { 107 if (mode === 'uploadLegacy') {
108 const fields = { ...baseCorrectParams, videoPasswords } 108 const fields = { ...baseCorrectParams, videoPasswords }
109 return checkUploadVideoParam(server, token, { ...fields, ...attaches }, expectedStatus, 'legacy') 109 return checkUploadVideoParam({ server, token, attributes: { ...fields, ...attaches }, expectedStatus, mode: 'legacy' })
110 } 110 }
111 111
112 if (mode === 'uploadResumable') { 112 if (mode === 'uploadResumable') {
113 const fields = { ...baseCorrectParams, videoPasswords } 113 const fields = { ...baseCorrectParams, videoPasswords }
114 return checkUploadVideoParam(server, token, { ...fields, ...attaches }, expectedStatus, 'resumable') 114 return checkUploadVideoParam({ server, token, attributes: { ...fields, ...attaches }, expectedStatus, mode: 'resumable' })
115 } 115 }
116 116
117 if (mode === 'import') { 117 if (mode === 'import') {
diff --git a/server/tests/api/check-params/videos.ts b/server/tests/api/check-params/videos.ts
index 6ee1955a7..f00698fe3 100644
--- a/server/tests/api/check-params/videos.ts
+++ b/server/tests/api/check-params/videos.ts
@@ -208,73 +208,82 @@ describe('Test videos API validator', function () {
208 208
209 function runSuite (mode: 'legacy' | 'resumable') { 209 function runSuite (mode: 'legacy' | 'resumable') {
210 210
211 const baseOptions = () => {
212 return {
213 server,
214 token: server.accessToken,
215 expectedStatus: HttpStatusCode.BAD_REQUEST_400,
216 mode
217 }
218 }
219
211 it('Should fail with nothing', async function () { 220 it('Should fail with nothing', async function () {
212 const fields = {} 221 const fields = {}
213 const attaches = {} 222 const attaches = {}
214 await checkUploadVideoParam(server, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode) 223 await checkUploadVideoParam({ ...baseOptions(), attributes: { ...fields, ...attaches } })
215 }) 224 })
216 225
217 it('Should fail without name', async function () { 226 it('Should fail without name', async function () {
218 const fields = omit(baseCorrectParams, [ 'name' ]) 227 const fields = omit(baseCorrectParams, [ 'name' ])
219 const attaches = baseCorrectAttaches 228 const attaches = baseCorrectAttaches
220 229
221 await checkUploadVideoParam(server, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode) 230 await checkUploadVideoParam({ ...baseOptions(), attributes: { ...fields, ...attaches } })
222 }) 231 })
223 232
224 it('Should fail with a long name', async function () { 233 it('Should fail with a long name', async function () {
225 const fields = { ...baseCorrectParams, name: 'super'.repeat(65) } 234 const fields = { ...baseCorrectParams, name: 'super'.repeat(65) }
226 const attaches = baseCorrectAttaches 235 const attaches = baseCorrectAttaches
227 236
228 await checkUploadVideoParam(server, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode) 237 await checkUploadVideoParam({ ...baseOptions(), attributes: { ...fields, ...attaches } })
229 }) 238 })
230 239
231 it('Should fail with a bad category', async function () { 240 it('Should fail with a bad category', async function () {
232 const fields = { ...baseCorrectParams, category: 125 } 241 const fields = { ...baseCorrectParams, category: 125 }
233 const attaches = baseCorrectAttaches 242 const attaches = baseCorrectAttaches
234 243
235 await checkUploadVideoParam(server, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode) 244 await checkUploadVideoParam({ ...baseOptions(), attributes: { ...fields, ...attaches } })
236 }) 245 })
237 246
238 it('Should fail with a bad licence', async function () { 247 it('Should fail with a bad licence', async function () {
239 const fields = { ...baseCorrectParams, licence: 125 } 248 const fields = { ...baseCorrectParams, licence: 125 }
240 const attaches = baseCorrectAttaches 249 const attaches = baseCorrectAttaches
241 250
242 await checkUploadVideoParam(server, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode) 251 await checkUploadVideoParam({ ...baseOptions(), attributes: { ...fields, ...attaches } })
243 }) 252 })
244 253
245 it('Should fail with a bad language', async function () { 254 it('Should fail with a bad language', async function () {
246 const fields = { ...baseCorrectParams, language: 'a'.repeat(15) } 255 const fields = { ...baseCorrectParams, language: 'a'.repeat(15) }
247 const attaches = baseCorrectAttaches 256 const attaches = baseCorrectAttaches
248 257
249 await checkUploadVideoParam(server, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode) 258 await checkUploadVideoParam({ ...baseOptions(), attributes: { ...fields, ...attaches } })
250 }) 259 })
251 260
252 it('Should fail with a long description', async function () { 261 it('Should fail with a long description', async function () {
253 const fields = { ...baseCorrectParams, description: 'super'.repeat(2500) } 262 const fields = { ...baseCorrectParams, description: 'super'.repeat(2500) }
254 const attaches = baseCorrectAttaches 263 const attaches = baseCorrectAttaches
255 264
256 await checkUploadVideoParam(server, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode) 265 await checkUploadVideoParam({ ...baseOptions(), attributes: { ...fields, ...attaches } })
257 }) 266 })
258 267
259 it('Should fail with a long support text', async function () { 268 it('Should fail with a long support text', async function () {
260 const fields = { ...baseCorrectParams, support: 'super'.repeat(201) } 269 const fields = { ...baseCorrectParams, support: 'super'.repeat(201) }
261 const attaches = baseCorrectAttaches 270 const attaches = baseCorrectAttaches
262 271
263 await checkUploadVideoParam(server, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode) 272 await checkUploadVideoParam({ ...baseOptions(), attributes: { ...fields, ...attaches } })
264 }) 273 })
265 274
266 it('Should fail without a channel', async function () { 275 it('Should fail without a channel', async function () {
267 const fields = omit(baseCorrectParams, [ 'channelId' ]) 276 const fields = omit(baseCorrectParams, [ 'channelId' ])
268 const attaches = baseCorrectAttaches 277 const attaches = baseCorrectAttaches
269 278
270 await checkUploadVideoParam(server, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode) 279 await checkUploadVideoParam({ ...baseOptions(), attributes: { ...fields, ...attaches } })
271 }) 280 })
272 281
273 it('Should fail with a bad channel', async function () { 282 it('Should fail with a bad channel', async function () {
274 const fields = { ...baseCorrectParams, channelId: 545454 } 283 const fields = { ...baseCorrectParams, channelId: 545454 }
275 const attaches = baseCorrectAttaches 284 const attaches = baseCorrectAttaches
276 285
277 await checkUploadVideoParam(server, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode) 286 await checkUploadVideoParam({ ...baseOptions(), attributes: { ...fields, ...attaches } })
278 }) 287 })
279 288
280 it('Should fail with another user channel', async function () { 289 it('Should fail with another user channel', async function () {
@@ -291,35 +300,39 @@ describe('Test videos API validator', function () {
291 const fields = { ...baseCorrectParams, channelId: customChannelId } 300 const fields = { ...baseCorrectParams, channelId: customChannelId }
292 const attaches = baseCorrectAttaches 301 const attaches = baseCorrectAttaches
293 302
294 await checkUploadVideoParam(server, userAccessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode) 303 await checkUploadVideoParam({
304 ...baseOptions(),
305 token: userAccessToken,
306 attributes: { ...fields, ...attaches }
307 })
295 }) 308 })
296 309
297 it('Should fail with too many tags', async function () { 310 it('Should fail with too many tags', async function () {
298 const fields = { ...baseCorrectParams, tags: [ 'tag1', 'tag2', 'tag3', 'tag4', 'tag5', 'tag6' ] } 311 const fields = { ...baseCorrectParams, tags: [ 'tag1', 'tag2', 'tag3', 'tag4', 'tag5', 'tag6' ] }
299 const attaches = baseCorrectAttaches 312 const attaches = baseCorrectAttaches
300 313
301 await checkUploadVideoParam(server, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode) 314 await checkUploadVideoParam({ ...baseOptions(), attributes: { ...fields, ...attaches } })
302 }) 315 })
303 316
304 it('Should fail with a tag length too low', async function () { 317 it('Should fail with a tag length too low', async function () {
305 const fields = { ...baseCorrectParams, tags: [ 'tag1', 't' ] } 318 const fields = { ...baseCorrectParams, tags: [ 'tag1', 't' ] }
306 const attaches = baseCorrectAttaches 319 const attaches = baseCorrectAttaches
307 320
308 await checkUploadVideoParam(server, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode) 321 await checkUploadVideoParam({ ...baseOptions(), attributes: { ...fields, ...attaches } })
309 }) 322 })
310 323
311 it('Should fail with a tag length too big', async function () { 324 it('Should fail with a tag length too big', async function () {
312 const fields = { ...baseCorrectParams, tags: [ 'tag1', 'my_super_tag_too_long_long_long_long_long_long' ] } 325 const fields = { ...baseCorrectParams, tags: [ 'tag1', 'my_super_tag_too_long_long_long_long_long_long' ] }
313 const attaches = baseCorrectAttaches 326 const attaches = baseCorrectAttaches
314 327
315 await checkUploadVideoParam(server, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode) 328 await checkUploadVideoParam({ ...baseOptions(), attributes: { ...fields, ...attaches } })
316 }) 329 })
317 330
318 it('Should fail with a bad schedule update (miss updateAt)', async function () { 331 it('Should fail with a bad schedule update (miss updateAt)', async function () {
319 const fields = { ...baseCorrectParams, scheduleUpdate: { privacy: VideoPrivacy.PUBLIC } } 332 const fields = { ...baseCorrectParams, scheduleUpdate: { privacy: VideoPrivacy.PUBLIC } }
320 const attaches = baseCorrectAttaches 333 const attaches = baseCorrectAttaches
321 334
322 await checkUploadVideoParam(server, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode) 335 await checkUploadVideoParam({ ...baseOptions(), attributes: { ...fields, ...attaches } })
323 }) 336 })
324 337
325 it('Should fail with a bad schedule update (wrong updateAt)', async function () { 338 it('Should fail with a bad schedule update (wrong updateAt)', async function () {
@@ -333,42 +346,40 @@ describe('Test videos API validator', function () {
333 } 346 }
334 const attaches = baseCorrectAttaches 347 const attaches = baseCorrectAttaches
335 348
336 await checkUploadVideoParam(server, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode) 349 await checkUploadVideoParam({ ...baseOptions(), attributes: { ...fields, ...attaches } })
337 }) 350 })
338 351
339 it('Should fail with a bad originally published at attribute', async function () { 352 it('Should fail with a bad originally published at attribute', async function () {
340 const fields = { ...baseCorrectParams, originallyPublishedAt: 'toto' } 353 const fields = { ...baseCorrectParams, originallyPublishedAt: 'toto' }
341 const attaches = baseCorrectAttaches 354 const attaches = baseCorrectAttaches
342 355
343 await checkUploadVideoParam(server, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode) 356 await checkUploadVideoParam({ ...baseOptions(), attributes: { ...fields, ...attaches } })
344 }) 357 })
345 358
346 it('Should fail without an input file', async function () { 359 it('Should fail without an input file', async function () {
347 const fields = baseCorrectParams 360 const fields = baseCorrectParams
348 const attaches = {} 361 const attaches = {}
349 await checkUploadVideoParam(server, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode) 362 await checkUploadVideoParam({ ...baseOptions(), attributes: { ...fields, ...attaches } })
350 }) 363 })
351 364
352 it('Should fail with an incorrect input file', async function () { 365 it('Should fail with an incorrect input file', async function () {
353 const fields = baseCorrectParams 366 const fields = baseCorrectParams
354 let attaches = { fixture: join(root(), 'server', 'tests', 'fixtures', 'video_short_fake.webm') } 367 let attaches = { fixture: join(root(), 'server', 'tests', 'fixtures', 'video_short_fake.webm') }
355 368
356 await checkUploadVideoParam( 369 await checkUploadVideoParam({
357 server, 370 ...baseOptions(),
358 server.accessToken, 371 attributes: { ...fields, ...attaches },
359 { ...fields, ...attaches }, 372 // 200 for the init request, 422 when the file has finished being uploaded
360 HttpStatusCode.UNPROCESSABLE_ENTITY_422, 373 expectedStatus: undefined,
361 mode 374 completedExpectedStatus: HttpStatusCode.UNPROCESSABLE_ENTITY_422
362 ) 375 })
363 376
364 attaches = { fixture: join(root(), 'server', 'tests', 'fixtures', 'video_short.mkv') } 377 attaches = { fixture: join(root(), 'server', 'tests', 'fixtures', 'video_short.mkv') }
365 await checkUploadVideoParam( 378 await checkUploadVideoParam({
366 server, 379 ...baseOptions(),
367 server.accessToken, 380 attributes: { ...fields, ...attaches },
368 { ...fields, ...attaches }, 381 expectedStatus: HttpStatusCode.UNSUPPORTED_MEDIA_TYPE_415
369 HttpStatusCode.UNSUPPORTED_MEDIA_TYPE_415, 382 })
370 mode
371 )
372 }) 383 })
373 384
374 it('Should fail with an incorrect thumbnail file', async function () { 385 it('Should fail with an incorrect thumbnail file', async function () {
@@ -378,7 +389,7 @@ describe('Test videos API validator', function () {
378 fixture: join(root(), 'server', 'tests', 'fixtures', 'video_short.mp4') 389 fixture: join(root(), 'server', 'tests', 'fixtures', 'video_short.mp4')
379 } 390 }
380 391
381 await checkUploadVideoParam(server, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode) 392 await checkUploadVideoParam({ ...baseOptions(), attributes: { ...fields, ...attaches } })
382 }) 393 })
383 394
384 it('Should fail with a big thumbnail file', async function () { 395 it('Should fail with a big thumbnail file', async function () {
@@ -388,7 +399,7 @@ describe('Test videos API validator', function () {
388 fixture: join(root(), 'server', 'tests', 'fixtures', 'video_short.mp4') 399 fixture: join(root(), 'server', 'tests', 'fixtures', 'video_short.mp4')
389 } 400 }
390 401
391 await checkUploadVideoParam(server, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode) 402 await checkUploadVideoParam({ ...baseOptions(), attributes: { ...fields, ...attaches } })
392 }) 403 })
393 404
394 it('Should fail with an incorrect preview file', async function () { 405 it('Should fail with an incorrect preview file', async function () {
@@ -398,7 +409,7 @@ describe('Test videos API validator', function () {
398 fixture: join(root(), 'server', 'tests', 'fixtures', 'video_short.mp4') 409 fixture: join(root(), 'server', 'tests', 'fixtures', 'video_short.mp4')
399 } 410 }
400 411
401 await checkUploadVideoParam(server, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode) 412 await checkUploadVideoParam({ ...baseOptions(), attributes: { ...fields, ...attaches } })
402 }) 413 })
403 414
404 it('Should fail with a big preview file', async function () { 415 it('Should fail with a big preview file', async function () {
@@ -408,7 +419,7 @@ describe('Test videos API validator', function () {
408 fixture: join(root(), 'server', 'tests', 'fixtures', 'video_short.mp4') 419 fixture: join(root(), 'server', 'tests', 'fixtures', 'video_short.mp4')
409 } 420 }
410 421
411 await checkUploadVideoParam(server, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode) 422 await checkUploadVideoParam({ ...baseOptions(), attributes: { ...fields, ...attaches } })
412 }) 423 })
413 424
414 it('Should report the appropriate error', async function () { 425 it('Should report the appropriate error', async function () {
@@ -416,7 +427,7 @@ describe('Test videos API validator', function () {
416 const attaches = baseCorrectAttaches 427 const attaches = baseCorrectAttaches
417 428
418 const attributes = { ...fields, ...attaches } 429 const attributes = { ...fields, ...attaches }
419 const body = await checkUploadVideoParam(server, server.accessToken, attributes, HttpStatusCode.BAD_REQUEST_400, mode) 430 const body = await checkUploadVideoParam({ ...baseOptions(), attributes })
420 431
421 const error = body as unknown as PeerTubeProblemDocument 432 const error = body as unknown as PeerTubeProblemDocument
422 433
@@ -443,7 +454,11 @@ describe('Test videos API validator', function () {
443 454
444 { 455 {
445 const attaches = baseCorrectAttaches 456 const attaches = baseCorrectAttaches
446 await checkUploadVideoParam(server, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.OK_200, mode) 457 await checkUploadVideoParam({
458 ...baseOptions(),
459 attributes: { ...fields, ...attaches },
460 expectedStatus: HttpStatusCode.OK_200
461 })
447 } 462 }
448 463
449 { 464 {
@@ -453,7 +468,11 @@ describe('Test videos API validator', function () {
453 videofile: join(root(), 'server', 'tests', 'fixtures', 'video_short.mp4') 468 videofile: join(root(), 'server', 'tests', 'fixtures', 'video_short.mp4')
454 } 469 }
455 470
456 await checkUploadVideoParam(server, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.OK_200, mode) 471 await checkUploadVideoParam({
472 ...baseOptions(),
473 attributes: { ...fields, ...attaches },
474 expectedStatus: HttpStatusCode.OK_200
475 })
457 } 476 }
458 477
459 { 478 {
@@ -463,7 +482,11 @@ describe('Test videos API validator', function () {
463 videofile: join(root(), 'server', 'tests', 'fixtures', 'video_short.ogv') 482 videofile: join(root(), 'server', 'tests', 'fixtures', 'video_short.ogv')
464 } 483 }
465 484
466 await checkUploadVideoParam(server, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.OK_200, mode) 485 await checkUploadVideoParam({
486 ...baseOptions(),
487 attributes: { ...fields, ...attaches },
488 expectedStatus: HttpStatusCode.OK_200
489 })
467 } 490 }
468 }) 491 })
469 } 492 }
diff --git a/server/tests/shared/videos.ts b/server/tests/shared/videos.ts
index 3f59c329f..ac24bb173 100644
--- a/server/tests/shared/videos.ts
+++ b/server/tests/shared/videos.ts
@@ -268,16 +268,25 @@ async function saveVideoInServers (servers: PeerTubeServer[], uuid: string) {
268 } 268 }
269} 269}
270 270
271function checkUploadVideoParam ( 271function checkUploadVideoParam (options: {
272 server: PeerTubeServer, 272 server: PeerTubeServer
273 token: string, 273 token: string
274 attributes: Partial<VideoEdit>, 274 attributes: Partial<VideoEdit>
275 expectedStatus = HttpStatusCode.OK_200, 275 expectedStatus?: HttpStatusCode
276 mode: 'legacy' | 'resumable' = 'legacy' 276 completedExpectedStatus?: HttpStatusCode
277) { 277 mode?: 'legacy' | 'resumable'
278}) {
279 const { server, token, attributes, completedExpectedStatus, expectedStatus, mode = 'legacy' } = options
280
278 return mode === 'legacy' 281 return mode === 'legacy'
279 ? server.videos.buildLegacyUpload({ token, attributes, expectedStatus }) 282 ? server.videos.buildLegacyUpload({ token, attributes, expectedStatus: expectedStatus || completedExpectedStatus })
280 : server.videos.buildResumeUpload({ token, attributes, expectedStatus, path: '/api/v1/videos/upload-resumable' }) 283 : server.videos.buildResumeUpload({
284 token,
285 attributes,
286 expectedStatus,
287 completedExpectedStatus,
288 path: '/api/v1/videos/upload-resumable'
289 })
281} 290}
282 291
283// serverNumber starts from 1 292// serverNumber starts from 1