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