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