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