aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests
diff options
context:
space:
mode:
Diffstat (limited to 'server/tests')
-rw-r--r--server/tests/fixtures/peertube-plugin-test/main.js26
-rw-r--r--server/tests/plugins/filter-hooks.ts63
2 files changed, 89 insertions, 0 deletions
diff --git a/server/tests/fixtures/peertube-plugin-test/main.js b/server/tests/fixtures/peertube-plugin-test/main.js
index 305d92002..9913d0846 100644
--- a/server/tests/fixtures/peertube-plugin-test/main.js
+++ b/server/tests/fixtures/peertube-plugin-test/main.js
@@ -184,6 +184,32 @@ async function register ({ registerHook, registerSetting, settingsManager, stora
184 return result 184 return result
185 } 185 }
186 }) 186 })
187
188 registerHook({
189 target: 'filter:api.download.torrent.allowed.result',
190 handler: (result, params) => {
191 if (params && params.downloadName.includes('bad torrent')) {
192 return { allowed: false, errorMessage: 'Liu Bei' }
193 }
194
195 return result
196 }
197 })
198
199 registerHook({
200 target: 'filter:api.download.video.allowed.result',
201 handler: (result, params) => {
202 if (params && !params.streamingPlaylist && params.video.name.includes('bad file')) {
203 return { allowed: false, errorMessage: 'Cao Cao' }
204 }
205
206 if (params && params.streamingPlaylist && params.video.name.includes('bad playlist file')) {
207 return { allowed: false, errorMessage: 'Sun Jian' }
208 }
209
210 return result
211 }
212 })
187} 213}
188 214
189async function unregister () { 215async function unregister () {
diff --git a/server/tests/plugins/filter-hooks.ts b/server/tests/plugins/filter-hooks.ts
index d88170201..6996ae788 100644
--- a/server/tests/plugins/filter-hooks.ts
+++ b/server/tests/plugins/filter-hooks.ts
@@ -20,12 +20,14 @@ import {
20 getVideoThreadComments, 20 getVideoThreadComments,
21 getVideoWithToken, 21 getVideoWithToken,
22 installPlugin, 22 installPlugin,
23 makeRawRequest,
23 registerUser, 24 registerUser,
24 setAccessTokensToServers, 25 setAccessTokensToServers,
25 setDefaultVideoChannel, 26 setDefaultVideoChannel,
26 updateCustomSubConfig, 27 updateCustomSubConfig,
27 updateVideo, 28 updateVideo,
28 uploadVideo, 29 uploadVideo,
30 uploadVideoAndGetId,
29 waitJobs 31 waitJobs
30} from '../../../shared/extra-utils' 32} from '../../../shared/extra-utils'
31import { cleanupTests, flushAndRunMultipleServers, ServerInfo } from '../../../shared/extra-utils/server/servers' 33import { cleanupTests, flushAndRunMultipleServers, ServerInfo } from '../../../shared/extra-utils/server/servers'
@@ -355,6 +357,67 @@ describe('Test plugin filter hooks', function () {
355 }) 357 })
356 }) 358 })
357 359
360 describe('Download hooks', function () {
361 const downloadVideos: VideoDetails[] = []
362
363 before(async function () {
364 this.timeout(60000)
365
366 await updateCustomSubConfig(servers[0].url, servers[0].accessToken, {
367 transcoding: {
368 webtorrent: {
369 enabled: true
370 },
371 hls: {
372 enabled: true
373 }
374 }
375 })
376
377 const uuids: string[] = []
378
379 for (const name of [ 'bad torrent', 'bad file', 'bad playlist file' ]) {
380 const uuid = (await uploadVideoAndGetId({ server: servers[0], videoName: name })).uuid
381 uuids.push(uuid)
382 }
383
384 await waitJobs(servers)
385
386 for (const uuid of uuids) {
387 const res = await getVideo(servers[0].url, uuid)
388 downloadVideos.push(res.body)
389 }
390 })
391
392 it('Should run filter:api.download.torrent.allowed.result', async function () {
393 const res = await makeRawRequest(downloadVideos[0].files[0].torrentDownloadUrl, 403)
394 expect(res.body.error).to.equal('Liu Bei')
395
396 await makeRawRequest(downloadVideos[1].files[0].torrentDownloadUrl, 200)
397 await makeRawRequest(downloadVideos[2].files[0].torrentDownloadUrl, 200)
398 })
399
400 it('Should run filter:api.download.video.allowed.result', async function () {
401 {
402 const res = await makeRawRequest(downloadVideos[1].files[0].fileDownloadUrl, 403)
403 expect(res.body.error).to.equal('Cao Cao')
404
405 await makeRawRequest(downloadVideos[0].files[0].fileDownloadUrl, 200)
406 await makeRawRequest(downloadVideos[2].files[0].fileDownloadUrl, 200)
407 }
408
409 {
410 const res = await makeRawRequest(downloadVideos[2].streamingPlaylists[0].files[0].fileDownloadUrl, 403)
411 expect(res.body.error).to.equal('Sun Jian')
412
413 await makeRawRequest(downloadVideos[2].files[0].fileDownloadUrl, 200)
414
415 await makeRawRequest(downloadVideos[0].streamingPlaylists[0].files[0].fileDownloadUrl, 200)
416 await makeRawRequest(downloadVideos[1].streamingPlaylists[0].files[0].fileDownloadUrl, 200)
417 }
418 })
419 })
420
358 after(async function () { 421 after(async function () {
359 await cleanupTests(servers) 422 await cleanupTests(servers)
360 }) 423 })