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