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