diff options
author | Florent <florent.git@zeteo.me> | 2022-08-10 09:53:39 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-08-10 09:53:39 +0200 |
commit | 2a491182e483b97afb1b65c908b23cb48d591807 (patch) | |
tree | ec13503216ad72a3ea8f1ce3b659899f8167fb47 /server/tests/api/check-params/video-channels.ts | |
parent | 06ac128958c489efe1008eeca1df683819bd2f18 (diff) | |
download | PeerTube-2a491182e483b97afb1b65c908b23cb48d591807.tar.gz PeerTube-2a491182e483b97afb1b65c908b23cb48d591807.tar.zst PeerTube-2a491182e483b97afb1b65c908b23cb48d591807.zip |
Channel sync (#5135)
* Add external channel URL for channel update / creation (#754)
* Disallow synchronisation if user has no video quota (#754)
* More constraints serverside (#754)
* Disable sync if server configuration does not allow HTTP import (#754)
* Working version synchronizing videos with a job (#754)
TODO: refactoring, too much code duplication
* More logs and try/catch (#754)
* Fix eslint error (#754)
* WIP: support synchronization time change (#754)
* New frontend #754
* WIP: Create sync front (#754)
* Enhance UI, sync creation form (#754)
* Warning message when HTTP upload is disallowed
* More consistent names (#754)
* Binding Front with API (#754)
* Add a /me API (#754)
* Improve list UI (#754)
* Implement creation and deletion routes (#754)
* Lint (#754)
* Lint again (#754)
* WIP: UI for triggering import existing videos (#754)
* Implement jobs for syncing and importing channels
* Don't sync videos before sync creation + avoid concurrency issue (#754)
* Cleanup (#754)
* Cleanup: OpenAPI + API rework (#754)
* Remove dead code (#754)
* Eslint (#754)
* Revert the mess with whitespaces in constants.ts (#754)
* Some fixes after rebase (#754)
* Several fixes after PR remarks (#754)
* Front + API: Rename video-channels-sync to video-channel-syncs (#754)
* Allow enabling channel sync through UI (#754)
* getChannelInfo (#754)
* Minor fixes: openapi + model + sql (#754)
* Simplified API validators (#754)
* Rename MChannelSync to MChannelSyncChannel (#754)
* Add command for VideoChannelSync (#754)
* Use synchronization.enabled config (#754)
* Check parameters test + some fixes (#754)
* Fix conflict mistake (#754)
* Restrict access to video channel sync list API (#754)
* Start adding unit test for synchronization (#754)
* Continue testing (#754)
* Tests finished + convertion of job to scheduler (#754)
* Add lastSyncAt field (#754)
* Fix externalRemoteUrl sort + creation date not well formatted (#754)
* Small fix (#754)
* Factorize addYoutubeDLImport and buildVideo (#754)
* Check duplicates on channel not on users (#754)
* factorize thumbnail generation (#754)
* Fetch error should return status 400 (#754)
* Separate video-channel-import and video-channel-sync-latest (#754)
* Bump DB migration version after rebase (#754)
* Prettier states in UI table (#754)
* Add DefaultScope in VideoChannelSyncModel (#754)
* Fix audit logs (#754)
* Ensure user can upload when importing channel + minor fixes (#754)
* Mark synchronization as failed on exception + typos (#754)
* Change REST API for importing videos into channel (#754)
* Add option for fully synchronize a chnanel (#754)
* Return a whole sync object on creation to avoid tricks in Front (#754)
* Various remarks (#754)
* Single quotes by default (#754)
* Rename synchronization to video_channel_synchronization
* Add check.latest_videos_count and max_per_user options (#754)
* Better channel rendering in list #754
* Allow sorting with channel name and state (#754)
* Add missing tests for channel imports (#754)
* Prefer using a parent job for channel sync
* Styling
* Client styling
Co-authored-by: Chocobozzz <me@florianbigard.com>
Diffstat (limited to 'server/tests/api/check-params/video-channels.ts')
-rw-r--r-- | server/tests/api/check-params/video-channels.ts | 134 |
1 files changed, 125 insertions, 9 deletions
diff --git a/server/tests/api/check-params/video-channels.ts b/server/tests/api/check-params/video-channels.ts index 5c2650fac..337ea1dd4 100644 --- a/server/tests/api/check-params/video-channels.ts +++ b/server/tests/api/check-params/video-channels.ts | |||
@@ -3,8 +3,8 @@ | |||
3 | import 'mocha' | 3 | import 'mocha' |
4 | import * as chai from 'chai' | 4 | import * as chai from 'chai' |
5 | import { omit } from 'lodash' | 5 | import { omit } from 'lodash' |
6 | import { checkBadCountPagination, checkBadSortPagination, checkBadStartPagination } from '@server/tests/shared' | 6 | import { checkBadCountPagination, checkBadSortPagination, checkBadStartPagination, FIXTURE_URLS } from '@server/tests/shared' |
7 | import { buildAbsoluteFixturePath } from '@shared/core-utils' | 7 | import { areHttpImportTestsDisabled, buildAbsoluteFixturePath } from '@shared/core-utils' |
8 | import { HttpStatusCode, VideoChannelUpdate } from '@shared/models' | 8 | import { HttpStatusCode, VideoChannelUpdate } from '@shared/models' |
9 | import { | 9 | import { |
10 | ChannelsCommand, | 10 | ChannelsCommand, |
@@ -23,7 +23,13 @@ const expect = chai.expect | |||
23 | describe('Test video channels API validator', function () { | 23 | describe('Test video channels API validator', function () { |
24 | const videoChannelPath = '/api/v1/video-channels' | 24 | const videoChannelPath = '/api/v1/video-channels' |
25 | let server: PeerTubeServer | 25 | let server: PeerTubeServer |
26 | let accessTokenUser: string | 26 | const userInfo = { |
27 | accessToken: '', | ||
28 | channelName: 'fake_channel', | ||
29 | id: -1, | ||
30 | videoQuota: -1, | ||
31 | videoQuotaDaily: -1 | ||
32 | } | ||
27 | let command: ChannelsCommand | 33 | let command: ChannelsCommand |
28 | 34 | ||
29 | // --------------------------------------------------------------- | 35 | // --------------------------------------------------------------- |
@@ -35,14 +41,15 @@ describe('Test video channels API validator', function () { | |||
35 | 41 | ||
36 | await setAccessTokensToServers([ server ]) | 42 | await setAccessTokensToServers([ server ]) |
37 | 43 | ||
38 | const user = { | 44 | const userCreds = { |
39 | username: 'fake', | 45 | username: 'fake', |
40 | password: 'fake_password' | 46 | password: 'fake_password' |
41 | } | 47 | } |
42 | 48 | ||
43 | { | 49 | { |
44 | await server.users.create({ username: user.username, password: user.password }) | 50 | const user = await server.users.create({ username: userCreds.username, password: userCreds.password }) |
45 | accessTokenUser = await server.login.getAccessToken(user) | 51 | userInfo.id = user.id |
52 | userInfo.accessToken = await server.login.getAccessToken(userCreds) | ||
46 | } | 53 | } |
47 | 54 | ||
48 | command = server.channels | 55 | command = server.channels |
@@ -191,7 +198,7 @@ describe('Test video channels API validator', function () { | |||
191 | await makePutBodyRequest({ | 198 | await makePutBodyRequest({ |
192 | url: server.url, | 199 | url: server.url, |
193 | path, | 200 | path, |
194 | token: accessTokenUser, | 201 | token: userInfo.accessToken, |
195 | fields: baseCorrectParams, | 202 | fields: baseCorrectParams, |
196 | expectedStatus: HttpStatusCode.FORBIDDEN_403 | 203 | expectedStatus: HttpStatusCode.FORBIDDEN_403 |
197 | }) | 204 | }) |
@@ -339,7 +346,7 @@ describe('Test video channels API validator', function () { | |||
339 | }) | 346 | }) |
340 | 347 | ||
341 | it('Should fail with a another user', async function () { | 348 | it('Should fail with a another user', async function () { |
342 | await makeGetRequest({ url: server.url, path, token: accessTokenUser, expectedStatus: HttpStatusCode.FORBIDDEN_403 }) | 349 | await makeGetRequest({ url: server.url, path, token: userInfo.accessToken, expectedStatus: HttpStatusCode.FORBIDDEN_403 }) |
343 | }) | 350 | }) |
344 | 351 | ||
345 | it('Should succeed with the correct params', async function () { | 352 | it('Should succeed with the correct params', async function () { |
@@ -347,13 +354,122 @@ describe('Test video channels API validator', function () { | |||
347 | }) | 354 | }) |
348 | }) | 355 | }) |
349 | 356 | ||
357 | describe('When triggering full synchronization', function () { | ||
358 | |||
359 | it('Should fail when HTTP upload is disabled', async function () { | ||
360 | await server.config.disableImports() | ||
361 | |||
362 | await command.importVideos({ | ||
363 | channelName: 'super_channel', | ||
364 | externalChannelUrl: FIXTURE_URLS.youtubeChannel, | ||
365 | token: server.accessToken, | ||
366 | expectedStatus: HttpStatusCode.FORBIDDEN_403 | ||
367 | }) | ||
368 | |||
369 | await server.config.enableImports() | ||
370 | }) | ||
371 | |||
372 | it('Should fail when externalChannelUrl is not provided', async function () { | ||
373 | await command.importVideos({ | ||
374 | channelName: 'super_channel', | ||
375 | externalChannelUrl: null, | ||
376 | token: server.accessToken, | ||
377 | expectedStatus: HttpStatusCode.BAD_REQUEST_400 | ||
378 | }) | ||
379 | }) | ||
380 | |||
381 | it('Should fail when externalChannelUrl is malformed', async function () { | ||
382 | await command.importVideos({ | ||
383 | channelName: 'super_channel', | ||
384 | externalChannelUrl: 'not-a-url', | ||
385 | token: server.accessToken, | ||
386 | expectedStatus: HttpStatusCode.BAD_REQUEST_400 | ||
387 | }) | ||
388 | }) | ||
389 | |||
390 | it('Should fail with no authentication', async function () { | ||
391 | await command.importVideos({ | ||
392 | channelName: 'super_channel', | ||
393 | externalChannelUrl: FIXTURE_URLS.youtubeChannel, | ||
394 | token: null, | ||
395 | expectedStatus: HttpStatusCode.UNAUTHORIZED_401 | ||
396 | }) | ||
397 | }) | ||
398 | |||
399 | it('Should fail when sync is not owned by the user', async function () { | ||
400 | await command.importVideos({ | ||
401 | channelName: 'super_channel', | ||
402 | externalChannelUrl: FIXTURE_URLS.youtubeChannel, | ||
403 | token: userInfo.accessToken, | ||
404 | expectedStatus: HttpStatusCode.FORBIDDEN_403 | ||
405 | }) | ||
406 | }) | ||
407 | |||
408 | it('Should fail when the user has no quota', async function () { | ||
409 | await server.users.update({ | ||
410 | userId: userInfo.id, | ||
411 | videoQuota: 0 | ||
412 | }) | ||
413 | |||
414 | await command.importVideos({ | ||
415 | channelName: 'fake_channel', | ||
416 | externalChannelUrl: FIXTURE_URLS.youtubeChannel, | ||
417 | token: userInfo.accessToken, | ||
418 | expectedStatus: HttpStatusCode.PAYLOAD_TOO_LARGE_413 | ||
419 | }) | ||
420 | |||
421 | await server.users.update({ | ||
422 | userId: userInfo.id, | ||
423 | videoQuota: userInfo.videoQuota | ||
424 | }) | ||
425 | }) | ||
426 | |||
427 | it('Should fail when the user has no daily quota', async function () { | ||
428 | await server.users.update({ | ||
429 | userId: userInfo.id, | ||
430 | videoQuotaDaily: 0 | ||
431 | }) | ||
432 | |||
433 | await command.importVideos({ | ||
434 | channelName: 'fake_channel', | ||
435 | externalChannelUrl: FIXTURE_URLS.youtubeChannel, | ||
436 | token: userInfo.accessToken, | ||
437 | expectedStatus: HttpStatusCode.PAYLOAD_TOO_LARGE_413 | ||
438 | }) | ||
439 | |||
440 | await server.users.update({ | ||
441 | userId: userInfo.id, | ||
442 | videoQuotaDaily: userInfo.videoQuotaDaily | ||
443 | }) | ||
444 | }) | ||
445 | |||
446 | it('Should succeed when sync is run by its owner', async function () { | ||
447 | if (!areHttpImportTestsDisabled()) return | ||
448 | |||
449 | await command.importVideos({ | ||
450 | channelName: 'fake_channel', | ||
451 | externalChannelUrl: FIXTURE_URLS.youtubeChannel, | ||
452 | token: userInfo.accessToken | ||
453 | }) | ||
454 | }) | ||
455 | |||
456 | it('Should succeed when sync is run with root and for another user\'s channel', async function () { | ||
457 | if (!areHttpImportTestsDisabled()) return | ||
458 | |||
459 | await command.importVideos({ | ||
460 | channelName: 'fake_channel', | ||
461 | externalChannelUrl: FIXTURE_URLS.youtubeChannel | ||
462 | }) | ||
463 | }) | ||
464 | }) | ||
465 | |||
350 | describe('When deleting a video channel', function () { | 466 | describe('When deleting a video channel', function () { |
351 | it('Should fail with a non authenticated user', async function () { | 467 | it('Should fail with a non authenticated user', async function () { |
352 | await command.delete({ token: 'coucou', channelName: 'super_channel', expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) | 468 | await command.delete({ token: 'coucou', channelName: 'super_channel', expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) |
353 | }) | 469 | }) |
354 | 470 | ||
355 | it('Should fail with another authenticated user', async function () { | 471 | it('Should fail with another authenticated user', async function () { |
356 | await command.delete({ token: accessTokenUser, channelName: 'super_channel', expectedStatus: HttpStatusCode.FORBIDDEN_403 }) | 472 | await command.delete({ token: userInfo.accessToken, channelName: 'super_channel', expectedStatus: HttpStatusCode.FORBIDDEN_403 }) |
357 | }) | 473 | }) |
358 | 474 | ||
359 | it('Should fail with an unknown video channel id', async function () { | 475 | it('Should fail with an unknown video channel id', async function () { |