1 /* tslint:disable:no-unused-expression */
3 import * as chai from 'chai'
5 import { VideoAbuse, VideoAbuseState } from '../../../../shared/models/videos'
9 flushAndRunMultipleServers,
14 setAccessTokensToServers,
17 } from '../../../../shared/extra-utils/index'
18 import { doubleFollow } from '../../../../shared/extra-utils/server/follows'
19 import { waitJobs } from '../../../../shared/extra-utils/server/jobs'
21 addAccountToServerBlocklist,
22 addServerToServerBlocklist,
23 removeAccountFromServerBlocklist,
24 removeServerFromServerBlocklist
25 } from '../../../../shared/extra-utils/users/blocklist'
27 const expect = chai.expect
29 describe('Test video abuses', function () {
30 let servers: ServerInfo[] = []
31 let abuseServer2: VideoAbuse
33 before(async function () {
37 servers = await flushAndRunMultipleServers(2)
39 // Get the access tokens
40 await setAccessTokensToServers(servers)
42 // Server 1 and server 2 follow each other
43 await doubleFollow(servers[0], servers[1])
45 // Upload some videos on each servers
46 const video1Attributes = {
47 name: 'my super name for server 1',
48 description: 'my super description for server 1'
50 await uploadVideo(servers[0].url, servers[0].accessToken, video1Attributes)
52 const video2Attributes = {
53 name: 'my super name for server 2',
54 description: 'my super description for server 2'
56 await uploadVideo(servers[1].url, servers[1].accessToken, video2Attributes)
58 // Wait videos propagation, server 2 has transcoding enabled
59 await waitJobs(servers)
61 const res = await getVideosList(servers[0].url)
62 const videos = res.body.data
64 expect(videos.length).to.equal(2)
66 servers[0].video = videos.find(video => video.name === 'my super name for server 1')
67 servers[1].video = videos.find(video => video.name === 'my super name for server 2')
70 it('Should not have video abuses', async function () {
71 const res = await getVideoAbusesList(servers[0].url, servers[0].accessToken)
73 expect(res.body.total).to.equal(0)
74 expect(res.body.data).to.be.an('array')
75 expect(res.body.data.length).to.equal(0)
78 it('Should report abuse on a local video', async function () {
81 const reason = 'my super bad reason'
82 await reportVideoAbuse(servers[0].url, servers[0].accessToken, servers[0].video.id, reason)
84 // We wait requests propagation, even if the server 1 is not supposed to make a request to server 2
85 await waitJobs(servers)
88 it('Should have 1 video abuses on server 1 and 0 on server 2', async function () {
89 const res1 = await getVideoAbusesList(servers[0].url, servers[0].accessToken)
91 expect(res1.body.total).to.equal(1)
92 expect(res1.body.data).to.be.an('array')
93 expect(res1.body.data.length).to.equal(1)
95 const abuse: VideoAbuse = res1.body.data[0]
96 expect(abuse.reason).to.equal('my super bad reason')
97 expect(abuse.reporterAccount.name).to.equal('root')
98 expect(abuse.reporterAccount.host).to.equal('localhost:' + servers[0].port)
99 expect(abuse.video.id).to.equal(servers[0].video.id)
101 const res2 = await getVideoAbusesList(servers[1].url, servers[1].accessToken)
102 expect(res2.body.total).to.equal(0)
103 expect(res2.body.data).to.be.an('array')
104 expect(res2.body.data.length).to.equal(0)
107 it('Should report abuse on a remote video', async function () {
110 const reason = 'my super bad reason 2'
111 await reportVideoAbuse(servers[0].url, servers[0].accessToken, servers[1].video.id, reason)
113 // We wait requests propagation
114 await waitJobs(servers)
117 it('Should have 2 video abuses on server 1 and 1 on server 2', async function () {
118 const res1 = await getVideoAbusesList(servers[0].url, servers[0].accessToken)
119 expect(res1.body.total).to.equal(2)
120 expect(res1.body.data).to.be.an('array')
121 expect(res1.body.data.length).to.equal(2)
123 const abuse1: VideoAbuse = res1.body.data[0]
124 expect(abuse1.reason).to.equal('my super bad reason')
125 expect(abuse1.reporterAccount.name).to.equal('root')
126 expect(abuse1.reporterAccount.host).to.equal('localhost:' + servers[0].port)
127 expect(abuse1.video.id).to.equal(servers[0].video.id)
128 expect(abuse1.state.id).to.equal(VideoAbuseState.PENDING)
129 expect(abuse1.state.label).to.equal('Pending')
130 expect(abuse1.moderationComment).to.be.null
132 const abuse2: VideoAbuse = res1.body.data[1]
133 expect(abuse2.reason).to.equal('my super bad reason 2')
134 expect(abuse2.reporterAccount.name).to.equal('root')
135 expect(abuse2.reporterAccount.host).to.equal('localhost:' + servers[0].port)
136 expect(abuse2.video.id).to.equal(servers[1].video.id)
137 expect(abuse2.state.id).to.equal(VideoAbuseState.PENDING)
138 expect(abuse2.state.label).to.equal('Pending')
139 expect(abuse2.moderationComment).to.be.null
141 const res2 = await getVideoAbusesList(servers[1].url, servers[1].accessToken)
142 expect(res2.body.total).to.equal(1)
143 expect(res2.body.data).to.be.an('array')
144 expect(res2.body.data.length).to.equal(1)
146 abuseServer2 = res2.body.data[0]
147 expect(abuseServer2.reason).to.equal('my super bad reason 2')
148 expect(abuseServer2.reporterAccount.name).to.equal('root')
149 expect(abuseServer2.reporterAccount.host).to.equal('localhost:' + servers[0].port)
150 expect(abuseServer2.state.id).to.equal(VideoAbuseState.PENDING)
151 expect(abuseServer2.state.label).to.equal('Pending')
152 expect(abuseServer2.moderationComment).to.be.null
155 it('Should update the state of a video abuse', async function () {
156 const body = { state: VideoAbuseState.REJECTED }
157 await updateVideoAbuse(servers[1].url, servers[1].accessToken, abuseServer2.video.uuid, abuseServer2.id, body)
159 const res = await getVideoAbusesList(servers[1].url, servers[1].accessToken)
160 expect(res.body.data[0].state.id).to.equal(VideoAbuseState.REJECTED)
163 it('Should add a moderation comment', async function () {
164 const body = { state: VideoAbuseState.ACCEPTED, moderationComment: 'It is valid' }
165 await updateVideoAbuse(servers[1].url, servers[1].accessToken, abuseServer2.video.uuid, abuseServer2.id, body)
167 const res = await getVideoAbusesList(servers[1].url, servers[1].accessToken)
168 expect(res.body.data[0].state.id).to.equal(VideoAbuseState.ACCEPTED)
169 expect(res.body.data[0].moderationComment).to.equal('It is valid')
172 it('Should hide video abuses from blocked accounts', async function () {
176 await reportVideoAbuse(servers[1].url, servers[1].accessToken, servers[0].video.uuid, 'will mute this')
177 await waitJobs(servers)
179 const res = await getVideoAbusesList(servers[0].url, servers[0].accessToken)
180 expect(res.body.total).to.equal(3)
183 const accountToBlock = 'root@localhost:' + servers[1].port
186 await addAccountToServerBlocklist(servers[ 0 ].url, servers[ 0 ].accessToken, accountToBlock)
188 const res = await getVideoAbusesList(servers[ 0 ].url, servers[ 0 ].accessToken)
189 expect(res.body.total).to.equal(2)
191 const abuse = res.body.data.find(a => a.reason === 'will mute this')
192 expect(abuse).to.be.undefined
196 await removeAccountFromServerBlocklist(servers[ 0 ].url, servers[ 0 ].accessToken, accountToBlock)
198 const res = await getVideoAbusesList(servers[ 0 ].url, servers[ 0 ].accessToken)
199 expect(res.body.total).to.equal(3)
203 it('Should hide video abuses from blocked servers', async function () {
204 const serverToBlock = servers[1].host
207 await addServerToServerBlocklist(servers[ 0 ].url, servers[ 0 ].accessToken, servers[1].host)
209 const res = await getVideoAbusesList(servers[ 0 ].url, servers[ 0 ].accessToken)
210 expect(res.body.total).to.equal(2)
212 const abuse = res.body.data.find(a => a.reason === 'will mute this')
213 expect(abuse).to.be.undefined
217 await removeServerFromServerBlocklist(servers[ 0 ].url, servers[ 0 ].accessToken, serverToBlock)
219 const res = await getVideoAbusesList(servers[ 0 ].url, servers[ 0 ].accessToken)
220 expect(res.body.total).to.equal(3)
224 it('Should delete the video abuse', async function () {
227 await deleteVideoAbuse(servers[1].url, servers[1].accessToken, abuseServer2.video.uuid, abuseServer2.id)
229 await waitJobs(servers)
232 const res = await getVideoAbusesList(servers[1].url, servers[1].accessToken)
233 expect(res.body.total).to.equal(1)
234 expect(res.body.data.length).to.equal(1)
235 expect(res.body.data[0].id).to.not.equal(abuseServer2.id)
239 const res = await getVideoAbusesList(servers[0].url, servers[0].accessToken)
240 expect(res.body.total).to.equal(3)
244 after(async function () {
245 await cleanupTests(servers)