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