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