1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
4 import * as chai from 'chai'
8 AbusePredefinedReasonsString,
14 } from '@shared/models'
17 addVideoCommentThread,
23 flushAndRunMultipleServers,
24 generateUserAccessToken,
28 getVideoCommentThreads,
37 setAccessTokensToServers,
42 } from '../../../../shared/extra-utils/index'
43 import { doubleFollow } from '../../../../shared/extra-utils/server/follows'
44 import { waitJobs } from '../../../../shared/extra-utils/server/jobs'
46 addAccountToServerBlocklist,
47 addServerToServerBlocklist,
48 removeAccountFromServerBlocklist,
49 removeServerFromServerBlocklist
50 } from '../../../../shared/extra-utils/users/blocklist'
52 const expect = chai.expect
54 describe('Test abuses', function () {
55 let servers: ServerInfo[] = []
56 let abuseServer1: AdminAbuse
57 let abuseServer2: AdminAbuse
59 before(async function () {
63 servers = await flushAndRunMultipleServers(2)
65 // Get the access tokens
66 await setAccessTokensToServers(servers)
68 // Server 1 and server 2 follow each other
69 await doubleFollow(servers[0], servers[1])
72 describe('Video abuses', function () {
74 before(async function () {
77 // Upload some videos on each servers
78 const video1Attributes = {
79 name: 'my super name for server 1',
80 description: 'my super description for server 1'
82 await uploadVideo(servers[0].url, servers[0].accessToken, video1Attributes)
84 const video2Attributes = {
85 name: 'my super name for server 2',
86 description: 'my super description for server 2'
88 await uploadVideo(servers[1].url, servers[1].accessToken, video2Attributes)
90 // Wait videos propagation, server 2 has transcoding enabled
91 await waitJobs(servers)
93 const res = await getVideosList(servers[0].url)
94 const videos = res.body.data
96 expect(videos.length).to.equal(2)
98 servers[0].video = videos.find(video => video.name === 'my super name for server 1')
99 servers[1].video = videos.find(video => video.name === 'my super name for server 2')
102 it('Should not have abuses', async function () {
103 const res = await getAdminAbusesList({ url: servers[0].url, token: servers[0].accessToken })
105 expect(res.body.total).to.equal(0)
106 expect(res.body.data).to.be.an('array')
107 expect(res.body.data.length).to.equal(0)
110 it('Should report abuse on a local video', async function () {
113 const reason = 'my super bad reason'
114 await reportAbuse({ url: servers[0].url, token: servers[0].accessToken, videoId: servers[0].video.id, reason })
116 // We wait requests propagation, even if the server 1 is not supposed to make a request to server 2
117 await waitJobs(servers)
120 it('Should have 1 video abuses on server 1 and 0 on server 2', async function () {
121 const res1 = await getAdminAbusesList({ url: servers[0].url, token: servers[0].accessToken })
123 expect(res1.body.total).to.equal(1)
124 expect(res1.body.data).to.be.an('array')
125 expect(res1.body.data.length).to.equal(1)
127 const abuse: AdminAbuse = res1.body.data[0]
128 expect(abuse.reason).to.equal('my super bad reason')
130 expect(abuse.reporterAccount.name).to.equal('root')
131 expect(abuse.reporterAccount.host).to.equal(servers[0].host)
133 expect(abuse.video.id).to.equal(servers[0].video.id)
134 expect(abuse.video.channel).to.exist
136 expect(abuse.comment).to.be.null
138 expect(abuse.flaggedAccount.name).to.equal('root')
139 expect(abuse.flaggedAccount.host).to.equal(servers[0].host)
141 expect(abuse.video.countReports).to.equal(1)
142 expect(abuse.video.nthReport).to.equal(1)
144 expect(abuse.countReportsForReporter).to.equal(1)
145 expect(abuse.countReportsForReportee).to.equal(1)
147 const res2 = await getAdminAbusesList({ url: servers[1].url, token: servers[1].accessToken })
148 expect(res2.body.total).to.equal(0)
149 expect(res2.body.data).to.be.an('array')
150 expect(res2.body.data.length).to.equal(0)
153 it('Should report abuse on a remote video', async function () {
156 const reason = 'my super bad reason 2'
157 const videoId = await getVideoIdFromUUID(servers[0].url, servers[1].video.uuid)
158 await reportAbuse({ url: servers[0].url, token: servers[0].accessToken, videoId, reason })
160 // We wait requests propagation
161 await waitJobs(servers)
164 it('Should have 2 video abuses on server 1 and 1 on server 2', async function () {
165 const res1 = await getAdminAbusesList({ url: servers[0].url, token: servers[0].accessToken })
167 expect(res1.body.total).to.equal(2)
168 expect(res1.body.data.length).to.equal(2)
170 const abuse1: AdminAbuse = res1.body.data[0]
171 expect(abuse1.reason).to.equal('my super bad reason')
172 expect(abuse1.reporterAccount.name).to.equal('root')
173 expect(abuse1.reporterAccount.host).to.equal(servers[0].host)
175 expect(abuse1.video.id).to.equal(servers[0].video.id)
176 expect(abuse1.video.countReports).to.equal(1)
177 expect(abuse1.video.nthReport).to.equal(1)
179 expect(abuse1.comment).to.be.null
181 expect(abuse1.flaggedAccount.name).to.equal('root')
182 expect(abuse1.flaggedAccount.host).to.equal(servers[0].host)
184 expect(abuse1.state.id).to.equal(AbuseState.PENDING)
185 expect(abuse1.state.label).to.equal('Pending')
186 expect(abuse1.moderationComment).to.be.null
188 const abuse2: AdminAbuse = res1.body.data[1]
189 expect(abuse2.reason).to.equal('my super bad reason 2')
191 expect(abuse2.reporterAccount.name).to.equal('root')
192 expect(abuse2.reporterAccount.host).to.equal(servers[0].host)
194 expect(abuse2.video.id).to.equal(servers[1].video.id)
196 expect(abuse2.comment).to.be.null
198 expect(abuse2.flaggedAccount.name).to.equal('root')
199 expect(abuse2.flaggedAccount.host).to.equal(servers[1].host)
201 expect(abuse2.state.id).to.equal(AbuseState.PENDING)
202 expect(abuse2.state.label).to.equal('Pending')
203 expect(abuse2.moderationComment).to.be.null
205 const res2 = await getAdminAbusesList({ url: servers[1].url, token: servers[1].accessToken })
206 expect(res2.body.total).to.equal(1)
207 expect(res2.body.data.length).to.equal(1)
209 abuseServer2 = res2.body.data[0]
210 expect(abuseServer2.reason).to.equal('my super bad reason 2')
211 expect(abuseServer2.reporterAccount.name).to.equal('root')
212 expect(abuseServer2.reporterAccount.host).to.equal(servers[0].host)
214 expect(abuse2.flaggedAccount.name).to.equal('root')
215 expect(abuse2.flaggedAccount.host).to.equal(servers[1].host)
217 expect(abuseServer2.state.id).to.equal(AbuseState.PENDING)
218 expect(abuseServer2.state.label).to.equal('Pending')
219 expect(abuseServer2.moderationComment).to.be.null
222 it('Should hide video abuses from blocked accounts', async function () {
226 const videoId = await getVideoIdFromUUID(servers[1].url, servers[0].video.uuid)
227 await reportAbuse({ url: servers[1].url, token: servers[1].accessToken, videoId, reason: 'will mute this' })
228 await waitJobs(servers)
230 const res = await getAdminAbusesList({ url: servers[0].url, token: servers[0].accessToken })
231 expect(res.body.total).to.equal(3)
234 const accountToBlock = 'root@' + servers[1].host
237 await addAccountToServerBlocklist(servers[0].url, servers[0].accessToken, accountToBlock)
239 const res = await getAdminAbusesList({ url: servers[0].url, token: servers[0].accessToken })
240 expect(res.body.total).to.equal(2)
242 const abuse = res.body.data.find(a => a.reason === 'will mute this')
243 expect(abuse).to.be.undefined
247 await removeAccountFromServerBlocklist(servers[0].url, servers[0].accessToken, accountToBlock)
249 const res = await getAdminAbusesList({ url: servers[0].url, token: servers[0].accessToken })
250 expect(res.body.total).to.equal(3)
254 it('Should hide video abuses from blocked servers', async function () {
255 const serverToBlock = servers[1].host
258 await addServerToServerBlocklist(servers[0].url, servers[0].accessToken, servers[1].host)
260 const res = await getAdminAbusesList({ url: servers[0].url, token: servers[0].accessToken })
261 expect(res.body.total).to.equal(2)
263 const abuse = res.body.data.find(a => a.reason === 'will mute this')
264 expect(abuse).to.be.undefined
268 await removeServerFromServerBlocklist(servers[0].url, servers[0].accessToken, serverToBlock)
270 const res = await getAdminAbusesList({ url: servers[0].url, token: servers[0].accessToken })
271 expect(res.body.total).to.equal(3)
275 it('Should keep the video abuse when deleting the video', async function () {
278 await removeVideo(servers[1].url, servers[1].accessToken, abuseServer2.video.uuid)
280 await waitJobs(servers)
282 const res = await getAdminAbusesList({ url: servers[1].url, token: servers[1].accessToken })
283 expect(res.body.total).to.equal(2, "wrong number of videos returned")
284 expect(res.body.data).to.have.lengthOf(2, "wrong number of videos returned")
286 const abuse: AdminAbuse = res.body.data[0]
287 expect(abuse.id).to.equal(abuseServer2.id, "wrong origin server id for first video")
288 expect(abuse.video.id).to.equal(abuseServer2.video.id, "wrong video id")
289 expect(abuse.video.channel).to.exist
290 expect(abuse.video.deleted).to.be.true
293 it('Should include counts of reports from reporter and reportee', async function () {
296 // register a second user to have two reporters/reportees
297 const user = { username: 'user2', password: 'password' }
298 await createUser({ url: servers[0].url, accessToken: servers[0].accessToken, ...user })
299 const userAccessToken = await userLogin(servers[0], user)
301 // upload a third video via this user
302 const video3Attributes = {
303 name: 'my second super name for server 1',
304 description: 'my second super description for server 1'
306 await uploadVideo(servers[0].url, userAccessToken, video3Attributes)
308 const res1 = await getVideosList(servers[0].url)
309 const videos = res1.body.data
310 const video3 = videos.find(video => video.name === 'my second super name for server 1')
312 // resume with the test
313 const reason3 = 'my super bad reason 3'
314 await reportAbuse({ url: servers[0].url, token: servers[0].accessToken, videoId: video3.id, reason: reason3 })
316 const reason4 = 'my super bad reason 4'
317 await reportAbuse({ url: servers[0].url, token: userAccessToken, videoId: servers[0].video.id, reason: reason4 })
320 const res2 = await getAdminAbusesList({ url: servers[0].url, token: servers[0].accessToken })
321 const abuses = res2.body.data as AdminAbuse[]
323 const abuseVideo3 = res2.body.data.find(a => a.video.id === video3.id)
324 expect(abuseVideo3).to.not.be.undefined
325 expect(abuseVideo3.video.countReports).to.equal(1, "wrong reports count for video 3")
326 expect(abuseVideo3.video.nthReport).to.equal(1, "wrong report position in report list for video 3")
327 expect(abuseVideo3.countReportsForReportee).to.equal(1, "wrong reports count for reporter on video 3 abuse")
328 expect(abuseVideo3.countReportsForReporter).to.equal(3, "wrong reports count for reportee on video 3 abuse")
330 const abuseServer1 = abuses.find(a => a.video.id === servers[0].video.id)
331 expect(abuseServer1.countReportsForReportee).to.equal(3, "wrong reports count for reporter on video 1 abuse")
335 it('Should list predefined reasons as well as timestamps for the reported video', async function () {
338 const reason5 = 'my super bad reason 5'
339 const predefinedReasons5: AbusePredefinedReasonsString[] = [ 'violentOrRepulsive', 'captions' ]
340 const createdAbuse = (await reportAbuse({
342 token: servers[0].accessToken,
343 videoId: servers[0].video.id,
345 predefinedReasons: predefinedReasons5,
350 const res = await getAdminAbusesList({ url: servers[0].url, token: servers[0].accessToken })
353 const abuse = (res.body.data as AdminAbuse[]).find(a => a.id === createdAbuse.id)
354 expect(abuse.reason).to.equals(reason5)
355 expect(abuse.predefinedReasons).to.deep.equals(predefinedReasons5, "predefined reasons do not match the one reported")
356 expect(abuse.video.startAt).to.equal(1, "starting timestamp doesn't match the one reported")
357 expect(abuse.video.endAt).to.equal(5, "ending timestamp doesn't match the one reported")
361 it('Should delete the video abuse', async function () {
364 await deleteAbuse(servers[1].url, servers[1].accessToken, abuseServer2.id)
366 await waitJobs(servers)
369 const res = await getAdminAbusesList({ url: servers[1].url, token: servers[1].accessToken })
370 expect(res.body.total).to.equal(1)
371 expect(res.body.data.length).to.equal(1)
372 expect(res.body.data[0].id).to.not.equal(abuseServer2.id)
376 const res = await getAdminAbusesList({ url: servers[0].url, token: servers[0].accessToken })
377 expect(res.body.total).to.equal(6)
381 it('Should list and filter video abuses', async function () {
384 async function list (query: Omit<Parameters<typeof getAdminAbusesList>[0], 'url' | 'token'>) {
387 token: servers[0].accessToken
390 Object.assign(options, query)
392 const res = await getAdminAbusesList(options)
394 return res.body.data as AdminAbuse[]
397 expect(await list({ id: 56 })).to.have.lengthOf(0)
398 expect(await list({ id: 1 })).to.have.lengthOf(1)
400 expect(await list({ search: 'my super name for server 1' })).to.have.lengthOf(4)
401 expect(await list({ search: 'aaaaaaaaaaaaaaaaaaaaaaaaaa' })).to.have.lengthOf(0)
403 expect(await list({ searchVideo: 'my second super name for server 1' })).to.have.lengthOf(1)
405 expect(await list({ searchVideoChannel: 'root' })).to.have.lengthOf(4)
406 expect(await list({ searchVideoChannel: 'aaaa' })).to.have.lengthOf(0)
408 expect(await list({ searchReporter: 'user2' })).to.have.lengthOf(1)
409 expect(await list({ searchReporter: 'root' })).to.have.lengthOf(5)
411 expect(await list({ searchReportee: 'root' })).to.have.lengthOf(5)
412 expect(await list({ searchReportee: 'aaaa' })).to.have.lengthOf(0)
414 expect(await list({ videoIs: 'deleted' })).to.have.lengthOf(1)
415 expect(await list({ videoIs: 'blacklisted' })).to.have.lengthOf(0)
417 expect(await list({ state: AbuseState.ACCEPTED })).to.have.lengthOf(0)
418 expect(await list({ state: AbuseState.PENDING })).to.have.lengthOf(6)
420 expect(await list({ predefinedReason: 'violentOrRepulsive' })).to.have.lengthOf(1)
421 expect(await list({ predefinedReason: 'serverRules' })).to.have.lengthOf(0)
425 describe('Comment abuses', function () {
427 async function getComment (url: string, videoIdArg: number | string) {
428 const videoId = typeof videoIdArg === 'string'
429 ? await getVideoIdFromUUID(url, videoIdArg)
432 const res = await getVideoCommentThreads(url, videoId, 0, 5)
434 return res.body.data[0] as VideoComment
437 before(async function () {
440 servers[0].video = await uploadVideoAndGetId({ server: servers[0], videoName: 'server 1' })
441 servers[1].video = await uploadVideoAndGetId({ server: servers[1], videoName: 'server 2' })
443 await addVideoCommentThread(servers[0].url, servers[0].accessToken, servers[0].video.id, 'comment server 1')
444 await addVideoCommentThread(servers[1].url, servers[1].accessToken, servers[1].video.id, 'comment server 2')
446 await waitJobs(servers)
449 it('Should report abuse on a comment', async function () {
452 const comment = await getComment(servers[0].url, servers[0].video.id)
454 const reason = 'it is a bad comment'
455 await reportAbuse({ url: servers[0].url, token: servers[0].accessToken, commentId: comment.id, reason })
457 await waitJobs(servers)
460 it('Should have 1 comment abuse on server 1 and 0 on server 2', async function () {
462 const comment = await getComment(servers[0].url, servers[0].video.id)
463 const res = await getAdminAbusesList({ url: servers[0].url, token: servers[0].accessToken, filter: 'comment' })
465 expect(res.body.total).to.equal(1)
466 expect(res.body.data).to.have.lengthOf(1)
468 const abuse: AdminAbuse = res.body.data[0]
469 expect(abuse.reason).to.equal('it is a bad comment')
471 expect(abuse.reporterAccount.name).to.equal('root')
472 expect(abuse.reporterAccount.host).to.equal(servers[0].host)
474 expect(abuse.video).to.be.null
476 expect(abuse.comment.deleted).to.be.false
477 expect(abuse.comment.id).to.equal(comment.id)
478 expect(abuse.comment.text).to.equal(comment.text)
479 expect(abuse.comment.video.name).to.equal('server 1')
480 expect(abuse.comment.video.id).to.equal(servers[0].video.id)
481 expect(abuse.comment.video.uuid).to.equal(servers[0].video.uuid)
483 expect(abuse.countReportsForReporter).to.equal(5)
484 expect(abuse.countReportsForReportee).to.equal(5)
488 const res = await getAdminAbusesList({ url: servers[1].url, token: servers[1].accessToken, filter: 'comment' })
489 expect(res.body.total).to.equal(0)
490 expect(res.body.data.length).to.equal(0)
494 it('Should report abuse on a remote comment', async function () {
497 const comment = await getComment(servers[0].url, servers[1].video.uuid)
499 const reason = 'it is a really bad comment'
500 await reportAbuse({ url: servers[0].url, token: servers[0].accessToken, commentId: comment.id, reason })
502 await waitJobs(servers)
505 it('Should have 2 comment abuses on server 1 and 1 on server 2', async function () {
506 const commentServer2 = await getComment(servers[0].url, servers[1].video.id)
508 const res1 = await getAdminAbusesList({ url: servers[0].url, token: servers[0].accessToken, filter: 'comment' })
509 expect(res1.body.total).to.equal(2)
510 expect(res1.body.data.length).to.equal(2)
512 const abuse: AdminAbuse = res1.body.data[0]
513 expect(abuse.reason).to.equal('it is a bad comment')
514 expect(abuse.countReportsForReporter).to.equal(6)
515 expect(abuse.countReportsForReportee).to.equal(5)
517 const abuse2: AdminAbuse = res1.body.data[1]
519 expect(abuse2.reason).to.equal('it is a really bad comment')
521 expect(abuse2.reporterAccount.name).to.equal('root')
522 expect(abuse2.reporterAccount.host).to.equal(servers[0].host)
524 expect(abuse2.video).to.be.null
526 expect(abuse2.comment.deleted).to.be.false
527 expect(abuse2.comment.id).to.equal(commentServer2.id)
528 expect(abuse2.comment.text).to.equal(commentServer2.text)
529 expect(abuse2.comment.video.name).to.equal('server 2')
530 expect(abuse2.comment.video.uuid).to.equal(servers[1].video.uuid)
532 expect(abuse2.state.id).to.equal(AbuseState.PENDING)
533 expect(abuse2.state.label).to.equal('Pending')
535 expect(abuse2.moderationComment).to.be.null
537 expect(abuse2.countReportsForReporter).to.equal(6)
538 expect(abuse2.countReportsForReportee).to.equal(2)
540 const res2 = await getAdminAbusesList({ url: servers[1].url, token: servers[1].accessToken, filter: 'comment' })
541 expect(res2.body.total).to.equal(1)
542 expect(res2.body.data.length).to.equal(1)
544 abuseServer2 = res2.body.data[0]
545 expect(abuseServer2.reason).to.equal('it is a really bad comment')
546 expect(abuseServer2.reporterAccount.name).to.equal('root')
547 expect(abuseServer2.reporterAccount.host).to.equal(servers[0].host)
549 expect(abuseServer2.state.id).to.equal(AbuseState.PENDING)
550 expect(abuseServer2.state.label).to.equal('Pending')
552 expect(abuseServer2.moderationComment).to.be.null
554 expect(abuseServer2.countReportsForReporter).to.equal(1)
555 expect(abuseServer2.countReportsForReportee).to.equal(1)
558 it('Should keep the comment abuse when deleting the comment', async function () {
561 const commentServer2 = await getComment(servers[0].url, servers[1].video.id)
563 await deleteVideoComment(servers[0].url, servers[0].accessToken, servers[1].video.uuid, commentServer2.id)
565 await waitJobs(servers)
567 const res = await getAdminAbusesList({ url: servers[0].url, token: servers[0].accessToken, filter: 'comment' })
568 expect(res.body.total).to.equal(2)
569 expect(res.body.data).to.have.lengthOf(2)
571 const abuse = (res.body.data as AdminAbuse[]).find(a => a.comment?.id === commentServer2.id)
572 expect(abuse).to.not.be.undefined
574 expect(abuse.comment.text).to.be.empty
575 expect(abuse.comment.video.name).to.equal('server 2')
576 expect(abuse.comment.deleted).to.be.true
579 it('Should delete the comment abuse', async function () {
582 await deleteAbuse(servers[1].url, servers[1].accessToken, abuseServer2.id)
584 await waitJobs(servers)
587 const res = await getAdminAbusesList({ url: servers[1].url, token: servers[1].accessToken, filter: 'comment' })
588 expect(res.body.total).to.equal(0)
589 expect(res.body.data.length).to.equal(0)
593 const res = await getAdminAbusesList({ url: servers[0].url, token: servers[0].accessToken, filter: 'comment' })
594 expect(res.body.total).to.equal(2)
598 it('Should list and filter video abuses', async function () {
600 const res = await getAdminAbusesList({
602 token: servers[0].accessToken,
604 searchReportee: 'foo'
606 expect(res.body.total).to.equal(0)
610 const res = await getAdminAbusesList({
612 token: servers[0].accessToken,
616 expect(res.body.total).to.equal(2)
620 const baseParams = { url: servers[0].url, token: servers[0].accessToken, filter: 'comment' as AbuseFilter, start: 1, count: 1 }
622 const res1 = await getAdminAbusesList(immutableAssign(baseParams, { sort: 'createdAt' }))
623 expect(res1.body.data).to.have.lengthOf(1)
624 expect(res1.body.data[0].comment.text).to.be.empty
626 const res2 = await getAdminAbusesList(immutableAssign(baseParams, { sort: '-createdAt' }))
627 expect(res2.body.data).to.have.lengthOf(1)
628 expect(res2.body.data[0].comment.text).to.equal('comment server 1')
633 describe('Account abuses', function () {
635 async function getAccountFromServer (url: string, name: string, server: ServerInfo) {
636 const res = await getAccount(url, name + '@' + server.host)
638 return res.body as Account
641 before(async function () {
644 await createUser({ url: servers[0].url, accessToken: servers[0].accessToken, username: 'user_1', password: 'donald' })
646 const token = await generateUserAccessToken(servers[1], 'user_2')
647 await uploadVideo(servers[1].url, token, { name: 'super video' })
649 await waitJobs(servers)
652 it('Should report abuse on an account', async function () {
655 const account = await getAccountFromServer(servers[0].url, 'user_1', servers[0])
657 const reason = 'it is a bad account'
658 await reportAbuse({ url: servers[0].url, token: servers[0].accessToken, accountId: account.id, reason })
660 await waitJobs(servers)
663 it('Should have 1 account abuse on server 1 and 0 on server 2', async function () {
665 const res = await getAdminAbusesList({ url: servers[0].url, token: servers[0].accessToken, filter: 'account' })
667 expect(res.body.total).to.equal(1)
668 expect(res.body.data).to.have.lengthOf(1)
670 const abuse: AdminAbuse = res.body.data[0]
671 expect(abuse.reason).to.equal('it is a bad account')
673 expect(abuse.reporterAccount.name).to.equal('root')
674 expect(abuse.reporterAccount.host).to.equal(servers[0].host)
676 expect(abuse.video).to.be.null
677 expect(abuse.comment).to.be.null
679 expect(abuse.flaggedAccount.name).to.equal('user_1')
680 expect(abuse.flaggedAccount.host).to.equal(servers[0].host)
684 const res = await getAdminAbusesList({ url: servers[1].url, token: servers[1].accessToken, filter: 'comment' })
685 expect(res.body.total).to.equal(0)
686 expect(res.body.data.length).to.equal(0)
690 it('Should report abuse on a remote account', async function () {
693 const account = await getAccountFromServer(servers[0].url, 'user_2', servers[1])
695 const reason = 'it is a really bad account'
696 await reportAbuse({ url: servers[0].url, token: servers[0].accessToken, accountId: account.id, reason })
698 await waitJobs(servers)
701 it('Should have 2 comment abuses on server 1 and 1 on server 2', async function () {
702 const res1 = await getAdminAbusesList({ url: servers[0].url, token: servers[0].accessToken, filter: 'account' })
703 expect(res1.body.total).to.equal(2)
704 expect(res1.body.data.length).to.equal(2)
706 const abuse: AdminAbuse = res1.body.data[0]
707 expect(abuse.reason).to.equal('it is a bad account')
709 const abuse2: AdminAbuse = res1.body.data[1]
710 expect(abuse2.reason).to.equal('it is a really bad account')
712 expect(abuse2.reporterAccount.name).to.equal('root')
713 expect(abuse2.reporterAccount.host).to.equal(servers[0].host)
715 expect(abuse2.video).to.be.null
716 expect(abuse2.comment).to.be.null
718 expect(abuse2.state.id).to.equal(AbuseState.PENDING)
719 expect(abuse2.state.label).to.equal('Pending')
721 expect(abuse2.moderationComment).to.be.null
723 const res2 = await getAdminAbusesList({ url: servers[1].url, token: servers[1].accessToken, filter: 'account' })
724 expect(res2.body.total).to.equal(1)
725 expect(res2.body.data.length).to.equal(1)
727 abuseServer2 = res2.body.data[0]
729 expect(abuseServer2.reason).to.equal('it is a really bad account')
731 expect(abuseServer2.reporterAccount.name).to.equal('root')
732 expect(abuseServer2.reporterAccount.host).to.equal(servers[0].host)
734 expect(abuseServer2.state.id).to.equal(AbuseState.PENDING)
735 expect(abuseServer2.state.label).to.equal('Pending')
737 expect(abuseServer2.moderationComment).to.be.null
740 it('Should keep the account abuse when deleting the account', async function () {
743 const account = await getAccountFromServer(servers[1].url, 'user_2', servers[1])
744 await removeUser(servers[1].url, account.userId, servers[1].accessToken)
746 await waitJobs(servers)
748 const res = await getAdminAbusesList({ url: servers[0].url, token: servers[0].accessToken, filter: 'account' })
749 expect(res.body.total).to.equal(2)
750 expect(res.body.data).to.have.lengthOf(2)
752 const abuse = (res.body.data as AdminAbuse[]).find(a => a.reason === 'it is a really bad account')
753 expect(abuse).to.not.be.undefined
756 it('Should delete the account abuse', async function () {
759 await deleteAbuse(servers[1].url, servers[1].accessToken, abuseServer2.id)
761 await waitJobs(servers)
764 const res = await getAdminAbusesList({ url: servers[1].url, token: servers[1].accessToken, filter: 'account' })
765 expect(res.body.total).to.equal(0)
766 expect(res.body.data.length).to.equal(0)
770 const res = await getAdminAbusesList({ url: servers[0].url, token: servers[0].accessToken, filter: 'account' })
771 expect(res.body.total).to.equal(2)
773 abuseServer1 = res.body.data[0]
778 describe('Common actions on abuses', function () {
780 it('Should update the state of an abuse', async function () {
781 const body = { state: AbuseState.REJECTED }
782 await updateAbuse(servers[0].url, servers[0].accessToken, abuseServer1.id, body)
784 const res = await getAdminAbusesList({ url: servers[0].url, token: servers[0].accessToken, id: abuseServer1.id })
785 expect(res.body.data[0].state.id).to.equal(AbuseState.REJECTED)
788 it('Should add a moderation comment', async function () {
789 const body = { state: AbuseState.ACCEPTED, moderationComment: 'It is valid' }
790 await updateAbuse(servers[0].url, servers[0].accessToken, abuseServer1.id, body)
792 const res = await getAdminAbusesList({ url: servers[0].url, token: servers[0].accessToken, id: abuseServer1.id })
793 expect(res.body.data[0].state.id).to.equal(AbuseState.ACCEPTED)
794 expect(res.body.data[0].moderationComment).to.equal('It is valid')
798 describe('My abuses', async function () {
800 let userAccessToken: string
802 before(async function () {
803 userAccessToken = await generateUserAccessToken(servers[0], 'user_42')
805 await reportAbuse({ url: servers[0].url, token: userAccessToken, videoId: servers[0].video.id, reason: 'user reason 1' })
807 const videoId = await getVideoIdFromUUID(servers[0].url, servers[1].video.uuid)
808 await reportAbuse({ url: servers[0].url, token: userAccessToken, videoId, reason: 'user reason 2' })
811 it('Should correctly list my abuses', async function () {
813 const res = await getUserAbusesList({ url: servers[0].url, token: userAccessToken, start: 0, count: 5, sort: 'createdAt' })
814 expect(res.body.total).to.equal(2)
816 const abuses: UserAbuse[] = res.body.data
817 expect(abuses[0].reason).to.equal('user reason 1')
818 expect(abuses[1].reason).to.equal('user reason 2')
820 abuseId1 = abuses[0].id
824 const res = await getUserAbusesList({ url: servers[0].url, token: userAccessToken, start: 1, count: 1, sort: 'createdAt' })
825 expect(res.body.total).to.equal(2)
827 const abuses: UserAbuse[] = res.body.data
828 expect(abuses[0].reason).to.equal('user reason 2')
832 const res = await getUserAbusesList({ url: servers[0].url, token: userAccessToken, start: 1, count: 1, sort: '-createdAt' })
833 expect(res.body.total).to.equal(2)
835 const abuses: UserAbuse[] = res.body.data
836 expect(abuses[0].reason).to.equal('user reason 1')
840 it('Should correctly filter my abuses by id', async function () {
841 const res = await getUserAbusesList({ url: servers[0].url, token: userAccessToken, id: abuseId1 })
843 expect(res.body.total).to.equal(1)
845 const abuses: UserAbuse[] = res.body.data
846 expect(abuses[0].reason).to.equal('user reason 1')
849 it('Should correctly filter my abuses by search', async function () {
850 const res = await getUserAbusesList({
852 token: userAccessToken,
856 expect(res.body.total).to.equal(1)
858 const abuses: UserAbuse[] = res.body.data
859 expect(abuses[0].reason).to.equal('user reason 2')
862 it('Should correctly filter my abuses by state', async function () {
863 const body = { state: AbuseState.REJECTED }
864 await updateAbuse(servers[0].url, servers[0].accessToken, abuseId1, body)
866 const res = await getUserAbusesList({
868 token: userAccessToken,
869 state: AbuseState.REJECTED
872 expect(res.body.total).to.equal(1)
874 const abuses: UserAbuse[] = res.body.data
875 expect(abuses[0].reason).to.equal('user reason 1')
879 describe('Abuse messages', async function () {
881 let userAccessToken: string
882 let abuseMessageUserId: number
883 let abuseMessageModerationId: number
885 before(async function () {
886 userAccessToken = await generateUserAccessToken(servers[0], 'user_43')
888 const res = await reportAbuse({
890 token: userAccessToken,
891 videoId: servers[0].video.id,
892 reason: 'user 43 reason 1'
895 abuseId = res.body.abuse.id
898 it('Should create some messages on the abuse', async function () {
899 await addAbuseMessage(servers[0].url, userAccessToken, abuseId, 'message 1')
900 await addAbuseMessage(servers[0].url, servers[0].accessToken, abuseId, 'message 2')
901 await addAbuseMessage(servers[0].url, servers[0].accessToken, abuseId, 'message 3')
902 await addAbuseMessage(servers[0].url, userAccessToken, abuseId, 'message 4')
905 it('Should have the correct messages count when listing abuses', async function () {
906 const results = await Promise.all([
907 getAdminAbusesList({ url: servers[0].url, token: servers[0].accessToken, start: 0, count: 50 }),
908 getUserAbusesList({ url: servers[0].url, token: userAccessToken, start: 0, count: 50 })
911 for (const res of results) {
912 const abuses: AdminAbuse[] = res.body.data
913 const abuse = abuses.find(a => a.id === abuseId)
914 expect(abuse.countMessages).to.equal(4)
918 it('Should correctly list messages of this abuse', async function () {
919 const results = await Promise.all([
920 listAbuseMessages(servers[0].url, servers[0].accessToken, abuseId),
921 listAbuseMessages(servers[0].url, userAccessToken, abuseId)
924 for (const res of results) {
925 expect(res.body.total).to.equal(4)
927 const abuseMessages: AbuseMessage[] = res.body.data
929 expect(abuseMessages[0].message).to.equal('message 1')
930 expect(abuseMessages[0].byModerator).to.be.false
931 expect(abuseMessages[0].account.name).to.equal('user_43')
933 abuseMessageUserId = abuseMessages[0].id
935 expect(abuseMessages[1].message).to.equal('message 2')
936 expect(abuseMessages[1].byModerator).to.be.true
937 expect(abuseMessages[1].account.name).to.equal('root')
939 expect(abuseMessages[2].message).to.equal('message 3')
940 expect(abuseMessages[2].byModerator).to.be.true
941 expect(abuseMessages[2].account.name).to.equal('root')
942 abuseMessageModerationId = abuseMessages[2].id
944 expect(abuseMessages[3].message).to.equal('message 4')
945 expect(abuseMessages[3].byModerator).to.be.false
946 expect(abuseMessages[3].account.name).to.equal('user_43')
950 it('Should delete messages', async function () {
951 await deleteAbuseMessage(servers[0].url, servers[0].accessToken, abuseId, abuseMessageModerationId)
952 await deleteAbuseMessage(servers[0].url, userAccessToken, abuseId, abuseMessageUserId)
954 const results = await Promise.all([
955 listAbuseMessages(servers[0].url, servers[0].accessToken, abuseId),
956 listAbuseMessages(servers[0].url, userAccessToken, abuseId)
959 for (const res of results) {
960 expect(res.body.total).to.equal(2)
962 const abuseMessages: AbuseMessage[] = res.body.data
964 expect(abuseMessages[0].message).to.equal('message 2')
965 expect(abuseMessages[1].message).to.equal('message 4')
970 after(async function () {
971 await cleanupTests(servers)