]>
Commit | Line | Data |
---|---|---|
1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ | |
2 | ||
3 | import { expect } from 'chai' | |
4 | import { HttpStatusCode, VideoDetails, VideoImportState, VideoPlaylist, VideoPlaylistPrivacy, VideoPrivacy } from '@shared/models' | |
5 | import { | |
6 | cleanupTests, | |
7 | createMultipleServers, | |
8 | doubleFollow, | |
9 | makeRawRequest, | |
10 | PeerTubeServer, | |
11 | PluginsCommand, | |
12 | setAccessTokensToServers, | |
13 | setDefaultVideoChannel, | |
14 | waitJobs | |
15 | } from '@shared/server-commands' | |
16 | import { FIXTURE_URLS } from '../shared' | |
17 | ||
18 | describe('Test plugin filter hooks', function () { | |
19 | let servers: PeerTubeServer[] | |
20 | let videoUUID: string | |
21 | let threadId: number | |
22 | let videoPlaylistUUID: string | |
23 | ||
24 | before(async function () { | |
25 | this.timeout(60000) | |
26 | ||
27 | servers = await createMultipleServers(2) | |
28 | await setAccessTokensToServers(servers) | |
29 | await setDefaultVideoChannel(servers) | |
30 | await doubleFollow(servers[0], servers[1]) | |
31 | ||
32 | await servers[0].plugins.install({ path: PluginsCommand.getPluginTestPath() }) | |
33 | await servers[0].plugins.install({ path: PluginsCommand.getPluginTestPath('-filter-translations') }) | |
34 | { | |
35 | ({ uuid: videoPlaylistUUID } = await servers[0].playlists.create({ | |
36 | attributes: { | |
37 | displayName: 'my super playlist', | |
38 | privacy: VideoPlaylistPrivacy.PUBLIC, | |
39 | description: 'my super description', | |
40 | videoChannelId: servers[0].store.channel.id | |
41 | } | |
42 | })) | |
43 | } | |
44 | ||
45 | for (let i = 0; i < 10; i++) { | |
46 | const video = await servers[0].videos.upload({ attributes: { name: 'default video ' + i } }) | |
47 | await servers[0].playlists.addElement({ playlistId: videoPlaylistUUID, attributes: { videoId: video.id } }) | |
48 | } | |
49 | ||
50 | const { data } = await servers[0].videos.list() | |
51 | videoUUID = data[0].uuid | |
52 | ||
53 | await servers[0].config.updateCustomSubConfig({ | |
54 | newConfig: { | |
55 | live: { enabled: true }, | |
56 | signup: { enabled: true }, | |
57 | import: { | |
58 | videos: { | |
59 | http: { enabled: true }, | |
60 | torrent: { enabled: true } | |
61 | } | |
62 | } | |
63 | } | |
64 | }) | |
65 | }) | |
66 | ||
67 | it('Should run filter:api.videos.list.params', async function () { | |
68 | const { data } = await servers[0].videos.list({ start: 0, count: 2 }) | |
69 | ||
70 | // 2 plugins do +1 to the count parameter | |
71 | expect(data).to.have.lengthOf(4) | |
72 | }) | |
73 | ||
74 | it('Should run filter:api.videos.list.result', async function () { | |
75 | const { total } = await servers[0].videos.list({ start: 0, count: 0 }) | |
76 | ||
77 | // Plugin do +1 to the total result | |
78 | expect(total).to.equal(11) | |
79 | }) | |
80 | ||
81 | it('Should run filter:api.video-playlist.videos.list.params', async function () { | |
82 | const { data } = await servers[0].playlists.listVideos({ | |
83 | count: 2, | |
84 | playlistId: videoPlaylistUUID | |
85 | }) | |
86 | ||
87 | // 1 plugin do +1 to the count parameter | |
88 | expect(data).to.have.lengthOf(3) | |
89 | }) | |
90 | ||
91 | it('Should run filter:api.video-playlist.videos.list.result', async function () { | |
92 | const { total } = await servers[0].playlists.listVideos({ | |
93 | count: 0, | |
94 | playlistId: videoPlaylistUUID | |
95 | }) | |
96 | ||
97 | // Plugin do +1 to the total result | |
98 | expect(total).to.equal(11) | |
99 | }) | |
100 | ||
101 | it('Should run filter:api.accounts.videos.list.params', async function () { | |
102 | const { data } = await servers[0].videos.listByAccount({ handle: 'root', start: 0, count: 2 }) | |
103 | ||
104 | // 1 plugin do +1 to the count parameter | |
105 | expect(data).to.have.lengthOf(3) | |
106 | }) | |
107 | ||
108 | it('Should run filter:api.accounts.videos.list.result', async function () { | |
109 | const { total } = await servers[0].videos.listByAccount({ handle: 'root', start: 0, count: 2 }) | |
110 | ||
111 | // Plugin do +2 to the total result | |
112 | expect(total).to.equal(12) | |
113 | }) | |
114 | ||
115 | it('Should run filter:api.video-channels.videos.list.params', async function () { | |
116 | const { data } = await servers[0].videos.listByChannel({ handle: 'root_channel', start: 0, count: 2 }) | |
117 | ||
118 | // 1 plugin do +3 to the count parameter | |
119 | expect(data).to.have.lengthOf(5) | |
120 | }) | |
121 | ||
122 | it('Should run filter:api.video-channels.videos.list.result', async function () { | |
123 | const { total } = await servers[0].videos.listByChannel({ handle: 'root_channel', start: 0, count: 2 }) | |
124 | ||
125 | // Plugin do +3 to the total result | |
126 | expect(total).to.equal(13) | |
127 | }) | |
128 | ||
129 | it('Should run filter:api.user.me.videos.list.params', async function () { | |
130 | const { data } = await servers[0].videos.listMyVideos({ start: 0, count: 2 }) | |
131 | ||
132 | // 1 plugin do +4 to the count parameter | |
133 | expect(data).to.have.lengthOf(6) | |
134 | }) | |
135 | ||
136 | it('Should run filter:api.user.me.videos.list.result', async function () { | |
137 | const { total } = await servers[0].videos.listMyVideos({ start: 0, count: 2 }) | |
138 | ||
139 | // Plugin do +4 to the total result | |
140 | expect(total).to.equal(14) | |
141 | }) | |
142 | ||
143 | it('Should run filter:api.video.get.result', async function () { | |
144 | const video = await servers[0].videos.get({ id: videoUUID }) | |
145 | expect(video.name).to.contain('<3') | |
146 | }) | |
147 | ||
148 | it('Should run filter:api.video.upload.accept.result', async function () { | |
149 | await servers[0].videos.upload({ attributes: { name: 'video with bad word' }, expectedStatus: HttpStatusCode.FORBIDDEN_403 }) | |
150 | }) | |
151 | ||
152 | it('Should run filter:api.live-video.create.accept.result', async function () { | |
153 | const attributes = { | |
154 | name: 'video with bad word', | |
155 | privacy: VideoPrivacy.PUBLIC, | |
156 | channelId: servers[0].store.channel.id | |
157 | } | |
158 | ||
159 | await servers[0].live.create({ fields: attributes, expectedStatus: HttpStatusCode.FORBIDDEN_403 }) | |
160 | }) | |
161 | ||
162 | it('Should run filter:api.video.pre-import-url.accept.result', async function () { | |
163 | const attributes = { | |
164 | name: 'normal title', | |
165 | privacy: VideoPrivacy.PUBLIC, | |
166 | channelId: servers[0].store.channel.id, | |
167 | targetUrl: FIXTURE_URLS.goodVideo + 'bad' | |
168 | } | |
169 | await servers[0].imports.importVideo({ attributes, expectedStatus: HttpStatusCode.FORBIDDEN_403 }) | |
170 | }) | |
171 | ||
172 | it('Should run filter:api.video.pre-import-torrent.accept.result', async function () { | |
173 | const attributes = { | |
174 | name: 'bad torrent', | |
175 | privacy: VideoPrivacy.PUBLIC, | |
176 | channelId: servers[0].store.channel.id, | |
177 | torrentfile: 'video-720p.torrent' as any | |
178 | } | |
179 | await servers[0].imports.importVideo({ attributes, expectedStatus: HttpStatusCode.FORBIDDEN_403 }) | |
180 | }) | |
181 | ||
182 | it('Should run filter:api.video.post-import-url.accept.result', async function () { | |
183 | this.timeout(60000) | |
184 | ||
185 | let videoImportId: number | |
186 | ||
187 | { | |
188 | const attributes = { | |
189 | name: 'title with bad word', | |
190 | privacy: VideoPrivacy.PUBLIC, | |
191 | channelId: servers[0].store.channel.id, | |
192 | targetUrl: FIXTURE_URLS.goodVideo | |
193 | } | |
194 | const body = await servers[0].imports.importVideo({ attributes }) | |
195 | videoImportId = body.id | |
196 | } | |
197 | ||
198 | await waitJobs(servers) | |
199 | ||
200 | { | |
201 | const body = await servers[0].imports.getMyVideoImports() | |
202 | const videoImports = body.data | |
203 | ||
204 | const videoImport = videoImports.find(i => i.id === videoImportId) | |
205 | ||
206 | expect(videoImport.state.id).to.equal(VideoImportState.REJECTED) | |
207 | expect(videoImport.state.label).to.equal('Rejected') | |
208 | } | |
209 | }) | |
210 | ||
211 | it('Should run filter:api.video.post-import-torrent.accept.result', async function () { | |
212 | this.timeout(60000) | |
213 | ||
214 | let videoImportId: number | |
215 | ||
216 | { | |
217 | const attributes = { | |
218 | name: 'title with bad word', | |
219 | privacy: VideoPrivacy.PUBLIC, | |
220 | channelId: servers[0].store.channel.id, | |
221 | torrentfile: 'video-720p.torrent' as any | |
222 | } | |
223 | const body = await servers[0].imports.importVideo({ attributes }) | |
224 | videoImportId = body.id | |
225 | } | |
226 | ||
227 | await waitJobs(servers) | |
228 | ||
229 | { | |
230 | const { data: videoImports } = await servers[0].imports.getMyVideoImports() | |
231 | ||
232 | const videoImport = videoImports.find(i => i.id === videoImportId) | |
233 | ||
234 | expect(videoImport.state.id).to.equal(VideoImportState.REJECTED) | |
235 | expect(videoImport.state.label).to.equal('Rejected') | |
236 | } | |
237 | }) | |
238 | ||
239 | it('Should run filter:api.video-thread.create.accept.result', async function () { | |
240 | await servers[0].comments.createThread({ | |
241 | videoId: videoUUID, | |
242 | text: 'comment with bad word', | |
243 | expectedStatus: HttpStatusCode.FORBIDDEN_403 | |
244 | }) | |
245 | }) | |
246 | ||
247 | it('Should run filter:api.video-comment-reply.create.accept.result', async function () { | |
248 | const created = await servers[0].comments.createThread({ videoId: videoUUID, text: 'thread' }) | |
249 | threadId = created.id | |
250 | ||
251 | await servers[0].comments.addReply({ | |
252 | videoId: videoUUID, | |
253 | toCommentId: threadId, | |
254 | text: 'comment with bad word', | |
255 | expectedStatus: HttpStatusCode.FORBIDDEN_403 | |
256 | }) | |
257 | await servers[0].comments.addReply({ | |
258 | videoId: videoUUID, | |
259 | toCommentId: threadId, | |
260 | text: 'comment with good word', | |
261 | expectedStatus: HttpStatusCode.OK_200 | |
262 | }) | |
263 | }) | |
264 | ||
265 | it('Should run filter:api.video-threads.list.params', async function () { | |
266 | const { data } = await servers[0].comments.listThreads({ videoId: videoUUID, start: 0, count: 0 }) | |
267 | ||
268 | // our plugin do +1 to the count parameter | |
269 | expect(data).to.have.lengthOf(1) | |
270 | }) | |
271 | ||
272 | it('Should run filter:api.video-threads.list.result', async function () { | |
273 | const { total } = await servers[0].comments.listThreads({ videoId: videoUUID, start: 0, count: 0 }) | |
274 | ||
275 | // Plugin do +1 to the total result | |
276 | expect(total).to.equal(2) | |
277 | }) | |
278 | ||
279 | it('Should run filter:api.video-thread-comments.list.params') | |
280 | ||
281 | it('Should run filter:api.video-thread-comments.list.result', async function () { | |
282 | const thread = await servers[0].comments.getThread({ videoId: videoUUID, threadId }) | |
283 | ||
284 | expect(thread.comment.text.endsWith(' <3')).to.be.true | |
285 | }) | |
286 | ||
287 | it('Should run filter:api.overviews.videos.list.{params,result}', async function () { | |
288 | await servers[0].overviews.getVideos({ page: 1 }) | |
289 | ||
290 | // 3 because we get 3 samples per page | |
291 | await servers[0].servers.waitUntilLog('Run hook filter:api.overviews.videos.list.params', 3) | |
292 | await servers[0].servers.waitUntilLog('Run hook filter:api.overviews.videos.list.result', 3) | |
293 | }) | |
294 | ||
295 | describe('filter:video.auto-blacklist.result', function () { | |
296 | ||
297 | async function checkIsBlacklisted (id: number | string, value: boolean) { | |
298 | const video = await servers[0].videos.getWithToken({ id }) | |
299 | expect(video.blacklisted).to.equal(value) | |
300 | } | |
301 | ||
302 | it('Should blacklist on upload', async function () { | |
303 | const { uuid } = await servers[0].videos.upload({ attributes: { name: 'video please blacklist me' } }) | |
304 | await checkIsBlacklisted(uuid, true) | |
305 | }) | |
306 | ||
307 | it('Should blacklist on import', async function () { | |
308 | this.timeout(15000) | |
309 | ||
310 | const attributes = { | |
311 | name: 'video please blacklist me', | |
312 | targetUrl: FIXTURE_URLS.goodVideo, | |
313 | channelId: servers[0].store.channel.id | |
314 | } | |
315 | const body = await servers[0].imports.importVideo({ attributes }) | |
316 | await checkIsBlacklisted(body.video.uuid, true) | |
317 | }) | |
318 | ||
319 | it('Should blacklist on update', async function () { | |
320 | const { uuid } = await servers[0].videos.upload({ attributes: { name: 'video' } }) | |
321 | await checkIsBlacklisted(uuid, false) | |
322 | ||
323 | await servers[0].videos.update({ id: uuid, attributes: { name: 'please blacklist me' } }) | |
324 | await checkIsBlacklisted(uuid, true) | |
325 | }) | |
326 | ||
327 | it('Should blacklist on remote upload', async function () { | |
328 | this.timeout(120000) | |
329 | ||
330 | const { uuid } = await servers[1].videos.upload({ attributes: { name: 'remote please blacklist me' } }) | |
331 | await waitJobs(servers) | |
332 | ||
333 | await checkIsBlacklisted(uuid, true) | |
334 | }) | |
335 | ||
336 | it('Should blacklist on remote update', async function () { | |
337 | this.timeout(120000) | |
338 | ||
339 | const { uuid } = await servers[1].videos.upload({ attributes: { name: 'video' } }) | |
340 | await waitJobs(servers) | |
341 | ||
342 | await checkIsBlacklisted(uuid, false) | |
343 | ||
344 | await servers[1].videos.update({ id: uuid, attributes: { name: 'please blacklist me' } }) | |
345 | await waitJobs(servers) | |
346 | ||
347 | await checkIsBlacklisted(uuid, true) | |
348 | }) | |
349 | }) | |
350 | ||
351 | describe('Should run filter:api.user.signup.allowed.result', function () { | |
352 | ||
353 | it('Should run on config endpoint', async function () { | |
354 | const body = await servers[0].config.getConfig() | |
355 | expect(body.signup.allowed).to.be.true | |
356 | }) | |
357 | ||
358 | it('Should allow a signup', async function () { | |
359 | await servers[0].users.register({ username: 'john', password: 'password' }) | |
360 | }) | |
361 | ||
362 | it('Should not allow a signup', async function () { | |
363 | const res = await servers[0].users.register({ | |
364 | username: 'jma', | |
365 | password: 'password', | |
366 | expectedStatus: HttpStatusCode.FORBIDDEN_403 | |
367 | }) | |
368 | ||
369 | expect(res.body.error).to.equal('No jma') | |
370 | }) | |
371 | }) | |
372 | ||
373 | describe('Download hooks', function () { | |
374 | const downloadVideos: VideoDetails[] = [] | |
375 | ||
376 | before(async function () { | |
377 | this.timeout(120000) | |
378 | ||
379 | await servers[0].config.updateCustomSubConfig({ | |
380 | newConfig: { | |
381 | transcoding: { | |
382 | webtorrent: { | |
383 | enabled: true | |
384 | }, | |
385 | hls: { | |
386 | enabled: true | |
387 | } | |
388 | } | |
389 | } | |
390 | }) | |
391 | ||
392 | const uuids: string[] = [] | |
393 | ||
394 | for (const name of [ 'bad torrent', 'bad file', 'bad playlist file' ]) { | |
395 | const uuid = (await servers[0].videos.quickUpload({ name })).uuid | |
396 | uuids.push(uuid) | |
397 | } | |
398 | ||
399 | await waitJobs(servers) | |
400 | ||
401 | for (const uuid of uuids) { | |
402 | downloadVideos.push(await servers[0].videos.get({ id: uuid })) | |
403 | } | |
404 | }) | |
405 | ||
406 | it('Should run filter:api.download.torrent.allowed.result', async function () { | |
407 | const res = await makeRawRequest(downloadVideos[0].files[0].torrentDownloadUrl, 403) | |
408 | expect(res.body.error).to.equal('Liu Bei') | |
409 | ||
410 | await makeRawRequest(downloadVideos[1].files[0].torrentDownloadUrl, 200) | |
411 | await makeRawRequest(downloadVideos[2].files[0].torrentDownloadUrl, 200) | |
412 | }) | |
413 | ||
414 | it('Should run filter:api.download.video.allowed.result', async function () { | |
415 | { | |
416 | const res = await makeRawRequest(downloadVideos[1].files[0].fileDownloadUrl, 403) | |
417 | expect(res.body.error).to.equal('Cao Cao') | |
418 | ||
419 | await makeRawRequest(downloadVideos[0].files[0].fileDownloadUrl, 200) | |
420 | await makeRawRequest(downloadVideos[2].files[0].fileDownloadUrl, 200) | |
421 | } | |
422 | ||
423 | { | |
424 | const res = await makeRawRequest(downloadVideos[2].streamingPlaylists[0].files[0].fileDownloadUrl, 403) | |
425 | expect(res.body.error).to.equal('Sun Jian') | |
426 | ||
427 | await makeRawRequest(downloadVideos[2].files[0].fileDownloadUrl, 200) | |
428 | ||
429 | await makeRawRequest(downloadVideos[0].streamingPlaylists[0].files[0].fileDownloadUrl, 200) | |
430 | await makeRawRequest(downloadVideos[1].streamingPlaylists[0].files[0].fileDownloadUrl, 200) | |
431 | } | |
432 | }) | |
433 | }) | |
434 | ||
435 | describe('Embed filters', function () { | |
436 | const embedVideos: VideoDetails[] = [] | |
437 | const embedPlaylists: VideoPlaylist[] = [] | |
438 | ||
439 | before(async function () { | |
440 | this.timeout(60000) | |
441 | ||
442 | await servers[0].config.disableTranscoding() | |
443 | ||
444 | for (const name of [ 'bad embed', 'good embed' ]) { | |
445 | { | |
446 | const uuid = (await servers[0].videos.quickUpload({ name })).uuid | |
447 | embedVideos.push(await servers[0].videos.get({ id: uuid })) | |
448 | } | |
449 | ||
450 | { | |
451 | const attributes = { displayName: name, videoChannelId: servers[0].store.channel.id, privacy: VideoPlaylistPrivacy.PUBLIC } | |
452 | const { id } = await servers[0].playlists.create({ attributes }) | |
453 | ||
454 | const playlist = await servers[0].playlists.get({ playlistId: id }) | |
455 | embedPlaylists.push(playlist) | |
456 | } | |
457 | } | |
458 | }) | |
459 | ||
460 | it('Should run filter:html.embed.video.allowed.result', async function () { | |
461 | const res = await makeRawRequest(servers[0].url + embedVideos[0].embedPath, 200) | |
462 | expect(res.text).to.equal('Lu Bu') | |
463 | }) | |
464 | ||
465 | it('Should run filter:html.embed.video-playlist.allowed.result', async function () { | |
466 | const res = await makeRawRequest(servers[0].url + embedPlaylists[0].embedPath, 200) | |
467 | expect(res.text).to.equal('Diao Chan') | |
468 | }) | |
469 | }) | |
470 | ||
471 | describe('Search filters', function () { | |
472 | ||
473 | before(async function () { | |
474 | await servers[0].config.updateCustomSubConfig({ | |
475 | newConfig: { | |
476 | search: { | |
477 | searchIndex: { | |
478 | enabled: true, | |
479 | isDefaultSearch: false, | |
480 | disableLocalSearch: false | |
481 | } | |
482 | } | |
483 | } | |
484 | }) | |
485 | }) | |
486 | ||
487 | it('Should run filter:api.search.videos.local.list.{params,result}', async function () { | |
488 | await servers[0].search.advancedVideoSearch({ | |
489 | search: { | |
490 | search: 'Sun Quan' | |
491 | } | |
492 | }) | |
493 | ||
494 | await servers[0].servers.waitUntilLog('Run hook filter:api.search.videos.local.list.params', 1) | |
495 | await servers[0].servers.waitUntilLog('Run hook filter:api.search.videos.local.list.result', 1) | |
496 | }) | |
497 | ||
498 | it('Should run filter:api.search.videos.index.list.{params,result}', async function () { | |
499 | await servers[0].search.advancedVideoSearch({ | |
500 | search: { | |
501 | search: 'Sun Quan', | |
502 | searchTarget: 'search-index' | |
503 | } | |
504 | }) | |
505 | ||
506 | await servers[0].servers.waitUntilLog('Run hook filter:api.search.videos.local.list.params', 1) | |
507 | await servers[0].servers.waitUntilLog('Run hook filter:api.search.videos.local.list.result', 1) | |
508 | await servers[0].servers.waitUntilLog('Run hook filter:api.search.videos.index.list.params', 1) | |
509 | await servers[0].servers.waitUntilLog('Run hook filter:api.search.videos.index.list.result', 1) | |
510 | }) | |
511 | ||
512 | it('Should run filter:api.search.video-channels.local.list.{params,result}', async function () { | |
513 | await servers[0].search.advancedChannelSearch({ | |
514 | search: { | |
515 | search: 'Sun Ce' | |
516 | } | |
517 | }) | |
518 | ||
519 | await servers[0].servers.waitUntilLog('Run hook filter:api.search.video-channels.local.list.params', 1) | |
520 | await servers[0].servers.waitUntilLog('Run hook filter:api.search.video-channels.local.list.result', 1) | |
521 | }) | |
522 | ||
523 | it('Should run filter:api.search.video-channels.index.list.{params,result}', async function () { | |
524 | await servers[0].search.advancedChannelSearch({ | |
525 | search: { | |
526 | search: 'Sun Ce', | |
527 | searchTarget: 'search-index' | |
528 | } | |
529 | }) | |
530 | ||
531 | await servers[0].servers.waitUntilLog('Run hook filter:api.search.video-channels.local.list.params', 1) | |
532 | await servers[0].servers.waitUntilLog('Run hook filter:api.search.video-channels.local.list.result', 1) | |
533 | await servers[0].servers.waitUntilLog('Run hook filter:api.search.video-channels.index.list.params', 1) | |
534 | await servers[0].servers.waitUntilLog('Run hook filter:api.search.video-channels.index.list.result', 1) | |
535 | }) | |
536 | ||
537 | it('Should run filter:api.search.video-playlists.local.list.{params,result}', async function () { | |
538 | await servers[0].search.advancedPlaylistSearch({ | |
539 | search: { | |
540 | search: 'Sun Jian' | |
541 | } | |
542 | }) | |
543 | ||
544 | await servers[0].servers.waitUntilLog('Run hook filter:api.search.video-playlists.local.list.params', 1) | |
545 | await servers[0].servers.waitUntilLog('Run hook filter:api.search.video-playlists.local.list.result', 1) | |
546 | }) | |
547 | ||
548 | it('Should run filter:api.search.video-playlists.index.list.{params,result}', async function () { | |
549 | await servers[0].search.advancedPlaylistSearch({ | |
550 | search: { | |
551 | search: 'Sun Jian', | |
552 | searchTarget: 'search-index' | |
553 | } | |
554 | }) | |
555 | ||
556 | await servers[0].servers.waitUntilLog('Run hook filter:api.search.video-playlists.local.list.params', 1) | |
557 | await servers[0].servers.waitUntilLog('Run hook filter:api.search.video-playlists.local.list.result', 1) | |
558 | await servers[0].servers.waitUntilLog('Run hook filter:api.search.video-playlists.index.list.params', 1) | |
559 | await servers[0].servers.waitUntilLog('Run hook filter:api.search.video-playlists.index.list.result', 1) | |
560 | }) | |
561 | }) | |
562 | ||
563 | describe('Upload/import/live attributes filters', function () { | |
564 | ||
565 | before(async function () { | |
566 | await servers[0].config.enableLive({ transcoding: false, allowReplay: false }) | |
567 | await servers[0].config.enableImports() | |
568 | await servers[0].config.disableTranscoding() | |
569 | }) | |
570 | ||
571 | it('Should run filter:api.video.upload.video-attribute.result', async function () { | |
572 | for (const mode of [ 'legacy' as 'legacy', 'resumable' as 'resumable' ]) { | |
573 | const { id } = await servers[0].videos.upload({ attributes: { name: 'video', description: 'upload' }, mode }) | |
574 | ||
575 | const video = await servers[0].videos.get({ id }) | |
576 | expect(video.description).to.equal('upload - filter:api.video.upload.video-attribute.result') | |
577 | } | |
578 | }) | |
579 | ||
580 | it('Should run filter:api.video.import-url.video-attribute.result', async function () { | |
581 | const attributes = { | |
582 | name: 'video', | |
583 | description: 'import url', | |
584 | channelId: servers[0].store.channel.id, | |
585 | targetUrl: FIXTURE_URLS.goodVideo, | |
586 | privacy: VideoPrivacy.PUBLIC | |
587 | } | |
588 | const { video: { id } } = await servers[0].imports.importVideo({ attributes }) | |
589 | ||
590 | const video = await servers[0].videos.get({ id }) | |
591 | expect(video.description).to.equal('import url - filter:api.video.import-url.video-attribute.result') | |
592 | }) | |
593 | ||
594 | it('Should run filter:api.video.import-torrent.video-attribute.result', async function () { | |
595 | const attributes = { | |
596 | name: 'video', | |
597 | description: 'import torrent', | |
598 | channelId: servers[0].store.channel.id, | |
599 | magnetUri: FIXTURE_URLS.magnet, | |
600 | privacy: VideoPrivacy.PUBLIC | |
601 | } | |
602 | const { video: { id } } = await servers[0].imports.importVideo({ attributes }) | |
603 | ||
604 | const video = await servers[0].videos.get({ id }) | |
605 | expect(video.description).to.equal('import torrent - filter:api.video.import-torrent.video-attribute.result') | |
606 | }) | |
607 | ||
608 | it('Should run filter:api.video.live.video-attribute.result', async function () { | |
609 | const fields = { | |
610 | name: 'live', | |
611 | description: 'live', | |
612 | channelId: servers[0].store.channel.id, | |
613 | privacy: VideoPrivacy.PUBLIC | |
614 | } | |
615 | const { id } = await servers[0].live.create({ fields }) | |
616 | ||
617 | const video = await servers[0].videos.get({ id }) | |
618 | expect(video.description).to.equal('live - filter:api.video.live.video-attribute.result') | |
619 | }) | |
620 | }) | |
621 | ||
622 | describe('Stats filters', function () { | |
623 | ||
624 | it('Should run filter:api.server.stats.get.result', async function () { | |
625 | const data = await servers[0].stats.get() | |
626 | ||
627 | expect((data as any).customStats).to.equal(14) | |
628 | }) | |
629 | ||
630 | }) | |
631 | ||
632 | describe('Job queue filters', function () { | |
633 | let videoUUID: string | |
634 | ||
635 | before(async function () { | |
636 | this.timeout(120_000) | |
637 | ||
638 | await servers[0].config.enableMinimumTranscoding() | |
639 | const { uuid } = await servers[0].videos.quickUpload({ name: 'studio' }) | |
640 | ||
641 | const video = await servers[0].videos.get({ id: uuid }) | |
642 | expect(video.duration).at.least(2) | |
643 | videoUUID = video.uuid | |
644 | ||
645 | await waitJobs(servers) | |
646 | ||
647 | await servers[0].config.enableStudio() | |
648 | }) | |
649 | ||
650 | it('Should run filter:job-queue.process.params', async function () { | |
651 | this.timeout(120_000) | |
652 | ||
653 | await servers[0].videoStudio.createEditionTasks({ | |
654 | videoId: videoUUID, | |
655 | tasks: [ | |
656 | { | |
657 | name: 'add-intro', | |
658 | options: { | |
659 | file: 'video_very_short_240p.mp4' | |
660 | } | |
661 | } | |
662 | ] | |
663 | }) | |
664 | ||
665 | await waitJobs(servers) | |
666 | ||
667 | await servers[0].servers.waitUntilLog('Run hook filter:job-queue.process.params', 1, false) | |
668 | ||
669 | const video = await servers[0].videos.get({ id: videoUUID }) | |
670 | expect(video.duration).at.most(2) | |
671 | }) | |
672 | ||
673 | it('Should run filter:job-queue.process.result', async function () { | |
674 | await servers[0].servers.waitUntilLog('Run hook filter:job-queue.process.result', 1, false) | |
675 | }) | |
676 | }) | |
677 | ||
678 | describe('Transcoding filters', async function () { | |
679 | ||
680 | it('Should run filter:transcoding.auto.resolutions-to-transcode.result', async function () { | |
681 | const { uuid } = await servers[0].videos.quickUpload({ name: 'transcode-filter' }) | |
682 | ||
683 | await waitJobs(servers) | |
684 | ||
685 | const video = await servers[0].videos.get({ id: uuid }) | |
686 | expect(video.files).to.have.lengthOf(2) | |
687 | expect(video.files.find(f => f.resolution.id === 100 as any)).to.exist | |
688 | }) | |
689 | }) | |
690 | ||
691 | describe('Video channel filters', async function () { | |
692 | ||
693 | it('Should run filter:api.video-channels.list.params', async function () { | |
694 | const { data } = await servers[0].channels.list({ start: 0, count: 0 }) | |
695 | ||
696 | // plugin do +1 to the count parameter | |
697 | expect(data).to.have.lengthOf(1) | |
698 | }) | |
699 | ||
700 | it('Should run filter:api.video-channels.list.result', async function () { | |
701 | const { total } = await servers[0].channels.list({ start: 0, count: 1 }) | |
702 | ||
703 | // plugin do +1 to the total parameter | |
704 | expect(total).to.equal(4) | |
705 | }) | |
706 | ||
707 | it('Should run filter:api.video-channel.get.result', async function () { | |
708 | const channel = await servers[0].channels.get({ channelName: 'root_channel' }) | |
709 | expect(channel.displayName).to.equal('Main root channel <3') | |
710 | }) | |
711 | }) | |
712 | ||
713 | after(async function () { | |
714 | await cleanupTests(servers) | |
715 | }) | |
716 | }) |