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