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