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