1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
4 import * as chai from 'chai'
5 import { AbuseFilter, AbusePredefinedReasonsString, AbuseState, Account, AdminAbuse, UserAbuse, VideoComment, AbuseMessage } from '@shared/models'
12 flushAndRunMultipleServers,
13 generateUserAccessToken,
17 getVideoCommentThreads,
25 setAccessTokensToServers,
33 } from '../../../../shared/extra-utils/index'
34 import { doubleFollow } from '../../../../shared/extra-utils/server/follows'
35 import { waitJobs } from '../../../../shared/extra-utils/server/jobs'
37 addAccountToServerBlocklist,
38 addServerToServerBlocklist,
39 removeAccountFromServerBlocklist,
40 removeServerFromServerBlocklist
41 } from '../../../../shared/extra-utils/users/blocklist'
43 const expect = chai.expect
45 describe('Test abuses', function () {
46 let servers: ServerInfo[] = []
47 let abuseServer1: AdminAbuse
48 let abuseServer2: AdminAbuse
50 before(async function () {
54 servers = await flushAndRunMultipleServers(2)
56 // Get the access tokens
57 await setAccessTokensToServers(servers)
59 // Server 1 and server 2 follow each other
60 await doubleFollow(servers[0], servers[1])
63 describe('Video abuses', function () {
65 before(async function () {
68 // Upload some videos on each servers
69 const video1Attributes = {
70 name: 'my super name for server 1',
71 description: 'my super description for server 1'
73 await uploadVideo(servers[0].url, servers[0].accessToken, video1Attributes)
75 const video2Attributes = {
76 name: 'my super name for server 2',
77 description: 'my super description for server 2'
79 await uploadVideo(servers[1].url, servers[1].accessToken, video2Attributes)
81 // Wait videos propagation, server 2 has transcoding enabled
82 await waitJobs(servers)
84 const res = await getVideosList(servers[0].url)
85 const videos = res.body.data
87 expect(videos.length).to.equal(2)
89 servers[0].video = videos.find(video => video.name === 'my super name for server 1')
90 servers[1].video = videos.find(video => video.name === 'my super name for server 2')
93 it('Should not have abuses', async function () {
94 const res = await getAdminAbusesList({ url: servers[0].url, token: servers[0].accessToken })
96 expect(res.body.total).to.equal(0)
97 expect(res.body.data).to.be.an('array')
98 expect(res.body.data.length).to.equal(0)
101 it('Should report abuse on a local video', async function () {
104 const reason = 'my super bad reason'
105 await reportAbuse({ url: servers[0].url, token: servers[0].accessToken, videoId: servers[0].video.id, reason })
107 // We wait requests propagation, even if the server 1 is not supposed to make a request to server 2
108 await waitJobs(servers)
111 it('Should have 1 video abuses on server 1 and 0 on server 2', async function () {
112 const res1 = await getAdminAbusesList({ url: servers[0].url, token: servers[0].accessToken })
114 expect(res1.body.total).to.equal(1)
115 expect(res1.body.data).to.be.an('array')
116 expect(res1.body.data.length).to.equal(1)
118 const abuse: AdminAbuse = res1.body.data[0]
119 expect(abuse.reason).to.equal('my super bad reason')
121 expect(abuse.reporterAccount.name).to.equal('root')
122 expect(abuse.reporterAccount.host).to.equal(servers[0].host)
124 expect(abuse.video.id).to.equal(servers[0].video.id)
125 expect(abuse.video.channel).to.exist
127 expect(abuse.comment).to.be.null
129 expect(abuse.flaggedAccount.name).to.equal('root')
130 expect(abuse.flaggedAccount.host).to.equal(servers[0].host)
132 expect(abuse.video.countReports).to.equal(1)
133 expect(abuse.video.nthReport).to.equal(1)
135 expect(abuse.countReportsForReporter).to.equal(1)
136 expect(abuse.countReportsForReportee).to.equal(1)
138 const res2 = await getAdminAbusesList({ url: servers[1].url, token: servers[1].accessToken })
139 expect(res2.body.total).to.equal(0)
140 expect(res2.body.data).to.be.an('array')
141 expect(res2.body.data.length).to.equal(0)
144 it('Should report abuse on a remote video', async function () {
147 const reason = 'my super bad reason 2'
148 const videoId = await getVideoIdFromUUID(servers[0].url, servers[1].video.uuid)
149 await reportAbuse({ url: servers[0].url, token: servers[0].accessToken, videoId, reason })
151 // We wait requests propagation
152 await waitJobs(servers)
155 it('Should have 2 video abuses on server 1 and 1 on server 2', async function () {
156 const res1 = await getAdminAbusesList({ url: servers[0].url, token: servers[0].accessToken })
158 expect(res1.body.total).to.equal(2)
159 expect(res1.body.data.length).to.equal(2)
161 const abuse1: AdminAbuse = res1.body.data[0]
162 expect(abuse1.reason).to.equal('my super bad reason')
163 expect(abuse1.reporterAccount.name).to.equal('root')
164 expect(abuse1.reporterAccount.host).to.equal(servers[0].host)
166 expect(abuse1.video.id).to.equal(servers[0].video.id)
167 expect(abuse1.video.countReports).to.equal(1)
168 expect(abuse1.video.nthReport).to.equal(1)
170 expect(abuse1.comment).to.be.null
172 expect(abuse1.flaggedAccount.name).to.equal('root')
173 expect(abuse1.flaggedAccount.host).to.equal(servers[0].host)
175 expect(abuse1.state.id).to.equal(AbuseState.PENDING)
176 expect(abuse1.state.label).to.equal('Pending')
177 expect(abuse1.moderationComment).to.be.null
179 const abuse2: AdminAbuse = res1.body.data[1]
180 expect(abuse2.reason).to.equal('my super bad reason 2')
182 expect(abuse2.reporterAccount.name).to.equal('root')
183 expect(abuse2.reporterAccount.host).to.equal(servers[0].host)
185 expect(abuse2.video.id).to.equal(servers[1].video.id)
187 expect(abuse2.comment).to.be.null
189 expect(abuse2.flaggedAccount.name).to.equal('root')
190 expect(abuse2.flaggedAccount.host).to.equal(servers[1].host)
192 expect(abuse2.state.id).to.equal(AbuseState.PENDING)
193 expect(abuse2.state.label).to.equal('Pending')
194 expect(abuse2.moderationComment).to.be.null
196 const res2 = await getAdminAbusesList({ url: servers[1].url, token: servers[1].accessToken })
197 expect(res2.body.total).to.equal(1)
198 expect(res2.body.data.length).to.equal(1)
200 abuseServer2 = res2.body.data[0]
201 expect(abuseServer2.reason).to.equal('my super bad reason 2')
202 expect(abuseServer2.reporterAccount.name).to.equal('root')
203 expect(abuseServer2.reporterAccount.host).to.equal(servers[0].host)
205 expect(abuse2.flaggedAccount.name).to.equal('root')
206 expect(abuse2.flaggedAccount.host).to.equal(servers[1].host)
208 expect(abuseServer2.state.id).to.equal(AbuseState.PENDING)
209 expect(abuseServer2.state.label).to.equal('Pending')
210 expect(abuseServer2.moderationComment).to.be.null
213 it('Should hide video abuses from blocked accounts', async function () {
217 const videoId = await getVideoIdFromUUID(servers[1].url, servers[0].video.uuid)
218 await reportAbuse({ url: servers[1].url, token: servers[1].accessToken, videoId, reason: 'will mute this' })
219 await waitJobs(servers)
221 const res = await getAdminAbusesList({ url: servers[0].url, token: servers[0].accessToken })
222 expect(res.body.total).to.equal(3)
225 const accountToBlock = 'root@' + servers[1].host
228 await addAccountToServerBlocklist(servers[0].url, servers[0].accessToken, accountToBlock)
230 const res = await getAdminAbusesList({ url: servers[0].url, token: servers[0].accessToken })
231 expect(res.body.total).to.equal(2)
233 const abuse = res.body.data.find(a => a.reason === 'will mute this')
234 expect(abuse).to.be.undefined
238 await removeAccountFromServerBlocklist(servers[0].url, servers[0].accessToken, accountToBlock)
240 const res = await getAdminAbusesList({ url: servers[0].url, token: servers[0].accessToken })
241 expect(res.body.total).to.equal(3)
245 it('Should hide video abuses from blocked servers', async function () {
246 const serverToBlock = servers[1].host
249 await addServerToServerBlocklist(servers[0].url, servers[0].accessToken, servers[1].host)
251 const res = await getAdminAbusesList({ url: servers[0].url, token: servers[0].accessToken })
252 expect(res.body.total).to.equal(2)
254 const abuse = res.body.data.find(a => a.reason === 'will mute this')
255 expect(abuse).to.be.undefined
259 await removeServerFromServerBlocklist(servers[0].url, servers[0].accessToken, serverToBlock)
261 const res = await getAdminAbusesList({ url: servers[0].url, token: servers[0].accessToken })
262 expect(res.body.total).to.equal(3)
266 it('Should keep the video abuse when deleting the video', async function () {
269 await removeVideo(servers[1].url, servers[1].accessToken, abuseServer2.video.uuid)
271 await waitJobs(servers)
273 const res = await getAdminAbusesList({ url: servers[1].url, token: servers[1].accessToken })
274 expect(res.body.total).to.equal(2, "wrong number of videos returned")
275 expect(res.body.data).to.have.lengthOf(2, "wrong number of videos returned")
277 const abuse: AdminAbuse = res.body.data[0]
278 expect(abuse.id).to.equal(abuseServer2.id, "wrong origin server id for first video")
279 expect(abuse.video.id).to.equal(abuseServer2.video.id, "wrong video id")
280 expect(abuse.video.channel).to.exist
281 expect(abuse.video.deleted).to.be.true
284 it('Should include counts of reports from reporter and reportee', async function () {
287 // register a second user to have two reporters/reportees
288 const user = { username: 'user2', password: 'password' }
289 await createUser({ url: servers[0].url, accessToken: servers[0].accessToken, ...user })
290 const userAccessToken = await userLogin(servers[0], user)
292 // upload a third video via this user
293 const video3Attributes = {
294 name: 'my second super name for server 1',
295 description: 'my second super description for server 1'
297 await uploadVideo(servers[0].url, userAccessToken, video3Attributes)
299 const res1 = await getVideosList(servers[0].url)
300 const videos = res1.body.data
301 const video3 = videos.find(video => video.name === 'my second super name for server 1')
303 // resume with the test
304 const reason3 = 'my super bad reason 3'
305 await reportAbuse({ url: servers[0].url, token: servers[0].accessToken, videoId: video3.id, reason: reason3 })
307 const reason4 = 'my super bad reason 4'
308 await reportAbuse({ url: servers[0].url, token: userAccessToken, videoId: servers[0].video.id, reason: reason4 })
311 const res2 = await getAdminAbusesList({ url: servers[0].url, token: servers[0].accessToken })
312 const abuses = res2.body.data as AdminAbuse[]
314 const abuseVideo3 = res2.body.data.find(a => a.video.id === video3.id)
315 expect(abuseVideo3).to.not.be.undefined
316 expect(abuseVideo3.video.countReports).to.equal(1, "wrong reports count for video 3")
317 expect(abuseVideo3.video.nthReport).to.equal(1, "wrong report position in report list for video 3")
318 expect(abuseVideo3.countReportsForReportee).to.equal(1, "wrong reports count for reporter on video 3 abuse")
319 expect(abuseVideo3.countReportsForReporter).to.equal(3, "wrong reports count for reportee on video 3 abuse")
321 const abuseServer1 = abuses.find(a => a.video.id === servers[0].video.id)
322 expect(abuseServer1.countReportsForReportee).to.equal(3, "wrong reports count for reporter on video 1 abuse")
326 it('Should list predefined reasons as well as timestamps for the reported video', async function () {
329 const reason5 = 'my super bad reason 5'
330 const predefinedReasons5: AbusePredefinedReasonsString[] = [ 'violentOrRepulsive', 'captions' ]
331 const createdAbuse = (await reportAbuse({
333 token: servers[0].accessToken,
334 videoId: servers[0].video.id,
336 predefinedReasons: predefinedReasons5,
341 const res = await getAdminAbusesList({ url: servers[0].url, token: servers[0].accessToken })
344 const abuse = (res.body.data as AdminAbuse[]).find(a => a.id === createdAbuse.id)
345 expect(abuse.reason).to.equals(reason5)
346 expect(abuse.predefinedReasons).to.deep.equals(predefinedReasons5, "predefined reasons do not match the one reported")
347 expect(abuse.video.startAt).to.equal(1, "starting timestamp doesn't match the one reported")
348 expect(abuse.video.endAt).to.equal(5, "ending timestamp doesn't match the one reported")
352 it('Should delete the video abuse', async function () {
355 await deleteAbuse(servers[1].url, servers[1].accessToken, abuseServer2.id)
357 await waitJobs(servers)
360 const res = await getAdminAbusesList({ url: servers[1].url, token: servers[1].accessToken })
361 expect(res.body.total).to.equal(1)
362 expect(res.body.data.length).to.equal(1)
363 expect(res.body.data[0].id).to.not.equal(abuseServer2.id)
367 const res = await getAdminAbusesList({ url: servers[0].url, token: servers[0].accessToken })
368 expect(res.body.total).to.equal(6)
372 it('Should list and filter video abuses', async function () {
375 async function list (query: Omit<Parameters<typeof getAdminAbusesList>[0], 'url' | 'token'>) {
378 token: servers[0].accessToken
381 Object.assign(options, query)
383 const res = await getAdminAbusesList(options)
385 return res.body.data as AdminAbuse[]
388 expect(await list({ id: 56 })).to.have.lengthOf(0)
389 expect(await list({ id: 1 })).to.have.lengthOf(1)
391 expect(await list({ search: 'my super name for server 1' })).to.have.lengthOf(4)
392 expect(await list({ search: 'aaaaaaaaaaaaaaaaaaaaaaaaaa' })).to.have.lengthOf(0)
394 expect(await list({ searchVideo: 'my second super name for server 1' })).to.have.lengthOf(1)
396 expect(await list({ searchVideoChannel: 'root' })).to.have.lengthOf(4)
397 expect(await list({ searchVideoChannel: 'aaaa' })).to.have.lengthOf(0)
399 expect(await list({ searchReporter: 'user2' })).to.have.lengthOf(1)
400 expect(await list({ searchReporter: 'root' })).to.have.lengthOf(5)
402 expect(await list({ searchReportee: 'root' })).to.have.lengthOf(5)
403 expect(await list({ searchReportee: 'aaaa' })).to.have.lengthOf(0)
405 expect(await list({ videoIs: 'deleted' })).to.have.lengthOf(1)
406 expect(await list({ videoIs: 'blacklisted' })).to.have.lengthOf(0)
408 expect(await list({ state: AbuseState.ACCEPTED })).to.have.lengthOf(0)
409 expect(await list({ state: AbuseState.PENDING })).to.have.lengthOf(6)
411 expect(await list({ predefinedReason: 'violentOrRepulsive' })).to.have.lengthOf(1)
412 expect(await list({ predefinedReason: 'serverRules' })).to.have.lengthOf(0)
416 describe('Comment abuses', function () {
418 async function getComment (url: string, videoIdArg: number | string) {
419 const videoId = typeof videoIdArg === 'string'
420 ? await getVideoIdFromUUID(url, videoIdArg)
423 const res = await getVideoCommentThreads(url, videoId, 0, 5)
425 return res.body.data[0] as VideoComment
428 before(async function () {
431 servers[0].video = await uploadVideoAndGetId({ server: servers[0], videoName: 'server 1' })
432 servers[1].video = await uploadVideoAndGetId({ server: servers[1], videoName: 'server 2' })
434 await addVideoCommentThread(servers[0].url, servers[0].accessToken, servers[0].video.id, 'comment server 1')
435 await addVideoCommentThread(servers[1].url, servers[1].accessToken, servers[1].video.id, 'comment server 2')
437 await waitJobs(servers)
440 it('Should report abuse on a comment', async function () {
443 const comment = await getComment(servers[0].url, servers[0].video.id)
445 const reason = 'it is a bad comment'
446 await reportAbuse({ url: servers[0].url, token: servers[0].accessToken, commentId: comment.id, reason })
448 await waitJobs(servers)
451 it('Should have 1 comment abuse on server 1 and 0 on server 2', async function () {
453 const comment = await getComment(servers[0].url, servers[0].video.id)
454 const res = await getAdminAbusesList({ url: servers[0].url, token: servers[0].accessToken, filter: 'comment' })
456 expect(res.body.total).to.equal(1)
457 expect(res.body.data).to.have.lengthOf(1)
459 const abuse: AdminAbuse = res.body.data[0]
460 expect(abuse.reason).to.equal('it is a bad comment')
462 expect(abuse.reporterAccount.name).to.equal('root')
463 expect(abuse.reporterAccount.host).to.equal(servers[0].host)
465 expect(abuse.video).to.be.null
467 expect(abuse.comment.deleted).to.be.false
468 expect(abuse.comment.id).to.equal(comment.id)
469 expect(abuse.comment.text).to.equal(comment.text)
470 expect(abuse.comment.video.name).to.equal('server 1')
471 expect(abuse.comment.video.id).to.equal(servers[0].video.id)
472 expect(abuse.comment.video.uuid).to.equal(servers[0].video.uuid)
474 expect(abuse.countReportsForReporter).to.equal(5)
475 expect(abuse.countReportsForReportee).to.equal(5)
479 const res = await getAdminAbusesList({ url: servers[1].url, token: servers[1].accessToken, filter: 'comment' })
480 expect(res.body.total).to.equal(0)
481 expect(res.body.data.length).to.equal(0)
485 it('Should report abuse on a remote comment', async function () {
488 const comment = await getComment(servers[0].url, servers[1].video.uuid)
490 const reason = 'it is a really bad comment'
491 await reportAbuse({ url: servers[0].url, token: servers[0].accessToken, commentId: comment.id, reason })
493 await waitJobs(servers)
496 it('Should have 2 comment abuses on server 1 and 1 on server 2', async function () {
497 const commentServer2 = await getComment(servers[0].url, servers[1].video.id)
499 const res1 = await getAdminAbusesList({ url: servers[0].url, token: servers[0].accessToken, filter: 'comment' })
500 expect(res1.body.total).to.equal(2)
501 expect(res1.body.data.length).to.equal(2)
503 const abuse: AdminAbuse = res1.body.data[0]
504 expect(abuse.reason).to.equal('it is a bad comment')
505 expect(abuse.countReportsForReporter).to.equal(6)
506 expect(abuse.countReportsForReportee).to.equal(5)
508 const abuse2: AdminAbuse = res1.body.data[1]
510 expect(abuse2.reason).to.equal('it is a really bad comment')
512 expect(abuse2.reporterAccount.name).to.equal('root')
513 expect(abuse2.reporterAccount.host).to.equal(servers[0].host)
515 expect(abuse2.video).to.be.null
517 expect(abuse2.comment.deleted).to.be.false
518 expect(abuse2.comment.id).to.equal(commentServer2.id)
519 expect(abuse2.comment.text).to.equal(commentServer2.text)
520 expect(abuse2.comment.video.name).to.equal('server 2')
521 expect(abuse2.comment.video.uuid).to.equal(servers[1].video.uuid)
523 expect(abuse2.state.id).to.equal(AbuseState.PENDING)
524 expect(abuse2.state.label).to.equal('Pending')
526 expect(abuse2.moderationComment).to.be.null
528 expect(abuse2.countReportsForReporter).to.equal(6)
529 expect(abuse2.countReportsForReportee).to.equal(2)
531 const res2 = await getAdminAbusesList({ url: servers[1].url, token: servers[1].accessToken, filter: 'comment' })
532 expect(res2.body.total).to.equal(1)
533 expect(res2.body.data.length).to.equal(1)
535 abuseServer2 = res2.body.data[0]
536 expect(abuseServer2.reason).to.equal('it is a really bad comment')
537 expect(abuseServer2.reporterAccount.name).to.equal('root')
538 expect(abuseServer2.reporterAccount.host).to.equal(servers[0].host)
540 expect(abuseServer2.state.id).to.equal(AbuseState.PENDING)
541 expect(abuseServer2.state.label).to.equal('Pending')
543 expect(abuseServer2.moderationComment).to.be.null
545 expect(abuseServer2.countReportsForReporter).to.equal(1)
546 expect(abuseServer2.countReportsForReportee).to.equal(1)
549 it('Should keep the comment abuse when deleting the comment', async function () {
552 const commentServer2 = await getComment(servers[0].url, servers[1].video.id)
554 await deleteVideoComment(servers[0].url, servers[0].accessToken, servers[1].video.uuid, commentServer2.id)
556 await waitJobs(servers)
558 const res = await getAdminAbusesList({ url: servers[0].url, token: servers[0].accessToken, filter: 'comment' })
559 expect(res.body.total).to.equal(2)
560 expect(res.body.data).to.have.lengthOf(2)
562 const abuse = (res.body.data as AdminAbuse[]).find(a => a.comment?.id === commentServer2.id)
563 expect(abuse).to.not.be.undefined
565 expect(abuse.comment.text).to.be.empty
566 expect(abuse.comment.video.name).to.equal('server 2')
567 expect(abuse.comment.deleted).to.be.true
570 it('Should delete the comment abuse', async function () {
573 await deleteAbuse(servers[1].url, servers[1].accessToken, abuseServer2.id)
575 await waitJobs(servers)
578 const res = await getAdminAbusesList({ url: servers[1].url, token: servers[1].accessToken, filter: 'comment' })
579 expect(res.body.total).to.equal(0)
580 expect(res.body.data.length).to.equal(0)
584 const res = await getAdminAbusesList({ url: servers[0].url, token: servers[0].accessToken, filter: 'comment' })
585 expect(res.body.total).to.equal(2)
589 it('Should list and filter video abuses', async function () {
591 const res = await getAdminAbusesList({
593 token: servers[0].accessToken,
595 searchReportee: 'foo'
597 expect(res.body.total).to.equal(0)
601 const res = await getAdminAbusesList({
603 token: servers[0].accessToken,
607 expect(res.body.total).to.equal(2)
611 const baseParams = { url: servers[0].url, token: servers[0].accessToken, filter: 'comment' as AbuseFilter, start: 1, count: 1 }
613 const res1 = await getAdminAbusesList(immutableAssign(baseParams, { sort: 'createdAt' }))
614 expect(res1.body.data).to.have.lengthOf(1)
615 expect(res1.body.data[0].comment.text).to.be.empty
617 const res2 = await getAdminAbusesList(immutableAssign(baseParams, { sort: '-createdAt' }))
618 expect(res2.body.data).to.have.lengthOf(1)
619 expect(res2.body.data[0].comment.text).to.equal('comment server 1')
624 describe('Account abuses', function () {
626 async function getAccountFromServer (url: string, name: string, server: ServerInfo) {
627 const res = await getAccount(url, name + '@' + server.host)
629 return res.body as Account
632 before(async function () {
635 await createUser({ url: servers[0].url, accessToken: servers[0].accessToken, username: 'user_1', password: 'donald' })
637 const token = await generateUserAccessToken(servers[1], 'user_2')
638 await uploadVideo(servers[1].url, token, { name: 'super video' })
640 await waitJobs(servers)
643 it('Should report abuse on an account', async function () {
646 const account = await getAccountFromServer(servers[0].url, 'user_1', servers[0])
648 const reason = 'it is a bad account'
649 await reportAbuse({ url: servers[0].url, token: servers[0].accessToken, accountId: account.id, reason })
651 await waitJobs(servers)
654 it('Should have 1 account abuse on server 1 and 0 on server 2', async function () {
656 const res = await getAdminAbusesList({ url: servers[0].url, token: servers[0].accessToken, filter: 'account' })
658 expect(res.body.total).to.equal(1)
659 expect(res.body.data).to.have.lengthOf(1)
661 const abuse: AdminAbuse = res.body.data[0]
662 expect(abuse.reason).to.equal('it is a bad account')
664 expect(abuse.reporterAccount.name).to.equal('root')
665 expect(abuse.reporterAccount.host).to.equal(servers[0].host)
667 expect(abuse.video).to.be.null
668 expect(abuse.comment).to.be.null
670 expect(abuse.flaggedAccount.name).to.equal('user_1')
671 expect(abuse.flaggedAccount.host).to.equal(servers[0].host)
675 const res = await getAdminAbusesList({ url: servers[1].url, token: servers[1].accessToken, filter: 'comment' })
676 expect(res.body.total).to.equal(0)
677 expect(res.body.data.length).to.equal(0)
681 it('Should report abuse on a remote account', async function () {
684 const account = await getAccountFromServer(servers[0].url, 'user_2', servers[1])
686 const reason = 'it is a really bad account'
687 await reportAbuse({ url: servers[0].url, token: servers[0].accessToken, accountId: account.id, reason })
689 await waitJobs(servers)
692 it('Should have 2 comment abuses on server 1 and 1 on server 2', async function () {
693 const res1 = await getAdminAbusesList({ url: servers[0].url, token: servers[0].accessToken, filter: 'account' })
694 expect(res1.body.total).to.equal(2)
695 expect(res1.body.data.length).to.equal(2)
697 const abuse: AdminAbuse = res1.body.data[0]
698 expect(abuse.reason).to.equal('it is a bad account')
700 const abuse2: AdminAbuse = res1.body.data[1]
701 expect(abuse2.reason).to.equal('it is a really bad account')
703 expect(abuse2.reporterAccount.name).to.equal('root')
704 expect(abuse2.reporterAccount.host).to.equal(servers[0].host)
706 expect(abuse2.video).to.be.null
707 expect(abuse2.comment).to.be.null
709 expect(abuse2.state.id).to.equal(AbuseState.PENDING)
710 expect(abuse2.state.label).to.equal('Pending')
712 expect(abuse2.moderationComment).to.be.null
714 const res2 = await getAdminAbusesList({ url: servers[1].url, token: servers[1].accessToken, filter: 'account' })
715 expect(res2.body.total).to.equal(1)
716 expect(res2.body.data.length).to.equal(1)
718 abuseServer2 = res2.body.data[0]
720 expect(abuseServer2.reason).to.equal('it is a really bad account')
722 expect(abuseServer2.reporterAccount.name).to.equal('root')
723 expect(abuseServer2.reporterAccount.host).to.equal(servers[0].host)
725 expect(abuseServer2.state.id).to.equal(AbuseState.PENDING)
726 expect(abuseServer2.state.label).to.equal('Pending')
728 expect(abuseServer2.moderationComment).to.be.null
731 it('Should keep the account abuse when deleting the account', async function () {
734 const account = await getAccountFromServer(servers[1].url, 'user_2', servers[1])
735 await removeUser(servers[1].url, account.userId, servers[1].accessToken)
737 await waitJobs(servers)
739 const res = await getAdminAbusesList({ url: servers[0].url, token: servers[0].accessToken, filter: 'account' })
740 expect(res.body.total).to.equal(2)
741 expect(res.body.data).to.have.lengthOf(2)
743 const abuse = (res.body.data as AdminAbuse[]).find(a => a.reason === 'it is a really bad account')
744 expect(abuse).to.not.be.undefined
747 it('Should delete the account abuse', async function () {
750 await deleteAbuse(servers[1].url, servers[1].accessToken, abuseServer2.id)
752 await waitJobs(servers)
755 const res = await getAdminAbusesList({ url: servers[1].url, token: servers[1].accessToken, filter: 'account' })
756 expect(res.body.total).to.equal(0)
757 expect(res.body.data.length).to.equal(0)
761 const res = await getAdminAbusesList({ url: servers[0].url, token: servers[0].accessToken, filter: 'account' })
762 expect(res.body.total).to.equal(2)
764 abuseServer1 = res.body.data[0]
769 describe('Common actions on abuses', function () {
771 it('Should update the state of an abuse', async function () {
772 const body = { state: AbuseState.REJECTED }
773 await updateAbuse(servers[0].url, servers[0].accessToken, abuseServer1.id, body)
775 const res = await getAdminAbusesList({ url: servers[0].url, token: servers[0].accessToken, id: abuseServer1.id })
776 expect(res.body.data[0].state.id).to.equal(AbuseState.REJECTED)
779 it('Should add a moderation comment', async function () {
780 const body = { state: AbuseState.ACCEPTED, moderationComment: 'It is valid' }
781 await updateAbuse(servers[0].url, servers[0].accessToken, abuseServer1.id, body)
783 const res = await getAdminAbusesList({ url: servers[0].url, token: servers[0].accessToken, id: abuseServer1.id })
784 expect(res.body.data[0].state.id).to.equal(AbuseState.ACCEPTED)
785 expect(res.body.data[0].moderationComment).to.equal('It is valid')
789 describe('My abuses', async function () {
791 let userAccessToken: string
793 before(async function () {
794 userAccessToken = await generateUserAccessToken(servers[0], 'user_42')
796 await reportAbuse({ url: servers[0].url, token: userAccessToken, videoId: servers[0].video.id, reason: 'user reason 1' })
798 const videoId = await getVideoIdFromUUID(servers[0].url, servers[1].video.uuid)
799 await reportAbuse({ url: servers[0].url, token: userAccessToken, videoId, reason: 'user reason 2' })
802 it('Should correctly list my abuses', async function () {
804 const res = await getUserAbusesList({ url: servers[0].url, token: userAccessToken, start: 0, count: 5, sort: 'createdAt' })
805 expect(res.body.total).to.equal(2)
807 const abuses: UserAbuse[] = res.body.data
808 expect(abuses[0].reason).to.equal('user reason 1')
809 expect(abuses[1].reason).to.equal('user reason 2')
811 abuseId1 = abuses[0].id
815 const res = await getUserAbusesList({ url: servers[0].url, token: userAccessToken, start: 1, count: 1, sort: 'createdAt' })
816 expect(res.body.total).to.equal(2)
818 const abuses: UserAbuse[] = res.body.data
819 expect(abuses[0].reason).to.equal('user reason 2')
823 const res = await getUserAbusesList({ url: servers[0].url, token: userAccessToken, start: 1, count: 1, sort: '-createdAt' })
824 expect(res.body.total).to.equal(2)
826 const abuses: UserAbuse[] = res.body.data
827 expect(abuses[0].reason).to.equal('user reason 1')
831 it('Should correctly filter my abuses by id', async function () {
832 const res = await getUserAbusesList({ url: servers[0].url, token: userAccessToken, id: abuseId1 })
834 expect(res.body.total).to.equal(1)
836 const abuses: UserAbuse[] = res.body.data
837 expect(abuses[0].reason).to.equal('user reason 1')
840 it('Should correctly filter my abuses by search', async function () {
841 const res = await getUserAbusesList({
843 token: userAccessToken,
847 expect(res.body.total).to.equal(1)
849 const abuses: UserAbuse[] = res.body.data
850 expect(abuses[0].reason).to.equal('user reason 2')
853 it('Should correctly filter my abuses by state', async function () {
854 const body = { state: AbuseState.REJECTED }
855 await updateAbuse(servers[0].url, servers[0].accessToken, abuseId1, body)
857 const res = await getUserAbusesList({
859 token: userAccessToken,
860 state: AbuseState.REJECTED
863 expect(res.body.total).to.equal(1)
865 const abuses: UserAbuse[] = res.body.data
866 expect(abuses[0].reason).to.equal('user reason 1')
870 describe('Abuse messages', async function () {
872 let userAccessToken: string
873 let abuseMessageUserId: number
874 let abuseMessageModerationId: number
876 before(async function () {
877 userAccessToken = await generateUserAccessToken(servers[0], 'user_43')
879 const res = await reportAbuse({
881 token: userAccessToken,
882 videoId: servers[0].video.id,
883 reason: 'user 43 reason 1'
886 abuseId = res.body.abuse.id
889 it('Should create some messages on the abuse', async function () {
890 await addAbuseMessage(servers[0].url, userAccessToken, abuseId, 'message 1')
891 await addAbuseMessage(servers[0].url, servers[0].accessToken, abuseId, 'message 2')
892 await addAbuseMessage(servers[0].url, servers[0].accessToken, abuseId, 'message 3')
893 await addAbuseMessage(servers[0].url, userAccessToken, abuseId, 'message 4')
896 it('Should have the correct messages count when listing abuses', async function () {
897 const results = await Promise.all([
898 getAdminAbusesList({ url: servers[0].url, token: servers[0].accessToken, start: 0, count: 50 }),
899 getUserAbusesList({ url: servers[0].url, token: userAccessToken, start: 0, count: 50 })
902 for (const res of results) {
903 const abuses: AdminAbuse[] = res.body.data
904 const abuse = abuses.find(a => a.id === abuseId)
905 expect(abuse.countMessages).to.equal(4)
909 it('Should correctly list messages of this abuse', async function () {
910 const results = await Promise.all([
911 listAbuseMessages(servers[0].url, servers[0].accessToken, abuseId),
912 listAbuseMessages(servers[0].url, userAccessToken, abuseId)
915 for (const res of results) {
916 expect(res.body.total).to.equal(4)
918 const abuseMessages: AbuseMessage[] = res.body.data
920 expect(abuseMessages[0].message).to.equal('message 1')
921 expect(abuseMessages[0].byModerator).to.be.false
922 expect(abuseMessages[0].account.name).to.equal('user_43')
924 abuseMessageUserId = abuseMessages[0].id
926 expect(abuseMessages[1].message).to.equal('message 2')
927 expect(abuseMessages[1].byModerator).to.be.true
928 expect(abuseMessages[1].account.name).to.equal('root')
930 expect(abuseMessages[2].message).to.equal('message 3')
931 expect(abuseMessages[2].byModerator).to.be.true
932 expect(abuseMessages[2].account.name).to.equal('root')
933 abuseMessageModerationId = abuseMessages[2].id
935 expect(abuseMessages[3].message).to.equal('message 4')
936 expect(abuseMessages[3].byModerator).to.be.false
937 expect(abuseMessages[3].account.name).to.equal('user_43')
941 it('Should delete messages', async function () {
942 await deleteAbuseMessage(servers[0].url, servers[0].accessToken, abuseId, abuseMessageModerationId)
943 await deleteAbuseMessage(servers[0].url, userAccessToken, abuseId, abuseMessageUserId)
945 const results = await Promise.all([
946 listAbuseMessages(servers[0].url, servers[0].accessToken, abuseId),
947 listAbuseMessages(servers[0].url, userAccessToken, abuseId)
950 for (const res of results) {
951 expect(res.body.total).to.equal(2)
953 const abuseMessages: AbuseMessage[] = res.body.data
955 expect(abuseMessages[0].message).to.equal('message 2')
956 expect(abuseMessages[1].message).to.equal('message 4')
961 after(async function () {
962 await cleanupTests(servers)