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