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.js42
-rw-r--r--server/tests/plugins/filter-hooks.ts88
2 files changed, 124 insertions, 6 deletions
diff --git a/server/tests/fixtures/peertube-plugin-test/main.js b/server/tests/fixtures/peertube-plugin-test/main.js
index 69796ab07..a45e98fb5 100644
--- a/server/tests/fixtures/peertube-plugin-test/main.js
+++ b/server/tests/fixtures/peertube-plugin-test/main.js
@@ -50,7 +50,47 @@ async function register ({ registerHook, registerSetting, settingsManager, stora
50 target: 'filter:api.video.upload.accept.result', 50 target: 'filter:api.video.upload.accept.result',
51 handler: ({ accepted }, { videoBody }) => { 51 handler: ({ accepted }, { videoBody }) => {
52 if (!accepted) return { accepted: false } 52 if (!accepted) return { accepted: false }
53 if (videoBody.name.indexOf('bad word') !== -1) return { accepted: false, errorMessage: 'bad word '} 53 if (videoBody.name.indexOf('bad word') !== -1) return { accepted: false, errorMessage: 'bad word' }
54
55 return { accepted: true }
56 }
57 })
58
59 registerHook({
60 target: 'filter:api.video.pre-import-url.accept.result',
61 handler: ({ accepted }, { videoImportBody }) => {
62 if (!accepted) return { accepted: false }
63 if (videoImportBody.targetUrl.includes('bad')) return { accepted: false, errorMessage: 'bad target url' }
64
65 return { accepted: true }
66 }
67 })
68
69 registerHook({
70 target: 'filter:api.video.pre-import-torrent.accept.result',
71 handler: ({ accepted }, { videoImportBody }) => {
72 if (!accepted) return { accepted: false }
73 if (videoImportBody.name.includes('bad torrent')) return { accepted: false, errorMessage: 'bad torrent' }
74
75 return { accepted: true }
76 }
77 })
78
79 registerHook({
80 target: 'filter:api.video.post-import-url.accept.result',
81 handler: ({ accepted }, { video }) => {
82 if (!accepted) return { accepted: false }
83 if (video.name.includes('bad word')) return { accepted: false, errorMessage: 'bad word' }
84
85 return { accepted: true }
86 }
87 })
88
89 registerHook({
90 target: 'filter:api.video.post-import-torrent.accept.result',
91 handler: ({ accepted }, { video }) => {
92 if (!accepted) return { accepted: false }
93 if (video.name.includes('bad word')) return { accepted: false, errorMessage: 'bad word' }
54 94
55 return { accepted: true } 95 return { accepted: true }
56 } 96 }
diff --git a/server/tests/plugins/filter-hooks.ts b/server/tests/plugins/filter-hooks.ts
index 6c1fd40ba..41242318e 100644
--- a/server/tests/plugins/filter-hooks.ts
+++ b/server/tests/plugins/filter-hooks.ts
@@ -1,8 +1,8 @@
1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ 1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2 2
3import * as chai from 'chai'
4import 'mocha' 3import 'mocha'
5import { cleanupTests, flushAndRunMultipleServers, ServerInfo } from '../../../shared/extra-utils/server/servers' 4import * as chai from 'chai'
5import { ServerConfig } from '@shared/models'
6import { 6import {
7 addVideoCommentReply, 7 addVideoCommentReply,
8 addVideoCommentThread, 8 addVideoCommentThread,
@@ -23,10 +23,10 @@ import {
23 uploadVideo, 23 uploadVideo,
24 waitJobs 24 waitJobs
25} from '../../../shared/extra-utils' 25} from '../../../shared/extra-utils'
26import { cleanupTests, flushAndRunMultipleServers, ServerInfo } from '../../../shared/extra-utils/server/servers'
27import { getMyVideoImports, getYoutubeVideoUrl, importVideo } from '../../../shared/extra-utils/videos/video-imports'
28import { VideoDetails, VideoImport, VideoImportState, VideoPrivacy } from '../../../shared/models/videos'
26import { VideoCommentThreadTree } from '../../../shared/models/videos/video-comment.model' 29import { VideoCommentThreadTree } from '../../../shared/models/videos/video-comment.model'
27import { VideoDetails } from '../../../shared/models/videos'
28import { getYoutubeVideoUrl, importVideo } from '../../../shared/extra-utils/videos/video-imports'
29import { ServerConfig } from '@shared/models'
30 30
31const expect = chai.expect 31const expect = chai.expect
32 32
@@ -87,6 +87,84 @@ describe('Test plugin filter hooks', function () {
87 await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'video with bad word' }, 403) 87 await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'video with bad word' }, 403)
88 }) 88 })
89 89
90 it('Should run filter:api.video.pre-import-url.accept.result', async function () {
91 const baseAttributes = {
92 name: 'normal title',
93 privacy: VideoPrivacy.PUBLIC,
94 channelId: servers[0].videoChannel.id,
95 targetUrl: getYoutubeVideoUrl() + 'bad'
96 }
97 await importVideo(servers[0].url, servers[0].accessToken, baseAttributes, 403)
98 })
99
100 it('Should run filter:api.video.pre-import-torrent.accept.result', async function () {
101 const baseAttributes = {
102 name: 'bad torrent',
103 privacy: VideoPrivacy.PUBLIC,
104 channelId: servers[0].videoChannel.id,
105 torrentfile: 'video-720p.torrent' as any
106 }
107 await importVideo(servers[0].url, servers[0].accessToken, baseAttributes, 403)
108 })
109
110 it('Should run filter:api.video.post-import-url.accept.result', async function () {
111 this.timeout(60000)
112
113 let videoImportId: number
114
115 {
116 const baseAttributes = {
117 name: 'title with bad word',
118 privacy: VideoPrivacy.PUBLIC,
119 channelId: servers[0].videoChannel.id,
120 targetUrl: getYoutubeVideoUrl()
121 }
122 const res = await importVideo(servers[0].url, servers[0].accessToken, baseAttributes)
123 videoImportId = res.body.id
124 }
125
126 await waitJobs(servers)
127
128 {
129 const res = await getMyVideoImports(servers[0].url, servers[0].accessToken)
130 const videoImports = res.body.data as VideoImport[]
131
132 const videoImport = videoImports.find(i => i.id === videoImportId)
133
134 expect(videoImport.state.id).to.equal(VideoImportState.REJECTED)
135 expect(videoImport.state.label).to.equal('Rejected')
136 }
137 })
138
139 it('Should run filter:api.video.post-import-torrent.accept.result', async function () {
140 this.timeout(60000)
141
142 let videoImportId: number
143
144 {
145 const baseAttributes = {
146 name: 'title with bad word',
147 privacy: VideoPrivacy.PUBLIC,
148 channelId: servers[0].videoChannel.id,
149 torrentfile: 'video-720p.torrent' as any
150 }
151 const res = await importVideo(servers[0].url, servers[0].accessToken, baseAttributes)
152 videoImportId = res.body.id
153 }
154
155 await waitJobs(servers)
156
157 {
158 const res = await getMyVideoImports(servers[0].url, servers[0].accessToken)
159 const videoImports = res.body.data as VideoImport[]
160
161 const videoImport = videoImports.find(i => i.id === videoImportId)
162
163 expect(videoImport.state.id).to.equal(VideoImportState.REJECTED)
164 expect(videoImport.state.label).to.equal('Rejected')
165 }
166 })
167
90 it('Should run filter:api.video-thread.create.accept.result', async function () { 168 it('Should run filter:api.video-thread.create.accept.result', async function () {
91 await addVideoCommentThread(servers[0].url, servers[0].accessToken, videoUUID, 'comment with bad word', 403) 169 await addVideoCommentThread(servers[0].url, servers[0].accessToken, videoUUID, 'comment with bad word', 403)
92 }) 170 })