diff options
author | Chocobozzz <me@florianbigard.com> | 2022-08-10 11:51:13 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2022-08-10 14:32:00 +0200 |
commit | a3b472a12ec6e57dbe2f650419f8064864686eab (patch) | |
tree | f36559488e34493c029b686772e986902150a647 /server/tests/api/check-params | |
parent | 0567049a9819d67070aa6d548a75a7e632a4aaa4 (diff) | |
download | PeerTube-a3b472a12ec6e57dbe2f650419f8064864686eab.tar.gz PeerTube-a3b472a12ec6e57dbe2f650419f8064864686eab.tar.zst PeerTube-a3b472a12ec6e57dbe2f650419f8064864686eab.zip |
Add ability to list imports of a channel sync
Diffstat (limited to 'server/tests/api/check-params')
-rw-r--r-- | server/tests/api/check-params/channel-import-videos.ts | 172 | ||||
-rw-r--r-- | server/tests/api/check-params/index.ts | 1 | ||||
-rw-r--r-- | server/tests/api/check-params/video-channels.ts | 113 | ||||
-rw-r--r-- | server/tests/api/check-params/video-imports.ts | 9 |
4 files changed, 184 insertions, 111 deletions
diff --git a/server/tests/api/check-params/channel-import-videos.ts b/server/tests/api/check-params/channel-import-videos.ts new file mode 100644 index 000000000..90d61f20a --- /dev/null +++ b/server/tests/api/check-params/channel-import-videos.ts | |||
@@ -0,0 +1,172 @@ | |||
1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ | ||
2 | |||
3 | import 'mocha' | ||
4 | import { FIXTURE_URLS } from '@server/tests/shared' | ||
5 | import { areHttpImportTestsDisabled } from '@shared/core-utils' | ||
6 | import { HttpStatusCode } from '@shared/models' | ||
7 | import { ChannelsCommand, cleanupTests, createSingleServer, PeerTubeServer, setAccessTokensToServers } from '@shared/server-commands' | ||
8 | |||
9 | describe('Test videos import in a channel API validator', function () { | ||
10 | let server: PeerTubeServer | ||
11 | const userInfo = { | ||
12 | accessToken: '', | ||
13 | channelName: 'fake_channel', | ||
14 | id: -1, | ||
15 | videoQuota: -1, | ||
16 | videoQuotaDaily: -1 | ||
17 | } | ||
18 | let command: ChannelsCommand | ||
19 | |||
20 | // --------------------------------------------------------------- | ||
21 | |||
22 | before(async function () { | ||
23 | this.timeout(30000) | ||
24 | |||
25 | server = await createSingleServer(1) | ||
26 | |||
27 | await setAccessTokensToServers([ server ]) | ||
28 | |||
29 | const userCreds = { | ||
30 | username: 'fake', | ||
31 | password: 'fake_password' | ||
32 | } | ||
33 | |||
34 | { | ||
35 | const user = await server.users.create({ username: userCreds.username, password: userCreds.password }) | ||
36 | userInfo.id = user.id | ||
37 | userInfo.accessToken = await server.login.getAccessToken(userCreds) | ||
38 | } | ||
39 | |||
40 | command = server.channels | ||
41 | }) | ||
42 | |||
43 | it('Should fail when HTTP upload is disabled', async function () { | ||
44 | await server.config.disableImports() | ||
45 | |||
46 | await command.importVideos({ | ||
47 | channelName: 'super_channel', | ||
48 | externalChannelUrl: FIXTURE_URLS.youtubeChannel, | ||
49 | token: server.accessToken, | ||
50 | expectedStatus: HttpStatusCode.FORBIDDEN_403 | ||
51 | }) | ||
52 | |||
53 | await server.config.enableImports() | ||
54 | }) | ||
55 | |||
56 | it('Should fail when externalChannelUrl is not provided', async function () { | ||
57 | await command.importVideos({ | ||
58 | channelName: 'super_channel', | ||
59 | externalChannelUrl: null, | ||
60 | token: server.accessToken, | ||
61 | expectedStatus: HttpStatusCode.BAD_REQUEST_400 | ||
62 | }) | ||
63 | }) | ||
64 | |||
65 | it('Should fail when externalChannelUrl is malformed', async function () { | ||
66 | await command.importVideos({ | ||
67 | channelName: 'super_channel', | ||
68 | externalChannelUrl: 'not-a-url', | ||
69 | token: server.accessToken, | ||
70 | expectedStatus: HttpStatusCode.BAD_REQUEST_400 | ||
71 | }) | ||
72 | }) | ||
73 | |||
74 | it('Should fail with a bad sync id', async function () { | ||
75 | await command.importVideos({ | ||
76 | channelName: 'super_channel', | ||
77 | externalChannelUrl: FIXTURE_URLS.youtubeChannel, | ||
78 | videoChannelSyncId: 'toto' as any, | ||
79 | token: server.accessToken, | ||
80 | expectedStatus: HttpStatusCode.BAD_REQUEST_400 | ||
81 | }) | ||
82 | }) | ||
83 | |||
84 | it('Should fail with a unknown sync id', async function () { | ||
85 | await command.importVideos({ | ||
86 | channelName: 'super_channel', | ||
87 | externalChannelUrl: FIXTURE_URLS.youtubeChannel, | ||
88 | videoChannelSyncId: 42, | ||
89 | token: server.accessToken, | ||
90 | expectedStatus: HttpStatusCode.NOT_FOUND_404 | ||
91 | }) | ||
92 | }) | ||
93 | |||
94 | it('Should fail with no authentication', async function () { | ||
95 | await command.importVideos({ | ||
96 | channelName: 'super_channel', | ||
97 | externalChannelUrl: FIXTURE_URLS.youtubeChannel, | ||
98 | token: null, | ||
99 | expectedStatus: HttpStatusCode.UNAUTHORIZED_401 | ||
100 | }) | ||
101 | }) | ||
102 | |||
103 | it('Should fail when sync is not owned by the user', async function () { | ||
104 | await command.importVideos({ | ||
105 | channelName: 'super_channel', | ||
106 | externalChannelUrl: FIXTURE_URLS.youtubeChannel, | ||
107 | token: userInfo.accessToken, | ||
108 | expectedStatus: HttpStatusCode.FORBIDDEN_403 | ||
109 | }) | ||
110 | }) | ||
111 | |||
112 | it('Should fail when the user has no quota', async function () { | ||
113 | await server.users.update({ | ||
114 | userId: userInfo.id, | ||
115 | videoQuota: 0 | ||
116 | }) | ||
117 | |||
118 | await command.importVideos({ | ||
119 | channelName: 'fake_channel', | ||
120 | externalChannelUrl: FIXTURE_URLS.youtubeChannel, | ||
121 | token: userInfo.accessToken, | ||
122 | expectedStatus: HttpStatusCode.PAYLOAD_TOO_LARGE_413 | ||
123 | }) | ||
124 | |||
125 | await server.users.update({ | ||
126 | userId: userInfo.id, | ||
127 | videoQuota: userInfo.videoQuota | ||
128 | }) | ||
129 | }) | ||
130 | |||
131 | it('Should fail when the user has no daily quota', async function () { | ||
132 | await server.users.update({ | ||
133 | userId: userInfo.id, | ||
134 | videoQuotaDaily: 0 | ||
135 | }) | ||
136 | |||
137 | await command.importVideos({ | ||
138 | channelName: 'fake_channel', | ||
139 | externalChannelUrl: FIXTURE_URLS.youtubeChannel, | ||
140 | token: userInfo.accessToken, | ||
141 | expectedStatus: HttpStatusCode.PAYLOAD_TOO_LARGE_413 | ||
142 | }) | ||
143 | |||
144 | await server.users.update({ | ||
145 | userId: userInfo.id, | ||
146 | videoQuotaDaily: userInfo.videoQuotaDaily | ||
147 | }) | ||
148 | }) | ||
149 | |||
150 | it('Should succeed when sync is run by its owner', async function () { | ||
151 | if (!areHttpImportTestsDisabled()) return | ||
152 | |||
153 | await command.importVideos({ | ||
154 | channelName: 'fake_channel', | ||
155 | externalChannelUrl: FIXTURE_URLS.youtubeChannel, | ||
156 | token: userInfo.accessToken | ||
157 | }) | ||
158 | }) | ||
159 | |||
160 | it('Should succeed when sync is run with root and for another user\'s channel', async function () { | ||
161 | if (!areHttpImportTestsDisabled()) return | ||
162 | |||
163 | await command.importVideos({ | ||
164 | channelName: 'fake_channel', | ||
165 | externalChannelUrl: FIXTURE_URLS.youtubeChannel | ||
166 | }) | ||
167 | }) | ||
168 | |||
169 | after(async function () { | ||
170 | await cleanupTests([ server ]) | ||
171 | }) | ||
172 | }) | ||
diff --git a/server/tests/api/check-params/index.ts b/server/tests/api/check-params/index.ts index 5f1168b53..149305f49 100644 --- a/server/tests/api/check-params/index.ts +++ b/server/tests/api/check-params/index.ts | |||
@@ -28,6 +28,7 @@ import './video-comments' | |||
28 | import './video-files' | 28 | import './video-files' |
29 | import './video-imports' | 29 | import './video-imports' |
30 | import './video-channel-syncs' | 30 | import './video-channel-syncs' |
31 | import './channel-import-videos' | ||
31 | import './video-playlists' | 32 | import './video-playlists' |
32 | import './video-source' | 33 | import './video-source' |
33 | import './video-studio' | 34 | import './video-studio' |
diff --git a/server/tests/api/check-params/video-channels.ts b/server/tests/api/check-params/video-channels.ts index 337ea1dd4..9024126c0 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, FIXTURE_URLS } from '@server/tests/shared' | 6 | import { checkBadCountPagination, checkBadSortPagination, checkBadStartPagination } from '@server/tests/shared' |
7 | import { areHttpImportTestsDisabled, buildAbsoluteFixturePath } from '@shared/core-utils' | 7 | import { 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, |
@@ -354,115 +354,6 @@ describe('Test video channels API validator', function () { | |||
354 | }) | 354 | }) |
355 | }) | 355 | }) |
356 | 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 | |||
466 | describe('When deleting a video channel', function () { | 357 | describe('When deleting a video channel', function () { |
467 | it('Should fail with a non authenticated user', async function () { | 358 | it('Should fail with a non authenticated user', async function () { |
468 | await command.delete({ token: 'coucou', channelName: 'super_channel', expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) | 359 | await command.delete({ token: 'coucou', channelName: 'super_channel', expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) |
diff --git a/server/tests/api/check-params/video-imports.ts b/server/tests/api/check-params/video-imports.ts index 5cdd0d925..85382b261 100644 --- a/server/tests/api/check-params/video-imports.ts +++ b/server/tests/api/check-params/video-imports.ts | |||
@@ -59,6 +59,15 @@ describe('Test video imports API validator', function () { | |||
59 | await checkBadSortPagination(server.url, myPath, server.accessToken) | 59 | await checkBadSortPagination(server.url, myPath, server.accessToken) |
60 | }) | 60 | }) |
61 | 61 | ||
62 | it('Should fail with a bad videoChannelSyncId param', async function () { | ||
63 | await makeGetRequest({ | ||
64 | url: server.url, | ||
65 | path: myPath, | ||
66 | query: { videoChannelSyncId: 'toto' }, | ||
67 | token: server.accessToken | ||
68 | }) | ||
69 | }) | ||
70 | |||
62 | it('Should success with the correct parameters', async function () { | 71 | it('Should success with the correct parameters', async function () { |
63 | await makeGetRequest({ url: server.url, path: myPath, expectedStatus: HttpStatusCode.OK_200, token: server.accessToken }) | 72 | await makeGetRequest({ url: server.url, path: myPath, expectedStatus: HttpStatusCode.OK_200, token: server.accessToken }) |
64 | }) | 73 | }) |