]>
Commit | Line | Data |
---|---|---|
a1587156 | 1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ |
0e1dc3e7 | 2 | |
afffe988 | 3 | import 'mocha' |
d95d1559 | 4 | import * as chai from 'chai' |
edbc9325 | 5 | import { AbusePredefinedReasonsString, AbuseState, AdminAbuse } from '@shared/models' |
0e1dc3e7 | 6 | import { |
7c3b7976 | 7 | cleanupTests, |
d95d1559 | 8 | createUser, |
268eebed | 9 | deleteVideoAbuse, |
0e1dc3e7 | 10 | flushAndRunMultipleServers, |
0e1dc3e7 | 11 | getVideoAbusesList, |
afffe988 | 12 | getVideosList, |
d95d1559 | 13 | removeVideo, |
afffe988 C |
14 | reportVideoAbuse, |
15 | ServerInfo, | |
16 | setAccessTokensToServers, | |
268eebed | 17 | updateVideoAbuse, |
197876ea | 18 | uploadVideo, |
d1261d9a | 19 | userLogin |
94565d52 C |
20 | } from '../../../../shared/extra-utils/index' |
21 | import { doubleFollow } from '../../../../shared/extra-utils/server/follows' | |
22 | import { waitJobs } from '../../../../shared/extra-utils/server/jobs' | |
f0a47bc9 C |
23 | import { |
24 | addAccountToServerBlocklist, | |
25 | addServerToServerBlocklist, | |
26 | removeAccountFromServerBlocklist, | |
27 | removeServerFromServerBlocklist | |
28 | } from '../../../../shared/extra-utils/users/blocklist' | |
afffe988 C |
29 | |
30 | const expect = chai.expect | |
0e1dc3e7 | 31 | |
d95d1559 C |
32 | // FIXME: deprecated in 2.3. Remove this controller |
33 | ||
0e1dc3e7 C |
34 | describe('Test video abuses', function () { |
35 | let servers: ServerInfo[] = [] | |
edbc9325 | 36 | let abuseServer2: AdminAbuse |
0e1dc3e7 C |
37 | |
38 | before(async function () { | |
572f8d3d | 39 | this.timeout(50000) |
0e1dc3e7 C |
40 | |
41 | // Run servers | |
42 | servers = await flushAndRunMultipleServers(2) | |
43 | ||
44 | // Get the access tokens | |
45 | await setAccessTokensToServers(servers) | |
46 | ||
afffe988 C |
47 | // Server 1 and server 2 follow each other |
48 | await doubleFollow(servers[0], servers[1]) | |
0e1dc3e7 | 49 | |
afffe988 | 50 | // Upload some videos on each servers |
0e1dc3e7 | 51 | const video1Attributes = { |
afffe988 C |
52 | name: 'my super name for server 1', |
53 | description: 'my super description for server 1' | |
0e1dc3e7 C |
54 | } |
55 | await uploadVideo(servers[0].url, servers[0].accessToken, video1Attributes) | |
56 | ||
57 | const video2Attributes = { | |
afffe988 C |
58 | name: 'my super name for server 2', |
59 | description: 'my super description for server 2' | |
0e1dc3e7 C |
60 | } |
61 | await uploadVideo(servers[1].url, servers[1].accessToken, video2Attributes) | |
62 | ||
572f8d3d | 63 | // Wait videos propagation, server 2 has transcoding enabled |
3cd0734f | 64 | await waitJobs(servers) |
0e1dc3e7 C |
65 | |
66 | const res = await getVideosList(servers[0].url) | |
67 | const videos = res.body.data | |
68 | ||
69 | expect(videos.length).to.equal(2) | |
70 | ||
afffe988 C |
71 | servers[0].video = videos.find(video => video.name === 'my super name for server 1') |
72 | servers[1].video = videos.find(video => video.name === 'my super name for server 2') | |
0e1dc3e7 C |
73 | }) |
74 | ||
75 | it('Should not have video abuses', async function () { | |
feb34f6b | 76 | const res = await getVideoAbusesList({ url: servers[0].url, token: servers[0].accessToken }) |
0e1dc3e7 C |
77 | |
78 | expect(res.body.total).to.equal(0) | |
79 | expect(res.body.data).to.be.an('array') | |
80 | expect(res.body.data.length).to.equal(0) | |
81 | }) | |
82 | ||
83 | it('Should report abuse on a local video', async function () { | |
3cd0734f | 84 | this.timeout(15000) |
0e1dc3e7 C |
85 | |
86 | const reason = 'my super bad reason' | |
87 | await reportVideoAbuse(servers[0].url, servers[0].accessToken, servers[0].video.id, reason) | |
88 | ||
afffe988 | 89 | // We wait requests propagation, even if the server 1 is not supposed to make a request to server 2 |
3cd0734f | 90 | await waitJobs(servers) |
0e1dc3e7 C |
91 | }) |
92 | ||
afffe988 | 93 | it('Should have 1 video abuses on server 1 and 0 on server 2', async function () { |
feb34f6b | 94 | const res1 = await getVideoAbusesList({ url: servers[0].url, token: servers[0].accessToken }) |
0e1dc3e7 C |
95 | |
96 | expect(res1.body.total).to.equal(1) | |
97 | expect(res1.body.data).to.be.an('array') | |
98 | expect(res1.body.data.length).to.equal(1) | |
99 | ||
edbc9325 | 100 | const abuse: AdminAbuse = res1.body.data[0] |
0e1dc3e7 | 101 | expect(abuse.reason).to.equal('my super bad reason') |
19a3b914 | 102 | expect(abuse.reporterAccount.name).to.equal('root') |
7243f84d | 103 | expect(abuse.reporterAccount.host).to.equal('localhost:' + servers[0].port) |
19a3b914 | 104 | expect(abuse.video.id).to.equal(servers[0].video.id) |
197876ea | 105 | expect(abuse.video.channel).to.exist |
4f32032f C |
106 | expect(abuse.video.countReports).to.equal(1) |
107 | expect(abuse.video.nthReport).to.equal(1) | |
197876ea RK |
108 | expect(abuse.countReportsForReporter).to.equal(1) |
109 | expect(abuse.countReportsForReportee).to.equal(1) | |
0e1dc3e7 | 110 | |
feb34f6b | 111 | const res2 = await getVideoAbusesList({ url: servers[1].url, token: servers[1].accessToken }) |
0e1dc3e7 C |
112 | expect(res2.body.total).to.equal(0) |
113 | expect(res2.body.data).to.be.an('array') | |
114 | expect(res2.body.data.length).to.equal(0) | |
115 | }) | |
116 | ||
117 | it('Should report abuse on a remote video', async function () { | |
572f8d3d | 118 | this.timeout(10000) |
0e1dc3e7 C |
119 | |
120 | const reason = 'my super bad reason 2' | |
121 | await reportVideoAbuse(servers[0].url, servers[0].accessToken, servers[1].video.id, reason) | |
122 | ||
123 | // We wait requests propagation | |
3cd0734f | 124 | await waitJobs(servers) |
0e1dc3e7 C |
125 | }) |
126 | ||
268eebed | 127 | it('Should have 2 video abuses on server 1 and 1 on server 2', async function () { |
feb34f6b | 128 | const res1 = await getVideoAbusesList({ url: servers[0].url, token: servers[0].accessToken }) |
0e1dc3e7 C |
129 | expect(res1.body.total).to.equal(2) |
130 | expect(res1.body.data).to.be.an('array') | |
131 | expect(res1.body.data.length).to.equal(2) | |
132 | ||
edbc9325 | 133 | const abuse1: AdminAbuse = res1.body.data[0] |
0e1dc3e7 | 134 | expect(abuse1.reason).to.equal('my super bad reason') |
19a3b914 | 135 | expect(abuse1.reporterAccount.name).to.equal('root') |
7243f84d | 136 | expect(abuse1.reporterAccount.host).to.equal('localhost:' + servers[0].port) |
19a3b914 | 137 | expect(abuse1.video.id).to.equal(servers[0].video.id) |
d95d1559 | 138 | expect(abuse1.state.id).to.equal(AbuseState.PENDING) |
268eebed C |
139 | expect(abuse1.state.label).to.equal('Pending') |
140 | expect(abuse1.moderationComment).to.be.null | |
4f32032f C |
141 | expect(abuse1.video.countReports).to.equal(1) |
142 | expect(abuse1.video.nthReport).to.equal(1) | |
0e1dc3e7 | 143 | |
edbc9325 | 144 | const abuse2: AdminAbuse = res1.body.data[1] |
0e1dc3e7 | 145 | expect(abuse2.reason).to.equal('my super bad reason 2') |
19a3b914 | 146 | expect(abuse2.reporterAccount.name).to.equal('root') |
7243f84d | 147 | expect(abuse2.reporterAccount.host).to.equal('localhost:' + servers[0].port) |
19a3b914 | 148 | expect(abuse2.video.id).to.equal(servers[1].video.id) |
d95d1559 | 149 | expect(abuse2.state.id).to.equal(AbuseState.PENDING) |
268eebed C |
150 | expect(abuse2.state.label).to.equal('Pending') |
151 | expect(abuse2.moderationComment).to.be.null | |
0e1dc3e7 | 152 | |
feb34f6b | 153 | const res2 = await getVideoAbusesList({ url: servers[1].url, token: servers[1].accessToken }) |
0e1dc3e7 C |
154 | expect(res2.body.total).to.equal(1) |
155 | expect(res2.body.data).to.be.an('array') | |
156 | expect(res2.body.data.length).to.equal(1) | |
157 | ||
268eebed C |
158 | abuseServer2 = res2.body.data[0] |
159 | expect(abuseServer2.reason).to.equal('my super bad reason 2') | |
160 | expect(abuseServer2.reporterAccount.name).to.equal('root') | |
7243f84d | 161 | expect(abuseServer2.reporterAccount.host).to.equal('localhost:' + servers[0].port) |
d95d1559 | 162 | expect(abuseServer2.state.id).to.equal(AbuseState.PENDING) |
268eebed C |
163 | expect(abuseServer2.state.label).to.equal('Pending') |
164 | expect(abuseServer2.moderationComment).to.be.null | |
165 | }) | |
166 | ||
167 | it('Should update the state of a video abuse', async function () { | |
d95d1559 | 168 | const body = { state: AbuseState.REJECTED } |
268eebed C |
169 | await updateVideoAbuse(servers[1].url, servers[1].accessToken, abuseServer2.video.uuid, abuseServer2.id, body) |
170 | ||
feb34f6b | 171 | const res = await getVideoAbusesList({ url: servers[1].url, token: servers[1].accessToken }) |
d95d1559 | 172 | expect(res.body.data[0].state.id).to.equal(AbuseState.REJECTED) |
268eebed C |
173 | }) |
174 | ||
175 | it('Should add a moderation comment', async function () { | |
d95d1559 | 176 | const body = { state: AbuseState.ACCEPTED, moderationComment: 'It is valid' } |
268eebed C |
177 | await updateVideoAbuse(servers[1].url, servers[1].accessToken, abuseServer2.video.uuid, abuseServer2.id, body) |
178 | ||
feb34f6b | 179 | const res = await getVideoAbusesList({ url: servers[1].url, token: servers[1].accessToken }) |
d95d1559 | 180 | expect(res.body.data[0].state.id).to.equal(AbuseState.ACCEPTED) |
268eebed C |
181 | expect(res.body.data[0].moderationComment).to.equal('It is valid') |
182 | }) | |
183 | ||
f0a47bc9 C |
184 | it('Should hide video abuses from blocked accounts', async function () { |
185 | this.timeout(10000) | |
186 | ||
187 | { | |
188 | await reportVideoAbuse(servers[1].url, servers[1].accessToken, servers[0].video.uuid, 'will mute this') | |
189 | await waitJobs(servers) | |
190 | ||
feb34f6b | 191 | const res = await getVideoAbusesList({ url: servers[0].url, token: servers[0].accessToken }) |
f0a47bc9 C |
192 | expect(res.body.total).to.equal(3) |
193 | } | |
194 | ||
195 | const accountToBlock = 'root@localhost:' + servers[1].port | |
196 | ||
197 | { | |
a1587156 | 198 | await addAccountToServerBlocklist(servers[0].url, servers[0].accessToken, accountToBlock) |
f0a47bc9 | 199 | |
feb34f6b | 200 | const res = await getVideoAbusesList({ url: servers[0].url, token: servers[0].accessToken }) |
f0a47bc9 C |
201 | expect(res.body.total).to.equal(2) |
202 | ||
203 | const abuse = res.body.data.find(a => a.reason === 'will mute this') | |
204 | expect(abuse).to.be.undefined | |
205 | } | |
206 | ||
207 | { | |
a1587156 | 208 | await removeAccountFromServerBlocklist(servers[0].url, servers[0].accessToken, accountToBlock) |
f0a47bc9 | 209 | |
feb34f6b | 210 | const res = await getVideoAbusesList({ url: servers[0].url, token: servers[0].accessToken }) |
f0a47bc9 C |
211 | expect(res.body.total).to.equal(3) |
212 | } | |
213 | }) | |
214 | ||
215 | it('Should hide video abuses from blocked servers', async function () { | |
216 | const serverToBlock = servers[1].host | |
217 | ||
218 | { | |
a1587156 | 219 | await addServerToServerBlocklist(servers[0].url, servers[0].accessToken, servers[1].host) |
f0a47bc9 | 220 | |
feb34f6b | 221 | const res = await getVideoAbusesList({ url: servers[0].url, token: servers[0].accessToken }) |
f0a47bc9 C |
222 | expect(res.body.total).to.equal(2) |
223 | ||
224 | const abuse = res.body.data.find(a => a.reason === 'will mute this') | |
225 | expect(abuse).to.be.undefined | |
226 | } | |
227 | ||
228 | { | |
a1587156 | 229 | await removeServerFromServerBlocklist(servers[0].url, servers[0].accessToken, serverToBlock) |
f0a47bc9 | 230 | |
feb34f6b | 231 | const res = await getVideoAbusesList({ url: servers[0].url, token: servers[0].accessToken }) |
f0a47bc9 C |
232 | expect(res.body.total).to.equal(3) |
233 | } | |
234 | }) | |
235 | ||
197876ea RK |
236 | it('Should keep the video abuse when deleting the video', async function () { |
237 | this.timeout(10000) | |
238 | ||
239 | await removeVideo(servers[1].url, servers[1].accessToken, abuseServer2.video.uuid) | |
240 | ||
241 | await waitJobs(servers) | |
242 | ||
feb34f6b | 243 | const res = await getVideoAbusesList({ url: servers[1].url, token: servers[1].accessToken }) |
d1261d9a RK |
244 | expect(res.body.total).to.equal(2, "wrong number of videos returned") |
245 | expect(res.body.data.length).to.equal(2, "wrong number of videos returned") | |
246 | expect(res.body.data[0].id).to.equal(abuseServer2.id, "wrong origin server id for first video") | |
247 | ||
edbc9325 | 248 | const abuse: AdminAbuse = res.body.data[0] |
d1261d9a RK |
249 | expect(abuse.video.id).to.equal(abuseServer2.video.id, "wrong video id") |
250 | expect(abuse.video.channel).to.exist | |
251 | expect(abuse.video.deleted).to.be.true | |
252 | }) | |
253 | ||
254 | it('Should include counts of reports from reporter and reportee', async function () { | |
255 | this.timeout(10000) | |
197876ea | 256 | |
d1261d9a RK |
257 | // register a second user to have two reporters/reportees |
258 | const user = { username: 'user2', password: 'password' } | |
259 | await createUser({ url: servers[0].url, accessToken: servers[0].accessToken, ...user }) | |
260 | const userAccessToken = await userLogin(servers[0], user) | |
261 | ||
262 | // upload a third video via this user | |
263 | const video3Attributes = { | |
264 | name: 'my second super name for server 1', | |
265 | description: 'my second super description for server 1' | |
266 | } | |
267 | await uploadVideo(servers[0].url, userAccessToken, video3Attributes) | |
268 | ||
269 | const res1 = await getVideosList(servers[0].url) | |
270 | const videos = res1.body.data | |
271 | const video3 = videos.find(video => video.name === 'my second super name for server 1') | |
272 | ||
273 | // resume with the test | |
274 | const reason3 = 'my super bad reason 3' | |
275 | await reportVideoAbuse(servers[0].url, servers[0].accessToken, video3.id, reason3) | |
276 | const reason4 = 'my super bad reason 4' | |
277 | await reportVideoAbuse(servers[0].url, userAccessToken, servers[0].video.id, reason4) | |
278 | ||
feb34f6b | 279 | const res2 = await getVideoAbusesList({ url: servers[0].url, token: servers[0].accessToken }) |
d1261d9a RK |
280 | |
281 | { | |
edbc9325 | 282 | for (const abuse of res2.body.data as AdminAbuse[]) { |
d1261d9a | 283 | if (abuse.video.id === video3.id) { |
4f32032f C |
284 | expect(abuse.video.countReports).to.equal(1, "wrong reports count for video 3") |
285 | expect(abuse.video.nthReport).to.equal(1, "wrong report position in report list for video 3") | |
d1261d9a RK |
286 | expect(abuse.countReportsForReportee).to.equal(1, "wrong reports count for reporter on video 3 abuse") |
287 | expect(abuse.countReportsForReporter).to.equal(3, "wrong reports count for reportee on video 3 abuse") | |
288 | } | |
289 | if (abuse.video.id === servers[0].video.id) { | |
290 | expect(abuse.countReportsForReportee).to.equal(3, "wrong reports count for reporter on video 1 abuse") | |
291 | } | |
292 | } | |
197876ea RK |
293 | } |
294 | }) | |
295 | ||
1ebddadd RK |
296 | it('Should list predefined reasons as well as timestamps for the reported video', async function () { |
297 | this.timeout(10000) | |
298 | ||
299 | const reason5 = 'my super bad reason 5' | |
d95d1559 | 300 | const predefinedReasons5: AbusePredefinedReasonsString[] = [ 'violentOrRepulsive', 'captions' ] |
1ebddadd RK |
301 | const createdAbuse = (await reportVideoAbuse( |
302 | servers[0].url, | |
303 | servers[0].accessToken, | |
304 | servers[0].video.id, | |
305 | reason5, | |
306 | predefinedReasons5, | |
307 | 1, | |
308 | 5 | |
d95d1559 | 309 | )).body.abuse |
1ebddadd RK |
310 | |
311 | const res = await getVideoAbusesList({ url: servers[0].url, token: servers[0].accessToken }) | |
312 | ||
313 | { | |
edbc9325 | 314 | const abuse = (res.body.data as AdminAbuse[]).find(a => a.id === createdAbuse.id) |
1ebddadd RK |
315 | expect(abuse.reason).to.equals(reason5) |
316 | expect(abuse.predefinedReasons).to.deep.equals(predefinedReasons5, "predefined reasons do not match the one reported") | |
d95d1559 C |
317 | expect(abuse.video.startAt).to.equal(1, "starting timestamp doesn't match the one reported") |
318 | expect(abuse.video.endAt).to.equal(5, "ending timestamp doesn't match the one reported") | |
1ebddadd RK |
319 | } |
320 | }) | |
321 | ||
268eebed | 322 | it('Should delete the video abuse', async function () { |
f0a47bc9 C |
323 | this.timeout(10000) |
324 | ||
268eebed C |
325 | await deleteVideoAbuse(servers[1].url, servers[1].accessToken, abuseServer2.video.uuid, abuseServer2.id) |
326 | ||
f0a47bc9 C |
327 | await waitJobs(servers) |
328 | ||
329 | { | |
feb34f6b | 330 | const res = await getVideoAbusesList({ url: servers[1].url, token: servers[1].accessToken }) |
f0a47bc9 C |
331 | expect(res.body.total).to.equal(1) |
332 | expect(res.body.data.length).to.equal(1) | |
333 | expect(res.body.data[0].id).to.not.equal(abuseServer2.id) | |
334 | } | |
335 | ||
336 | { | |
feb34f6b | 337 | const res = await getVideoAbusesList({ url: servers[0].url, token: servers[0].accessToken }) |
1ebddadd | 338 | expect(res.body.total).to.equal(6) |
f0a47bc9 | 339 | } |
0e1dc3e7 C |
340 | }) |
341 | ||
feb34f6b C |
342 | it('Should list and filter video abuses', async function () { |
343 | async function list (query: Omit<Parameters<typeof getVideoAbusesList>[0], 'url' | 'token'>) { | |
344 | const options = { | |
345 | url: servers[0].url, | |
346 | token: servers[0].accessToken | |
347 | } | |
348 | ||
349 | Object.assign(options, query) | |
350 | ||
351 | const res = await getVideoAbusesList(options) | |
352 | ||
edbc9325 | 353 | return res.body.data as AdminAbuse[] |
feb34f6b C |
354 | } |
355 | ||
356 | expect(await list({ id: 56 })).to.have.lengthOf(0) | |
357 | expect(await list({ id: 1 })).to.have.lengthOf(1) | |
358 | ||
1ebddadd | 359 | expect(await list({ search: 'my super name for server 1' })).to.have.lengthOf(4) |
feb34f6b C |
360 | expect(await list({ search: 'aaaaaaaaaaaaaaaaaaaaaaaaaa' })).to.have.lengthOf(0) |
361 | ||
362 | expect(await list({ searchVideo: 'my second super name for server 1' })).to.have.lengthOf(1) | |
363 | ||
1ebddadd | 364 | expect(await list({ searchVideoChannel: 'root' })).to.have.lengthOf(4) |
feb34f6b C |
365 | expect(await list({ searchVideoChannel: 'aaaa' })).to.have.lengthOf(0) |
366 | ||
367 | expect(await list({ searchReporter: 'user2' })).to.have.lengthOf(1) | |
1ebddadd | 368 | expect(await list({ searchReporter: 'root' })).to.have.lengthOf(5) |
feb34f6b | 369 | |
d95d1559 | 370 | expect(await list({ searchReportee: 'root' })).to.have.lengthOf(5) |
feb34f6b C |
371 | expect(await list({ searchReportee: 'aaaa' })).to.have.lengthOf(0) |
372 | ||
373 | expect(await list({ videoIs: 'deleted' })).to.have.lengthOf(1) | |
374 | expect(await list({ videoIs: 'blacklisted' })).to.have.lengthOf(0) | |
375 | ||
d95d1559 C |
376 | expect(await list({ state: AbuseState.ACCEPTED })).to.have.lengthOf(0) |
377 | expect(await list({ state: AbuseState.PENDING })).to.have.lengthOf(6) | |
1ebddadd RK |
378 | |
379 | expect(await list({ predefinedReason: 'violentOrRepulsive' })).to.have.lengthOf(1) | |
380 | expect(await list({ predefinedReason: 'serverRules' })).to.have.lengthOf(0) | |
feb34f6b C |
381 | }) |
382 | ||
7c3b7976 C |
383 | after(async function () { |
384 | await cleanupTests(servers) | |
0e1dc3e7 C |
385 | }) |
386 | }) |