]>
Commit | Line | Data |
---|---|---|
a1587156 | 1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ |
0e1dc3e7 | 2 | |
b488ba1e | 3 | import 'mocha' |
0e1dc3e7 | 4 | import * as chai from 'chai' |
5abb9fbb | 5 | import { orderBy } from 'lodash' |
0e1dc3e7 | 6 | import { |
03371ad9 C |
7 | addVideoToBlacklist, |
8 | cleanupTests, | |
1eddc9a7 | 9 | createUser, |
af971e06 | 10 | doubleFollow, |
975e6e0e | 11 | flushAndRunMultipleServers, |
a1587156 C |
12 | getBlacklistedVideosList, |
13 | getMyUserInformation, | |
5abb9fbb | 14 | getMyVideos, |
0e1dc3e7 | 15 | getVideosList, |
975e6e0e | 16 | killallServers, |
5abb9fbb | 17 | removeVideoFromBlacklist, |
1eddc9a7 | 18 | reRunServer, |
975e6e0e C |
19 | ServerInfo, |
20 | setAccessTokensToServers, | |
5abb9fbb C |
21 | updateVideo, |
22 | updateVideoBlacklist, | |
23 | uploadVideo, | |
af971e06 C |
24 | userLogin, |
25 | waitJobs | |
26 | } from '@shared/extra-utils' | |
27 | import { getGoodVideoUrl, getMagnetURI, importVideo } from '@shared/extra-utils/videos/video-imports' | |
28 | import { User, UserAdminFlag, UserRole, VideoBlacklist, VideoBlacklistType } from '@shared/models' | |
975e6e0e C |
29 | |
30 | const expect = chai.expect | |
0e1dc3e7 | 31 | |
1eddc9a7 | 32 | describe('Test video blacklist', function () { |
0e1dc3e7 | 33 | let servers: ServerInfo[] = [] |
5abb9fbb C |
34 | let videoId: number |
35 | ||
36 | async function blacklistVideosOnServer (server: ServerInfo) { | |
37 | const res = await getVideosList(server.url) | |
38 | ||
39 | const videos = res.body.data | |
a1587156 | 40 | for (const video of videos) { |
5abb9fbb C |
41 | await addVideoToBlacklist(server.url, server.accessToken, video.id, 'super reason') |
42 | } | |
43 | } | |
0e1dc3e7 C |
44 | |
45 | before(async function () { | |
572f8d3d | 46 | this.timeout(50000) |
0e1dc3e7 C |
47 | |
48 | // Run servers | |
49 | servers = await flushAndRunMultipleServers(2) | |
50 | ||
51 | // Get the access tokens | |
52 | await setAccessTokensToServers(servers) | |
53 | ||
975e6e0e C |
54 | // Server 1 and server 2 follow each other |
55 | await doubleFollow(servers[0], servers[1]) | |
0e1dc3e7 | 56 | |
5abb9fbb C |
57 | // Upload 2 videos on server 2 |
58 | await uploadVideo(servers[1].url, servers[1].accessToken, { name: 'My 1st video', description: 'A video on server 2' }) | |
59 | await uploadVideo(servers[1].url, servers[1].accessToken, { name: 'My 2nd video', description: 'A video on server 2' }) | |
0e1dc3e7 | 60 | |
572f8d3d | 61 | // Wait videos propagation, server 2 has transcoding enabled |
3cd0734f | 62 | await waitJobs(servers) |
0e1dc3e7 | 63 | |
5abb9fbb C |
64 | // Blacklist the two videos on server 1 |
65 | await blacklistVideosOnServer(servers[0]) | |
66 | }) | |
67 | ||
68 | describe('When listing/searching videos', function () { | |
0e1dc3e7 | 69 | |
5abb9fbb C |
70 | it('Should not have the video blacklisted in videos list/search on server 1', async function () { |
71 | { | |
a1587156 | 72 | const res = await getVideosList(servers[0].url) |
0e1dc3e7 | 73 | |
5abb9fbb C |
74 | expect(res.body.total).to.equal(0) |
75 | expect(res.body.data).to.be.an('array') | |
76 | expect(res.body.data.length).to.equal(0) | |
77 | } | |
78 | ||
79 | { | |
af971e06 | 80 | const body = await servers[0].searchCommand.searchVideos({ search: 'name' }) |
5abb9fbb | 81 | |
af971e06 C |
82 | expect(body.total).to.equal(0) |
83 | expect(body.data).to.be.an('array') | |
84 | expect(body.data.length).to.equal(0) | |
5abb9fbb C |
85 | } |
86 | }) | |
87 | ||
88 | it('Should have the blacklisted video in videos list/search on server 2', async function () { | |
89 | { | |
a1587156 | 90 | const res = await getVideosList(servers[1].url) |
5abb9fbb C |
91 | |
92 | expect(res.body.total).to.equal(2) | |
93 | expect(res.body.data).to.be.an('array') | |
94 | expect(res.body.data.length).to.equal(2) | |
95 | } | |
96 | ||
97 | { | |
af971e06 | 98 | const body = await servers[1].searchCommand.searchVideos({ search: 'name' }) |
5abb9fbb | 99 | |
af971e06 C |
100 | expect(body.total).to.equal(2) |
101 | expect(body.data).to.be.an('array') | |
102 | expect(body.data.length).to.equal(2) | |
5abb9fbb C |
103 | } |
104 | }) | |
0e1dc3e7 C |
105 | }) |
106 | ||
7ccddd7b | 107 | describe('When listing manually blacklisted videos', function () { |
5abb9fbb | 108 | it('Should display all the blacklisted videos', async function () { |
1eddc9a7 | 109 | const res = await getBlacklistedVideosList({ url: servers[0].url, token: servers[0].accessToken }) |
5abb9fbb C |
110 | |
111 | expect(res.body.total).to.equal(2) | |
112 | ||
113 | const blacklistedVideos = res.body.data | |
114 | expect(blacklistedVideos).to.be.an('array') | |
115 | expect(blacklistedVideos.length).to.equal(2) | |
116 | ||
117 | for (const blacklistedVideo of blacklistedVideos) { | |
118 | expect(blacklistedVideo.reason).to.equal('super reason') | |
119 | videoId = blacklistedVideo.video.id | |
120 | } | |
121 | }) | |
122 | ||
7ccddd7b | 123 | it('Should display all the blacklisted videos when applying manual type filter', async function () { |
1eddc9a7 | 124 | const res = await getBlacklistedVideosList({ |
a1587156 C |
125 | url: servers[0].url, |
126 | token: servers[0].accessToken, | |
3487330d | 127 | type: VideoBlacklistType.MANUAL |
1eddc9a7 | 128 | }) |
7ccddd7b JM |
129 | |
130 | expect(res.body.total).to.equal(2) | |
131 | ||
132 | const blacklistedVideos = res.body.data | |
133 | expect(blacklistedVideos).to.be.an('array') | |
134 | expect(blacklistedVideos.length).to.equal(2) | |
135 | }) | |
136 | ||
137 | it('Should display nothing when applying automatic type filter', async function () { | |
1eddc9a7 | 138 | const res = await getBlacklistedVideosList({ |
a1587156 C |
139 | url: servers[0].url, |
140 | token: servers[0].accessToken, | |
3487330d | 141 | type: VideoBlacklistType.AUTO_BEFORE_PUBLISHED |
1eddc9a7 | 142 | }) |
7ccddd7b JM |
143 | |
144 | expect(res.body.total).to.equal(0) | |
145 | ||
146 | const blacklistedVideos = res.body.data | |
147 | expect(blacklistedVideos).to.be.an('array') | |
148 | expect(blacklistedVideos.length).to.equal(0) | |
149 | }) | |
150 | ||
5abb9fbb | 151 | it('Should get the correct sort when sorting by descending id', async function () { |
a1587156 | 152 | const res = await getBlacklistedVideosList({ url: servers[0].url, token: servers[0].accessToken, sort: '-id' }) |
5abb9fbb C |
153 | expect(res.body.total).to.equal(2) |
154 | ||
155 | const blacklistedVideos = res.body.data | |
156 | expect(blacklistedVideos).to.be.an('array') | |
157 | expect(blacklistedVideos.length).to.equal(2) | |
158 | ||
159 | const result = orderBy(res.body.data, [ 'id' ], [ 'desc' ]) | |
160 | ||
161 | expect(blacklistedVideos).to.deep.equal(result) | |
162 | }) | |
163 | ||
164 | it('Should get the correct sort when sorting by descending video name', async function () { | |
a1587156 | 165 | const res = await getBlacklistedVideosList({ url: servers[0].url, token: servers[0].accessToken, sort: '-name' }) |
5abb9fbb C |
166 | expect(res.body.total).to.equal(2) |
167 | ||
168 | const blacklistedVideos = res.body.data | |
169 | expect(blacklistedVideos).to.be.an('array') | |
170 | expect(blacklistedVideos.length).to.equal(2) | |
171 | ||
172 | const result = orderBy(res.body.data, [ 'name' ], [ 'desc' ]) | |
173 | ||
174 | expect(blacklistedVideos).to.deep.equal(result) | |
175 | }) | |
176 | ||
177 | it('Should get the correct sort when sorting by ascending creation date', async function () { | |
a1587156 | 178 | const res = await getBlacklistedVideosList({ url: servers[0].url, token: servers[0].accessToken, sort: 'createdAt' }) |
5abb9fbb C |
179 | expect(res.body.total).to.equal(2) |
180 | ||
181 | const blacklistedVideos = res.body.data | |
182 | expect(blacklistedVideos).to.be.an('array') | |
183 | expect(blacklistedVideos.length).to.equal(2) | |
184 | ||
185 | const result = orderBy(res.body.data, [ 'createdAt' ]) | |
186 | ||
187 | expect(blacklistedVideos).to.deep.equal(result) | |
188 | }) | |
0e1dc3e7 C |
189 | }) |
190 | ||
5abb9fbb C |
191 | describe('When updating blacklisted videos', function () { |
192 | it('Should change the reason', async function () { | |
193 | await updateVideoBlacklist(servers[0].url, servers[0].accessToken, videoId, 'my super reason updated') | |
194 | ||
a1587156 | 195 | const res = await getBlacklistedVideosList({ url: servers[0].url, token: servers[0].accessToken, sort: '-name' }) |
5abb9fbb | 196 | const video = res.body.data.find(b => b.video.id === videoId) |
0e1dc3e7 | 197 | |
5abb9fbb C |
198 | expect(video.reason).to.equal('my super reason updated') |
199 | }) | |
0e1dc3e7 C |
200 | }) |
201 | ||
5abb9fbb C |
202 | describe('When listing my videos', function () { |
203 | it('Should display blacklisted videos', async function () { | |
204 | await blacklistVideosOnServer(servers[1]) | |
205 | ||
206 | const res = await getMyVideos(servers[1].url, servers[1].accessToken, 0, 5) | |
0e1dc3e7 | 207 | |
5abb9fbb C |
208 | expect(res.body.total).to.equal(2) |
209 | expect(res.body.data).to.have.lengthOf(2) | |
210 | ||
211 | for (const video of res.body.data) { | |
212 | expect(video.blacklisted).to.be.true | |
213 | expect(video.blacklistedReason).to.equal('super reason') | |
214 | } | |
215 | }) | |
0e1dc3e7 C |
216 | }) |
217 | ||
5abb9fbb | 218 | describe('When removing a blacklisted video', function () { |
3487330d | 219 | let videoToRemove: VideoBlacklist |
5abb9fbb C |
220 | let blacklist = [] |
221 | ||
222 | it('Should not have any video in videos list on server 1', async function () { | |
223 | const res = await getVideosList(servers[0].url) | |
224 | expect(res.body.total).to.equal(0) | |
225 | expect(res.body.data).to.be.an('array') | |
226 | expect(res.body.data.length).to.equal(0) | |
227 | }) | |
228 | ||
229 | it('Should remove a video from the blacklist on server 1', async function () { | |
230 | // Get one video in the blacklist | |
a1587156 | 231 | const res = await getBlacklistedVideosList({ url: servers[0].url, token: servers[0].accessToken, sort: '-name' }) |
5abb9fbb C |
232 | videoToRemove = res.body.data[0] |
233 | blacklist = res.body.data.slice(1) | |
234 | ||
235 | // Remove it | |
236 | await removeVideoFromBlacklist(servers[0].url, servers[0].accessToken, videoToRemove.video.id) | |
237 | }) | |
238 | ||
239 | it('Should have the ex-blacklisted video in videos list on server 1', async function () { | |
240 | const res = await getVideosList(servers[0].url) | |
241 | expect(res.body.total).to.equal(1) | |
242 | ||
243 | const videos = res.body.data | |
244 | expect(videos).to.be.an('array') | |
245 | expect(videos.length).to.equal(1) | |
246 | ||
247 | expect(videos[0].name).to.equal(videoToRemove.video.name) | |
248 | expect(videos[0].id).to.equal(videoToRemove.video.id) | |
249 | }) | |
250 | ||
251 | it('Should not have the ex-blacklisted video in videos blacklist list on server 1', async function () { | |
a1587156 | 252 | const res = await getBlacklistedVideosList({ url: servers[0].url, token: servers[0].accessToken, sort: '-name' }) |
5abb9fbb | 253 | expect(res.body.total).to.equal(1) |
0e1dc3e7 | 254 | |
5abb9fbb C |
255 | const videos = res.body.data |
256 | expect(videos).to.be.an('array') | |
257 | expect(videos.length).to.equal(1) | |
258 | expect(videos).to.deep.equal(blacklist) | |
259 | }) | |
0e1dc3e7 C |
260 | }) |
261 | ||
5abb9fbb C |
262 | describe('When blacklisting local videos', function () { |
263 | let video3UUID: string | |
264 | let video4UUID: string | |
265 | ||
266 | before(async function () { | |
267 | this.timeout(10000) | |
268 | ||
269 | { | |
270 | const res = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'Video 3' }) | |
271 | video3UUID = res.body.video.uuid | |
272 | } | |
273 | { | |
a1587156 | 274 | const res = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'Video 4' }) |
5abb9fbb C |
275 | video4UUID = res.body.video.uuid |
276 | } | |
277 | ||
278 | await waitJobs(servers) | |
279 | }) | |
280 | ||
281 | it('Should blacklist video 3 and keep it federated', async function () { | |
282 | this.timeout(10000) | |
283 | ||
a1587156 | 284 | await addVideoToBlacklist(servers[0].url, servers[0].accessToken, video3UUID, 'super reason', false) |
5abb9fbb C |
285 | |
286 | await waitJobs(servers) | |
287 | ||
288 | { | |
a1587156 | 289 | const res = await getVideosList(servers[0].url) |
5abb9fbb C |
290 | expect(res.body.data.find(v => v.uuid === video3UUID)).to.be.undefined |
291 | } | |
292 | ||
293 | { | |
a1587156 | 294 | const res = await getVideosList(servers[1].url) |
5abb9fbb C |
295 | expect(res.body.data.find(v => v.uuid === video3UUID)).to.not.be.undefined |
296 | } | |
297 | }) | |
298 | ||
299 | it('Should unfederate the video', async function () { | |
300 | this.timeout(10000) | |
301 | ||
a1587156 | 302 | await addVideoToBlacklist(servers[0].url, servers[0].accessToken, video4UUID, 'super reason', true) |
5abb9fbb C |
303 | |
304 | await waitJobs(servers) | |
305 | ||
306 | for (const server of servers) { | |
307 | const res = await getVideosList(server.url) | |
308 | expect(res.body.data.find(v => v.uuid === video4UUID)).to.be.undefined | |
309 | } | |
310 | }) | |
311 | ||
312 | it('Should have the video unfederated even after an Update AP message', async function () { | |
313 | this.timeout(10000) | |
314 | ||
a1587156 | 315 | await updateVideo(servers[0].url, servers[0].accessToken, video4UUID, { description: 'super description' }) |
5abb9fbb C |
316 | |
317 | await waitJobs(servers) | |
318 | ||
319 | for (const server of servers) { | |
320 | const res = await getVideosList(server.url) | |
321 | expect(res.body.data.find(v => v.uuid === video4UUID)).to.be.undefined | |
322 | } | |
323 | }) | |
324 | ||
325 | it('Should have the correct video blacklist unfederate attribute', async function () { | |
a1587156 | 326 | const res = await getBlacklistedVideosList({ url: servers[0].url, token: servers[0].accessToken, sort: 'createdAt' }) |
5abb9fbb | 327 | |
3487330d | 328 | const blacklistedVideos: VideoBlacklist[] = res.body.data |
5abb9fbb C |
329 | const video3Blacklisted = blacklistedVideos.find(b => b.video.uuid === video3UUID) |
330 | const video4Blacklisted = blacklistedVideos.find(b => b.video.uuid === video4UUID) | |
331 | ||
332 | expect(video3Blacklisted.unfederated).to.be.false | |
333 | expect(video4Blacklisted.unfederated).to.be.true | |
334 | }) | |
335 | ||
336 | it('Should remove the video from blacklist and refederate the video', async function () { | |
337 | this.timeout(10000) | |
338 | ||
a1587156 | 339 | await removeVideoFromBlacklist(servers[0].url, servers[0].accessToken, video4UUID) |
5abb9fbb C |
340 | |
341 | await waitJobs(servers) | |
342 | ||
343 | for (const server of servers) { | |
344 | const res = await getVideosList(server.url) | |
345 | expect(res.body.data.find(v => v.uuid === video4UUID)).to.not.be.undefined | |
346 | } | |
347 | }) | |
0e1dc3e7 | 348 | |
0e1dc3e7 C |
349 | }) |
350 | ||
1eddc9a7 C |
351 | describe('When auto blacklist videos', function () { |
352 | let userWithoutFlag: string | |
353 | let userWithFlag: string | |
03371ad9 | 354 | let channelOfUserWithoutFlag: number |
1eddc9a7 C |
355 | |
356 | before(async function () { | |
357 | this.timeout(20000) | |
358 | ||
359 | killallServers([ servers[0] ]) | |
360 | ||
361 | const config = { | |
a1587156 | 362 | auto_blacklist: { |
1eddc9a7 | 363 | videos: { |
a1587156 | 364 | of_users: { |
1eddc9a7 C |
365 | enabled: true |
366 | } | |
367 | } | |
368 | } | |
369 | } | |
370 | await reRunServer(servers[0], config) | |
371 | ||
372 | { | |
373 | const user = { username: 'user_without_flag', password: 'password' } | |
374 | await createUser({ | |
a1587156 C |
375 | url: servers[0].url, |
376 | accessToken: servers[0].accessToken, | |
1eddc9a7 C |
377 | username: user.username, |
378 | adminFlags: UserAdminFlag.NONE, | |
379 | password: user.password, | |
380 | role: UserRole.USER | |
381 | }) | |
382 | ||
383 | userWithoutFlag = await userLogin(servers[0], user) | |
03371ad9 C |
384 | |
385 | const res = await getMyUserInformation(servers[0].url, userWithoutFlag) | |
386 | const body: User = res.body | |
387 | channelOfUserWithoutFlag = body.videoChannels[0].id | |
1eddc9a7 C |
388 | } |
389 | ||
390 | { | |
391 | const user = { username: 'user_with_flag', password: 'password' } | |
392 | await createUser({ | |
a1587156 C |
393 | url: servers[0].url, |
394 | accessToken: servers[0].accessToken, | |
1eddc9a7 | 395 | username: user.username, |
3487330d | 396 | adminFlags: UserAdminFlag.BYPASS_VIDEO_AUTO_BLACKLIST, |
1eddc9a7 C |
397 | password: user.password, |
398 | role: UserRole.USER | |
399 | }) | |
400 | ||
401 | userWithFlag = await userLogin(servers[0], user) | |
402 | } | |
403 | ||
404 | await waitJobs(servers) | |
405 | }) | |
406 | ||
03371ad9 | 407 | it('Should auto blacklist a video on upload', async function () { |
1eddc9a7 C |
408 | await uploadVideo(servers[0].url, userWithoutFlag, { name: 'blacklisted' }) |
409 | ||
410 | const res = await getBlacklistedVideosList({ | |
a1587156 C |
411 | url: servers[0].url, |
412 | token: servers[0].accessToken, | |
3487330d | 413 | type: VideoBlacklistType.AUTO_BEFORE_PUBLISHED |
1eddc9a7 C |
414 | }) |
415 | ||
416 | expect(res.body.total).to.equal(1) | |
417 | expect(res.body.data[0].video.name).to.equal('blacklisted') | |
418 | }) | |
419 | ||
03371ad9 | 420 | it('Should auto blacklist a video on URL import', async function () { |
109d893f C |
421 | this.timeout(15000) |
422 | ||
03371ad9 | 423 | const attributes = { |
b488ba1e | 424 | targetUrl: getGoodVideoUrl(), |
03371ad9 C |
425 | name: 'URL import', |
426 | channelId: channelOfUserWithoutFlag | |
427 | } | |
a1587156 | 428 | await importVideo(servers[0].url, userWithoutFlag, attributes) |
03371ad9 C |
429 | |
430 | const res = await getBlacklistedVideosList({ | |
a1587156 C |
431 | url: servers[0].url, |
432 | token: servers[0].accessToken, | |
03371ad9 | 433 | sort: 'createdAt', |
3487330d | 434 | type: VideoBlacklistType.AUTO_BEFORE_PUBLISHED |
03371ad9 C |
435 | }) |
436 | ||
437 | expect(res.body.total).to.equal(2) | |
438 | expect(res.body.data[1].video.name).to.equal('URL import') | |
439 | }) | |
440 | ||
441 | it('Should auto blacklist a video on torrent import', async function () { | |
442 | const attributes = { | |
443 | magnetUri: getMagnetURI(), | |
444 | name: 'Torrent import', | |
445 | channelId: channelOfUserWithoutFlag | |
446 | } | |
a1587156 | 447 | await importVideo(servers[0].url, userWithoutFlag, attributes) |
03371ad9 C |
448 | |
449 | const res = await getBlacklistedVideosList({ | |
a1587156 C |
450 | url: servers[0].url, |
451 | token: servers[0].accessToken, | |
03371ad9 | 452 | sort: 'createdAt', |
3487330d | 453 | type: VideoBlacklistType.AUTO_BEFORE_PUBLISHED |
03371ad9 C |
454 | }) |
455 | ||
456 | expect(res.body.total).to.equal(3) | |
457 | expect(res.body.data[2].video.name).to.equal('Torrent import') | |
458 | }) | |
459 | ||
460 | it('Should not auto blacklist a video on upload if the user has the bypass blacklist flag', async function () { | |
1eddc9a7 C |
461 | await uploadVideo(servers[0].url, userWithFlag, { name: 'not blacklisted' }) |
462 | ||
463 | const res = await getBlacklistedVideosList({ | |
a1587156 C |
464 | url: servers[0].url, |
465 | token: servers[0].accessToken, | |
3487330d | 466 | type: VideoBlacklistType.AUTO_BEFORE_PUBLISHED |
1eddc9a7 C |
467 | }) |
468 | ||
03371ad9 | 469 | expect(res.body.total).to.equal(3) |
1eddc9a7 C |
470 | }) |
471 | }) | |
472 | ||
7c3b7976 C |
473 | after(async function () { |
474 | await cleanupTests(servers) | |
0e1dc3e7 C |
475 | }) |
476 | }) |