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