diff options
Diffstat (limited to 'server/tests/api/moderation')
-rw-r--r-- | server/tests/api/moderation/abuses.ts | 887 | ||||
-rw-r--r-- | server/tests/api/moderation/blocklist-notification.ts | 231 | ||||
-rw-r--r-- | server/tests/api/moderation/blocklist.ts | 902 | ||||
-rw-r--r-- | server/tests/api/moderation/index.ts | 4 | ||||
-rw-r--r-- | server/tests/api/moderation/video-blacklist.ts | 414 |
5 files changed, 0 insertions, 2438 deletions
diff --git a/server/tests/api/moderation/abuses.ts b/server/tests/api/moderation/abuses.ts deleted file mode 100644 index 9fc296ea8..000000000 --- a/server/tests/api/moderation/abuses.ts +++ /dev/null | |||
@@ -1,887 +0,0 @@ | |||
1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ | ||
2 | |||
3 | import { expect } from 'chai' | ||
4 | import { AbuseMessage, AbusePredefinedReasonsString, AbuseState, AdminAbuse, UserAbuse } from '@shared/models' | ||
5 | import { | ||
6 | AbusesCommand, | ||
7 | cleanupTests, | ||
8 | createMultipleServers, | ||
9 | doubleFollow, | ||
10 | PeerTubeServer, | ||
11 | setAccessTokensToServers, | ||
12 | setDefaultAccountAvatar, | ||
13 | setDefaultChannelAvatar, | ||
14 | waitJobs | ||
15 | } from '@shared/server-commands' | ||
16 | |||
17 | describe('Test abuses', function () { | ||
18 | let servers: PeerTubeServer[] = [] | ||
19 | let abuseServer1: AdminAbuse | ||
20 | let abuseServer2: AdminAbuse | ||
21 | let commands: AbusesCommand[] | ||
22 | |||
23 | before(async function () { | ||
24 | this.timeout(50000) | ||
25 | |||
26 | // Run servers | ||
27 | servers = await createMultipleServers(2) | ||
28 | |||
29 | await setAccessTokensToServers(servers) | ||
30 | await setDefaultChannelAvatar(servers) | ||
31 | await setDefaultAccountAvatar(servers) | ||
32 | |||
33 | // Server 1 and server 2 follow each other | ||
34 | await doubleFollow(servers[0], servers[1]) | ||
35 | |||
36 | commands = servers.map(s => s.abuses) | ||
37 | }) | ||
38 | |||
39 | describe('Video abuses', function () { | ||
40 | |||
41 | before(async function () { | ||
42 | this.timeout(50000) | ||
43 | |||
44 | // Upload some videos on each servers | ||
45 | { | ||
46 | const attributes = { | ||
47 | name: 'my super name for server 1', | ||
48 | description: 'my super description for server 1' | ||
49 | } | ||
50 | await servers[0].videos.upload({ attributes }) | ||
51 | } | ||
52 | |||
53 | { | ||
54 | const attributes = { | ||
55 | name: 'my super name for server 2', | ||
56 | description: 'my super description for server 2' | ||
57 | } | ||
58 | await servers[1].videos.upload({ attributes }) | ||
59 | } | ||
60 | |||
61 | // Wait videos propagation, server 2 has transcoding enabled | ||
62 | await waitJobs(servers) | ||
63 | |||
64 | const { data } = await servers[0].videos.list() | ||
65 | expect(data.length).to.equal(2) | ||
66 | |||
67 | servers[0].store.videoCreated = data.find(video => video.name === 'my super name for server 1') | ||
68 | servers[1].store.videoCreated = data.find(video => video.name === 'my super name for server 2') | ||
69 | }) | ||
70 | |||
71 | it('Should not have abuses', async function () { | ||
72 | const body = await commands[0].getAdminList() | ||
73 | |||
74 | expect(body.total).to.equal(0) | ||
75 | expect(body.data).to.be.an('array') | ||
76 | expect(body.data.length).to.equal(0) | ||
77 | }) | ||
78 | |||
79 | it('Should report abuse on a local video', async function () { | ||
80 | this.timeout(15000) | ||
81 | |||
82 | const reason = 'my super bad reason' | ||
83 | await commands[0].report({ videoId: servers[0].store.videoCreated.id, reason }) | ||
84 | |||
85 | // We wait requests propagation, even if the server 1 is not supposed to make a request to server 2 | ||
86 | await waitJobs(servers) | ||
87 | }) | ||
88 | |||
89 | it('Should have 1 video abuses on server 1 and 0 on server 2', async function () { | ||
90 | { | ||
91 | const body = await commands[0].getAdminList() | ||
92 | |||
93 | expect(body.total).to.equal(1) | ||
94 | expect(body.data).to.be.an('array') | ||
95 | expect(body.data.length).to.equal(1) | ||
96 | |||
97 | const abuse = body.data[0] | ||
98 | expect(abuse.reason).to.equal('my super bad reason') | ||
99 | |||
100 | expect(abuse.reporterAccount.name).to.equal('root') | ||
101 | expect(abuse.reporterAccount.host).to.equal(servers[0].host) | ||
102 | |||
103 | expect(abuse.video.id).to.equal(servers[0].store.videoCreated.id) | ||
104 | expect(abuse.video.channel).to.exist | ||
105 | |||
106 | expect(abuse.comment).to.be.null | ||
107 | |||
108 | expect(abuse.flaggedAccount.name).to.equal('root') | ||
109 | expect(abuse.flaggedAccount.host).to.equal(servers[0].host) | ||
110 | |||
111 | expect(abuse.video.countReports).to.equal(1) | ||
112 | expect(abuse.video.nthReport).to.equal(1) | ||
113 | |||
114 | expect(abuse.countReportsForReporter).to.equal(1) | ||
115 | expect(abuse.countReportsForReportee).to.equal(1) | ||
116 | } | ||
117 | |||
118 | { | ||
119 | const body = await commands[1].getAdminList() | ||
120 | expect(body.total).to.equal(0) | ||
121 | expect(body.data).to.be.an('array') | ||
122 | expect(body.data.length).to.equal(0) | ||
123 | } | ||
124 | }) | ||
125 | |||
126 | it('Should report abuse on a remote video', async function () { | ||
127 | const reason = 'my super bad reason 2' | ||
128 | const videoId = await servers[0].videos.getId({ uuid: servers[1].store.videoCreated.uuid }) | ||
129 | await commands[0].report({ videoId, reason }) | ||
130 | |||
131 | // We wait requests propagation | ||
132 | await waitJobs(servers) | ||
133 | }) | ||
134 | |||
135 | it('Should have 2 video abuses on server 1 and 1 on server 2', async function () { | ||
136 | { | ||
137 | const body = await commands[0].getAdminList() | ||
138 | |||
139 | expect(body.total).to.equal(2) | ||
140 | expect(body.data.length).to.equal(2) | ||
141 | |||
142 | const abuse1 = body.data[0] | ||
143 | expect(abuse1.reason).to.equal('my super bad reason') | ||
144 | expect(abuse1.reporterAccount.name).to.equal('root') | ||
145 | expect(abuse1.reporterAccount.host).to.equal(servers[0].host) | ||
146 | |||
147 | expect(abuse1.video.id).to.equal(servers[0].store.videoCreated.id) | ||
148 | expect(abuse1.video.countReports).to.equal(1) | ||
149 | expect(abuse1.video.nthReport).to.equal(1) | ||
150 | |||
151 | expect(abuse1.comment).to.be.null | ||
152 | |||
153 | expect(abuse1.flaggedAccount.name).to.equal('root') | ||
154 | expect(abuse1.flaggedAccount.host).to.equal(servers[0].host) | ||
155 | |||
156 | expect(abuse1.state.id).to.equal(AbuseState.PENDING) | ||
157 | expect(abuse1.state.label).to.equal('Pending') | ||
158 | expect(abuse1.moderationComment).to.be.null | ||
159 | |||
160 | const abuse2 = body.data[1] | ||
161 | expect(abuse2.reason).to.equal('my super bad reason 2') | ||
162 | |||
163 | expect(abuse2.reporterAccount.name).to.equal('root') | ||
164 | expect(abuse2.reporterAccount.host).to.equal(servers[0].host) | ||
165 | |||
166 | expect(abuse2.video.uuid).to.equal(servers[1].store.videoCreated.uuid) | ||
167 | |||
168 | expect(abuse2.comment).to.be.null | ||
169 | |||
170 | expect(abuse2.flaggedAccount.name).to.equal('root') | ||
171 | expect(abuse2.flaggedAccount.host).to.equal(servers[1].host) | ||
172 | |||
173 | expect(abuse2.state.id).to.equal(AbuseState.PENDING) | ||
174 | expect(abuse2.state.label).to.equal('Pending') | ||
175 | expect(abuse2.moderationComment).to.be.null | ||
176 | } | ||
177 | |||
178 | { | ||
179 | const body = await commands[1].getAdminList() | ||
180 | expect(body.total).to.equal(1) | ||
181 | expect(body.data.length).to.equal(1) | ||
182 | |||
183 | abuseServer2 = body.data[0] | ||
184 | expect(abuseServer2.reason).to.equal('my super bad reason 2') | ||
185 | expect(abuseServer2.reporterAccount.name).to.equal('root') | ||
186 | expect(abuseServer2.reporterAccount.host).to.equal(servers[0].host) | ||
187 | |||
188 | expect(abuseServer2.flaggedAccount.name).to.equal('root') | ||
189 | expect(abuseServer2.flaggedAccount.host).to.equal(servers[1].host) | ||
190 | |||
191 | expect(abuseServer2.state.id).to.equal(AbuseState.PENDING) | ||
192 | expect(abuseServer2.state.label).to.equal('Pending') | ||
193 | expect(abuseServer2.moderationComment).to.be.null | ||
194 | } | ||
195 | }) | ||
196 | |||
197 | it('Should hide video abuses from blocked accounts', async function () { | ||
198 | { | ||
199 | const videoId = await servers[1].videos.getId({ uuid: servers[0].store.videoCreated.uuid }) | ||
200 | await commands[1].report({ videoId, reason: 'will mute this' }) | ||
201 | await waitJobs(servers) | ||
202 | |||
203 | const body = await commands[0].getAdminList() | ||
204 | expect(body.total).to.equal(3) | ||
205 | } | ||
206 | |||
207 | const accountToBlock = 'root@' + servers[1].host | ||
208 | |||
209 | { | ||
210 | await servers[0].blocklist.addToServerBlocklist({ account: accountToBlock }) | ||
211 | |||
212 | const body = await commands[0].getAdminList() | ||
213 | expect(body.total).to.equal(2) | ||
214 | |||
215 | const abuse = body.data.find(a => a.reason === 'will mute this') | ||
216 | expect(abuse).to.be.undefined | ||
217 | } | ||
218 | |||
219 | { | ||
220 | await servers[0].blocklist.removeFromServerBlocklist({ account: accountToBlock }) | ||
221 | |||
222 | const body = await commands[0].getAdminList() | ||
223 | expect(body.total).to.equal(3) | ||
224 | } | ||
225 | }) | ||
226 | |||
227 | it('Should hide video abuses from blocked servers', async function () { | ||
228 | const serverToBlock = servers[1].host | ||
229 | |||
230 | { | ||
231 | await servers[0].blocklist.addToServerBlocklist({ server: serverToBlock }) | ||
232 | |||
233 | const body = await commands[0].getAdminList() | ||
234 | expect(body.total).to.equal(2) | ||
235 | |||
236 | const abuse = body.data.find(a => a.reason === 'will mute this') | ||
237 | expect(abuse).to.be.undefined | ||
238 | } | ||
239 | |||
240 | { | ||
241 | await servers[0].blocklist.removeFromServerBlocklist({ server: serverToBlock }) | ||
242 | |||
243 | const body = await commands[0].getAdminList() | ||
244 | expect(body.total).to.equal(3) | ||
245 | } | ||
246 | }) | ||
247 | |||
248 | it('Should keep the video abuse when deleting the video', async function () { | ||
249 | await servers[1].videos.remove({ id: abuseServer2.video.uuid }) | ||
250 | |||
251 | await waitJobs(servers) | ||
252 | |||
253 | const body = await commands[1].getAdminList() | ||
254 | expect(body.total).to.equal(2, 'wrong number of videos returned') | ||
255 | expect(body.data).to.have.lengthOf(2, 'wrong number of videos returned') | ||
256 | |||
257 | const abuse = body.data[0] | ||
258 | expect(abuse.id).to.equal(abuseServer2.id, 'wrong origin server id for first video') | ||
259 | expect(abuse.video.id).to.equal(abuseServer2.video.id, 'wrong video id') | ||
260 | expect(abuse.video.channel).to.exist | ||
261 | expect(abuse.video.deleted).to.be.true | ||
262 | }) | ||
263 | |||
264 | it('Should include counts of reports from reporter and reportee', async function () { | ||
265 | // register a second user to have two reporters/reportees | ||
266 | const user = { username: 'user2', password: 'password' } | ||
267 | await servers[0].users.create({ ...user }) | ||
268 | const userAccessToken = await servers[0].login.getAccessToken(user) | ||
269 | |||
270 | // upload a third video via this user | ||
271 | const attributes = { | ||
272 | name: 'my second super name for server 1', | ||
273 | description: 'my second super description for server 1' | ||
274 | } | ||
275 | const { id } = await servers[0].videos.upload({ token: userAccessToken, attributes }) | ||
276 | const video3Id = id | ||
277 | |||
278 | // resume with the test | ||
279 | const reason3 = 'my super bad reason 3' | ||
280 | await commands[0].report({ videoId: video3Id, reason: reason3 }) | ||
281 | |||
282 | const reason4 = 'my super bad reason 4' | ||
283 | await commands[0].report({ token: userAccessToken, videoId: servers[0].store.videoCreated.id, reason: reason4 }) | ||
284 | |||
285 | { | ||
286 | const body = await commands[0].getAdminList() | ||
287 | const abuses = body.data | ||
288 | |||
289 | const abuseVideo3 = body.data.find(a => a.video.id === video3Id) | ||
290 | expect(abuseVideo3).to.not.be.undefined | ||
291 | expect(abuseVideo3.video.countReports).to.equal(1, 'wrong reports count for video 3') | ||
292 | expect(abuseVideo3.video.nthReport).to.equal(1, 'wrong report position in report list for video 3') | ||
293 | expect(abuseVideo3.countReportsForReportee).to.equal(1, 'wrong reports count for reporter on video 3 abuse') | ||
294 | expect(abuseVideo3.countReportsForReporter).to.equal(3, 'wrong reports count for reportee on video 3 abuse') | ||
295 | |||
296 | const abuseServer1 = abuses.find(a => a.video.id === servers[0].store.videoCreated.id) | ||
297 | expect(abuseServer1.countReportsForReportee).to.equal(3, 'wrong reports count for reporter on video 1 abuse') | ||
298 | } | ||
299 | }) | ||
300 | |||
301 | it('Should list predefined reasons as well as timestamps for the reported video', async function () { | ||
302 | const reason5 = 'my super bad reason 5' | ||
303 | const predefinedReasons5: AbusePredefinedReasonsString[] = [ 'violentOrRepulsive', 'captions' ] | ||
304 | const createRes = await commands[0].report({ | ||
305 | videoId: servers[0].store.videoCreated.id, | ||
306 | reason: reason5, | ||
307 | predefinedReasons: predefinedReasons5, | ||
308 | startAt: 1, | ||
309 | endAt: 5 | ||
310 | }) | ||
311 | |||
312 | const body = await commands[0].getAdminList() | ||
313 | |||
314 | { | ||
315 | const abuse = body.data.find(a => a.id === createRes.abuse.id) | ||
316 | expect(abuse.reason).to.equals(reason5) | ||
317 | expect(abuse.predefinedReasons).to.deep.equals(predefinedReasons5, 'predefined reasons do not match the one reported') | ||
318 | expect(abuse.video.startAt).to.equal(1, "starting timestamp doesn't match the one reported") | ||
319 | expect(abuse.video.endAt).to.equal(5, "ending timestamp doesn't match the one reported") | ||
320 | } | ||
321 | }) | ||
322 | |||
323 | it('Should delete the video abuse', async function () { | ||
324 | await commands[1].delete({ abuseId: abuseServer2.id }) | ||
325 | |||
326 | await waitJobs(servers) | ||
327 | |||
328 | { | ||
329 | const body = await commands[1].getAdminList() | ||
330 | expect(body.total).to.equal(1) | ||
331 | expect(body.data.length).to.equal(1) | ||
332 | expect(body.data[0].id).to.not.equal(abuseServer2.id) | ||
333 | } | ||
334 | |||
335 | { | ||
336 | const body = await commands[0].getAdminList() | ||
337 | expect(body.total).to.equal(6) | ||
338 | } | ||
339 | }) | ||
340 | |||
341 | it('Should list and filter video abuses', async function () { | ||
342 | async function list (query: Parameters<AbusesCommand['getAdminList']>[0]) { | ||
343 | const body = await commands[0].getAdminList(query) | ||
344 | |||
345 | return body.data | ||
346 | } | ||
347 | |||
348 | expect(await list({ id: 56 })).to.have.lengthOf(0) | ||
349 | expect(await list({ id: 1 })).to.have.lengthOf(1) | ||
350 | |||
351 | expect(await list({ search: 'my super name for server 1' })).to.have.lengthOf(4) | ||
352 | expect(await list({ search: 'aaaaaaaaaaaaaaaaaaaaaaaaaa' })).to.have.lengthOf(0) | ||
353 | |||
354 | expect(await list({ searchVideo: 'my second super name for server 1' })).to.have.lengthOf(1) | ||
355 | |||
356 | expect(await list({ searchVideoChannel: 'root' })).to.have.lengthOf(4) | ||
357 | expect(await list({ searchVideoChannel: 'aaaa' })).to.have.lengthOf(0) | ||
358 | |||
359 | expect(await list({ searchReporter: 'user2' })).to.have.lengthOf(1) | ||
360 | expect(await list({ searchReporter: 'root' })).to.have.lengthOf(5) | ||
361 | |||
362 | expect(await list({ searchReportee: 'root' })).to.have.lengthOf(5) | ||
363 | expect(await list({ searchReportee: 'aaaa' })).to.have.lengthOf(0) | ||
364 | |||
365 | expect(await list({ videoIs: 'deleted' })).to.have.lengthOf(1) | ||
366 | expect(await list({ videoIs: 'blacklisted' })).to.have.lengthOf(0) | ||
367 | |||
368 | expect(await list({ state: AbuseState.ACCEPTED })).to.have.lengthOf(0) | ||
369 | expect(await list({ state: AbuseState.PENDING })).to.have.lengthOf(6) | ||
370 | |||
371 | expect(await list({ predefinedReason: 'violentOrRepulsive' })).to.have.lengthOf(1) | ||
372 | expect(await list({ predefinedReason: 'serverRules' })).to.have.lengthOf(0) | ||
373 | }) | ||
374 | }) | ||
375 | |||
376 | describe('Comment abuses', function () { | ||
377 | |||
378 | async function getComment (server: PeerTubeServer, videoIdArg: number | string) { | ||
379 | const videoId = typeof videoIdArg === 'string' | ||
380 | ? await server.videos.getId({ uuid: videoIdArg }) | ||
381 | : videoIdArg | ||
382 | |||
383 | const { data } = await server.comments.listThreads({ videoId }) | ||
384 | |||
385 | return data[0] | ||
386 | } | ||
387 | |||
388 | before(async function () { | ||
389 | this.timeout(50000) | ||
390 | |||
391 | servers[0].store.videoCreated = await servers[0].videos.quickUpload({ name: 'server 1' }) | ||
392 | servers[1].store.videoCreated = await servers[1].videos.quickUpload({ name: 'server 2' }) | ||
393 | |||
394 | await servers[0].comments.createThread({ videoId: servers[0].store.videoCreated.id, text: 'comment server 1' }) | ||
395 | await servers[1].comments.createThread({ videoId: servers[1].store.videoCreated.id, text: 'comment server 2' }) | ||
396 | |||
397 | await waitJobs(servers) | ||
398 | }) | ||
399 | |||
400 | it('Should report abuse on a comment', async function () { | ||
401 | this.timeout(15000) | ||
402 | |||
403 | const comment = await getComment(servers[0], servers[0].store.videoCreated.id) | ||
404 | |||
405 | const reason = 'it is a bad comment' | ||
406 | await commands[0].report({ commentId: comment.id, reason }) | ||
407 | |||
408 | await waitJobs(servers) | ||
409 | }) | ||
410 | |||
411 | it('Should have 1 comment abuse on server 1 and 0 on server 2', async function () { | ||
412 | { | ||
413 | const comment = await getComment(servers[0], servers[0].store.videoCreated.id) | ||
414 | const body = await commands[0].getAdminList({ filter: 'comment' }) | ||
415 | |||
416 | expect(body.total).to.equal(1) | ||
417 | expect(body.data).to.have.lengthOf(1) | ||
418 | |||
419 | const abuse = body.data[0] | ||
420 | expect(abuse.reason).to.equal('it is a bad comment') | ||
421 | |||
422 | expect(abuse.reporterAccount.name).to.equal('root') | ||
423 | expect(abuse.reporterAccount.host).to.equal(servers[0].host) | ||
424 | |||
425 | expect(abuse.video).to.be.null | ||
426 | |||
427 | expect(abuse.comment.deleted).to.be.false | ||
428 | expect(abuse.comment.id).to.equal(comment.id) | ||
429 | expect(abuse.comment.text).to.equal(comment.text) | ||
430 | expect(abuse.comment.video.name).to.equal('server 1') | ||
431 | expect(abuse.comment.video.id).to.equal(servers[0].store.videoCreated.id) | ||
432 | expect(abuse.comment.video.uuid).to.equal(servers[0].store.videoCreated.uuid) | ||
433 | |||
434 | expect(abuse.countReportsForReporter).to.equal(5) | ||
435 | expect(abuse.countReportsForReportee).to.equal(5) | ||
436 | } | ||
437 | |||
438 | { | ||
439 | const body = await commands[1].getAdminList({ filter: 'comment' }) | ||
440 | expect(body.total).to.equal(0) | ||
441 | expect(body.data.length).to.equal(0) | ||
442 | } | ||
443 | }) | ||
444 | |||
445 | it('Should report abuse on a remote comment', async function () { | ||
446 | const comment = await getComment(servers[0], servers[1].store.videoCreated.uuid) | ||
447 | |||
448 | const reason = 'it is a really bad comment' | ||
449 | await commands[0].report({ commentId: comment.id, reason }) | ||
450 | |||
451 | await waitJobs(servers) | ||
452 | }) | ||
453 | |||
454 | it('Should have 2 comment abuses on server 1 and 1 on server 2', async function () { | ||
455 | const commentServer2 = await getComment(servers[0], servers[1].store.videoCreated.shortUUID) | ||
456 | |||
457 | { | ||
458 | const body = await commands[0].getAdminList({ filter: 'comment' }) | ||
459 | expect(body.total).to.equal(2) | ||
460 | expect(body.data.length).to.equal(2) | ||
461 | |||
462 | const abuse = body.data[0] | ||
463 | expect(abuse.reason).to.equal('it is a bad comment') | ||
464 | expect(abuse.countReportsForReporter).to.equal(6) | ||
465 | expect(abuse.countReportsForReportee).to.equal(5) | ||
466 | |||
467 | const abuse2 = body.data[1] | ||
468 | |||
469 | expect(abuse2.reason).to.equal('it is a really bad comment') | ||
470 | |||
471 | expect(abuse2.reporterAccount.name).to.equal('root') | ||
472 | expect(abuse2.reporterAccount.host).to.equal(servers[0].host) | ||
473 | |||
474 | expect(abuse2.video).to.be.null | ||
475 | |||
476 | expect(abuse2.comment.deleted).to.be.false | ||
477 | expect(abuse2.comment.id).to.equal(commentServer2.id) | ||
478 | expect(abuse2.comment.text).to.equal(commentServer2.text) | ||
479 | expect(abuse2.comment.video.name).to.equal('server 2') | ||
480 | expect(abuse2.comment.video.uuid).to.equal(servers[1].store.videoCreated.uuid) | ||
481 | |||
482 | expect(abuse2.state.id).to.equal(AbuseState.PENDING) | ||
483 | expect(abuse2.state.label).to.equal('Pending') | ||
484 | |||
485 | expect(abuse2.moderationComment).to.be.null | ||
486 | |||
487 | expect(abuse2.countReportsForReporter).to.equal(6) | ||
488 | expect(abuse2.countReportsForReportee).to.equal(2) | ||
489 | } | ||
490 | |||
491 | { | ||
492 | const body = await commands[1].getAdminList({ filter: 'comment' }) | ||
493 | expect(body.total).to.equal(1) | ||
494 | expect(body.data.length).to.equal(1) | ||
495 | |||
496 | abuseServer2 = body.data[0] | ||
497 | expect(abuseServer2.reason).to.equal('it is a really bad comment') | ||
498 | expect(abuseServer2.reporterAccount.name).to.equal('root') | ||
499 | expect(abuseServer2.reporterAccount.host).to.equal(servers[0].host) | ||
500 | |||
501 | expect(abuseServer2.state.id).to.equal(AbuseState.PENDING) | ||
502 | expect(abuseServer2.state.label).to.equal('Pending') | ||
503 | |||
504 | expect(abuseServer2.moderationComment).to.be.null | ||
505 | |||
506 | expect(abuseServer2.countReportsForReporter).to.equal(1) | ||
507 | expect(abuseServer2.countReportsForReportee).to.equal(1) | ||
508 | } | ||
509 | }) | ||
510 | |||
511 | it('Should keep the comment abuse when deleting the comment', async function () { | ||
512 | const commentServer2 = await getComment(servers[0], servers[1].store.videoCreated.uuid) | ||
513 | |||
514 | await servers[0].comments.delete({ videoId: servers[1].store.videoCreated.uuid, commentId: commentServer2.id }) | ||
515 | |||
516 | await waitJobs(servers) | ||
517 | |||
518 | const body = await commands[0].getAdminList({ filter: 'comment' }) | ||
519 | expect(body.total).to.equal(2) | ||
520 | expect(body.data).to.have.lengthOf(2) | ||
521 | |||
522 | const abuse = body.data.find(a => a.comment?.id === commentServer2.id) | ||
523 | expect(abuse).to.not.be.undefined | ||
524 | |||
525 | expect(abuse.comment.text).to.be.empty | ||
526 | expect(abuse.comment.video.name).to.equal('server 2') | ||
527 | expect(abuse.comment.deleted).to.be.true | ||
528 | }) | ||
529 | |||
530 | it('Should delete the comment abuse', async function () { | ||
531 | await commands[1].delete({ abuseId: abuseServer2.id }) | ||
532 | |||
533 | await waitJobs(servers) | ||
534 | |||
535 | { | ||
536 | const body = await commands[1].getAdminList({ filter: 'comment' }) | ||
537 | expect(body.total).to.equal(0) | ||
538 | expect(body.data.length).to.equal(0) | ||
539 | } | ||
540 | |||
541 | { | ||
542 | const body = await commands[0].getAdminList({ filter: 'comment' }) | ||
543 | expect(body.total).to.equal(2) | ||
544 | } | ||
545 | }) | ||
546 | |||
547 | it('Should list and filter video abuses', async function () { | ||
548 | { | ||
549 | const body = await commands[0].getAdminList({ filter: 'comment', searchReportee: 'foo' }) | ||
550 | expect(body.total).to.equal(0) | ||
551 | } | ||
552 | |||
553 | { | ||
554 | const body = await commands[0].getAdminList({ filter: 'comment', searchReportee: 'ot' }) | ||
555 | expect(body.total).to.equal(2) | ||
556 | } | ||
557 | |||
558 | { | ||
559 | const body = await commands[0].getAdminList({ filter: 'comment', start: 1, count: 1, sort: 'createdAt' }) | ||
560 | expect(body.data).to.have.lengthOf(1) | ||
561 | expect(body.data[0].comment.text).to.be.empty | ||
562 | } | ||
563 | |||
564 | { | ||
565 | const body = await commands[0].getAdminList({ filter: 'comment', start: 1, count: 1, sort: '-createdAt' }) | ||
566 | expect(body.data).to.have.lengthOf(1) | ||
567 | expect(body.data[0].comment.text).to.equal('comment server 1') | ||
568 | } | ||
569 | }) | ||
570 | }) | ||
571 | |||
572 | describe('Account abuses', function () { | ||
573 | |||
574 | function getAccountFromServer (server: PeerTubeServer, targetName: string, targetServer: PeerTubeServer) { | ||
575 | return server.accounts.get({ accountName: targetName + '@' + targetServer.host }) | ||
576 | } | ||
577 | |||
578 | before(async function () { | ||
579 | this.timeout(50000) | ||
580 | |||
581 | await servers[0].users.create({ username: 'user_1', password: 'donald' }) | ||
582 | |||
583 | const token = await servers[1].users.generateUserAndToken('user_2') | ||
584 | await servers[1].videos.upload({ token, attributes: { name: 'super video' } }) | ||
585 | |||
586 | await waitJobs(servers) | ||
587 | }) | ||
588 | |||
589 | it('Should report abuse on an account', async function () { | ||
590 | this.timeout(15000) | ||
591 | |||
592 | const account = await getAccountFromServer(servers[0], 'user_1', servers[0]) | ||
593 | |||
594 | const reason = 'it is a bad account' | ||
595 | await commands[0].report({ accountId: account.id, reason }) | ||
596 | |||
597 | await waitJobs(servers) | ||
598 | }) | ||
599 | |||
600 | it('Should have 1 account abuse on server 1 and 0 on server 2', async function () { | ||
601 | { | ||
602 | const body = await commands[0].getAdminList({ filter: 'account' }) | ||
603 | |||
604 | expect(body.total).to.equal(1) | ||
605 | expect(body.data).to.have.lengthOf(1) | ||
606 | |||
607 | const abuse = body.data[0] | ||
608 | expect(abuse.reason).to.equal('it is a bad account') | ||
609 | |||
610 | expect(abuse.reporterAccount.name).to.equal('root') | ||
611 | expect(abuse.reporterAccount.host).to.equal(servers[0].host) | ||
612 | |||
613 | expect(abuse.video).to.be.null | ||
614 | expect(abuse.comment).to.be.null | ||
615 | |||
616 | expect(abuse.flaggedAccount.name).to.equal('user_1') | ||
617 | expect(abuse.flaggedAccount.host).to.equal(servers[0].host) | ||
618 | } | ||
619 | |||
620 | { | ||
621 | const body = await commands[1].getAdminList({ filter: 'comment' }) | ||
622 | expect(body.total).to.equal(0) | ||
623 | expect(body.data.length).to.equal(0) | ||
624 | } | ||
625 | }) | ||
626 | |||
627 | it('Should report abuse on a remote account', async function () { | ||
628 | const account = await getAccountFromServer(servers[0], 'user_2', servers[1]) | ||
629 | |||
630 | const reason = 'it is a really bad account' | ||
631 | await commands[0].report({ accountId: account.id, reason }) | ||
632 | |||
633 | await waitJobs(servers) | ||
634 | }) | ||
635 | |||
636 | it('Should have 2 comment abuses on server 1 and 1 on server 2', async function () { | ||
637 | { | ||
638 | const body = await commands[0].getAdminList({ filter: 'account' }) | ||
639 | expect(body.total).to.equal(2) | ||
640 | expect(body.data.length).to.equal(2) | ||
641 | |||
642 | const abuse: AdminAbuse = body.data[0] | ||
643 | expect(abuse.reason).to.equal('it is a bad account') | ||
644 | |||
645 | const abuse2: AdminAbuse = body.data[1] | ||
646 | expect(abuse2.reason).to.equal('it is a really bad account') | ||
647 | |||
648 | expect(abuse2.reporterAccount.name).to.equal('root') | ||
649 | expect(abuse2.reporterAccount.host).to.equal(servers[0].host) | ||
650 | |||
651 | expect(abuse2.video).to.be.null | ||
652 | expect(abuse2.comment).to.be.null | ||
653 | |||
654 | expect(abuse2.state.id).to.equal(AbuseState.PENDING) | ||
655 | expect(abuse2.state.label).to.equal('Pending') | ||
656 | |||
657 | expect(abuse2.moderationComment).to.be.null | ||
658 | } | ||
659 | |||
660 | { | ||
661 | const body = await commands[1].getAdminList({ filter: 'account' }) | ||
662 | expect(body.total).to.equal(1) | ||
663 | expect(body.data.length).to.equal(1) | ||
664 | |||
665 | abuseServer2 = body.data[0] | ||
666 | |||
667 | expect(abuseServer2.reason).to.equal('it is a really bad account') | ||
668 | |||
669 | expect(abuseServer2.reporterAccount.name).to.equal('root') | ||
670 | expect(abuseServer2.reporterAccount.host).to.equal(servers[0].host) | ||
671 | |||
672 | expect(abuseServer2.state.id).to.equal(AbuseState.PENDING) | ||
673 | expect(abuseServer2.state.label).to.equal('Pending') | ||
674 | |||
675 | expect(abuseServer2.moderationComment).to.be.null | ||
676 | } | ||
677 | }) | ||
678 | |||
679 | it('Should keep the account abuse when deleting the account', async function () { | ||
680 | const account = await getAccountFromServer(servers[1], 'user_2', servers[1]) | ||
681 | await servers[1].users.remove({ userId: account.userId }) | ||
682 | |||
683 | await waitJobs(servers) | ||
684 | |||
685 | const body = await commands[0].getAdminList({ filter: 'account' }) | ||
686 | expect(body.total).to.equal(2) | ||
687 | expect(body.data).to.have.lengthOf(2) | ||
688 | |||
689 | const abuse = body.data.find(a => a.reason === 'it is a really bad account') | ||
690 | expect(abuse).to.not.be.undefined | ||
691 | }) | ||
692 | |||
693 | it('Should delete the account abuse', async function () { | ||
694 | await commands[1].delete({ abuseId: abuseServer2.id }) | ||
695 | |||
696 | await waitJobs(servers) | ||
697 | |||
698 | { | ||
699 | const body = await commands[1].getAdminList({ filter: 'account' }) | ||
700 | expect(body.total).to.equal(0) | ||
701 | expect(body.data.length).to.equal(0) | ||
702 | } | ||
703 | |||
704 | { | ||
705 | const body = await commands[0].getAdminList({ filter: 'account' }) | ||
706 | expect(body.total).to.equal(2) | ||
707 | |||
708 | abuseServer1 = body.data[0] | ||
709 | } | ||
710 | }) | ||
711 | }) | ||
712 | |||
713 | describe('Common actions on abuses', function () { | ||
714 | |||
715 | it('Should update the state of an abuse', async function () { | ||
716 | await commands[0].update({ abuseId: abuseServer1.id, body: { state: AbuseState.REJECTED } }) | ||
717 | |||
718 | const body = await commands[0].getAdminList({ id: abuseServer1.id }) | ||
719 | expect(body.data[0].state.id).to.equal(AbuseState.REJECTED) | ||
720 | }) | ||
721 | |||
722 | it('Should add a moderation comment', async function () { | ||
723 | await commands[0].update({ abuseId: abuseServer1.id, body: { state: AbuseState.ACCEPTED, moderationComment: 'Valid' } }) | ||
724 | |||
725 | const body = await commands[0].getAdminList({ id: abuseServer1.id }) | ||
726 | expect(body.data[0].state.id).to.equal(AbuseState.ACCEPTED) | ||
727 | expect(body.data[0].moderationComment).to.equal('Valid') | ||
728 | }) | ||
729 | }) | ||
730 | |||
731 | describe('My abuses', async function () { | ||
732 | let abuseId1: number | ||
733 | let userAccessToken: string | ||
734 | |||
735 | before(async function () { | ||
736 | userAccessToken = await servers[0].users.generateUserAndToken('user_42') | ||
737 | |||
738 | await commands[0].report({ token: userAccessToken, videoId: servers[0].store.videoCreated.id, reason: 'user reason 1' }) | ||
739 | |||
740 | const videoId = await servers[0].videos.getId({ uuid: servers[1].store.videoCreated.uuid }) | ||
741 | await commands[0].report({ token: userAccessToken, videoId, reason: 'user reason 2' }) | ||
742 | }) | ||
743 | |||
744 | it('Should correctly list my abuses', async function () { | ||
745 | { | ||
746 | const body = await commands[0].getUserList({ token: userAccessToken, start: 0, count: 5, sort: 'createdAt' }) | ||
747 | expect(body.total).to.equal(2) | ||
748 | |||
749 | const abuses = body.data | ||
750 | expect(abuses[0].reason).to.equal('user reason 1') | ||
751 | expect(abuses[1].reason).to.equal('user reason 2') | ||
752 | |||
753 | abuseId1 = abuses[0].id | ||
754 | } | ||
755 | |||
756 | { | ||
757 | const body = await commands[0].getUserList({ token: userAccessToken, start: 1, count: 1, sort: 'createdAt' }) | ||
758 | expect(body.total).to.equal(2) | ||
759 | |||
760 | const abuses: UserAbuse[] = body.data | ||
761 | expect(abuses[0].reason).to.equal('user reason 2') | ||
762 | } | ||
763 | |||
764 | { | ||
765 | const body = await commands[0].getUserList({ token: userAccessToken, start: 1, count: 1, sort: '-createdAt' }) | ||
766 | expect(body.total).to.equal(2) | ||
767 | |||
768 | const abuses: UserAbuse[] = body.data | ||
769 | expect(abuses[0].reason).to.equal('user reason 1') | ||
770 | } | ||
771 | }) | ||
772 | |||
773 | it('Should correctly filter my abuses by id', async function () { | ||
774 | const body = await commands[0].getUserList({ token: userAccessToken, id: abuseId1 }) | ||
775 | expect(body.total).to.equal(1) | ||
776 | |||
777 | const abuses: UserAbuse[] = body.data | ||
778 | expect(abuses[0].reason).to.equal('user reason 1') | ||
779 | }) | ||
780 | |||
781 | it('Should correctly filter my abuses by search', async function () { | ||
782 | const body = await commands[0].getUserList({ token: userAccessToken, search: 'server 2' }) | ||
783 | expect(body.total).to.equal(1) | ||
784 | |||
785 | const abuses: UserAbuse[] = body.data | ||
786 | expect(abuses[0].reason).to.equal('user reason 2') | ||
787 | }) | ||
788 | |||
789 | it('Should correctly filter my abuses by state', async function () { | ||
790 | await commands[0].update({ abuseId: abuseId1, body: { state: AbuseState.REJECTED } }) | ||
791 | |||
792 | const body = await commands[0].getUserList({ token: userAccessToken, state: AbuseState.REJECTED }) | ||
793 | expect(body.total).to.equal(1) | ||
794 | |||
795 | const abuses: UserAbuse[] = body.data | ||
796 | expect(abuses[0].reason).to.equal('user reason 1') | ||
797 | }) | ||
798 | }) | ||
799 | |||
800 | describe('Abuse messages', async function () { | ||
801 | let abuseId: number | ||
802 | let userToken: string | ||
803 | let abuseMessageUserId: number | ||
804 | let abuseMessageModerationId: number | ||
805 | |||
806 | before(async function () { | ||
807 | userToken = await servers[0].users.generateUserAndToken('user_43') | ||
808 | |||
809 | const body = await commands[0].report({ token: userToken, videoId: servers[0].store.videoCreated.id, reason: 'user 43 reason 1' }) | ||
810 | abuseId = body.abuse.id | ||
811 | }) | ||
812 | |||
813 | it('Should create some messages on the abuse', async function () { | ||
814 | await commands[0].addMessage({ token: userToken, abuseId, message: 'message 1' }) | ||
815 | await commands[0].addMessage({ abuseId, message: 'message 2' }) | ||
816 | await commands[0].addMessage({ abuseId, message: 'message 3' }) | ||
817 | await commands[0].addMessage({ token: userToken, abuseId, message: 'message 4' }) | ||
818 | }) | ||
819 | |||
820 | it('Should have the correct messages count when listing abuses', async function () { | ||
821 | const results = await Promise.all([ | ||
822 | commands[0].getAdminList({ start: 0, count: 50 }), | ||
823 | commands[0].getUserList({ token: userToken, start: 0, count: 50 }) | ||
824 | ]) | ||
825 | |||
826 | for (const body of results) { | ||
827 | const abuses = body.data | ||
828 | const abuse = abuses.find(a => a.id === abuseId) | ||
829 | expect(abuse.countMessages).to.equal(4) | ||
830 | } | ||
831 | }) | ||
832 | |||
833 | it('Should correctly list messages of this abuse', async function () { | ||
834 | const results = await Promise.all([ | ||
835 | commands[0].listMessages({ abuseId }), | ||
836 | commands[0].listMessages({ token: userToken, abuseId }) | ||
837 | ]) | ||
838 | |||
839 | for (const body of results) { | ||
840 | expect(body.total).to.equal(4) | ||
841 | |||
842 | const abuseMessages: AbuseMessage[] = body.data | ||
843 | |||
844 | expect(abuseMessages[0].message).to.equal('message 1') | ||
845 | expect(abuseMessages[0].byModerator).to.be.false | ||
846 | expect(abuseMessages[0].account.name).to.equal('user_43') | ||
847 | |||
848 | abuseMessageUserId = abuseMessages[0].id | ||
849 | |||
850 | expect(abuseMessages[1].message).to.equal('message 2') | ||
851 | expect(abuseMessages[1].byModerator).to.be.true | ||
852 | expect(abuseMessages[1].account.name).to.equal('root') | ||
853 | |||
854 | expect(abuseMessages[2].message).to.equal('message 3') | ||
855 | expect(abuseMessages[2].byModerator).to.be.true | ||
856 | expect(abuseMessages[2].account.name).to.equal('root') | ||
857 | abuseMessageModerationId = abuseMessages[2].id | ||
858 | |||
859 | expect(abuseMessages[3].message).to.equal('message 4') | ||
860 | expect(abuseMessages[3].byModerator).to.be.false | ||
861 | expect(abuseMessages[3].account.name).to.equal('user_43') | ||
862 | } | ||
863 | }) | ||
864 | |||
865 | it('Should delete messages', async function () { | ||
866 | await commands[0].deleteMessage({ abuseId, messageId: abuseMessageModerationId }) | ||
867 | await commands[0].deleteMessage({ token: userToken, abuseId, messageId: abuseMessageUserId }) | ||
868 | |||
869 | const results = await Promise.all([ | ||
870 | commands[0].listMessages({ abuseId }), | ||
871 | commands[0].listMessages({ token: userToken, abuseId }) | ||
872 | ]) | ||
873 | |||
874 | for (const body of results) { | ||
875 | expect(body.total).to.equal(2) | ||
876 | |||
877 | const abuseMessages: AbuseMessage[] = body.data | ||
878 | expect(abuseMessages[0].message).to.equal('message 2') | ||
879 | expect(abuseMessages[1].message).to.equal('message 4') | ||
880 | } | ||
881 | }) | ||
882 | }) | ||
883 | |||
884 | after(async function () { | ||
885 | await cleanupTests(servers) | ||
886 | }) | ||
887 | }) | ||
diff --git a/server/tests/api/moderation/blocklist-notification.ts b/server/tests/api/moderation/blocklist-notification.ts deleted file mode 100644 index 9c2863a58..000000000 --- a/server/tests/api/moderation/blocklist-notification.ts +++ /dev/null | |||
@@ -1,231 +0,0 @@ | |||
1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ | ||
2 | |||
3 | import { expect } from 'chai' | ||
4 | import { UserNotificationType } from '@shared/models' | ||
5 | import { | ||
6 | cleanupTests, | ||
7 | createMultipleServers, | ||
8 | doubleFollow, | ||
9 | PeerTubeServer, | ||
10 | setAccessTokensToServers, | ||
11 | waitJobs | ||
12 | } from '@shared/server-commands' | ||
13 | |||
14 | async function checkNotifications (server: PeerTubeServer, token: string, expected: UserNotificationType[]) { | ||
15 | const { data } = await server.notifications.list({ token, start: 0, count: 10, unread: true }) | ||
16 | expect(data).to.have.lengthOf(expected.length) | ||
17 | |||
18 | for (const type of expected) { | ||
19 | expect(data.find(n => n.type === type)).to.exist | ||
20 | } | ||
21 | } | ||
22 | |||
23 | describe('Test blocklist notifications', function () { | ||
24 | let servers: PeerTubeServer[] | ||
25 | let videoUUID: string | ||
26 | |||
27 | let userToken1: string | ||
28 | let userToken2: string | ||
29 | let remoteUserToken: string | ||
30 | |||
31 | async function resetState () { | ||
32 | try { | ||
33 | await servers[1].subscriptions.remove({ token: remoteUserToken, uri: 'user1_channel@' + servers[0].host }) | ||
34 | await servers[1].subscriptions.remove({ token: remoteUserToken, uri: 'user2_channel@' + servers[0].host }) | ||
35 | } catch {} | ||
36 | |||
37 | await waitJobs(servers) | ||
38 | |||
39 | await servers[0].notifications.markAsReadAll({ token: userToken1 }) | ||
40 | await servers[0].notifications.markAsReadAll({ token: userToken2 }) | ||
41 | |||
42 | { | ||
43 | const { uuid } = await servers[0].videos.upload({ token: userToken1, attributes: { name: 'video' } }) | ||
44 | videoUUID = uuid | ||
45 | |||
46 | await waitJobs(servers) | ||
47 | } | ||
48 | |||
49 | { | ||
50 | await servers[1].comments.createThread({ | ||
51 | token: remoteUserToken, | ||
52 | videoId: videoUUID, | ||
53 | text: '@user2@' + servers[0].host + ' hello' | ||
54 | }) | ||
55 | } | ||
56 | |||
57 | { | ||
58 | |||
59 | await servers[1].subscriptions.add({ token: remoteUserToken, targetUri: 'user1_channel@' + servers[0].host }) | ||
60 | await servers[1].subscriptions.add({ token: remoteUserToken, targetUri: 'user2_channel@' + servers[0].host }) | ||
61 | } | ||
62 | |||
63 | await waitJobs(servers) | ||
64 | } | ||
65 | |||
66 | before(async function () { | ||
67 | this.timeout(60000) | ||
68 | |||
69 | servers = await createMultipleServers(2) | ||
70 | await setAccessTokensToServers(servers) | ||
71 | |||
72 | { | ||
73 | const user = { username: 'user1', password: 'password' } | ||
74 | await servers[0].users.create({ | ||
75 | username: user.username, | ||
76 | password: user.password, | ||
77 | videoQuota: -1, | ||
78 | videoQuotaDaily: -1 | ||
79 | }) | ||
80 | |||
81 | userToken1 = await servers[0].login.getAccessToken(user) | ||
82 | await servers[0].videos.upload({ token: userToken1, attributes: { name: 'video user 1' } }) | ||
83 | } | ||
84 | |||
85 | { | ||
86 | const user = { username: 'user2', password: 'password' } | ||
87 | await servers[0].users.create({ username: user.username, password: user.password }) | ||
88 | |||
89 | userToken2 = await servers[0].login.getAccessToken(user) | ||
90 | } | ||
91 | |||
92 | { | ||
93 | const user = { username: 'user3', password: 'password' } | ||
94 | await servers[1].users.create({ username: user.username, password: user.password }) | ||
95 | |||
96 | remoteUserToken = await servers[1].login.getAccessToken(user) | ||
97 | } | ||
98 | |||
99 | await doubleFollow(servers[0], servers[1]) | ||
100 | }) | ||
101 | |||
102 | describe('User blocks another user', function () { | ||
103 | |||
104 | before(async function () { | ||
105 | this.timeout(30000) | ||
106 | |||
107 | await resetState() | ||
108 | }) | ||
109 | |||
110 | it('Should have appropriate notifications', async function () { | ||
111 | const notifs = [ UserNotificationType.NEW_COMMENT_ON_MY_VIDEO, UserNotificationType.NEW_FOLLOW ] | ||
112 | await checkNotifications(servers[0], userToken1, notifs) | ||
113 | }) | ||
114 | |||
115 | it('Should block an account', async function () { | ||
116 | await servers[0].blocklist.addToMyBlocklist({ token: userToken1, account: 'user3@' + servers[1].host }) | ||
117 | await waitJobs(servers) | ||
118 | }) | ||
119 | |||
120 | it('Should not have notifications from this account', async function () { | ||
121 | await checkNotifications(servers[0], userToken1, []) | ||
122 | }) | ||
123 | |||
124 | it('Should have notifications of this account on user 2', async function () { | ||
125 | const notifs = [ UserNotificationType.COMMENT_MENTION, UserNotificationType.NEW_FOLLOW ] | ||
126 | |||
127 | await checkNotifications(servers[0], userToken2, notifs) | ||
128 | |||
129 | await servers[0].blocklist.removeFromMyBlocklist({ token: userToken1, account: 'user3@' + servers[1].host }) | ||
130 | }) | ||
131 | }) | ||
132 | |||
133 | describe('User blocks another server', function () { | ||
134 | |||
135 | before(async function () { | ||
136 | this.timeout(30000) | ||
137 | |||
138 | await resetState() | ||
139 | }) | ||
140 | |||
141 | it('Should have appropriate notifications', async function () { | ||
142 | const notifs = [ UserNotificationType.NEW_COMMENT_ON_MY_VIDEO, UserNotificationType.NEW_FOLLOW ] | ||
143 | await checkNotifications(servers[0], userToken1, notifs) | ||
144 | }) | ||
145 | |||
146 | it('Should block an account', async function () { | ||
147 | await servers[0].blocklist.addToMyBlocklist({ token: userToken1, server: servers[1].host }) | ||
148 | await waitJobs(servers) | ||
149 | }) | ||
150 | |||
151 | it('Should not have notifications from this account', async function () { | ||
152 | await checkNotifications(servers[0], userToken1, []) | ||
153 | }) | ||
154 | |||
155 | it('Should have notifications of this account on user 2', async function () { | ||
156 | const notifs = [ UserNotificationType.COMMENT_MENTION, UserNotificationType.NEW_FOLLOW ] | ||
157 | |||
158 | await checkNotifications(servers[0], userToken2, notifs) | ||
159 | |||
160 | await servers[0].blocklist.removeFromMyBlocklist({ token: userToken1, server: servers[1].host }) | ||
161 | }) | ||
162 | }) | ||
163 | |||
164 | describe('Server blocks a user', function () { | ||
165 | |||
166 | before(async function () { | ||
167 | this.timeout(30000) | ||
168 | |||
169 | await resetState() | ||
170 | }) | ||
171 | |||
172 | it('Should have appropriate notifications', async function () { | ||
173 | { | ||
174 | const notifs = [ UserNotificationType.NEW_COMMENT_ON_MY_VIDEO, UserNotificationType.NEW_FOLLOW ] | ||
175 | await checkNotifications(servers[0], userToken1, notifs) | ||
176 | } | ||
177 | |||
178 | { | ||
179 | const notifs = [ UserNotificationType.COMMENT_MENTION, UserNotificationType.NEW_FOLLOW ] | ||
180 | await checkNotifications(servers[0], userToken2, notifs) | ||
181 | } | ||
182 | }) | ||
183 | |||
184 | it('Should block an account', async function () { | ||
185 | await servers[0].blocklist.addToServerBlocklist({ account: 'user3@' + servers[1].host }) | ||
186 | await waitJobs(servers) | ||
187 | }) | ||
188 | |||
189 | it('Should not have notifications from this account', async function () { | ||
190 | await checkNotifications(servers[0], userToken1, []) | ||
191 | await checkNotifications(servers[0], userToken2, []) | ||
192 | |||
193 | await servers[0].blocklist.removeFromServerBlocklist({ account: 'user3@' + servers[1].host }) | ||
194 | }) | ||
195 | }) | ||
196 | |||
197 | describe('Server blocks a server', function () { | ||
198 | |||
199 | before(async function () { | ||
200 | this.timeout(30000) | ||
201 | |||
202 | await resetState() | ||
203 | }) | ||
204 | |||
205 | it('Should have appropriate notifications', async function () { | ||
206 | { | ||
207 | const notifs = [ UserNotificationType.NEW_COMMENT_ON_MY_VIDEO, UserNotificationType.NEW_FOLLOW ] | ||
208 | await checkNotifications(servers[0], userToken1, notifs) | ||
209 | } | ||
210 | |||
211 | { | ||
212 | const notifs = [ UserNotificationType.COMMENT_MENTION, UserNotificationType.NEW_FOLLOW ] | ||
213 | await checkNotifications(servers[0], userToken2, notifs) | ||
214 | } | ||
215 | }) | ||
216 | |||
217 | it('Should block an account', async function () { | ||
218 | await servers[0].blocklist.addToServerBlocklist({ server: servers[1].host }) | ||
219 | await waitJobs(servers) | ||
220 | }) | ||
221 | |||
222 | it('Should not have notifications from this account', async function () { | ||
223 | await checkNotifications(servers[0], userToken1, []) | ||
224 | await checkNotifications(servers[0], userToken2, []) | ||
225 | }) | ||
226 | }) | ||
227 | |||
228 | after(async function () { | ||
229 | await cleanupTests(servers) | ||
230 | }) | ||
231 | }) | ||
diff --git a/server/tests/api/moderation/blocklist.ts b/server/tests/api/moderation/blocklist.ts deleted file mode 100644 index b90d8c16c..000000000 --- a/server/tests/api/moderation/blocklist.ts +++ /dev/null | |||
@@ -1,902 +0,0 @@ | |||
1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ | ||
2 | |||
3 | import { expect } from 'chai' | ||
4 | import { UserNotificationType } from '@shared/models' | ||
5 | import { | ||
6 | BlocklistCommand, | ||
7 | cleanupTests, | ||
8 | CommentsCommand, | ||
9 | createMultipleServers, | ||
10 | doubleFollow, | ||
11 | PeerTubeServer, | ||
12 | setAccessTokensToServers, | ||
13 | setDefaultAccountAvatar, | ||
14 | waitJobs | ||
15 | } from '@shared/server-commands' | ||
16 | |||
17 | async function checkAllVideos (server: PeerTubeServer, token: string) { | ||
18 | { | ||
19 | const { data } = await server.videos.listWithToken({ token }) | ||
20 | expect(data).to.have.lengthOf(5) | ||
21 | } | ||
22 | |||
23 | { | ||
24 | const { data } = await server.videos.list() | ||
25 | expect(data).to.have.lengthOf(5) | ||
26 | } | ||
27 | } | ||
28 | |||
29 | async function checkAllComments (server: PeerTubeServer, token: string, videoUUID: string) { | ||
30 | const { data } = await server.comments.listThreads({ videoId: videoUUID, start: 0, count: 25, sort: '-createdAt', token }) | ||
31 | |||
32 | const threads = data.filter(t => t.isDeleted === false) | ||
33 | expect(threads).to.have.lengthOf(2) | ||
34 | |||
35 | for (const thread of threads) { | ||
36 | const tree = await server.comments.getThread({ videoId: videoUUID, threadId: thread.id, token }) | ||
37 | expect(tree.children).to.have.lengthOf(1) | ||
38 | } | ||
39 | } | ||
40 | |||
41 | async function checkCommentNotification ( | ||
42 | mainServer: PeerTubeServer, | ||
43 | comment: { server: PeerTubeServer, token: string, videoUUID: string, text: string }, | ||
44 | check: 'presence' | 'absence' | ||
45 | ) { | ||
46 | const command = comment.server.comments | ||
47 | |||
48 | const { threadId, createdAt } = await command.createThread({ token: comment.token, videoId: comment.videoUUID, text: comment.text }) | ||
49 | |||
50 | await waitJobs([ mainServer, comment.server ]) | ||
51 | |||
52 | const { data } = await mainServer.notifications.list({ start: 0, count: 30 }) | ||
53 | const commentNotifications = data.filter(n => n.comment && n.comment.video.uuid === comment.videoUUID && n.createdAt >= createdAt) | ||
54 | |||
55 | if (check === 'presence') expect(commentNotifications).to.have.lengthOf(1) | ||
56 | else expect(commentNotifications).to.have.lengthOf(0) | ||
57 | |||
58 | await command.delete({ token: comment.token, videoId: comment.videoUUID, commentId: threadId }) | ||
59 | |||
60 | await waitJobs([ mainServer, comment.server ]) | ||
61 | } | ||
62 | |||
63 | describe('Test blocklist', function () { | ||
64 | let servers: PeerTubeServer[] | ||
65 | let videoUUID1: string | ||
66 | let videoUUID2: string | ||
67 | let videoUUID3: string | ||
68 | let userToken1: string | ||
69 | let userModeratorToken: string | ||
70 | let userToken2: string | ||
71 | |||
72 | let command: BlocklistCommand | ||
73 | let commentsCommand: CommentsCommand[] | ||
74 | |||
75 | before(async function () { | ||
76 | this.timeout(120000) | ||
77 | |||
78 | servers = await createMultipleServers(3) | ||
79 | await setAccessTokensToServers(servers) | ||
80 | await setDefaultAccountAvatar(servers) | ||
81 | |||
82 | command = servers[0].blocklist | ||
83 | commentsCommand = servers.map(s => s.comments) | ||
84 | |||
85 | { | ||
86 | const user = { username: 'user1', password: 'password' } | ||
87 | await servers[0].users.create({ username: user.username, password: user.password }) | ||
88 | |||
89 | userToken1 = await servers[0].login.getAccessToken(user) | ||
90 | await servers[0].videos.upload({ token: userToken1, attributes: { name: 'video user 1' } }) | ||
91 | } | ||
92 | |||
93 | { | ||
94 | const user = { username: 'moderator', password: 'password' } | ||
95 | await servers[0].users.create({ username: user.username, password: user.password }) | ||
96 | |||
97 | userModeratorToken = await servers[0].login.getAccessToken(user) | ||
98 | } | ||
99 | |||
100 | { | ||
101 | const user = { username: 'user2', password: 'password' } | ||
102 | await servers[1].users.create({ username: user.username, password: user.password }) | ||
103 | |||
104 | userToken2 = await servers[1].login.getAccessToken(user) | ||
105 | await servers[1].videos.upload({ token: userToken2, attributes: { name: 'video user 2' } }) | ||
106 | } | ||
107 | |||
108 | { | ||
109 | const { uuid } = await servers[0].videos.upload({ attributes: { name: 'video server 1' } }) | ||
110 | videoUUID1 = uuid | ||
111 | } | ||
112 | |||
113 | { | ||
114 | const { uuid } = await servers[1].videos.upload({ attributes: { name: 'video server 2' } }) | ||
115 | videoUUID2 = uuid | ||
116 | } | ||
117 | |||
118 | { | ||
119 | const { uuid } = await servers[0].videos.upload({ attributes: { name: 'video 2 server 1' } }) | ||
120 | videoUUID3 = uuid | ||
121 | } | ||
122 | |||
123 | await doubleFollow(servers[0], servers[1]) | ||
124 | await doubleFollow(servers[0], servers[2]) | ||
125 | |||
126 | { | ||
127 | const created = await commentsCommand[0].createThread({ videoId: videoUUID1, text: 'comment root 1' }) | ||
128 | const reply = await commentsCommand[0].addReply({ | ||
129 | token: userToken1, | ||
130 | videoId: videoUUID1, | ||
131 | toCommentId: created.id, | ||
132 | text: 'comment user 1' | ||
133 | }) | ||
134 | await commentsCommand[0].addReply({ videoId: videoUUID1, toCommentId: reply.id, text: 'comment root 1' }) | ||
135 | } | ||
136 | |||
137 | { | ||
138 | const created = await commentsCommand[0].createThread({ token: userToken1, videoId: videoUUID1, text: 'comment user 1' }) | ||
139 | await commentsCommand[0].addReply({ videoId: videoUUID1, toCommentId: created.id, text: 'comment root 1' }) | ||
140 | } | ||
141 | |||
142 | await waitJobs(servers) | ||
143 | }) | ||
144 | |||
145 | describe('User blocklist', function () { | ||
146 | |||
147 | describe('When managing account blocklist', function () { | ||
148 | it('Should list all videos', function () { | ||
149 | return checkAllVideos(servers[0], servers[0].accessToken) | ||
150 | }) | ||
151 | |||
152 | it('Should list the comments', function () { | ||
153 | return checkAllComments(servers[0], servers[0].accessToken, videoUUID1) | ||
154 | }) | ||
155 | |||
156 | it('Should block a remote account', async function () { | ||
157 | await command.addToMyBlocklist({ account: 'user2@' + servers[1].host }) | ||
158 | }) | ||
159 | |||
160 | it('Should hide its videos', async function () { | ||
161 | const { data } = await servers[0].videos.listWithToken() | ||
162 | |||
163 | expect(data).to.have.lengthOf(4) | ||
164 | |||
165 | const v = data.find(v => v.name === 'video user 2') | ||
166 | expect(v).to.be.undefined | ||
167 | }) | ||
168 | |||
169 | it('Should block a local account', async function () { | ||
170 | await command.addToMyBlocklist({ account: 'user1' }) | ||
171 | }) | ||
172 | |||
173 | it('Should hide its videos', async function () { | ||
174 | const { data } = await servers[0].videos.listWithToken() | ||
175 | |||
176 | expect(data).to.have.lengthOf(3) | ||
177 | |||
178 | const v = data.find(v => v.name === 'video user 1') | ||
179 | expect(v).to.be.undefined | ||
180 | }) | ||
181 | |||
182 | it('Should hide its comments', async function () { | ||
183 | const { data } = await commentsCommand[0].listThreads({ | ||
184 | token: servers[0].accessToken, | ||
185 | videoId: videoUUID1, | ||
186 | start: 0, | ||
187 | count: 25, | ||
188 | sort: '-createdAt' | ||
189 | }) | ||
190 | |||
191 | expect(data).to.have.lengthOf(1) | ||
192 | expect(data[0].totalReplies).to.equal(1) | ||
193 | |||
194 | const t = data.find(t => t.text === 'comment user 1') | ||
195 | expect(t).to.be.undefined | ||
196 | |||
197 | for (const thread of data) { | ||
198 | const tree = await commentsCommand[0].getThread({ | ||
199 | videoId: videoUUID1, | ||
200 | threadId: thread.id, | ||
201 | token: servers[0].accessToken | ||
202 | }) | ||
203 | expect(tree.children).to.have.lengthOf(0) | ||
204 | } | ||
205 | }) | ||
206 | |||
207 | it('Should not have notifications from blocked accounts', async function () { | ||
208 | this.timeout(20000) | ||
209 | |||
210 | { | ||
211 | const comment = { server: servers[0], token: userToken1, videoUUID: videoUUID1, text: 'hidden comment' } | ||
212 | await checkCommentNotification(servers[0], comment, 'absence') | ||
213 | } | ||
214 | |||
215 | { | ||
216 | const comment = { | ||
217 | server: servers[0], | ||
218 | token: userToken1, | ||
219 | videoUUID: videoUUID2, | ||
220 | text: 'hello @root@' + servers[0].host | ||
221 | } | ||
222 | await checkCommentNotification(servers[0], comment, 'absence') | ||
223 | } | ||
224 | }) | ||
225 | |||
226 | it('Should list all the videos with another user', async function () { | ||
227 | return checkAllVideos(servers[0], userToken1) | ||
228 | }) | ||
229 | |||
230 | it('Should list blocked accounts', async function () { | ||
231 | { | ||
232 | const body = await command.listMyAccountBlocklist({ start: 0, count: 1, sort: 'createdAt' }) | ||
233 | expect(body.total).to.equal(2) | ||
234 | |||
235 | const block = body.data[0] | ||
236 | expect(block.byAccount.displayName).to.equal('root') | ||
237 | expect(block.byAccount.name).to.equal('root') | ||
238 | expect(block.blockedAccount.displayName).to.equal('user2') | ||
239 | expect(block.blockedAccount.name).to.equal('user2') | ||
240 | expect(block.blockedAccount.host).to.equal('' + servers[1].host) | ||
241 | } | ||
242 | |||
243 | { | ||
244 | const body = await command.listMyAccountBlocklist({ start: 1, count: 2, sort: 'createdAt' }) | ||
245 | expect(body.total).to.equal(2) | ||
246 | |||
247 | const block = body.data[0] | ||
248 | expect(block.byAccount.displayName).to.equal('root') | ||
249 | expect(block.byAccount.name).to.equal('root') | ||
250 | expect(block.blockedAccount.displayName).to.equal('user1') | ||
251 | expect(block.blockedAccount.name).to.equal('user1') | ||
252 | expect(block.blockedAccount.host).to.equal('' + servers[0].host) | ||
253 | } | ||
254 | }) | ||
255 | |||
256 | it('Should search blocked accounts', async function () { | ||
257 | const body = await command.listMyAccountBlocklist({ start: 0, count: 10, search: 'user2' }) | ||
258 | expect(body.total).to.equal(1) | ||
259 | |||
260 | expect(body.data[0].blockedAccount.name).to.equal('user2') | ||
261 | }) | ||
262 | |||
263 | it('Should get blocked status', async function () { | ||
264 | const remoteHandle = 'user2@' + servers[1].host | ||
265 | const localHandle = 'user1@' + servers[0].host | ||
266 | const unknownHandle = 'user5@' + servers[0].host | ||
267 | |||
268 | { | ||
269 | const status = await command.getStatus({ accounts: [ remoteHandle ] }) | ||
270 | expect(Object.keys(status.accounts)).to.have.lengthOf(1) | ||
271 | expect(status.accounts[remoteHandle].blockedByUser).to.be.false | ||
272 | expect(status.accounts[remoteHandle].blockedByServer).to.be.false | ||
273 | |||
274 | expect(Object.keys(status.hosts)).to.have.lengthOf(0) | ||
275 | } | ||
276 | |||
277 | { | ||
278 | const status = await command.getStatus({ token: servers[0].accessToken, accounts: [ remoteHandle ] }) | ||
279 | expect(Object.keys(status.accounts)).to.have.lengthOf(1) | ||
280 | expect(status.accounts[remoteHandle].blockedByUser).to.be.true | ||
281 | expect(status.accounts[remoteHandle].blockedByServer).to.be.false | ||
282 | |||
283 | expect(Object.keys(status.hosts)).to.have.lengthOf(0) | ||
284 | } | ||
285 | |||
286 | { | ||
287 | const status = await command.getStatus({ token: servers[0].accessToken, accounts: [ localHandle, remoteHandle, unknownHandle ] }) | ||
288 | expect(Object.keys(status.accounts)).to.have.lengthOf(3) | ||
289 | |||
290 | for (const handle of [ localHandle, remoteHandle ]) { | ||
291 | expect(status.accounts[handle].blockedByUser).to.be.true | ||
292 | expect(status.accounts[handle].blockedByServer).to.be.false | ||
293 | } | ||
294 | |||
295 | expect(status.accounts[unknownHandle].blockedByUser).to.be.false | ||
296 | expect(status.accounts[unknownHandle].blockedByServer).to.be.false | ||
297 | |||
298 | expect(Object.keys(status.hosts)).to.have.lengthOf(0) | ||
299 | } | ||
300 | }) | ||
301 | |||
302 | it('Should not allow a remote blocked user to comment my videos', async function () { | ||
303 | this.timeout(60000) | ||
304 | |||
305 | { | ||
306 | await commentsCommand[1].createThread({ token: userToken2, videoId: videoUUID3, text: 'comment user 2' }) | ||
307 | await waitJobs(servers) | ||
308 | |||
309 | await commentsCommand[0].createThread({ token: servers[0].accessToken, videoId: videoUUID3, text: 'uploader' }) | ||
310 | await waitJobs(servers) | ||
311 | |||
312 | const commentId = await commentsCommand[1].findCommentId({ videoId: videoUUID3, text: 'uploader' }) | ||
313 | const message = 'reply by user 2' | ||
314 | const reply = await commentsCommand[1].addReply({ token: userToken2, videoId: videoUUID3, toCommentId: commentId, text: message }) | ||
315 | await commentsCommand[1].addReply({ videoId: videoUUID3, toCommentId: reply.id, text: 'another reply' }) | ||
316 | |||
317 | await waitJobs(servers) | ||
318 | } | ||
319 | |||
320 | // Server 2 has all the comments | ||
321 | { | ||
322 | const { data } = await commentsCommand[1].listThreads({ videoId: videoUUID3, count: 25, sort: '-createdAt' }) | ||
323 | |||
324 | expect(data).to.have.lengthOf(2) | ||
325 | expect(data[0].text).to.equal('uploader') | ||
326 | expect(data[1].text).to.equal('comment user 2') | ||
327 | |||
328 | const tree = await commentsCommand[1].getThread({ videoId: videoUUID3, threadId: data[0].id }) | ||
329 | expect(tree.children).to.have.lengthOf(1) | ||
330 | expect(tree.children[0].comment.text).to.equal('reply by user 2') | ||
331 | expect(tree.children[0].children).to.have.lengthOf(1) | ||
332 | expect(tree.children[0].children[0].comment.text).to.equal('another reply') | ||
333 | } | ||
334 | |||
335 | // Server 1 and 3 should only have uploader comments | ||
336 | for (const server of [ servers[0], servers[2] ]) { | ||
337 | const { data } = await server.comments.listThreads({ videoId: videoUUID3, count: 25, sort: '-createdAt' }) | ||
338 | |||
339 | expect(data).to.have.lengthOf(1) | ||
340 | expect(data[0].text).to.equal('uploader') | ||
341 | |||
342 | const tree = await server.comments.getThread({ videoId: videoUUID3, threadId: data[0].id }) | ||
343 | |||
344 | if (server.serverNumber === 1) expect(tree.children).to.have.lengthOf(0) | ||
345 | else expect(tree.children).to.have.lengthOf(1) | ||
346 | } | ||
347 | }) | ||
348 | |||
349 | it('Should unblock the remote account', async function () { | ||
350 | await command.removeFromMyBlocklist({ account: 'user2@' + servers[1].host }) | ||
351 | }) | ||
352 | |||
353 | it('Should display its videos', async function () { | ||
354 | const { data } = await servers[0].videos.listWithToken() | ||
355 | expect(data).to.have.lengthOf(4) | ||
356 | |||
357 | const v = data.find(v => v.name === 'video user 2') | ||
358 | expect(v).not.to.be.undefined | ||
359 | }) | ||
360 | |||
361 | it('Should display its comments on my video', async function () { | ||
362 | for (const server of servers) { | ||
363 | const { data } = await server.comments.listThreads({ videoId: videoUUID3, count: 25, sort: '-createdAt' }) | ||
364 | |||
365 | // Server 3 should not have 2 comment threads, because server 1 did not forward the server 2 comment | ||
366 | if (server.serverNumber === 3) { | ||
367 | expect(data).to.have.lengthOf(1) | ||
368 | continue | ||
369 | } | ||
370 | |||
371 | expect(data).to.have.lengthOf(2) | ||
372 | expect(data[0].text).to.equal('uploader') | ||
373 | expect(data[1].text).to.equal('comment user 2') | ||
374 | |||
375 | const tree = await server.comments.getThread({ videoId: videoUUID3, threadId: data[0].id }) | ||
376 | expect(tree.children).to.have.lengthOf(1) | ||
377 | expect(tree.children[0].comment.text).to.equal('reply by user 2') | ||
378 | expect(tree.children[0].children).to.have.lengthOf(1) | ||
379 | expect(tree.children[0].children[0].comment.text).to.equal('another reply') | ||
380 | } | ||
381 | }) | ||
382 | |||
383 | it('Should unblock the local account', async function () { | ||
384 | await command.removeFromMyBlocklist({ account: 'user1' }) | ||
385 | }) | ||
386 | |||
387 | it('Should display its comments', function () { | ||
388 | return checkAllComments(servers[0], servers[0].accessToken, videoUUID1) | ||
389 | }) | ||
390 | |||
391 | it('Should have a notification from a non blocked account', async function () { | ||
392 | this.timeout(20000) | ||
393 | |||
394 | { | ||
395 | const comment = { server: servers[1], token: userToken2, videoUUID: videoUUID1, text: 'displayed comment' } | ||
396 | await checkCommentNotification(servers[0], comment, 'presence') | ||
397 | } | ||
398 | |||
399 | { | ||
400 | const comment = { | ||
401 | server: servers[0], | ||
402 | token: userToken1, | ||
403 | videoUUID: videoUUID2, | ||
404 | text: 'hello @root@' + servers[0].host | ||
405 | } | ||
406 | await checkCommentNotification(servers[0], comment, 'presence') | ||
407 | } | ||
408 | }) | ||
409 | }) | ||
410 | |||
411 | describe('When managing server blocklist', function () { | ||
412 | |||
413 | it('Should list all videos', function () { | ||
414 | return checkAllVideos(servers[0], servers[0].accessToken) | ||
415 | }) | ||
416 | |||
417 | it('Should list the comments', function () { | ||
418 | return checkAllComments(servers[0], servers[0].accessToken, videoUUID1) | ||
419 | }) | ||
420 | |||
421 | it('Should block a remote server', async function () { | ||
422 | await command.addToMyBlocklist({ server: '' + servers[1].host }) | ||
423 | }) | ||
424 | |||
425 | it('Should hide its videos', async function () { | ||
426 | const { data } = await servers[0].videos.listWithToken() | ||
427 | |||
428 | expect(data).to.have.lengthOf(3) | ||
429 | |||
430 | const v1 = data.find(v => v.name === 'video user 2') | ||
431 | const v2 = data.find(v => v.name === 'video server 2') | ||
432 | |||
433 | expect(v1).to.be.undefined | ||
434 | expect(v2).to.be.undefined | ||
435 | }) | ||
436 | |||
437 | it('Should list all the videos with another user', async function () { | ||
438 | return checkAllVideos(servers[0], userToken1) | ||
439 | }) | ||
440 | |||
441 | it('Should hide its comments', async function () { | ||
442 | const { id } = await commentsCommand[1].createThread({ token: userToken2, videoId: videoUUID1, text: 'hidden comment 2' }) | ||
443 | |||
444 | await waitJobs(servers) | ||
445 | |||
446 | await checkAllComments(servers[0], servers[0].accessToken, videoUUID1) | ||
447 | |||
448 | await commentsCommand[1].delete({ token: userToken2, videoId: videoUUID1, commentId: id }) | ||
449 | }) | ||
450 | |||
451 | it('Should not have notifications from blocked server', async function () { | ||
452 | this.timeout(20000) | ||
453 | |||
454 | { | ||
455 | const comment = { server: servers[1], token: userToken2, videoUUID: videoUUID1, text: 'hidden comment' } | ||
456 | await checkCommentNotification(servers[0], comment, 'absence') | ||
457 | } | ||
458 | |||
459 | { | ||
460 | const comment = { | ||
461 | server: servers[1], | ||
462 | token: userToken2, | ||
463 | videoUUID: videoUUID1, | ||
464 | text: 'hello @root@' + servers[0].host | ||
465 | } | ||
466 | await checkCommentNotification(servers[0], comment, 'absence') | ||
467 | } | ||
468 | }) | ||
469 | |||
470 | it('Should list blocked servers', async function () { | ||
471 | const body = await command.listMyServerBlocklist({ start: 0, count: 1, sort: 'createdAt' }) | ||
472 | expect(body.total).to.equal(1) | ||
473 | |||
474 | const block = body.data[0] | ||
475 | expect(block.byAccount.displayName).to.equal('root') | ||
476 | expect(block.byAccount.name).to.equal('root') | ||
477 | expect(block.blockedServer.host).to.equal('' + servers[1].host) | ||
478 | }) | ||
479 | |||
480 | it('Should search blocked servers', async function () { | ||
481 | const body = await command.listMyServerBlocklist({ start: 0, count: 10, search: servers[1].host }) | ||
482 | expect(body.total).to.equal(1) | ||
483 | |||
484 | expect(body.data[0].blockedServer.host).to.equal(servers[1].host) | ||
485 | }) | ||
486 | |||
487 | it('Should get blocklist status', async function () { | ||
488 | const blockedServer = servers[1].host | ||
489 | const notBlockedServer = 'example.com' | ||
490 | |||
491 | { | ||
492 | const status = await command.getStatus({ hosts: [ blockedServer, notBlockedServer ] }) | ||
493 | expect(Object.keys(status.accounts)).to.have.lengthOf(0) | ||
494 | |||
495 | expect(Object.keys(status.hosts)).to.have.lengthOf(2) | ||
496 | expect(status.hosts[blockedServer].blockedByUser).to.be.false | ||
497 | expect(status.hosts[blockedServer].blockedByServer).to.be.false | ||
498 | |||
499 | expect(status.hosts[notBlockedServer].blockedByUser).to.be.false | ||
500 | expect(status.hosts[notBlockedServer].blockedByServer).to.be.false | ||
501 | } | ||
502 | |||
503 | { | ||
504 | const status = await command.getStatus({ token: servers[0].accessToken, hosts: [ blockedServer, notBlockedServer ] }) | ||
505 | expect(Object.keys(status.accounts)).to.have.lengthOf(0) | ||
506 | |||
507 | expect(Object.keys(status.hosts)).to.have.lengthOf(2) | ||
508 | expect(status.hosts[blockedServer].blockedByUser).to.be.true | ||
509 | expect(status.hosts[blockedServer].blockedByServer).to.be.false | ||
510 | |||
511 | expect(status.hosts[notBlockedServer].blockedByUser).to.be.false | ||
512 | expect(status.hosts[notBlockedServer].blockedByServer).to.be.false | ||
513 | } | ||
514 | }) | ||
515 | |||
516 | it('Should unblock the remote server', async function () { | ||
517 | await command.removeFromMyBlocklist({ server: '' + servers[1].host }) | ||
518 | }) | ||
519 | |||
520 | it('Should display its videos', function () { | ||
521 | return checkAllVideos(servers[0], servers[0].accessToken) | ||
522 | }) | ||
523 | |||
524 | it('Should display its comments', function () { | ||
525 | return checkAllComments(servers[0], servers[0].accessToken, videoUUID1) | ||
526 | }) | ||
527 | |||
528 | it('Should have notification from unblocked server', async function () { | ||
529 | this.timeout(20000) | ||
530 | |||
531 | { | ||
532 | const comment = { server: servers[1], token: userToken2, videoUUID: videoUUID1, text: 'displayed comment' } | ||
533 | await checkCommentNotification(servers[0], comment, 'presence') | ||
534 | } | ||
535 | |||
536 | { | ||
537 | const comment = { | ||
538 | server: servers[1], | ||
539 | token: userToken2, | ||
540 | videoUUID: videoUUID1, | ||
541 | text: 'hello @root@' + servers[0].host | ||
542 | } | ||
543 | await checkCommentNotification(servers[0], comment, 'presence') | ||
544 | } | ||
545 | }) | ||
546 | }) | ||
547 | }) | ||
548 | |||
549 | describe('Server blocklist', function () { | ||
550 | |||
551 | describe('When managing account blocklist', function () { | ||
552 | it('Should list all videos', async function () { | ||
553 | for (const token of [ userModeratorToken, servers[0].accessToken ]) { | ||
554 | await checkAllVideos(servers[0], token) | ||
555 | } | ||
556 | }) | ||
557 | |||
558 | it('Should list the comments', async function () { | ||
559 | for (const token of [ userModeratorToken, servers[0].accessToken ]) { | ||
560 | await checkAllComments(servers[0], token, videoUUID1) | ||
561 | } | ||
562 | }) | ||
563 | |||
564 | it('Should block a remote account', async function () { | ||
565 | await command.addToServerBlocklist({ account: 'user2@' + servers[1].host }) | ||
566 | }) | ||
567 | |||
568 | it('Should hide its videos', async function () { | ||
569 | for (const token of [ userModeratorToken, servers[0].accessToken ]) { | ||
570 | const { data } = await servers[0].videos.listWithToken({ token }) | ||
571 | |||
572 | expect(data).to.have.lengthOf(4) | ||
573 | |||
574 | const v = data.find(v => v.name === 'video user 2') | ||
575 | expect(v).to.be.undefined | ||
576 | } | ||
577 | }) | ||
578 | |||
579 | it('Should block a local account', async function () { | ||
580 | await command.addToServerBlocklist({ account: 'user1' }) | ||
581 | }) | ||
582 | |||
583 | it('Should hide its videos', async function () { | ||
584 | for (const token of [ userModeratorToken, servers[0].accessToken ]) { | ||
585 | const { data } = await servers[0].videos.listWithToken({ token }) | ||
586 | |||
587 | expect(data).to.have.lengthOf(3) | ||
588 | |||
589 | const v = data.find(v => v.name === 'video user 1') | ||
590 | expect(v).to.be.undefined | ||
591 | } | ||
592 | }) | ||
593 | |||
594 | it('Should hide its comments', async function () { | ||
595 | for (const token of [ userModeratorToken, servers[0].accessToken ]) { | ||
596 | const { data } = await commentsCommand[0].listThreads({ videoId: videoUUID1, count: 20, sort: '-createdAt', token }) | ||
597 | const threads = data.filter(t => t.isDeleted === false) | ||
598 | |||
599 | expect(threads).to.have.lengthOf(1) | ||
600 | expect(threads[0].totalReplies).to.equal(1) | ||
601 | |||
602 | const t = threads.find(t => t.text === 'comment user 1') | ||
603 | expect(t).to.be.undefined | ||
604 | |||
605 | for (const thread of threads) { | ||
606 | const tree = await commentsCommand[0].getThread({ videoId: videoUUID1, threadId: thread.id, token }) | ||
607 | expect(tree.children).to.have.lengthOf(0) | ||
608 | } | ||
609 | } | ||
610 | }) | ||
611 | |||
612 | it('Should not have notification from blocked accounts by instance', async function () { | ||
613 | this.timeout(20000) | ||
614 | |||
615 | { | ||
616 | const comment = { server: servers[0], token: userToken1, videoUUID: videoUUID1, text: 'hidden comment' } | ||
617 | await checkCommentNotification(servers[0], comment, 'absence') | ||
618 | } | ||
619 | |||
620 | { | ||
621 | const comment = { | ||
622 | server: servers[1], | ||
623 | token: userToken2, | ||
624 | videoUUID: videoUUID1, | ||
625 | text: 'hello @root@' + servers[0].host | ||
626 | } | ||
627 | await checkCommentNotification(servers[0], comment, 'absence') | ||
628 | } | ||
629 | }) | ||
630 | |||
631 | it('Should list blocked accounts', async function () { | ||
632 | { | ||
633 | const body = await command.listServerAccountBlocklist({ start: 0, count: 1, sort: 'createdAt' }) | ||
634 | expect(body.total).to.equal(2) | ||
635 | |||
636 | const block = body.data[0] | ||
637 | expect(block.byAccount.displayName).to.equal('peertube') | ||
638 | expect(block.byAccount.name).to.equal('peertube') | ||
639 | expect(block.blockedAccount.displayName).to.equal('user2') | ||
640 | expect(block.blockedAccount.name).to.equal('user2') | ||
641 | expect(block.blockedAccount.host).to.equal('' + servers[1].host) | ||
642 | } | ||
643 | |||
644 | { | ||
645 | const body = await command.listServerAccountBlocklist({ start: 1, count: 2, sort: 'createdAt' }) | ||
646 | expect(body.total).to.equal(2) | ||
647 | |||
648 | const block = body.data[0] | ||
649 | expect(block.byAccount.displayName).to.equal('peertube') | ||
650 | expect(block.byAccount.name).to.equal('peertube') | ||
651 | expect(block.blockedAccount.displayName).to.equal('user1') | ||
652 | expect(block.blockedAccount.name).to.equal('user1') | ||
653 | expect(block.blockedAccount.host).to.equal('' + servers[0].host) | ||
654 | } | ||
655 | }) | ||
656 | |||
657 | it('Should search blocked accounts', async function () { | ||
658 | const body = await command.listServerAccountBlocklist({ start: 0, count: 10, search: 'user2' }) | ||
659 | expect(body.total).to.equal(1) | ||
660 | |||
661 | expect(body.data[0].blockedAccount.name).to.equal('user2') | ||
662 | }) | ||
663 | |||
664 | it('Should get blocked status', async function () { | ||
665 | const remoteHandle = 'user2@' + servers[1].host | ||
666 | const localHandle = 'user1@' + servers[0].host | ||
667 | const unknownHandle = 'user5@' + servers[0].host | ||
668 | |||
669 | for (const token of [ undefined, servers[0].accessToken ]) { | ||
670 | const status = await command.getStatus({ token, accounts: [ localHandle, remoteHandle, unknownHandle ] }) | ||
671 | expect(Object.keys(status.accounts)).to.have.lengthOf(3) | ||
672 | |||
673 | for (const handle of [ localHandle, remoteHandle ]) { | ||
674 | expect(status.accounts[handle].blockedByUser).to.be.false | ||
675 | expect(status.accounts[handle].blockedByServer).to.be.true | ||
676 | } | ||
677 | |||
678 | expect(status.accounts[unknownHandle].blockedByUser).to.be.false | ||
679 | expect(status.accounts[unknownHandle].blockedByServer).to.be.false | ||
680 | |||
681 | expect(Object.keys(status.hosts)).to.have.lengthOf(0) | ||
682 | } | ||
683 | }) | ||
684 | |||
685 | it('Should unblock the remote account', async function () { | ||
686 | await command.removeFromServerBlocklist({ account: 'user2@' + servers[1].host }) | ||
687 | }) | ||
688 | |||
689 | it('Should display its videos', async function () { | ||
690 | for (const token of [ userModeratorToken, servers[0].accessToken ]) { | ||
691 | const { data } = await servers[0].videos.listWithToken({ token }) | ||
692 | expect(data).to.have.lengthOf(4) | ||
693 | |||
694 | const v = data.find(v => v.name === 'video user 2') | ||
695 | expect(v).not.to.be.undefined | ||
696 | } | ||
697 | }) | ||
698 | |||
699 | it('Should unblock the local account', async function () { | ||
700 | await command.removeFromServerBlocklist({ account: 'user1' }) | ||
701 | }) | ||
702 | |||
703 | it('Should display its comments', async function () { | ||
704 | for (const token of [ userModeratorToken, servers[0].accessToken ]) { | ||
705 | await checkAllComments(servers[0], token, videoUUID1) | ||
706 | } | ||
707 | }) | ||
708 | |||
709 | it('Should have notifications from unblocked accounts', async function () { | ||
710 | this.timeout(20000) | ||
711 | |||
712 | { | ||
713 | const comment = { server: servers[0], token: userToken1, videoUUID: videoUUID1, text: 'displayed comment' } | ||
714 | await checkCommentNotification(servers[0], comment, 'presence') | ||
715 | } | ||
716 | |||
717 | { | ||
718 | const comment = { | ||
719 | server: servers[1], | ||
720 | token: userToken2, | ||
721 | videoUUID: videoUUID1, | ||
722 | text: 'hello @root@' + servers[0].host | ||
723 | } | ||
724 | await checkCommentNotification(servers[0], comment, 'presence') | ||
725 | } | ||
726 | }) | ||
727 | }) | ||
728 | |||
729 | describe('When managing server blocklist', function () { | ||
730 | |||
731 | it('Should list all videos', async function () { | ||
732 | for (const token of [ userModeratorToken, servers[0].accessToken ]) { | ||
733 | await checkAllVideos(servers[0], token) | ||
734 | } | ||
735 | }) | ||
736 | |||
737 | it('Should list the comments', async function () { | ||
738 | for (const token of [ userModeratorToken, servers[0].accessToken ]) { | ||
739 | await checkAllComments(servers[0], token, videoUUID1) | ||
740 | } | ||
741 | }) | ||
742 | |||
743 | it('Should block a remote server', async function () { | ||
744 | await command.addToServerBlocklist({ server: '' + servers[1].host }) | ||
745 | }) | ||
746 | |||
747 | it('Should hide its videos', async function () { | ||
748 | for (const token of [ userModeratorToken, servers[0].accessToken ]) { | ||
749 | const requests = [ | ||
750 | servers[0].videos.list(), | ||
751 | servers[0].videos.listWithToken({ token }) | ||
752 | ] | ||
753 | |||
754 | for (const req of requests) { | ||
755 | const { data } = await req | ||
756 | expect(data).to.have.lengthOf(3) | ||
757 | |||
758 | const v1 = data.find(v => v.name === 'video user 2') | ||
759 | const v2 = data.find(v => v.name === 'video server 2') | ||
760 | |||
761 | expect(v1).to.be.undefined | ||
762 | expect(v2).to.be.undefined | ||
763 | } | ||
764 | } | ||
765 | }) | ||
766 | |||
767 | it('Should hide its comments', async function () { | ||
768 | const { id } = await commentsCommand[1].createThread({ token: userToken2, videoId: videoUUID1, text: 'hidden comment 2' }) | ||
769 | |||
770 | await waitJobs(servers) | ||
771 | |||
772 | await checkAllComments(servers[0], servers[0].accessToken, videoUUID1) | ||
773 | |||
774 | await commentsCommand[1].delete({ token: userToken2, videoId: videoUUID1, commentId: id }) | ||
775 | }) | ||
776 | |||
777 | it('Should not have notification from blocked instances by instance', async function () { | ||
778 | this.timeout(50000) | ||
779 | |||
780 | { | ||
781 | const comment = { server: servers[1], token: userToken2, videoUUID: videoUUID1, text: 'hidden comment' } | ||
782 | await checkCommentNotification(servers[0], comment, 'absence') | ||
783 | } | ||
784 | |||
785 | { | ||
786 | const comment = { | ||
787 | server: servers[1], | ||
788 | token: userToken2, | ||
789 | videoUUID: videoUUID1, | ||
790 | text: 'hello @root@' + servers[0].host | ||
791 | } | ||
792 | await checkCommentNotification(servers[0], comment, 'absence') | ||
793 | } | ||
794 | |||
795 | { | ||
796 | const now = new Date() | ||
797 | await servers[1].follows.unfollow({ target: servers[0] }) | ||
798 | await waitJobs(servers) | ||
799 | await servers[1].follows.follow({ hosts: [ servers[0].host ] }) | ||
800 | |||
801 | await waitJobs(servers) | ||
802 | |||
803 | const { data } = await servers[0].notifications.list({ start: 0, count: 30 }) | ||
804 | const commentNotifications = data.filter(n => { | ||
805 | return n.type === UserNotificationType.NEW_INSTANCE_FOLLOWER && n.createdAt >= now.toISOString() | ||
806 | }) | ||
807 | |||
808 | expect(commentNotifications).to.have.lengthOf(0) | ||
809 | } | ||
810 | }) | ||
811 | |||
812 | it('Should list blocked servers', async function () { | ||
813 | const body = await command.listServerServerBlocklist({ start: 0, count: 1, sort: 'createdAt' }) | ||
814 | expect(body.total).to.equal(1) | ||
815 | |||
816 | const block = body.data[0] | ||
817 | expect(block.byAccount.displayName).to.equal('peertube') | ||
818 | expect(block.byAccount.name).to.equal('peertube') | ||
819 | expect(block.blockedServer.host).to.equal('' + servers[1].host) | ||
820 | }) | ||
821 | |||
822 | it('Should search blocked servers', async function () { | ||
823 | const body = await command.listServerServerBlocklist({ start: 0, count: 10, search: servers[1].host }) | ||
824 | expect(body.total).to.equal(1) | ||
825 | |||
826 | expect(body.data[0].blockedServer.host).to.equal(servers[1].host) | ||
827 | }) | ||
828 | |||
829 | it('Should get blocklist status', async function () { | ||
830 | const blockedServer = servers[1].host | ||
831 | const notBlockedServer = 'example.com' | ||
832 | |||
833 | for (const token of [ undefined, servers[0].accessToken ]) { | ||
834 | const status = await command.getStatus({ token, hosts: [ blockedServer, notBlockedServer ] }) | ||
835 | expect(Object.keys(status.accounts)).to.have.lengthOf(0) | ||
836 | |||
837 | expect(Object.keys(status.hosts)).to.have.lengthOf(2) | ||
838 | expect(status.hosts[blockedServer].blockedByUser).to.be.false | ||
839 | expect(status.hosts[blockedServer].blockedByServer).to.be.true | ||
840 | |||
841 | expect(status.hosts[notBlockedServer].blockedByUser).to.be.false | ||
842 | expect(status.hosts[notBlockedServer].blockedByServer).to.be.false | ||
843 | } | ||
844 | }) | ||
845 | |||
846 | it('Should unblock the remote server', async function () { | ||
847 | await command.removeFromServerBlocklist({ server: '' + servers[1].host }) | ||
848 | }) | ||
849 | |||
850 | it('Should list all videos', async function () { | ||
851 | for (const token of [ userModeratorToken, servers[0].accessToken ]) { | ||
852 | await checkAllVideos(servers[0], token) | ||
853 | } | ||
854 | }) | ||
855 | |||
856 | it('Should list the comments', async function () { | ||
857 | for (const token of [ userModeratorToken, servers[0].accessToken ]) { | ||
858 | await checkAllComments(servers[0], token, videoUUID1) | ||
859 | } | ||
860 | }) | ||
861 | |||
862 | it('Should have notification from unblocked instances', async function () { | ||
863 | this.timeout(50000) | ||
864 | |||
865 | { | ||
866 | const comment = { server: servers[1], token: userToken2, videoUUID: videoUUID1, text: 'displayed comment' } | ||
867 | await checkCommentNotification(servers[0], comment, 'presence') | ||
868 | } | ||
869 | |||
870 | { | ||
871 | const comment = { | ||
872 | server: servers[1], | ||
873 | token: userToken2, | ||
874 | videoUUID: videoUUID1, | ||
875 | text: 'hello @root@' + servers[0].host | ||
876 | } | ||
877 | await checkCommentNotification(servers[0], comment, 'presence') | ||
878 | } | ||
879 | |||
880 | { | ||
881 | const now = new Date() | ||
882 | await servers[1].follows.unfollow({ target: servers[0] }) | ||
883 | await waitJobs(servers) | ||
884 | await servers[1].follows.follow({ hosts: [ servers[0].host ] }) | ||
885 | |||
886 | await waitJobs(servers) | ||
887 | |||
888 | const { data } = await servers[0].notifications.list({ start: 0, count: 30 }) | ||
889 | const commentNotifications = data.filter(n => { | ||
890 | return n.type === UserNotificationType.NEW_INSTANCE_FOLLOWER && n.createdAt >= now.toISOString() | ||
891 | }) | ||
892 | |||
893 | expect(commentNotifications).to.have.lengthOf(1) | ||
894 | } | ||
895 | }) | ||
896 | }) | ||
897 | }) | ||
898 | |||
899 | after(async function () { | ||
900 | await cleanupTests(servers) | ||
901 | }) | ||
902 | }) | ||
diff --git a/server/tests/api/moderation/index.ts b/server/tests/api/moderation/index.ts deleted file mode 100644 index 874be03d5..000000000 --- a/server/tests/api/moderation/index.ts +++ /dev/null | |||
@@ -1,4 +0,0 @@ | |||
1 | export * from './abuses' | ||
2 | export * from './blocklist-notification' | ||
3 | export * from './blocklist' | ||
4 | export * from './video-blacklist' | ||
diff --git a/server/tests/api/moderation/video-blacklist.ts b/server/tests/api/moderation/video-blacklist.ts deleted file mode 100644 index ef087a93b..000000000 --- a/server/tests/api/moderation/video-blacklist.ts +++ /dev/null | |||
@@ -1,414 +0,0 @@ | |||
1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ | ||
2 | |||
3 | import { expect } from 'chai' | ||
4 | import { FIXTURE_URLS } from '@server/tests/shared' | ||
5 | import { sortObjectComparator } from '@shared/core-utils' | ||
6 | import { UserAdminFlag, UserRole, VideoBlacklist, VideoBlacklistType } from '@shared/models' | ||
7 | import { | ||
8 | BlacklistCommand, | ||
9 | cleanupTests, | ||
10 | createMultipleServers, | ||
11 | doubleFollow, | ||
12 | killallServers, | ||
13 | PeerTubeServer, | ||
14 | setAccessTokensToServers, | ||
15 | setDefaultChannelAvatar, | ||
16 | waitJobs | ||
17 | } from '@shared/server-commands' | ||
18 | |||
19 | describe('Test video blacklist', function () { | ||
20 | let servers: PeerTubeServer[] = [] | ||
21 | let videoId: number | ||
22 | let command: BlacklistCommand | ||
23 | |||
24 | async function blacklistVideosOnServer (server: PeerTubeServer) { | ||
25 | const { data } = await server.videos.list() | ||
26 | |||
27 | for (const video of data) { | ||
28 | await server.blacklist.add({ videoId: video.id, reason: 'super reason' }) | ||
29 | } | ||
30 | } | ||
31 | |||
32 | before(async function () { | ||
33 | this.timeout(120000) | ||
34 | |||
35 | // Run servers | ||
36 | servers = await createMultipleServers(2) | ||
37 | |||
38 | // Get the access tokens | ||
39 | await setAccessTokensToServers(servers) | ||
40 | |||
41 | // Server 1 and server 2 follow each other | ||
42 | await doubleFollow(servers[0], servers[1]) | ||
43 | await setDefaultChannelAvatar(servers[0]) | ||
44 | |||
45 | // Upload 2 videos on server 2 | ||
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' } }) | ||
48 | |||
49 | // Wait videos propagation, server 2 has transcoding enabled | ||
50 | await waitJobs(servers) | ||
51 | |||
52 | command = servers[0].blacklist | ||
53 | |||
54 | // Blacklist the two videos on server 1 | ||
55 | await blacklistVideosOnServer(servers[0]) | ||
56 | }) | ||
57 | |||
58 | describe('When listing/searching videos', function () { | ||
59 | |||
60 | it('Should not have the video blacklisted in videos list/search on server 1', async function () { | ||
61 | { | ||
62 | const { total, data } = await servers[0].videos.list() | ||
63 | |||
64 | expect(total).to.equal(0) | ||
65 | expect(data).to.be.an('array') | ||
66 | expect(data.length).to.equal(0) | ||
67 | } | ||
68 | |||
69 | { | ||
70 | const body = await servers[0].search.searchVideos({ search: 'video' }) | ||
71 | |||
72 | expect(body.total).to.equal(0) | ||
73 | expect(body.data).to.be.an('array') | ||
74 | expect(body.data.length).to.equal(0) | ||
75 | } | ||
76 | }) | ||
77 | |||
78 | it('Should have the blacklisted video in videos list/search on server 2', async function () { | ||
79 | { | ||
80 | const { total, data } = await servers[1].videos.list() | ||
81 | |||
82 | expect(total).to.equal(2) | ||
83 | expect(data).to.be.an('array') | ||
84 | expect(data.length).to.equal(2) | ||
85 | } | ||
86 | |||
87 | { | ||
88 | const body = await servers[1].search.searchVideos({ search: 'video' }) | ||
89 | |||
90 | expect(body.total).to.equal(2) | ||
91 | expect(body.data).to.be.an('array') | ||
92 | expect(body.data.length).to.equal(2) | ||
93 | } | ||
94 | }) | ||
95 | }) | ||
96 | |||
97 | describe('When listing manually blacklisted videos', function () { | ||
98 | it('Should display all the blacklisted videos', async function () { | ||
99 | const body = await command.list() | ||
100 | expect(body.total).to.equal(2) | ||
101 | |||
102 | const blacklistedVideos = body.data | ||
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 | |||
112 | it('Should display all the blacklisted videos when applying manual type filter', async function () { | ||
113 | const body = await command.list({ type: VideoBlacklistType.MANUAL }) | ||
114 | expect(body.total).to.equal(2) | ||
115 | |||
116 | const blacklistedVideos = body.data | ||
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 () { | ||
122 | const body = await command.list({ type: VideoBlacklistType.AUTO_BEFORE_PUBLISHED }) | ||
123 | expect(body.total).to.equal(0) | ||
124 | |||
125 | const blacklistedVideos = body.data | ||
126 | expect(blacklistedVideos).to.be.an('array') | ||
127 | expect(blacklistedVideos.length).to.equal(0) | ||
128 | }) | ||
129 | |||
130 | it('Should get the correct sort when sorting by descending id', async function () { | ||
131 | const body = await command.list({ sort: '-id' }) | ||
132 | expect(body.total).to.equal(2) | ||
133 | |||
134 | const blacklistedVideos = body.data | ||
135 | expect(blacklistedVideos).to.be.an('array') | ||
136 | expect(blacklistedVideos.length).to.equal(2) | ||
137 | |||
138 | const result = [ ...body.data ].sort(sortObjectComparator('id', 'desc')) | ||
139 | expect(blacklistedVideos).to.deep.equal(result) | ||
140 | }) | ||
141 | |||
142 | it('Should get the correct sort when sorting by descending video name', async function () { | ||
143 | const body = await command.list({ sort: '-name' }) | ||
144 | expect(body.total).to.equal(2) | ||
145 | |||
146 | const blacklistedVideos = body.data | ||
147 | expect(blacklistedVideos).to.be.an('array') | ||
148 | expect(blacklistedVideos.length).to.equal(2) | ||
149 | |||
150 | const result = [ ...body.data ].sort(sortObjectComparator('name', 'desc')) | ||
151 | expect(blacklistedVideos).to.deep.equal(result) | ||
152 | }) | ||
153 | |||
154 | it('Should get the correct sort when sorting by ascending creation date', async function () { | ||
155 | const body = await command.list({ sort: 'createdAt' }) | ||
156 | expect(body.total).to.equal(2) | ||
157 | |||
158 | const blacklistedVideos = body.data | ||
159 | expect(blacklistedVideos).to.be.an('array') | ||
160 | expect(blacklistedVideos.length).to.equal(2) | ||
161 | |||
162 | const result = [ ...body.data ].sort(sortObjectComparator('createdAt', 'asc')) | ||
163 | expect(blacklistedVideos).to.deep.equal(result) | ||
164 | }) | ||
165 | }) | ||
166 | |||
167 | describe('When updating blacklisted videos', function () { | ||
168 | it('Should change the reason', async function () { | ||
169 | await command.update({ videoId, reason: 'my super reason updated' }) | ||
170 | |||
171 | const body = await command.list({ sort: '-name' }) | ||
172 | const video = body.data.find(b => b.video.id === videoId) | ||
173 | |||
174 | expect(video.reason).to.equal('my super reason updated') | ||
175 | }) | ||
176 | }) | ||
177 | |||
178 | describe('When listing my videos', function () { | ||
179 | it('Should display blacklisted videos', async function () { | ||
180 | await blacklistVideosOnServer(servers[1]) | ||
181 | |||
182 | const { total, data } = await servers[1].videos.listMyVideos() | ||
183 | |||
184 | expect(total).to.equal(2) | ||
185 | expect(data).to.have.lengthOf(2) | ||
186 | |||
187 | for (const video of data) { | ||
188 | expect(video.blacklisted).to.be.true | ||
189 | expect(video.blacklistedReason).to.equal('super reason') | ||
190 | } | ||
191 | }) | ||
192 | }) | ||
193 | |||
194 | describe('When removing a blacklisted video', function () { | ||
195 | let videoToRemove: VideoBlacklist | ||
196 | let blacklist = [] | ||
197 | |||
198 | it('Should not have any video in videos list on server 1', async function () { | ||
199 | const { total, data } = await servers[0].videos.list() | ||
200 | expect(total).to.equal(0) | ||
201 | expect(data).to.be.an('array') | ||
202 | expect(data.length).to.equal(0) | ||
203 | }) | ||
204 | |||
205 | it('Should remove a video from the blacklist on server 1', async function () { | ||
206 | // Get one video in the blacklist | ||
207 | const body = await command.list({ sort: '-name' }) | ||
208 | videoToRemove = body.data[0] | ||
209 | blacklist = body.data.slice(1) | ||
210 | |||
211 | // Remove it | ||
212 | await command.remove({ videoId: videoToRemove.video.id }) | ||
213 | }) | ||
214 | |||
215 | it('Should have the ex-blacklisted video in videos list on server 1', async function () { | ||
216 | const { total, data } = await servers[0].videos.list() | ||
217 | expect(total).to.equal(1) | ||
218 | |||
219 | expect(data).to.be.an('array') | ||
220 | expect(data.length).to.equal(1) | ||
221 | |||
222 | expect(data[0].name).to.equal(videoToRemove.video.name) | ||
223 | expect(data[0].id).to.equal(videoToRemove.video.id) | ||
224 | }) | ||
225 | |||
226 | it('Should not have the ex-blacklisted video in videos blacklist list on server 1', async function () { | ||
227 | const body = await command.list({ sort: '-name' }) | ||
228 | expect(body.total).to.equal(1) | ||
229 | |||
230 | const videos = body.data | ||
231 | expect(videos).to.be.an('array') | ||
232 | expect(videos.length).to.equal(1) | ||
233 | expect(videos).to.deep.equal(blacklist) | ||
234 | }) | ||
235 | }) | ||
236 | |||
237 | describe('When blacklisting local videos', function () { | ||
238 | let video3UUID: string | ||
239 | let video4UUID: string | ||
240 | |||
241 | before(async function () { | ||
242 | { | ||
243 | const { uuid } = await servers[0].videos.upload({ attributes: { name: 'Video 3' } }) | ||
244 | video3UUID = uuid | ||
245 | } | ||
246 | { | ||
247 | const { uuid } = await servers[0].videos.upload({ attributes: { name: 'Video 4' } }) | ||
248 | video4UUID = uuid | ||
249 | } | ||
250 | |||
251 | await waitJobs(servers) | ||
252 | }) | ||
253 | |||
254 | it('Should blacklist video 3 and keep it federated', async function () { | ||
255 | await command.add({ videoId: video3UUID, reason: 'super reason', unfederate: false }) | ||
256 | |||
257 | await waitJobs(servers) | ||
258 | |||
259 | { | ||
260 | const { data } = await servers[0].videos.list() | ||
261 | expect(data.find(v => v.uuid === video3UUID)).to.be.undefined | ||
262 | } | ||
263 | |||
264 | { | ||
265 | const { data } = await servers[1].videos.list() | ||
266 | expect(data.find(v => v.uuid === video3UUID)).to.not.be.undefined | ||
267 | } | ||
268 | }) | ||
269 | |||
270 | it('Should unfederate the video', async function () { | ||
271 | await command.add({ videoId: video4UUID, reason: 'super reason', unfederate: true }) | ||
272 | |||
273 | await waitJobs(servers) | ||
274 | |||
275 | for (const server of servers) { | ||
276 | const { data } = await server.videos.list() | ||
277 | expect(data.find(v => v.uuid === video4UUID)).to.be.undefined | ||
278 | } | ||
279 | }) | ||
280 | |||
281 | it('Should have the video unfederated even after an Update AP message', async function () { | ||
282 | await servers[0].videos.update({ id: video4UUID, attributes: { description: 'super description' } }) | ||
283 | |||
284 | await waitJobs(servers) | ||
285 | |||
286 | for (const server of servers) { | ||
287 | const { data } = await server.videos.list() | ||
288 | expect(data.find(v => v.uuid === video4UUID)).to.be.undefined | ||
289 | } | ||
290 | }) | ||
291 | |||
292 | it('Should have the correct video blacklist unfederate attribute', async function () { | ||
293 | const body = await command.list({ sort: 'createdAt' }) | ||
294 | |||
295 | const blacklistedVideos = body.data | ||
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 () { | ||
304 | await command.remove({ videoId: video4UUID }) | ||
305 | |||
306 | await waitJobs(servers) | ||
307 | |||
308 | for (const server of servers) { | ||
309 | const { data } = await server.videos.list() | ||
310 | expect(data.find(v => v.uuid === video4UUID)).to.not.be.undefined | ||
311 | } | ||
312 | }) | ||
313 | |||
314 | }) | ||
315 | |||
316 | describe('When auto blacklist videos', function () { | ||
317 | let userWithoutFlag: string | ||
318 | let userWithFlag: string | ||
319 | let channelOfUserWithoutFlag: number | ||
320 | |||
321 | before(async function () { | ||
322 | this.timeout(20000) | ||
323 | |||
324 | await killallServers([ servers[0] ]) | ||
325 | |||
326 | const config = { | ||
327 | auto_blacklist: { | ||
328 | videos: { | ||
329 | of_users: { | ||
330 | enabled: true | ||
331 | } | ||
332 | } | ||
333 | } | ||
334 | } | ||
335 | await servers[0].run(config) | ||
336 | |||
337 | { | ||
338 | const user = { username: 'user_without_flag', password: 'password' } | ||
339 | await servers[0].users.create({ | ||
340 | username: user.username, | ||
341 | adminFlags: UserAdminFlag.NONE, | ||
342 | password: user.password, | ||
343 | role: UserRole.USER | ||
344 | }) | ||
345 | |||
346 | userWithoutFlag = await servers[0].login.getAccessToken(user) | ||
347 | |||
348 | const { videoChannels } = await servers[0].users.getMyInfo({ token: userWithoutFlag }) | ||
349 | channelOfUserWithoutFlag = videoChannels[0].id | ||
350 | } | ||
351 | |||
352 | { | ||
353 | const user = { username: 'user_with_flag', password: 'password' } | ||
354 | await servers[0].users.create({ | ||
355 | username: user.username, | ||
356 | adminFlags: UserAdminFlag.BYPASS_VIDEO_AUTO_BLACKLIST, | ||
357 | password: user.password, | ||
358 | role: UserRole.USER | ||
359 | }) | ||
360 | |||
361 | userWithFlag = await servers[0].login.getAccessToken(user) | ||
362 | } | ||
363 | |||
364 | await waitJobs(servers) | ||
365 | }) | ||
366 | |||
367 | it('Should auto blacklist a video on upload', async function () { | ||
368 | await servers[0].videos.upload({ token: userWithoutFlag, attributes: { name: 'blacklisted' } }) | ||
369 | |||
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') | ||
373 | }) | ||
374 | |||
375 | it('Should auto blacklist a video on URL import', async function () { | ||
376 | this.timeout(15000) | ||
377 | |||
378 | const attributes = { | ||
379 | targetUrl: FIXTURE_URLS.goodVideo, | ||
380 | name: 'URL import', | ||
381 | channelId: channelOfUserWithoutFlag | ||
382 | } | ||
383 | await servers[0].imports.importVideo({ token: userWithoutFlag, attributes }) | ||
384 | |||
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') | ||
388 | }) | ||
389 | |||
390 | it('Should auto blacklist a video on torrent import', async function () { | ||
391 | const attributes = { | ||
392 | magnetUri: FIXTURE_URLS.magnet, | ||
393 | name: 'Torrent import', | ||
394 | channelId: channelOfUserWithoutFlag | ||
395 | } | ||
396 | await servers[0].imports.importVideo({ token: userWithoutFlag, attributes }) | ||
397 | |||
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') | ||
401 | }) | ||
402 | |||
403 | it('Should not auto blacklist a video on upload if the user has the bypass blacklist flag', async function () { | ||
404 | await servers[0].videos.upload({ token: userWithFlag, attributes: { name: 'not blacklisted' } }) | ||
405 | |||
406 | const body = await command.list({ type: VideoBlacklistType.AUTO_BEFORE_PUBLISHED }) | ||
407 | expect(body.total).to.equal(3) | ||
408 | }) | ||
409 | }) | ||
410 | |||
411 | after(async function () { | ||
412 | await cleanupTests(servers) | ||
413 | }) | ||
414 | }) | ||