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