]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/tests/api/moderation/abuses.ts
Introduce redundancy command
[github/Chocobozzz/PeerTube.git] / server / tests / api / moderation / abuses.ts
1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2
3 import 'mocha'
4 import * as chai from 'chai'
5 import {
6 AbusesCommand,
7 addAccountToServerBlocklist,
8 addServerToServerBlocklist,
9 addVideoCommentThread,
10 cleanupTests,
11 createUser,
12 deleteVideoComment,
13 doubleFollow,
14 flushAndRunMultipleServers,
15 generateUserAccessToken,
16 getAccount,
17 getVideoCommentThreads,
18 getVideoIdFromUUID,
19 getVideosList,
20 removeAccountFromServerBlocklist,
21 removeServerFromServerBlocklist,
22 removeUser,
23 removeVideo,
24 ServerInfo,
25 setAccessTokensToServers,
26 uploadVideo,
27 uploadVideoAndGetId,
28 userLogin,
29 waitJobs
30 } from '@shared/extra-utils'
31 import { AbuseMessage, AbusePredefinedReasonsString, AbuseState, Account, AdminAbuse, UserAbuse, VideoComment } from '@shared/models'
32
33 const expect = chai.expect
34
35 describe('Test abuses', function () {
36 let servers: ServerInfo[] = []
37 let abuseServer1: AdminAbuse
38 let abuseServer2: AdminAbuse
39 let commands: AbusesCommand[]
40
41 before(async function () {
42 this.timeout(50000)
43
44 // Run servers
45 servers = await flushAndRunMultipleServers(2)
46
47 // Get the access tokens
48 await setAccessTokensToServers(servers)
49
50 // Server 1 and server 2 follow each other
51 await doubleFollow(servers[0], servers[1])
52
53 commands = servers.map(s => s.abusesCommand)
54 })
55
56 describe('Video abuses', function () {
57
58 before(async function () {
59 this.timeout(50000)
60
61 // Upload some videos on each servers
62 const video1Attributes = {
63 name: 'my super name for server 1',
64 description: 'my super description for server 1'
65 }
66 await uploadVideo(servers[0].url, servers[0].accessToken, video1Attributes)
67
68 const video2Attributes = {
69 name: 'my super name for server 2',
70 description: 'my super description for server 2'
71 }
72 await uploadVideo(servers[1].url, servers[1].accessToken, video2Attributes)
73
74 // Wait videos propagation, server 2 has transcoding enabled
75 await waitJobs(servers)
76
77 const res = await getVideosList(servers[0].url)
78 const videos = res.body.data
79
80 expect(videos.length).to.equal(2)
81
82 servers[0].video = videos.find(video => video.name === 'my super name for server 1')
83 servers[1].video = videos.find(video => video.name === 'my super name for server 2')
84 })
85
86 it('Should not have abuses', async function () {
87 const body = await commands[0].getAdminList()
88
89 expect(body.total).to.equal(0)
90 expect(body.data).to.be.an('array')
91 expect(body.data.length).to.equal(0)
92 })
93
94 it('Should report abuse on a local video', async function () {
95 this.timeout(15000)
96
97 const reason = 'my super bad reason'
98 await commands[0].report({ videoId: servers[0].video.id, reason })
99
100 // We wait requests propagation, even if the server 1 is not supposed to make a request to server 2
101 await waitJobs(servers)
102 })
103
104 it('Should have 1 video abuses on server 1 and 0 on server 2', async function () {
105 {
106 const body = await commands[0].getAdminList()
107
108 expect(body.total).to.equal(1)
109 expect(body.data).to.be.an('array')
110 expect(body.data.length).to.equal(1)
111
112 const abuse = body.data[0]
113 expect(abuse.reason).to.equal('my super bad reason')
114
115 expect(abuse.reporterAccount.name).to.equal('root')
116 expect(abuse.reporterAccount.host).to.equal(servers[0].host)
117
118 expect(abuse.video.id).to.equal(servers[0].video.id)
119 expect(abuse.video.channel).to.exist
120
121 expect(abuse.comment).to.be.null
122
123 expect(abuse.flaggedAccount.name).to.equal('root')
124 expect(abuse.flaggedAccount.host).to.equal(servers[0].host)
125
126 expect(abuse.video.countReports).to.equal(1)
127 expect(abuse.video.nthReport).to.equal(1)
128
129 expect(abuse.countReportsForReporter).to.equal(1)
130 expect(abuse.countReportsForReportee).to.equal(1)
131 }
132
133 {
134 const body = await commands[1].getAdminList()
135 expect(body.total).to.equal(0)
136 expect(body.data).to.be.an('array')
137 expect(body.data.length).to.equal(0)
138 }
139 })
140
141 it('Should report abuse on a remote video', async function () {
142 this.timeout(10000)
143
144 const reason = 'my super bad reason 2'
145 const videoId = await getVideoIdFromUUID(servers[0].url, servers[1].video.uuid)
146 await commands[0].report({ videoId, reason })
147
148 // We wait requests propagation
149 await waitJobs(servers)
150 })
151
152 it('Should have 2 video abuses on server 1 and 1 on server 2', async function () {
153 {
154 const body = await commands[0].getAdminList()
155
156 expect(body.total).to.equal(2)
157 expect(body.data.length).to.equal(2)
158
159 const abuse1 = body.data[0]
160 expect(abuse1.reason).to.equal('my super bad reason')
161 expect(abuse1.reporterAccount.name).to.equal('root')
162 expect(abuse1.reporterAccount.host).to.equal(servers[0].host)
163
164 expect(abuse1.video.id).to.equal(servers[0].video.id)
165 expect(abuse1.video.countReports).to.equal(1)
166 expect(abuse1.video.nthReport).to.equal(1)
167
168 expect(abuse1.comment).to.be.null
169
170 expect(abuse1.flaggedAccount.name).to.equal('root')
171 expect(abuse1.flaggedAccount.host).to.equal(servers[0].host)
172
173 expect(abuse1.state.id).to.equal(AbuseState.PENDING)
174 expect(abuse1.state.label).to.equal('Pending')
175 expect(abuse1.moderationComment).to.be.null
176
177 const abuse2 = body.data[1]
178 expect(abuse2.reason).to.equal('my super bad reason 2')
179
180 expect(abuse2.reporterAccount.name).to.equal('root')
181 expect(abuse2.reporterAccount.host).to.equal(servers[0].host)
182
183 expect(abuse2.video.id).to.equal(servers[1].video.id)
184
185 expect(abuse2.comment).to.be.null
186
187 expect(abuse2.flaggedAccount.name).to.equal('root')
188 expect(abuse2.flaggedAccount.host).to.equal(servers[1].host)
189
190 expect(abuse2.state.id).to.equal(AbuseState.PENDING)
191 expect(abuse2.state.label).to.equal('Pending')
192 expect(abuse2.moderationComment).to.be.null
193 }
194
195 {
196 const body = await commands[1].getAdminList()
197 expect(body.total).to.equal(1)
198 expect(body.data.length).to.equal(1)
199
200 abuseServer2 = body.data[0]
201 expect(abuseServer2.reason).to.equal('my super bad reason 2')
202 expect(abuseServer2.reporterAccount.name).to.equal('root')
203 expect(abuseServer2.reporterAccount.host).to.equal(servers[0].host)
204
205 expect(abuseServer2.flaggedAccount.name).to.equal('root')
206 expect(abuseServer2.flaggedAccount.host).to.equal(servers[1].host)
207
208 expect(abuseServer2.state.id).to.equal(AbuseState.PENDING)
209 expect(abuseServer2.state.label).to.equal('Pending')
210 expect(abuseServer2.moderationComment).to.be.null
211 }
212 })
213
214 it('Should hide video abuses from blocked accounts', async function () {
215 this.timeout(10000)
216
217 {
218 const videoId = await getVideoIdFromUUID(servers[1].url, servers[0].video.uuid)
219 await commands[1].report({ videoId, reason: 'will mute this' })
220 await waitJobs(servers)
221
222 const body = await commands[0].getAdminList()
223 expect(body.total).to.equal(3)
224 }
225
226 const accountToBlock = 'root@' + servers[1].host
227
228 {
229 await addAccountToServerBlocklist(servers[0].url, servers[0].accessToken, accountToBlock)
230
231 const body = await commands[0].getAdminList()
232 expect(body.total).to.equal(2)
233
234 const abuse = body.data.find(a => a.reason === 'will mute this')
235 expect(abuse).to.be.undefined
236 }
237
238 {
239 await removeAccountFromServerBlocklist(servers[0].url, servers[0].accessToken, accountToBlock)
240
241 const body = await commands[0].getAdminList()
242 expect(body.total).to.equal(3)
243 }
244 })
245
246 it('Should hide video abuses from blocked servers', async function () {
247 const serverToBlock = servers[1].host
248
249 {
250 await addServerToServerBlocklist(servers[0].url, servers[0].accessToken, servers[1].host)
251
252 const body = await commands[0].getAdminList()
253 expect(body.total).to.equal(2)
254
255 const abuse = body.data.find(a => a.reason === 'will mute this')
256 expect(abuse).to.be.undefined
257 }
258
259 {
260 await removeServerFromServerBlocklist(servers[0].url, servers[0].accessToken, serverToBlock)
261
262 const body = await commands[0].getAdminList()
263 expect(body.total).to.equal(3)
264 }
265 })
266
267 it('Should keep the video abuse when deleting the video', async function () {
268 this.timeout(10000)
269
270 await removeVideo(servers[1].url, servers[1].accessToken, abuseServer2.video.uuid)
271
272 await waitJobs(servers)
273
274 const body = await commands[1].getAdminList()
275 expect(body.total).to.equal(2, "wrong number of videos returned")
276 expect(body.data).to.have.lengthOf(2, "wrong number of videos returned")
277
278 const abuse = body.data[0]
279 expect(abuse.id).to.equal(abuseServer2.id, "wrong origin server id for first video")
280 expect(abuse.video.id).to.equal(abuseServer2.video.id, "wrong video id")
281 expect(abuse.video.channel).to.exist
282 expect(abuse.video.deleted).to.be.true
283 })
284
285 it('Should include counts of reports from reporter and reportee', async function () {
286 this.timeout(10000)
287
288 // register a second user to have two reporters/reportees
289 const user = { username: 'user2', password: 'password' }
290 await createUser({ url: servers[0].url, accessToken: servers[0].accessToken, ...user })
291 const userAccessToken = await userLogin(servers[0], user)
292
293 // upload a third video via this user
294 const video3Attributes = {
295 name: 'my second super name for server 1',
296 description: 'my second super description for server 1'
297 }
298 const resUpload = await uploadVideo(servers[0].url, userAccessToken, video3Attributes)
299 const video3Id = resUpload.body.video.id
300
301 // resume with the test
302 const reason3 = 'my super bad reason 3'
303 await commands[0].report({ videoId: video3Id, reason: reason3 })
304
305 const reason4 = 'my super bad reason 4'
306 await commands[0].report({ token: userAccessToken, videoId: servers[0].video.id, reason: reason4 })
307
308 {
309 const body = await commands[0].getAdminList()
310 const abuses = body.data
311
312 const abuseVideo3 = body.data.find(a => a.video.id === video3Id)
313 expect(abuseVideo3).to.not.be.undefined
314 expect(abuseVideo3.video.countReports).to.equal(1, "wrong reports count for video 3")
315 expect(abuseVideo3.video.nthReport).to.equal(1, "wrong report position in report list for video 3")
316 expect(abuseVideo3.countReportsForReportee).to.equal(1, "wrong reports count for reporter on video 3 abuse")
317 expect(abuseVideo3.countReportsForReporter).to.equal(3, "wrong reports count for reportee on video 3 abuse")
318
319 const abuseServer1 = abuses.find(a => a.video.id === servers[0].video.id)
320 expect(abuseServer1.countReportsForReportee).to.equal(3, "wrong reports count for reporter on video 1 abuse")
321 }
322 })
323
324 it('Should list predefined reasons as well as timestamps for the reported video', async function () {
325 this.timeout(10000)
326
327 const reason5 = 'my super bad reason 5'
328 const predefinedReasons5: AbusePredefinedReasonsString[] = [ 'violentOrRepulsive', 'captions' ]
329 const createRes = await commands[0].report({
330 videoId: servers[0].video.id,
331 reason: reason5,
332 predefinedReasons: predefinedReasons5,
333 startAt: 1,
334 endAt: 5
335 })
336
337 const body = await commands[0].getAdminList()
338
339 {
340 const abuse = body.data.find(a => a.id === createRes.abuse.id)
341 expect(abuse.reason).to.equals(reason5)
342 expect(abuse.predefinedReasons).to.deep.equals(predefinedReasons5, "predefined reasons do not match the one reported")
343 expect(abuse.video.startAt).to.equal(1, "starting timestamp doesn't match the one reported")
344 expect(abuse.video.endAt).to.equal(5, "ending timestamp doesn't match the one reported")
345 }
346 })
347
348 it('Should delete the video abuse', async function () {
349 this.timeout(10000)
350
351 await commands[1].delete({ abuseId: abuseServer2.id })
352
353 await waitJobs(servers)
354
355 {
356 const body = await commands[1].getAdminList()
357 expect(body.total).to.equal(1)
358 expect(body.data.length).to.equal(1)
359 expect(body.data[0].id).to.not.equal(abuseServer2.id)
360 }
361
362 {
363 const body = await commands[0].getAdminList()
364 expect(body.total).to.equal(6)
365 }
366 })
367
368 it('Should list and filter video abuses', async function () {
369 this.timeout(10000)
370
371 async function list (query: Parameters<AbusesCommand['getAdminList']>[0]) {
372 const body = await commands[0].getAdminList(query)
373
374 return body.data
375 }
376
377 expect(await list({ id: 56 })).to.have.lengthOf(0)
378 expect(await list({ id: 1 })).to.have.lengthOf(1)
379
380 expect(await list({ search: 'my super name for server 1' })).to.have.lengthOf(4)
381 expect(await list({ search: 'aaaaaaaaaaaaaaaaaaaaaaaaaa' })).to.have.lengthOf(0)
382
383 expect(await list({ searchVideo: 'my second super name for server 1' })).to.have.lengthOf(1)
384
385 expect(await list({ searchVideoChannel: 'root' })).to.have.lengthOf(4)
386 expect(await list({ searchVideoChannel: 'aaaa' })).to.have.lengthOf(0)
387
388 expect(await list({ searchReporter: 'user2' })).to.have.lengthOf(1)
389 expect(await list({ searchReporter: 'root' })).to.have.lengthOf(5)
390
391 expect(await list({ searchReportee: 'root' })).to.have.lengthOf(5)
392 expect(await list({ searchReportee: 'aaaa' })).to.have.lengthOf(0)
393
394 expect(await list({ videoIs: 'deleted' })).to.have.lengthOf(1)
395 expect(await list({ videoIs: 'blacklisted' })).to.have.lengthOf(0)
396
397 expect(await list({ state: AbuseState.ACCEPTED })).to.have.lengthOf(0)
398 expect(await list({ state: AbuseState.PENDING })).to.have.lengthOf(6)
399
400 expect(await list({ predefinedReason: 'violentOrRepulsive' })).to.have.lengthOf(1)
401 expect(await list({ predefinedReason: 'serverRules' })).to.have.lengthOf(0)
402 })
403 })
404
405 describe('Comment abuses', function () {
406
407 async function getComment (url: string, videoIdArg: number | string) {
408 const videoId = typeof videoIdArg === 'string'
409 ? await getVideoIdFromUUID(url, videoIdArg)
410 : videoIdArg
411
412 const res = await getVideoCommentThreads(url, videoId, 0, 5)
413
414 return res.body.data[0] as VideoComment
415 }
416
417 before(async function () {
418 this.timeout(50000)
419
420 servers[0].video = await uploadVideoAndGetId({ server: servers[0], videoName: 'server 1' })
421 servers[1].video = await uploadVideoAndGetId({ server: servers[1], videoName: 'server 2' })
422
423 await addVideoCommentThread(servers[0].url, servers[0].accessToken, servers[0].video.id, 'comment server 1')
424 await addVideoCommentThread(servers[1].url, servers[1].accessToken, servers[1].video.id, 'comment server 2')
425
426 await waitJobs(servers)
427 })
428
429 it('Should report abuse on a comment', async function () {
430 this.timeout(15000)
431
432 const comment = await getComment(servers[0].url, servers[0].video.id)
433
434 const reason = 'it is a bad comment'
435 await commands[0].report({ commentId: comment.id, reason })
436
437 await waitJobs(servers)
438 })
439
440 it('Should have 1 comment abuse on server 1 and 0 on server 2', async function () {
441 {
442 const comment = await getComment(servers[0].url, servers[0].video.id)
443 const body = await commands[0].getAdminList({ filter: 'comment' })
444
445 expect(body.total).to.equal(1)
446 expect(body.data).to.have.lengthOf(1)
447
448 const abuse = body.data[0]
449 expect(abuse.reason).to.equal('it is a bad comment')
450
451 expect(abuse.reporterAccount.name).to.equal('root')
452 expect(abuse.reporterAccount.host).to.equal(servers[0].host)
453
454 expect(abuse.video).to.be.null
455
456 expect(abuse.comment.deleted).to.be.false
457 expect(abuse.comment.id).to.equal(comment.id)
458 expect(abuse.comment.text).to.equal(comment.text)
459 expect(abuse.comment.video.name).to.equal('server 1')
460 expect(abuse.comment.video.id).to.equal(servers[0].video.id)
461 expect(abuse.comment.video.uuid).to.equal(servers[0].video.uuid)
462
463 expect(abuse.countReportsForReporter).to.equal(5)
464 expect(abuse.countReportsForReportee).to.equal(5)
465 }
466
467 {
468 const body = await commands[1].getAdminList({ filter: 'comment' })
469 expect(body.total).to.equal(0)
470 expect(body.data.length).to.equal(0)
471 }
472 })
473
474 it('Should report abuse on a remote comment', async function () {
475 this.timeout(10000)
476
477 const comment = await getComment(servers[0].url, servers[1].video.uuid)
478
479 const reason = 'it is a really bad comment'
480 await commands[0].report({ commentId: comment.id, reason })
481
482 await waitJobs(servers)
483 })
484
485 it('Should have 2 comment abuses on server 1 and 1 on server 2', async function () {
486 const commentServer2 = await getComment(servers[0].url, servers[1].video.id)
487
488 {
489 const body = await commands[0].getAdminList({ filter: 'comment' })
490 expect(body.total).to.equal(2)
491 expect(body.data.length).to.equal(2)
492
493 const abuse = body.data[0]
494 expect(abuse.reason).to.equal('it is a bad comment')
495 expect(abuse.countReportsForReporter).to.equal(6)
496 expect(abuse.countReportsForReportee).to.equal(5)
497
498 const abuse2 = body.data[1]
499
500 expect(abuse2.reason).to.equal('it is a really bad comment')
501
502 expect(abuse2.reporterAccount.name).to.equal('root')
503 expect(abuse2.reporterAccount.host).to.equal(servers[0].host)
504
505 expect(abuse2.video).to.be.null
506
507 expect(abuse2.comment.deleted).to.be.false
508 expect(abuse2.comment.id).to.equal(commentServer2.id)
509 expect(abuse2.comment.text).to.equal(commentServer2.text)
510 expect(abuse2.comment.video.name).to.equal('server 2')
511 expect(abuse2.comment.video.uuid).to.equal(servers[1].video.uuid)
512
513 expect(abuse2.state.id).to.equal(AbuseState.PENDING)
514 expect(abuse2.state.label).to.equal('Pending')
515
516 expect(abuse2.moderationComment).to.be.null
517
518 expect(abuse2.countReportsForReporter).to.equal(6)
519 expect(abuse2.countReportsForReportee).to.equal(2)
520 }
521
522 {
523 const body = await commands[1].getAdminList({ filter: 'comment' })
524 expect(body.total).to.equal(1)
525 expect(body.data.length).to.equal(1)
526
527 abuseServer2 = body.data[0]
528 expect(abuseServer2.reason).to.equal('it is a really bad comment')
529 expect(abuseServer2.reporterAccount.name).to.equal('root')
530 expect(abuseServer2.reporterAccount.host).to.equal(servers[0].host)
531
532 expect(abuseServer2.state.id).to.equal(AbuseState.PENDING)
533 expect(abuseServer2.state.label).to.equal('Pending')
534
535 expect(abuseServer2.moderationComment).to.be.null
536
537 expect(abuseServer2.countReportsForReporter).to.equal(1)
538 expect(abuseServer2.countReportsForReportee).to.equal(1)
539 }
540 })
541
542 it('Should keep the comment abuse when deleting the comment', async function () {
543 this.timeout(10000)
544
545 const commentServer2 = await getComment(servers[0].url, servers[1].video.id)
546
547 await deleteVideoComment(servers[0].url, servers[0].accessToken, servers[1].video.uuid, commentServer2.id)
548
549 await waitJobs(servers)
550
551 const body = await commands[0].getAdminList({ filter: 'comment' })
552 expect(body.total).to.equal(2)
553 expect(body.data).to.have.lengthOf(2)
554
555 const abuse = body.data.find(a => a.comment?.id === commentServer2.id)
556 expect(abuse).to.not.be.undefined
557
558 expect(abuse.comment.text).to.be.empty
559 expect(abuse.comment.video.name).to.equal('server 2')
560 expect(abuse.comment.deleted).to.be.true
561 })
562
563 it('Should delete the comment abuse', async function () {
564 this.timeout(10000)
565
566 await commands[1].delete({ abuseId: abuseServer2.id })
567
568 await waitJobs(servers)
569
570 {
571 const body = await commands[1].getAdminList({ filter: 'comment' })
572 expect(body.total).to.equal(0)
573 expect(body.data.length).to.equal(0)
574 }
575
576 {
577 const body = await commands[0].getAdminList({ filter: 'comment' })
578 expect(body.total).to.equal(2)
579 }
580 })
581
582 it('Should list and filter video abuses', async function () {
583 {
584 const body = await commands[0].getAdminList({ filter: 'comment', searchReportee: 'foo' })
585 expect(body.total).to.equal(0)
586 }
587
588 {
589 const body = await commands[0].getAdminList({ filter: 'comment', searchReportee: 'ot' })
590 expect(body.total).to.equal(2)
591 }
592
593 {
594 const body = await commands[0].getAdminList({ filter: 'comment', start: 1, count: 1, sort: 'createdAt' })
595 expect(body.data).to.have.lengthOf(1)
596 expect(body.data[0].comment.text).to.be.empty
597 }
598
599 {
600 const body = await commands[0].getAdminList({ filter: 'comment', start: 1, count: 1, sort: '-createdAt' })
601 expect(body.data).to.have.lengthOf(1)
602 expect(body.data[0].comment.text).to.equal('comment server 1')
603 }
604 })
605 })
606
607 describe('Account abuses', function () {
608
609 async function getAccountFromServer (url: string, name: string, server: ServerInfo) {
610 const res = await getAccount(url, name + '@' + server.host)
611
612 return res.body as Account
613 }
614
615 before(async function () {
616 this.timeout(50000)
617
618 await createUser({ url: servers[0].url, accessToken: servers[0].accessToken, username: 'user_1', password: 'donald' })
619
620 const token = await generateUserAccessToken(servers[1], 'user_2')
621 await uploadVideo(servers[1].url, token, { name: 'super video' })
622
623 await waitJobs(servers)
624 })
625
626 it('Should report abuse on an account', async function () {
627 this.timeout(15000)
628
629 const account = await getAccountFromServer(servers[0].url, 'user_1', servers[0])
630
631 const reason = 'it is a bad account'
632 await commands[0].report({ accountId: account.id, reason })
633
634 await waitJobs(servers)
635 })
636
637 it('Should have 1 account abuse on server 1 and 0 on server 2', async function () {
638 {
639 const body = await commands[0].getAdminList({ filter: 'account' })
640
641 expect(body.total).to.equal(1)
642 expect(body.data).to.have.lengthOf(1)
643
644 const abuse = body.data[0]
645 expect(abuse.reason).to.equal('it is a bad account')
646
647 expect(abuse.reporterAccount.name).to.equal('root')
648 expect(abuse.reporterAccount.host).to.equal(servers[0].host)
649
650 expect(abuse.video).to.be.null
651 expect(abuse.comment).to.be.null
652
653 expect(abuse.flaggedAccount.name).to.equal('user_1')
654 expect(abuse.flaggedAccount.host).to.equal(servers[0].host)
655 }
656
657 {
658 const body = await commands[1].getAdminList({ filter: 'comment' })
659 expect(body.total).to.equal(0)
660 expect(body.data.length).to.equal(0)
661 }
662 })
663
664 it('Should report abuse on a remote account', async function () {
665 this.timeout(10000)
666
667 const account = await getAccountFromServer(servers[0].url, 'user_2', servers[1])
668
669 const reason = 'it is a really bad account'
670 await commands[0].report({ accountId: account.id, reason })
671
672 await waitJobs(servers)
673 })
674
675 it('Should have 2 comment abuses on server 1 and 1 on server 2', async function () {
676 {
677 const body = await commands[0].getAdminList({ filter: 'account' })
678 expect(body.total).to.equal(2)
679 expect(body.data.length).to.equal(2)
680
681 const abuse: AdminAbuse = body.data[0]
682 expect(abuse.reason).to.equal('it is a bad account')
683
684 const abuse2: AdminAbuse = body.data[1]
685 expect(abuse2.reason).to.equal('it is a really bad account')
686
687 expect(abuse2.reporterAccount.name).to.equal('root')
688 expect(abuse2.reporterAccount.host).to.equal(servers[0].host)
689
690 expect(abuse2.video).to.be.null
691 expect(abuse2.comment).to.be.null
692
693 expect(abuse2.state.id).to.equal(AbuseState.PENDING)
694 expect(abuse2.state.label).to.equal('Pending')
695
696 expect(abuse2.moderationComment).to.be.null
697 }
698
699 {
700 const body = await commands[1].getAdminList({ filter: 'account' })
701 expect(body.total).to.equal(1)
702 expect(body.data.length).to.equal(1)
703
704 abuseServer2 = body.data[0]
705
706 expect(abuseServer2.reason).to.equal('it is a really bad account')
707
708 expect(abuseServer2.reporterAccount.name).to.equal('root')
709 expect(abuseServer2.reporterAccount.host).to.equal(servers[0].host)
710
711 expect(abuseServer2.state.id).to.equal(AbuseState.PENDING)
712 expect(abuseServer2.state.label).to.equal('Pending')
713
714 expect(abuseServer2.moderationComment).to.be.null
715 }
716 })
717
718 it('Should keep the account abuse when deleting the account', async function () {
719 this.timeout(10000)
720
721 const account = await getAccountFromServer(servers[1].url, 'user_2', servers[1])
722 await removeUser(servers[1].url, account.userId, servers[1].accessToken)
723
724 await waitJobs(servers)
725
726 const body = await commands[0].getAdminList({ filter: 'account' })
727 expect(body.total).to.equal(2)
728 expect(body.data).to.have.lengthOf(2)
729
730 const abuse = body.data.find(a => a.reason === 'it is a really bad account')
731 expect(abuse).to.not.be.undefined
732 })
733
734 it('Should delete the account abuse', async function () {
735 this.timeout(10000)
736
737 await commands[1].delete({ abuseId: abuseServer2.id })
738
739 await waitJobs(servers)
740
741 {
742 const body = await commands[1].getAdminList({ filter: 'account' })
743 expect(body.total).to.equal(0)
744 expect(body.data.length).to.equal(0)
745 }
746
747 {
748 const body = await commands[0].getAdminList({ filter: 'account' })
749 expect(body.total).to.equal(2)
750
751 abuseServer1 = body.data[0]
752 }
753 })
754 })
755
756 describe('Common actions on abuses', function () {
757
758 it('Should update the state of an abuse', async function () {
759 await commands[0].update({ abuseId: abuseServer1.id, body: { state: AbuseState.REJECTED } })
760
761 const body = await commands[0].getAdminList({ id: abuseServer1.id })
762 expect(body.data[0].state.id).to.equal(AbuseState.REJECTED)
763 })
764
765 it('Should add a moderation comment', async function () {
766 await commands[0].update({ abuseId: abuseServer1.id, body: { state: AbuseState.ACCEPTED, moderationComment: 'Valid' } })
767
768 const body = await commands[0].getAdminList({ id: abuseServer1.id })
769 expect(body.data[0].state.id).to.equal(AbuseState.ACCEPTED)
770 expect(body.data[0].moderationComment).to.equal('Valid')
771 })
772 })
773
774 describe('My abuses', async function () {
775 let abuseId1: number
776 let userAccessToken: string
777
778 before(async function () {
779 userAccessToken = await generateUserAccessToken(servers[0], 'user_42')
780
781 await commands[0].report({ token: userAccessToken, videoId: servers[0].video.id, reason: 'user reason 1' })
782
783 const videoId = await getVideoIdFromUUID(servers[0].url, servers[1].video.uuid)
784 await commands[0].report({ token: userAccessToken, videoId, reason: 'user reason 2' })
785 })
786
787 it('Should correctly list my abuses', async function () {
788 {
789 const body = await commands[0].getUserList({ token: userAccessToken, start: 0, count: 5, sort: 'createdAt' })
790 expect(body.total).to.equal(2)
791
792 const abuses = body.data
793 expect(abuses[0].reason).to.equal('user reason 1')
794 expect(abuses[1].reason).to.equal('user reason 2')
795
796 abuseId1 = abuses[0].id
797 }
798
799 {
800 const body = await commands[0].getUserList({ token: userAccessToken, start: 1, count: 1, sort: 'createdAt' })
801 expect(body.total).to.equal(2)
802
803 const abuses: UserAbuse[] = body.data
804 expect(abuses[0].reason).to.equal('user reason 2')
805 }
806
807 {
808 const body = await commands[0].getUserList({ token: userAccessToken, start: 1, count: 1, sort: '-createdAt' })
809 expect(body.total).to.equal(2)
810
811 const abuses: UserAbuse[] = body.data
812 expect(abuses[0].reason).to.equal('user reason 1')
813 }
814 })
815
816 it('Should correctly filter my abuses by id', async function () {
817 const body = await commands[0].getUserList({ token: userAccessToken, id: abuseId1 })
818 expect(body.total).to.equal(1)
819
820 const abuses: UserAbuse[] = body.data
821 expect(abuses[0].reason).to.equal('user reason 1')
822 })
823
824 it('Should correctly filter my abuses by search', async function () {
825 const body = await commands[0].getUserList({ token: userAccessToken, search: 'server 2' })
826 expect(body.total).to.equal(1)
827
828 const abuses: UserAbuse[] = body.data
829 expect(abuses[0].reason).to.equal('user reason 2')
830 })
831
832 it('Should correctly filter my abuses by state', async function () {
833 await commands[0].update({ abuseId: abuseId1, body: { state: AbuseState.REJECTED } })
834
835 const body = await commands[0].getUserList({ token: userAccessToken, state: AbuseState.REJECTED })
836 expect(body.total).to.equal(1)
837
838 const abuses: UserAbuse[] = body.data
839 expect(abuses[0].reason).to.equal('user reason 1')
840 })
841 })
842
843 describe('Abuse messages', async function () {
844 let abuseId: number
845 let userToken: string
846 let abuseMessageUserId: number
847 let abuseMessageModerationId: number
848
849 before(async function () {
850 userToken = await generateUserAccessToken(servers[0], 'user_43')
851
852 const body = await commands[0].report({ token: userToken, videoId: servers[0].video.id, reason: 'user 43 reason 1' })
853 abuseId = body.abuse.id
854 })
855
856 it('Should create some messages on the abuse', async function () {
857 await commands[0].addMessage({ token: userToken, abuseId, message: 'message 1' })
858 await commands[0].addMessage({ abuseId, message: 'message 2' })
859 await commands[0].addMessage({ abuseId, message: 'message 3' })
860 await commands[0].addMessage({ token: userToken, abuseId, message: 'message 4' })
861 })
862
863 it('Should have the correct messages count when listing abuses', async function () {
864 const results = await Promise.all([
865 commands[0].getAdminList({ start: 0, count: 50 }),
866 commands[0].getUserList({ token: userToken, start: 0, count: 50 })
867 ])
868
869 for (const body of results) {
870 const abuses = body.data
871 const abuse = abuses.find(a => a.id === abuseId)
872 expect(abuse.countMessages).to.equal(4)
873 }
874 })
875
876 it('Should correctly list messages of this abuse', async function () {
877 const results = await Promise.all([
878 commands[0].listMessages({ abuseId }),
879 commands[0].listMessages({ token: userToken, abuseId })
880 ])
881
882 for (const body of results) {
883 expect(body.total).to.equal(4)
884
885 const abuseMessages: AbuseMessage[] = body.data
886
887 expect(abuseMessages[0].message).to.equal('message 1')
888 expect(abuseMessages[0].byModerator).to.be.false
889 expect(abuseMessages[0].account.name).to.equal('user_43')
890
891 abuseMessageUserId = abuseMessages[0].id
892
893 expect(abuseMessages[1].message).to.equal('message 2')
894 expect(abuseMessages[1].byModerator).to.be.true
895 expect(abuseMessages[1].account.name).to.equal('root')
896
897 expect(abuseMessages[2].message).to.equal('message 3')
898 expect(abuseMessages[2].byModerator).to.be.true
899 expect(abuseMessages[2].account.name).to.equal('root')
900 abuseMessageModerationId = abuseMessages[2].id
901
902 expect(abuseMessages[3].message).to.equal('message 4')
903 expect(abuseMessages[3].byModerator).to.be.false
904 expect(abuseMessages[3].account.name).to.equal('user_43')
905 }
906 })
907
908 it('Should delete messages', async function () {
909 await commands[0].deleteMessage({ abuseId, messageId: abuseMessageModerationId })
910 await commands[0].deleteMessage({ token: userToken, abuseId, messageId: abuseMessageUserId })
911
912 const results = await Promise.all([
913 commands[0].listMessages({ abuseId }),
914 commands[0].listMessages({ token: userToken, abuseId })
915 ])
916
917 for (const body of results) {
918 expect(body.total).to.equal(2)
919
920 const abuseMessages: AbuseMessage[] = body.data
921 expect(abuseMessages[0].message).to.equal('message 2')
922 expect(abuseMessages[1].message).to.equal('message 4')
923 }
924 })
925 })
926
927 after(async function () {
928 await cleanupTests(servers)
929 })
930 })