]>
Commit | Line | Data |
---|---|---|
a1587156 | 1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ |
9b474844 | 2 | |
86347717 | 3 | import { expect } from 'chai' |
b379759f C |
4 | import { |
5 | HttpStatusCode, | |
6 | PeerTubeProblemDocument, | |
7 | VideoDetails, | |
8 | VideoImportState, | |
9 | VideoPlaylist, | |
10 | VideoPlaylistPrivacy, | |
11 | VideoPrivacy | |
12 | } from '@shared/models' | |
89cd1275 | 13 | import { |
af971e06 | 14 | cleanupTests, |
254d3579 | 15 | createMultipleServers, |
59bbcced | 16 | doubleFollow, |
3545e72c | 17 | makeGetRequest, |
4bc45da3 | 18 | makeRawRequest, |
254d3579 | 19 | PeerTubeServer, |
59bbcced | 20 | PluginsCommand, |
a1587156 | 21 | setAccessTokensToServers, |
6691c522 | 22 | setDefaultVideoChannel, |
6c5065a0 | 23 | waitJobs |
bf54587a | 24 | } from '@shared/server-commands' |
c55e3d72 | 25 | import { FIXTURE_URLS } from '../shared' |
9b474844 | 26 | |
9b474844 | 27 | describe('Test plugin filter hooks', function () { |
254d3579 | 28 | let servers: PeerTubeServer[] |
89cd1275 C |
29 | let videoUUID: string |
30 | let threadId: number | |
c5ca7e1e | 31 | let videoPlaylistUUID: string |
9b474844 C |
32 | |
33 | before(async function () { | |
4076e2ef | 34 | this.timeout(60000) |
9b474844 | 35 | |
254d3579 | 36 | servers = await createMultipleServers(2) |
89cd1275 | 37 | await setAccessTokensToServers(servers) |
6691c522 C |
38 | await setDefaultVideoChannel(servers) |
39 | await doubleFollow(servers[0], servers[1]) | |
89cd1275 | 40 | |
89d241a7 C |
41 | await servers[0].plugins.install({ path: PluginsCommand.getPluginTestPath() }) |
42 | await servers[0].plugins.install({ path: PluginsCommand.getPluginTestPath('-filter-translations') }) | |
c5ca7e1e | 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 | } | |
89cd1275 C |
53 | |
54 | for (let i = 0; i < 10; i++) { | |
c5ca7e1e | 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 } }) | |
89cd1275 C |
57 | } |
58 | ||
89d241a7 | 59 | const { data } = await servers[0].videos.list() |
d23dd9fb | 60 | videoUUID = data[0].uuid |
3cabf353 | 61 | |
89d241a7 | 62 | await servers[0].config.updateCustomSubConfig({ |
65e6e260 C |
63 | newConfig: { |
64 | live: { enabled: true }, | |
65 | signup: { enabled: true }, | |
66 | import: { | |
67 | videos: { | |
68 | http: { enabled: true }, | |
69 | torrent: { enabled: true } | |
70 | } | |
3cabf353 C |
71 | } |
72 | } | |
73 | }) | |
9b474844 C |
74 | }) |
75 | ||
b2a70e3c | 76 | describe('Videos', function () { |
89cd1275 | 77 | |
b2a70e3c C |
78 | it('Should run filter:api.videos.list.params', async function () { |
79 | const { data } = await servers[0].videos.list({ start: 0, count: 2 }) | |
89cd1275 | 80 | |
b2a70e3c C |
81 | // 2 plugins do +1 to the count parameter |
82 | expect(data).to.have.lengthOf(4) | |
83 | }) | |
89cd1275 | 84 | |
b2a70e3c C |
85 | it('Should run filter:api.videos.list.result', async function () { |
86 | const { total } = await servers[0].videos.list({ start: 0, count: 0 }) | |
89cd1275 | 87 | |
b2a70e3c C |
88 | // Plugin do +1 to the total result |
89 | expect(total).to.equal(11) | |
c5ca7e1e | 90 | }) |
91 | ||
b2a70e3c C |
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 | }) | |
c5ca7e1e | 97 | |
b2a70e3c C |
98 | // 1 plugin do +1 to the count parameter |
99 | expect(data).to.have.lengthOf(3) | |
c5ca7e1e | 100 | }) |
101 | ||
b2a70e3c C |
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 | }) | |
c5ca7e1e | 107 | |
b2a70e3c C |
108 | // Plugin do +1 to the total result |
109 | expect(total).to.equal(11) | |
110 | }) | |
38267c0c | 111 | |
b2a70e3c C |
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 }) | |
38267c0c | 114 | |
b2a70e3c C |
115 | // 1 plugin do +1 to the count parameter |
116 | expect(data).to.have.lengthOf(3) | |
117 | }) | |
38267c0c | 118 | |
b2a70e3c C |
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 }) | |
38267c0c | 121 | |
b2a70e3c C |
122 | // Plugin do +2 to the total result |
123 | expect(total).to.equal(12) | |
124 | }) | |
38267c0c | 125 | |
b2a70e3c C |
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 }) | |
38267c0c | 128 | |
b2a70e3c C |
129 | // 1 plugin do +3 to the count parameter |
130 | expect(data).to.have.lengthOf(5) | |
131 | }) | |
38267c0c | 132 | |
b2a70e3c C |
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 }) | |
38267c0c | 135 | |
b2a70e3c C |
136 | // Plugin do +3 to the total result |
137 | expect(total).to.equal(13) | |
138 | }) | |
a4d2ca07 | 139 | |
b2a70e3c C |
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 }) | |
a4d2ca07 | 142 | |
b2a70e3c C |
143 | // 1 plugin do +4 to the count parameter |
144 | expect(data).to.have.lengthOf(6) | |
145 | }) | |
a4d2ca07 | 146 | |
b2a70e3c C |
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 }) | |
a4d2ca07 | 149 | |
b2a70e3c C |
150 | // Plugin do +4 to the total result |
151 | expect(total).to.equal(14) | |
152 | }) | |
9b474844 | 153 | |
b2a70e3c C |
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 | }) | |
6691c522 C |
158 | }) |
159 | ||
b2a70e3c | 160 | describe('Video/live/import accept', function () { |
3cabf353 | 161 | |
b2a70e3c C |
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 | }) | |
2158ac90 | 165 | |
b2a70e3c C |
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 | } | |
2158ac90 | 172 | |
b2a70e3c C |
173 | await servers[0].live.create({ fields: attributes, expectedStatus: HttpStatusCode.FORBIDDEN_403 }) |
174 | }) | |
2158ac90 | 175 | |
b2a70e3c C |
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 | }) | |
2158ac90 | 185 | |
b2a70e3c | 186 | it('Should run filter:api.video.pre-import-torrent.accept.result', async function () { |
6910f20f | 187 | const attributes = { |
b2a70e3c | 188 | name: 'bad torrent', |
2158ac90 | 189 | privacy: VideoPrivacy.PUBLIC, |
89d241a7 | 190 | channelId: servers[0].store.channel.id, |
b2a70e3c | 191 | torrentfile: 'video-720p.torrent' as any |
2158ac90 | 192 | } |
b2a70e3c C |
193 | await servers[0].imports.importVideo({ attributes, expectedStatus: HttpStatusCode.FORBIDDEN_403 }) |
194 | }) | |
2158ac90 | 195 | |
b2a70e3c C |
196 | it('Should run filter:api.video.post-import-url.accept.result', async function () { |
197 | this.timeout(60000) | |
2158ac90 | 198 | |
b2a70e3c | 199 | let videoImportId: number |
2158ac90 | 200 | |
b2a70e3c C |
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 | } | |
2158ac90 | 211 | |
b2a70e3c | 212 | await waitJobs(servers) |
2158ac90 | 213 | |
b2a70e3c C |
214 | { |
215 | const body = await servers[0].imports.getMyVideoImports() | |
216 | const videoImports = body.data | |
2158ac90 | 217 | |
b2a70e3c | 218 | const videoImport = videoImports.find(i => i.id === videoImportId) |
2158ac90 | 219 | |
b2a70e3c C |
220 | expect(videoImport.state.id).to.equal(VideoImportState.REJECTED) |
221 | expect(videoImport.state.label).to.equal('Rejected') | |
2158ac90 | 222 | } |
b2a70e3c | 223 | }) |
2158ac90 | 224 | |
b2a70e3c C |
225 | it('Should run filter:api.video.post-import-torrent.accept.result', async function () { |
226 | this.timeout(60000) | |
2158ac90 | 227 | |
b2a70e3c | 228 | let videoImportId: number |
2158ac90 | 229 | |
b2a70e3c C |
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 | } | |
2158ac90 | 240 | |
b2a70e3c C |
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) | |
2158ac90 | 247 | |
b2a70e3c C |
248 | expect(videoImport.state.id).to.equal(VideoImportState.REJECTED) |
249 | expect(videoImport.state.label).to.equal('Rejected') | |
250 | } | |
12edc149 | 251 | }) |
6691c522 C |
252 | }) |
253 | ||
b2a70e3c | 254 | describe('Video comments accept', function () { |
12edc149 | 255 | |
b2a70e3c C |
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 | }) | |
12edc149 | 262 | }) |
b2a70e3c C |
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 | }) | |
12edc149 | 280 | }) |
6691c522 | 281 | |
b2a70e3c C |
282 | it('Should run filter:activity-pub.remote-video-comment.create.accept.result on a thread creation', async function () { |
283 | this.timeout(30000) | |
6691c522 | 284 | |
b2a70e3c | 285 | await servers[1].comments.createThread({ videoId: videoUUID, text: 'comment with bad word' }) |
6691c522 | 286 | |
b2a70e3c | 287 | await waitJobs(servers) |
6691c522 | 288 | |
b2a70e3c C |
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 | |
6691c522 | 306 | |
b2a70e3c C |
307 | await servers[1].comments.addReply({ |
308 | videoId: videoUUID, | |
309 | toCommentId: threadIdServer2, | |
310 | text: 'comment with bad word' | |
311 | }) | |
6691c522 | 312 | |
b2a70e3c | 313 | await waitJobs(servers) |
6691c522 | 314 | |
b2a70e3c C |
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 | }) | |
6691c522 C |
326 | }) |
327 | ||
b2a70e3c C |
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 }) | |
d1aed103 | 332 | |
b2a70e3c C |
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 | }) | |
d1aed103 C |
359 | }) |
360 | ||
0260dc8a | 361 | describe('filter:video.auto-blacklist.result', function () { |
6691c522 | 362 | |
6910f20f | 363 | async function checkIsBlacklisted (id: number | string, value: boolean) { |
89d241a7 | 364 | const video = await servers[0].videos.getWithToken({ id }) |
6691c522 C |
365 | expect(video.blacklisted).to.equal(value) |
366 | } | |
367 | ||
368 | it('Should blacklist on upload', async function () { | |
89d241a7 | 369 | const { uuid } = await servers[0].videos.upload({ attributes: { name: 'video please blacklist me' } }) |
d23dd9fb | 370 | await checkIsBlacklisted(uuid, true) |
6691c522 C |
371 | }) |
372 | ||
373 | it('Should blacklist on import', async function () { | |
89566f77 C |
374 | this.timeout(15000) |
375 | ||
6691c522 C |
376 | const attributes = { |
377 | name: 'video please blacklist me', | |
59bbcced | 378 | targetUrl: FIXTURE_URLS.goodVideo, |
89d241a7 | 379 | channelId: servers[0].store.channel.id |
6691c522 | 380 | } |
89d241a7 | 381 | const body = await servers[0].imports.importVideo({ attributes }) |
6910f20f | 382 | await checkIsBlacklisted(body.video.uuid, true) |
6691c522 C |
383 | }) |
384 | ||
385 | it('Should blacklist on update', async function () { | |
89d241a7 | 386 | const { uuid } = await servers[0].videos.upload({ attributes: { name: 'video' } }) |
d23dd9fb | 387 | await checkIsBlacklisted(uuid, false) |
6691c522 | 388 | |
89d241a7 | 389 | await servers[0].videos.update({ id: uuid, attributes: { name: 'please blacklist me' } }) |
d23dd9fb | 390 | await checkIsBlacklisted(uuid, true) |
6691c522 C |
391 | }) |
392 | ||
393 | it('Should blacklist on remote upload', async function () { | |
3d470a53 | 394 | this.timeout(120000) |
6691c522 | 395 | |
89d241a7 | 396 | const { uuid } = await servers[1].videos.upload({ attributes: { name: 'remote please blacklist me' } }) |
6691c522 C |
397 | await waitJobs(servers) |
398 | ||
d23dd9fb | 399 | await checkIsBlacklisted(uuid, true) |
6691c522 C |
400 | }) |
401 | ||
402 | it('Should blacklist on remote update', async function () { | |
3d470a53 | 403 | this.timeout(120000) |
6691c522 | 404 | |
89d241a7 | 405 | const { uuid } = await servers[1].videos.upload({ attributes: { name: 'video' } }) |
6691c522 C |
406 | await waitJobs(servers) |
407 | ||
d23dd9fb | 408 | await checkIsBlacklisted(uuid, false) |
6691c522 | 409 | |
89d241a7 | 410 | await servers[1].videos.update({ id: uuid, attributes: { name: 'please blacklist me' } }) |
6691c522 C |
411 | await waitJobs(servers) |
412 | ||
d23dd9fb | 413 | await checkIsBlacklisted(uuid, true) |
6691c522 C |
414 | }) |
415 | }) | |
416 | ||
4ce7eb71 C |
417 | describe('Should run filter:api.user.signup.allowed.result', function () { |
418 | ||
b379759f C |
419 | before(async function () { |
420 | await servers[0].config.updateExistingSubConfig({ newConfig: { signup: { requiresApproval: false } } }) | |
421 | }) | |
422 | ||
4ce7eb71 | 423 | it('Should run on config endpoint', async function () { |
89d241a7 | 424 | const body = await servers[0].config.getConfig() |
65e6e260 | 425 | expect(body.signup.allowed).to.be.true |
4ce7eb71 C |
426 | }) |
427 | ||
428 | it('Should allow a signup', async function () { | |
b379759f | 429 | await servers[0].registrations.register({ username: 'john1' }) |
4ce7eb71 C |
430 | }) |
431 | ||
432 | it('Should not allow a signup', async function () { | |
b379759f C |
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', | |
7926c5f9 C |
461 | expectedStatus: HttpStatusCode.FORBIDDEN_403 |
462 | }) | |
4ce7eb71 | 463 | |
b379759f | 464 | expect((body as unknown as PeerTubeProblemDocument).error).to.equal('No jma 2') |
4ce7eb71 C |
465 | }) |
466 | }) | |
467 | ||
4bc45da3 C |
468 | describe('Download hooks', function () { |
469 | const downloadVideos: VideoDetails[] = [] | |
868314e8 | 470 | let downloadVideo2Token: string |
4bc45da3 C |
471 | |
472 | before(async function () { | |
c4244cfd | 473 | this.timeout(120000) |
4bc45da3 | 474 | |
89d241a7 | 475 | await servers[0].config.updateCustomSubConfig({ |
65e6e260 C |
476 | newConfig: { |
477 | transcoding: { | |
478 | webtorrent: { | |
479 | enabled: true | |
480 | }, | |
481 | hls: { | |
482 | enabled: true | |
483 | } | |
4bc45da3 C |
484 | } |
485 | } | |
486 | }) | |
487 | ||
488 | const uuids: string[] = [] | |
489 | ||
490 | for (const name of [ 'bad torrent', 'bad file', 'bad playlist file' ]) { | |
ba2684ce | 491 | const uuid = (await servers[0].videos.quickUpload({ name })).uuid |
4bc45da3 C |
492 | uuids.push(uuid) |
493 | } | |
494 | ||
495 | await waitJobs(servers) | |
496 | ||
497 | for (const uuid of uuids) { | |
89d241a7 | 498 | downloadVideos.push(await servers[0].videos.get({ id: uuid })) |
4bc45da3 | 499 | } |
868314e8 C |
500 | |
501 | downloadVideo2Token = await servers[0].videoToken.getVideoFileToken({ videoId: downloadVideos[2].uuid }) | |
4bc45da3 C |
502 | }) |
503 | ||
504 | it('Should run filter:api.download.torrent.allowed.result', async function () { | |
3545e72c | 505 | const res = await makeRawRequest({ url: downloadVideos[0].files[0].torrentDownloadUrl, expectedStatus: HttpStatusCode.FORBIDDEN_403 }) |
4bc45da3 C |
506 | expect(res.body.error).to.equal('Liu Bei') |
507 | ||
3545e72c C |
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 }) | |
4bc45da3 C |
510 | }) |
511 | ||
512 | it('Should run filter:api.download.video.allowed.result', async function () { | |
513 | { | |
868314e8 C |
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 }) | |
4bc45da3 C |
521 | expect(res.body.error).to.equal('Cao Cao') |
522 | ||
868314e8 C |
523 | for (const url of allowed) { |
524 | await makeRawRequest({ url, expectedStatus: HttpStatusCode.OK_200 }) | |
525 | await makeRawRequest({ url, expectedStatus: HttpStatusCode.OK_200 }) | |
526 | } | |
4bc45da3 C |
527 | } |
528 | ||
529 | { | |
868314e8 | 530 | const refused = downloadVideos[2].streamingPlaylists[0].files[0].fileDownloadUrl |
3545e72c | 531 | |
868314e8 C |
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 | ] | |
4bc45da3 | 537 | |
868314e8 C |
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') | |
3545e72c | 541 | |
868314e8 C |
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 }) | |
4bc45da3 | 545 | |
868314e8 C |
546 | // Other files work |
547 | for (const url of allowed) { | |
548 | await makeRawRequest({ url, expectedStatus: HttpStatusCode.OK_200 }) | |
549 | } | |
4bc45da3 C |
550 | } |
551 | }) | |
552 | }) | |
553 | ||
eebd9838 C |
554 | describe('Embed filters', function () { |
555 | const embedVideos: VideoDetails[] = [] | |
556 | const embedPlaylists: VideoPlaylist[] = [] | |
557 | ||
558 | before(async function () { | |
559 | this.timeout(60000) | |
560 | ||
c729caf6 | 561 | await servers[0].config.disableTranscoding() |
eebd9838 C |
562 | |
563 | for (const name of [ 'bad embed', 'good embed' ]) { | |
564 | { | |
ba2684ce | 565 | const uuid = (await servers[0].videos.quickUpload({ name })).uuid |
89d241a7 | 566 | embedVideos.push(await servers[0].videos.get({ id: uuid })) |
eebd9838 C |
567 | } |
568 | ||
569 | { | |
89d241a7 C |
570 | const attributes = { displayName: name, videoChannelId: servers[0].store.channel.id, privacy: VideoPlaylistPrivacy.PUBLIC } |
571 | const { id } = await servers[0].playlists.create({ attributes }) | |
eebd9838 | 572 | |
89d241a7 | 573 | const playlist = await servers[0].playlists.get({ playlistId: id }) |
e6346d59 | 574 | embedPlaylists.push(playlist) |
eebd9838 C |
575 | } |
576 | } | |
577 | }) | |
578 | ||
579 | it('Should run filter:html.embed.video.allowed.result', async function () { | |
3545e72c | 580 | const res = await makeGetRequest({ url: servers[0].url, path: embedVideos[0].embedPath, expectedStatus: HttpStatusCode.OK_200 }) |
eebd9838 C |
581 | expect(res.text).to.equal('Lu Bu') |
582 | }) | |
583 | ||
584 | it('Should run filter:html.embed.video-playlist.allowed.result', async function () { | |
3545e72c | 585 | const res = await makeGetRequest({ url: servers[0].url, path: embedPlaylists[0].embedPath, expectedStatus: HttpStatusCode.OK_200 }) |
eebd9838 C |
586 | expect(res.text).to.equal('Diao Chan') |
587 | }) | |
588 | }) | |
589 | ||
74a4d531 C |
590 | describe('Search filters', function () { |
591 | ||
592 | before(async function () { | |
89d241a7 | 593 | await servers[0].config.updateCustomSubConfig({ |
65e6e260 C |
594 | newConfig: { |
595 | search: { | |
596 | searchIndex: { | |
597 | enabled: true, | |
598 | isDefaultSearch: false, | |
599 | disableLocalSearch: false | |
600 | } | |
74a4d531 C |
601 | } |
602 | } | |
603 | }) | |
604 | }) | |
605 | ||
606 | it('Should run filter:api.search.videos.local.list.{params,result}', async function () { | |
89d241a7 | 607 | await servers[0].search.advancedVideoSearch({ |
af971e06 C |
608 | search: { |
609 | search: 'Sun Quan' | |
610 | } | |
74a4d531 C |
611 | }) |
612 | ||
89d241a7 C |
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) | |
74a4d531 C |
615 | }) |
616 | ||
617 | it('Should run filter:api.search.videos.index.list.{params,result}', async function () { | |
89d241a7 | 618 | await servers[0].search.advancedVideoSearch({ |
af971e06 C |
619 | search: { |
620 | search: 'Sun Quan', | |
621 | searchTarget: 'search-index' | |
622 | } | |
74a4d531 C |
623 | }) |
624 | ||
89d241a7 C |
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) | |
74a4d531 C |
629 | }) |
630 | ||
631 | it('Should run filter:api.search.video-channels.local.list.{params,result}', async function () { | |
89d241a7 | 632 | await servers[0].search.advancedChannelSearch({ |
af971e06 C |
633 | search: { |
634 | search: 'Sun Ce' | |
635 | } | |
74a4d531 C |
636 | }) |
637 | ||
89d241a7 C |
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) | |
74a4d531 C |
640 | }) |
641 | ||
642 | it('Should run filter:api.search.video-channels.index.list.{params,result}', async function () { | |
89d241a7 | 643 | await servers[0].search.advancedChannelSearch({ |
af971e06 C |
644 | search: { |
645 | search: 'Sun Ce', | |
646 | searchTarget: 'search-index' | |
647 | } | |
74a4d531 C |
648 | }) |
649 | ||
89d241a7 C |
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) | |
74a4d531 | 654 | }) |
37a44fc9 C |
655 | |
656 | it('Should run filter:api.search.video-playlists.local.list.{params,result}', async function () { | |
89d241a7 | 657 | await servers[0].search.advancedPlaylistSearch({ |
af971e06 C |
658 | search: { |
659 | search: 'Sun Jian' | |
660 | } | |
37a44fc9 C |
661 | }) |
662 | ||
89d241a7 C |
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) | |
37a44fc9 C |
665 | }) |
666 | ||
667 | it('Should run filter:api.search.video-playlists.index.list.{params,result}', async function () { | |
89d241a7 | 668 | await servers[0].search.advancedPlaylistSearch({ |
af971e06 C |
669 | search: { |
670 | search: 'Sun Jian', | |
671 | searchTarget: 'search-index' | |
672 | } | |
37a44fc9 C |
673 | }) |
674 | ||
89d241a7 C |
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) | |
37a44fc9 | 679 | }) |
74a4d531 C |
680 | }) |
681 | ||
d17d7430 C |
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 | ||
65058050 C |
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 | ||
22df69fd C |
751 | describe('Job queue filters', function () { |
752 | let videoUUID: string | |
753 | ||
754 | before(async function () { | |
755 | this.timeout(120_000) | |
756 | ||
f59462ec | 757 | await servers[0].config.enableMinimumTranscoding() |
22df69fd C |
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 | ||
ebb9e53a C |
797 | describe('Transcoding filters', async function () { |
798 | ||
64fd6158 | 799 | it('Should run filter:transcoding.auto.resolutions-to-transcode.result', async function () { |
ebb9e53a C |
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 | ||
0260dc8a C |
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 | ||
9b474844 | 832 | after(async function () { |
89cd1275 | 833 | await cleanupTests(servers) |
9b474844 C |
834 | }) |
835 | }) |