]>
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' | |
d0800f76 | 5 | import { AbuseMessage, AbusePredefinedReasonsString, AbuseState, AdminAbuse, UserAbuse } from '@shared/models' |
4f32032f | 6 | import { |
0c1a77e9 | 7 | AbusesCommand, |
4f32032f | 8 | cleanupTests, |
254d3579 | 9 | createMultipleServers, |
c0e8b12e | 10 | doubleFollow, |
254d3579 | 11 | PeerTubeServer, |
4f32032f | 12 | setAccessTokensToServers, |
d0800f76 | 13 | setDefaultAccountAvatar, |
14 | setDefaultChannelAvatar, | |
0c1a77e9 | 15 | waitJobs |
bf54587a | 16 | } from '@shared/server-commands' |
4f32032f C |
17 | |
18 | const expect = chai.expect | |
19 | ||
20 | describe('Test abuses', function () { | |
254d3579 | 21 | let servers: PeerTubeServer[] = [] |
edbc9325 C |
22 | let abuseServer1: AdminAbuse |
23 | let abuseServer2: AdminAbuse | |
0c1a77e9 | 24 | let commands: AbusesCommand[] |
4f32032f C |
25 | |
26 | before(async function () { | |
27 | this.timeout(50000) | |
28 | ||
29 | // Run servers | |
254d3579 | 30 | servers = await createMultipleServers(2) |
4f32032f | 31 | |
4f32032f | 32 | await setAccessTokensToServers(servers) |
d0800f76 | 33 | await setDefaultChannelAvatar(servers) |
34 | await setDefaultAccountAvatar(servers) | |
4f32032f C |
35 | |
36 | // Server 1 and server 2 follow each other | |
37 | await doubleFollow(servers[0], servers[1]) | |
0c1a77e9 | 38 | |
89d241a7 | 39 | commands = servers.map(s => s.abuses) |
310b5219 | 40 | }) |
4f32032f | 41 | |
310b5219 | 42 | describe('Video abuses', function () { |
4f32032f | 43 | |
310b5219 C |
44 | before(async function () { |
45 | this.timeout(50000) | |
4f32032f | 46 | |
310b5219 | 47 | // Upload some videos on each servers |
d23dd9fb C |
48 | { |
49 | const attributes = { | |
50 | name: 'my super name for server 1', | |
51 | description: 'my super description for server 1' | |
52 | } | |
89d241a7 | 53 | await servers[0].videos.upload({ attributes }) |
310b5219 | 54 | } |
4f32032f | 55 | |
d23dd9fb C |
56 | { |
57 | const attributes = { | |
58 | name: 'my super name for server 2', | |
59 | description: 'my super description for server 2' | |
60 | } | |
89d241a7 | 61 | await servers[1].videos.upload({ attributes }) |
310b5219 | 62 | } |
4f32032f | 63 | |
310b5219 C |
64 | // Wait videos propagation, server 2 has transcoding enabled |
65 | await waitJobs(servers) | |
4f32032f | 66 | |
89d241a7 | 67 | const { data } = await servers[0].videos.list() |
d23dd9fb | 68 | expect(data.length).to.equal(2) |
4f32032f | 69 | |
83903cb6 C |
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') | |
310b5219 | 72 | }) |
4f32032f | 73 | |
310b5219 | 74 | it('Should not have abuses', async function () { |
0c1a77e9 | 75 | const body = await commands[0].getAdminList() |
4f32032f | 76 | |
0c1a77e9 C |
77 | expect(body.total).to.equal(0) |
78 | expect(body.data).to.be.an('array') | |
79 | expect(body.data.length).to.equal(0) | |
310b5219 | 80 | }) |
4f32032f | 81 | |
310b5219 C |
82 | it('Should report abuse on a local video', async function () { |
83 | this.timeout(15000) | |
4f32032f | 84 | |
310b5219 | 85 | const reason = 'my super bad reason' |
83903cb6 | 86 | await commands[0].report({ videoId: servers[0].store.videoCreated.id, reason }) |
4f32032f | 87 | |
310b5219 C |
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 | }) | |
4f32032f | 91 | |
310b5219 | 92 | it('Should have 1 video abuses on server 1 and 0 on server 2', async function () { |
0c1a77e9 C |
93 | { |
94 | const body = await commands[0].getAdminList() | |
4f32032f | 95 | |
0c1a77e9 C |
96 | expect(body.total).to.equal(1) |
97 | expect(body.data).to.be.an('array') | |
98 | expect(body.data.length).to.equal(1) | |
4f32032f | 99 | |
0c1a77e9 C |
100 | const abuse = body.data[0] |
101 | expect(abuse.reason).to.equal('my super bad reason') | |
4f32032f | 102 | |
0c1a77e9 C |
103 | expect(abuse.reporterAccount.name).to.equal('root') |
104 | expect(abuse.reporterAccount.host).to.equal(servers[0].host) | |
4f32032f | 105 | |
83903cb6 | 106 | expect(abuse.video.id).to.equal(servers[0].store.videoCreated.id) |
0c1a77e9 | 107 | expect(abuse.video.channel).to.exist |
4f32032f | 108 | |
0c1a77e9 | 109 | expect(abuse.comment).to.be.null |
4f32032f | 110 | |
0c1a77e9 C |
111 | expect(abuse.flaggedAccount.name).to.equal('root') |
112 | expect(abuse.flaggedAccount.host).to.equal(servers[0].host) | |
310b5219 | 113 | |
0c1a77e9 C |
114 | expect(abuse.video.countReports).to.equal(1) |
115 | expect(abuse.video.nthReport).to.equal(1) | |
310b5219 | 116 | |
0c1a77e9 C |
117 | expect(abuse.countReportsForReporter).to.equal(1) |
118 | expect(abuse.countReportsForReportee).to.equal(1) | |
119 | } | |
4f32032f | 120 | |
0c1a77e9 C |
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 | } | |
310b5219 | 127 | }) |
4f32032f | 128 | |
310b5219 C |
129 | it('Should report abuse on a remote video', async function () { |
130 | this.timeout(10000) | |
131 | ||
132 | const reason = 'my super bad reason 2' | |
83903cb6 | 133 | const videoId = await servers[0].videos.getId({ uuid: servers[1].store.videoCreated.uuid }) |
0c1a77e9 | 134 | await commands[0].report({ videoId, reason }) |
310b5219 C |
135 | |
136 | // We wait requests propagation | |
4f32032f | 137 | await waitJobs(servers) |
310b5219 | 138 | }) |
4f32032f | 139 | |
310b5219 | 140 | it('Should have 2 video abuses on server 1 and 1 on server 2', async function () { |
0c1a77e9 C |
141 | { |
142 | const body = await commands[0].getAdminList() | |
4f32032f | 143 | |
0c1a77e9 C |
144 | expect(body.total).to.equal(2) |
145 | expect(body.data.length).to.equal(2) | |
4f32032f | 146 | |
0c1a77e9 C |
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) | |
4f32032f | 151 | |
83903cb6 | 152 | expect(abuse1.video.id).to.equal(servers[0].store.videoCreated.id) |
0c1a77e9 C |
153 | expect(abuse1.video.countReports).to.equal(1) |
154 | expect(abuse1.video.nthReport).to.equal(1) | |
4f32032f | 155 | |
0c1a77e9 | 156 | expect(abuse1.comment).to.be.null |
4f32032f | 157 | |
0c1a77e9 C |
158 | expect(abuse1.flaggedAccount.name).to.equal('root') |
159 | expect(abuse1.flaggedAccount.host).to.equal(servers[0].host) | |
4f32032f | 160 | |
0c1a77e9 C |
161 | expect(abuse1.state.id).to.equal(AbuseState.PENDING) |
162 | expect(abuse1.state.label).to.equal('Pending') | |
163 | expect(abuse1.moderationComment).to.be.null | |
4f32032f | 164 | |
0c1a77e9 C |
165 | const abuse2 = body.data[1] |
166 | expect(abuse2.reason).to.equal('my super bad reason 2') | |
4f32032f | 167 | |
0c1a77e9 C |
168 | expect(abuse2.reporterAccount.name).to.equal('root') |
169 | expect(abuse2.reporterAccount.host).to.equal(servers[0].host) | |
4f32032f | 170 | |
e435cf44 | 171 | expect(abuse2.video.uuid).to.equal(servers[1].store.videoCreated.uuid) |
4f32032f | 172 | |
0c1a77e9 | 173 | expect(abuse2.comment).to.be.null |
4f32032f | 174 | |
0c1a77e9 C |
175 | expect(abuse2.flaggedAccount.name).to.equal('root') |
176 | expect(abuse2.flaggedAccount.host).to.equal(servers[1].host) | |
4f32032f | 177 | |
0c1a77e9 C |
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 | } | |
4f32032f | 182 | |
0c1a77e9 C |
183 | { |
184 | const body = await commands[1].getAdminList() | |
185 | expect(body.total).to.equal(1) | |
186 | expect(body.data.length).to.equal(1) | |
4f32032f | 187 | |
0c1a77e9 C |
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) | |
4f32032f | 192 | |
0c1a77e9 C |
193 | expect(abuseServer2.flaggedAccount.name).to.equal('root') |
194 | expect(abuseServer2.flaggedAccount.host).to.equal(servers[1].host) | |
4f32032f | 195 | |
0c1a77e9 C |
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 | } | |
310b5219 | 200 | }) |
4f32032f | 201 | |
310b5219 C |
202 | it('Should hide video abuses from blocked accounts', async function () { |
203 | this.timeout(10000) | |
4f32032f | 204 | |
310b5219 | 205 | { |
83903cb6 | 206 | const videoId = await servers[1].videos.getId({ uuid: servers[0].store.videoCreated.uuid }) |
0c1a77e9 | 207 | await commands[1].report({ videoId, reason: 'will mute this' }) |
310b5219 | 208 | await waitJobs(servers) |
4f32032f | 209 | |
0c1a77e9 C |
210 | const body = await commands[0].getAdminList() |
211 | expect(body.total).to.equal(3) | |
310b5219 | 212 | } |
4f32032f | 213 | |
310b5219 C |
214 | const accountToBlock = 'root@' + servers[1].host |
215 | ||
216 | { | |
89d241a7 | 217 | await servers[0].blocklist.addToServerBlocklist({ account: accountToBlock }) |
310b5219 | 218 | |
0c1a77e9 C |
219 | const body = await commands[0].getAdminList() |
220 | expect(body.total).to.equal(2) | |
310b5219 | 221 | |
0c1a77e9 | 222 | const abuse = body.data.find(a => a.reason === 'will mute this') |
310b5219 C |
223 | expect(abuse).to.be.undefined |
224 | } | |
225 | ||
226 | { | |
89d241a7 | 227 | await servers[0].blocklist.removeFromServerBlocklist({ account: accountToBlock }) |
310b5219 | 228 | |
0c1a77e9 C |
229 | const body = await commands[0].getAdminList() |
230 | expect(body.total).to.equal(3) | |
310b5219 C |
231 | } |
232 | }) | |
233 | ||
234 | it('Should hide video abuses from blocked servers', async function () { | |
235 | const serverToBlock = servers[1].host | |
236 | ||
237 | { | |
89d241a7 | 238 | await servers[0].blocklist.addToServerBlocklist({ server: serverToBlock }) |
310b5219 | 239 | |
0c1a77e9 C |
240 | const body = await commands[0].getAdminList() |
241 | expect(body.total).to.equal(2) | |
310b5219 | 242 | |
0c1a77e9 | 243 | const abuse = body.data.find(a => a.reason === 'will mute this') |
310b5219 C |
244 | expect(abuse).to.be.undefined |
245 | } | |
246 | ||
247 | { | |
89d241a7 | 248 | await servers[0].blocklist.removeFromServerBlocklist({ server: serverToBlock }) |
310b5219 | 249 | |
0c1a77e9 C |
250 | const body = await commands[0].getAdminList() |
251 | expect(body.total).to.equal(3) | |
310b5219 C |
252 | } |
253 | }) | |
254 | ||
255 | it('Should keep the video abuse when deleting the video', async function () { | |
256 | this.timeout(10000) | |
257 | ||
89d241a7 | 258 | await servers[1].videos.remove({ id: abuseServer2.video.uuid }) |
310b5219 C |
259 | |
260 | await waitJobs(servers) | |
261 | ||
0c1a77e9 C |
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") | |
310b5219 | 265 | |
0c1a77e9 | 266 | const abuse = body.data[0] |
310b5219 C |
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' } | |
89d241a7 C |
278 | await servers[0].users.create({ ...user }) |
279 | const userAccessToken = await servers[0].login.getAccessToken(user) | |
310b5219 C |
280 | |
281 | // upload a third video via this user | |
d23dd9fb | 282 | const attributes = { |
310b5219 C |
283 | name: 'my second super name for server 1', |
284 | description: 'my second super description for server 1' | |
285 | } | |
89d241a7 | 286 | const { id } = await servers[0].videos.upload({ token: userAccessToken, attributes }) |
d23dd9fb | 287 | const video3Id = id |
310b5219 C |
288 | |
289 | // resume with the test | |
290 | const reason3 = 'my super bad reason 3' | |
0c1a77e9 | 291 | await commands[0].report({ videoId: video3Id, reason: reason3 }) |
310b5219 C |
292 | |
293 | const reason4 = 'my super bad reason 4' | |
83903cb6 | 294 | await commands[0].report({ token: userAccessToken, videoId: servers[0].store.videoCreated.id, reason: reason4 }) |
310b5219 C |
295 | |
296 | { | |
0c1a77e9 C |
297 | const body = await commands[0].getAdminList() |
298 | const abuses = body.data | |
310b5219 | 299 | |
0c1a77e9 | 300 | const abuseVideo3 = body.data.find(a => a.video.id === video3Id) |
310b5219 C |
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 | ||
83903cb6 | 307 | const abuseServer1 = abuses.find(a => a.video.id === servers[0].store.videoCreated.id) |
310b5219 C |
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' ] | |
0c1a77e9 | 317 | const createRes = await commands[0].report({ |
83903cb6 | 318 | videoId: servers[0].store.videoCreated.id, |
310b5219 C |
319 | reason: reason5, |
320 | predefinedReasons: predefinedReasons5, | |
321 | startAt: 1, | |
322 | endAt: 5 | |
0c1a77e9 | 323 | }) |
310b5219 | 324 | |
0c1a77e9 | 325 | const body = await commands[0].getAdminList() |
310b5219 C |
326 | |
327 | { | |
0c1a77e9 | 328 | const abuse = body.data.find(a => a.id === createRes.abuse.id) |
310b5219 C |
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 | ||
0c1a77e9 | 339 | await commands[1].delete({ abuseId: abuseServer2.id }) |
310b5219 C |
340 | |
341 | await waitJobs(servers) | |
342 | ||
343 | { | |
0c1a77e9 C |
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) | |
310b5219 C |
348 | } |
349 | ||
350 | { | |
0c1a77e9 C |
351 | const body = await commands[0].getAdminList() |
352 | expect(body.total).to.equal(6) | |
310b5219 C |
353 | } |
354 | }) | |
355 | ||
356 | it('Should list and filter video abuses', async function () { | |
357 | this.timeout(10000) | |
358 | ||
0c1a77e9 C |
359 | async function list (query: Parameters<AbusesCommand['getAdminList']>[0]) { |
360 | const body = await commands[0].getAdminList(query) | |
310b5219 | 361 | |
0c1a77e9 | 362 | return body.data |
4f32032f | 363 | } |
4f32032f | 364 | |
310b5219 C |
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 | }) | |
4f32032f C |
391 | }) |
392 | ||
310b5219 | 393 | describe('Comment abuses', function () { |
4f32032f | 394 | |
254d3579 | 395 | async function getComment (server: PeerTubeServer, videoIdArg: number | string) { |
310b5219 | 396 | const videoId = typeof videoIdArg === 'string' |
89d241a7 | 397 | ? await server.videos.getId({ uuid: videoIdArg }) |
310b5219 | 398 | : videoIdArg |
4f32032f | 399 | |
89d241a7 | 400 | const { data } = await server.comments.listThreads({ videoId }) |
4f32032f | 401 | |
12edc149 | 402 | return data[0] |
4f32032f C |
403 | } |
404 | ||
310b5219 C |
405 | before(async function () { |
406 | this.timeout(50000) | |
4f32032f | 407 | |
83903cb6 C |
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' }) | |
310b5219 | 410 | |
83903cb6 C |
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' }) | |
310b5219 C |
413 | |
414 | await waitJobs(servers) | |
415 | }) | |
416 | ||
417 | it('Should report abuse on a comment', async function () { | |
418 | this.timeout(15000) | |
419 | ||
83903cb6 | 420 | const comment = await getComment(servers[0], servers[0].store.videoCreated.id) |
310b5219 C |
421 | |
422 | const reason = 'it is a bad comment' | |
0c1a77e9 | 423 | await commands[0].report({ commentId: comment.id, reason }) |
310b5219 C |
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 | { | |
83903cb6 | 430 | const comment = await getComment(servers[0], servers[0].store.videoCreated.id) |
0c1a77e9 | 431 | const body = await commands[0].getAdminList({ filter: 'comment' }) |
310b5219 | 432 | |
0c1a77e9 C |
433 | expect(body.total).to.equal(1) |
434 | expect(body.data).to.have.lengthOf(1) | |
310b5219 | 435 | |
0c1a77e9 | 436 | const abuse = body.data[0] |
310b5219 C |
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') | |
83903cb6 C |
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) | |
310b5219 C |
450 | |
451 | expect(abuse.countReportsForReporter).to.equal(5) | |
452 | expect(abuse.countReportsForReportee).to.equal(5) | |
453 | } | |
454 | ||
455 | { | |
0c1a77e9 C |
456 | const body = await commands[1].getAdminList({ filter: 'comment' }) |
457 | expect(body.total).to.equal(0) | |
458 | expect(body.data.length).to.equal(0) | |
310b5219 C |
459 | } |
460 | }) | |
461 | ||
462 | it('Should report abuse on a remote comment', async function () { | |
463 | this.timeout(10000) | |
464 | ||
83903cb6 | 465 | const comment = await getComment(servers[0], servers[1].store.videoCreated.uuid) |
310b5219 C |
466 | |
467 | const reason = 'it is a really bad comment' | |
0c1a77e9 | 468 | await commands[0].report({ commentId: comment.id, reason }) |
310b5219 C |
469 | |
470 | await waitJobs(servers) | |
471 | }) | |
472 | ||
473 | it('Should have 2 comment abuses on server 1 and 1 on server 2', async function () { | |
f332d502 | 474 | const commentServer2 = await getComment(servers[0], servers[1].store.videoCreated.shortUUID) |
310b5219 | 475 | |
0c1a77e9 C |
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) | |
310b5219 | 480 | |
0c1a77e9 C |
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) | |
310b5219 | 485 | |
0c1a77e9 | 486 | const abuse2 = body.data[1] |
310b5219 | 487 | |
0c1a77e9 | 488 | expect(abuse2.reason).to.equal('it is a really bad comment') |
310b5219 | 489 | |
0c1a77e9 C |
490 | expect(abuse2.reporterAccount.name).to.equal('root') |
491 | expect(abuse2.reporterAccount.host).to.equal(servers[0].host) | |
310b5219 | 492 | |
0c1a77e9 | 493 | expect(abuse2.video).to.be.null |
310b5219 | 494 | |
0c1a77e9 C |
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') | |
83903cb6 | 499 | expect(abuse2.comment.video.uuid).to.equal(servers[1].store.videoCreated.uuid) |
310b5219 | 500 | |
0c1a77e9 C |
501 | expect(abuse2.state.id).to.equal(AbuseState.PENDING) |
502 | expect(abuse2.state.label).to.equal('Pending') | |
310b5219 | 503 | |
0c1a77e9 | 504 | expect(abuse2.moderationComment).to.be.null |
310b5219 | 505 | |
0c1a77e9 C |
506 | expect(abuse2.countReportsForReporter).to.equal(6) |
507 | expect(abuse2.countReportsForReportee).to.equal(2) | |
508 | } | |
310b5219 | 509 | |
0c1a77e9 C |
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) | |
310b5219 | 514 | |
0c1a77e9 C |
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) | |
310b5219 | 519 | |
0c1a77e9 C |
520 | expect(abuseServer2.state.id).to.equal(AbuseState.PENDING) |
521 | expect(abuseServer2.state.label).to.equal('Pending') | |
310b5219 | 522 | |
0c1a77e9 | 523 | expect(abuseServer2.moderationComment).to.be.null |
310b5219 | 524 | |
0c1a77e9 C |
525 | expect(abuseServer2.countReportsForReporter).to.equal(1) |
526 | expect(abuseServer2.countReportsForReportee).to.equal(1) | |
527 | } | |
310b5219 C |
528 | }) |
529 | ||
530 | it('Should keep the comment abuse when deleting the comment', async function () { | |
531 | this.timeout(10000) | |
532 | ||
e435cf44 | 533 | const commentServer2 = await getComment(servers[0], servers[1].store.videoCreated.uuid) |
310b5219 | 534 | |
83903cb6 | 535 | await servers[0].comments.delete({ videoId: servers[1].store.videoCreated.uuid, commentId: commentServer2.id }) |
310b5219 C |
536 | |
537 | await waitJobs(servers) | |
538 | ||
0c1a77e9 C |
539 | const body = await commands[0].getAdminList({ filter: 'comment' }) |
540 | expect(body.total).to.equal(2) | |
541 | expect(body.data).to.have.lengthOf(2) | |
310b5219 | 542 | |
0c1a77e9 | 543 | const abuse = body.data.find(a => a.comment?.id === commentServer2.id) |
310b5219 C |
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 | ||
0c1a77e9 | 554 | await commands[1].delete({ abuseId: abuseServer2.id }) |
310b5219 C |
555 | |
556 | await waitJobs(servers) | |
557 | ||
558 | { | |
0c1a77e9 C |
559 | const body = await commands[1].getAdminList({ filter: 'comment' }) |
560 | expect(body.total).to.equal(0) | |
561 | expect(body.data.length).to.equal(0) | |
310b5219 C |
562 | } |
563 | ||
564 | { | |
0c1a77e9 C |
565 | const body = await commands[0].getAdminList({ filter: 'comment' }) |
566 | expect(body.total).to.equal(2) | |
310b5219 C |
567 | } |
568 | }) | |
569 | ||
570 | it('Should list and filter video abuses', async function () { | |
571 | { | |
0c1a77e9 C |
572 | const body = await commands[0].getAdminList({ filter: 'comment', searchReportee: 'foo' }) |
573 | expect(body.total).to.equal(0) | |
310b5219 C |
574 | } |
575 | ||
576 | { | |
0c1a77e9 C |
577 | const body = await commands[0].getAdminList({ filter: 'comment', searchReportee: 'ot' }) |
578 | expect(body.total).to.equal(2) | |
310b5219 C |
579 | } |
580 | ||
581 | { | |
0c1a77e9 C |
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 | } | |
310b5219 | 586 | |
0c1a77e9 C |
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') | |
4f32032f | 591 | } |
310b5219 C |
592 | }) |
593 | }) | |
4f32032f | 594 | |
310b5219 | 595 | describe('Account abuses', function () { |
4f32032f | 596 | |
254d3579 | 597 | function getAccountFromServer (server: PeerTubeServer, targetName: string, targetServer: PeerTubeServer) { |
89d241a7 | 598 | return server.accounts.get({ accountName: targetName + '@' + targetServer.host }) |
4f32032f C |
599 | } |
600 | ||
310b5219 C |
601 | before(async function () { |
602 | this.timeout(50000) | |
603 | ||
89d241a7 | 604 | await servers[0].users.create({ username: 'user_1', password: 'donald' }) |
310b5219 | 605 | |
89d241a7 C |
606 | const token = await servers[1].users.generateUserAndToken('user_2') |
607 | await servers[1].videos.upload({ token, attributes: { name: 'super video' } }) | |
310b5219 C |
608 | |
609 | await waitJobs(servers) | |
610 | }) | |
611 | ||
612 | it('Should report abuse on an account', async function () { | |
613 | this.timeout(15000) | |
614 | ||
9fff08cf | 615 | const account = await getAccountFromServer(servers[0], 'user_1', servers[0]) |
310b5219 C |
616 | |
617 | const reason = 'it is a bad account' | |
0c1a77e9 | 618 | await commands[0].report({ accountId: account.id, reason }) |
310b5219 C |
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 | { | |
0c1a77e9 | 625 | const body = await commands[0].getAdminList({ filter: 'account' }) |
310b5219 | 626 | |
0c1a77e9 C |
627 | expect(body.total).to.equal(1) |
628 | expect(body.data).to.have.lengthOf(1) | |
310b5219 | 629 | |
0c1a77e9 | 630 | const abuse = body.data[0] |
310b5219 C |
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 | { | |
0c1a77e9 C |
644 | const body = await commands[1].getAdminList({ filter: 'comment' }) |
645 | expect(body.total).to.equal(0) | |
646 | expect(body.data.length).to.equal(0) | |
310b5219 C |
647 | } |
648 | }) | |
649 | ||
650 | it('Should report abuse on a remote account', async function () { | |
651 | this.timeout(10000) | |
652 | ||
9fff08cf | 653 | const account = await getAccountFromServer(servers[0], 'user_2', servers[1]) |
310b5219 C |
654 | |
655 | const reason = 'it is a really bad account' | |
0c1a77e9 | 656 | await commands[0].report({ accountId: account.id, reason }) |
310b5219 C |
657 | |
658 | await waitJobs(servers) | |
659 | }) | |
660 | ||
661 | it('Should have 2 comment abuses on server 1 and 1 on server 2', async function () { | |
0c1a77e9 C |
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) | |
310b5219 | 666 | |
0c1a77e9 C |
667 | const abuse: AdminAbuse = body.data[0] |
668 | expect(abuse.reason).to.equal('it is a bad account') | |
4f32032f | 669 | |
0c1a77e9 C |
670 | const abuse2: AdminAbuse = body.data[1] |
671 | expect(abuse2.reason).to.equal('it is a really bad account') | |
4f32032f | 672 | |
0c1a77e9 C |
673 | expect(abuse2.reporterAccount.name).to.equal('root') |
674 | expect(abuse2.reporterAccount.host).to.equal(servers[0].host) | |
4f32032f | 675 | |
0c1a77e9 C |
676 | expect(abuse2.video).to.be.null |
677 | expect(abuse2.comment).to.be.null | |
310b5219 | 678 | |
0c1a77e9 C |
679 | expect(abuse2.state.id).to.equal(AbuseState.PENDING) |
680 | expect(abuse2.state.label).to.equal('Pending') | |
310b5219 | 681 | |
0c1a77e9 C |
682 | expect(abuse2.moderationComment).to.be.null |
683 | } | |
310b5219 | 684 | |
0c1a77e9 C |
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) | |
310b5219 | 689 | |
0c1a77e9 | 690 | abuseServer2 = body.data[0] |
310b5219 | 691 | |
0c1a77e9 | 692 | expect(abuseServer2.reason).to.equal('it is a really bad account') |
310b5219 | 693 | |
0c1a77e9 C |
694 | expect(abuseServer2.reporterAccount.name).to.equal('root') |
695 | expect(abuseServer2.reporterAccount.host).to.equal(servers[0].host) | |
310b5219 | 696 | |
0c1a77e9 C |
697 | expect(abuseServer2.state.id).to.equal(AbuseState.PENDING) |
698 | expect(abuseServer2.state.label).to.equal('Pending') | |
310b5219 | 699 | |
0c1a77e9 C |
700 | expect(abuseServer2.moderationComment).to.be.null |
701 | } | |
310b5219 C |
702 | }) |
703 | ||
704 | it('Should keep the account abuse when deleting the account', async function () { | |
705 | this.timeout(10000) | |
706 | ||
9fff08cf | 707 | const account = await getAccountFromServer(servers[1], 'user_2', servers[1]) |
89d241a7 | 708 | await servers[1].users.remove({ userId: account.userId }) |
310b5219 C |
709 | |
710 | await waitJobs(servers) | |
711 | ||
0c1a77e9 C |
712 | const body = await commands[0].getAdminList({ filter: 'account' }) |
713 | expect(body.total).to.equal(2) | |
714 | expect(body.data).to.have.lengthOf(2) | |
310b5219 | 715 | |
0c1a77e9 | 716 | const abuse = body.data.find(a => a.reason === 'it is a really bad account') |
310b5219 C |
717 | expect(abuse).to.not.be.undefined |
718 | }) | |
719 | ||
720 | it('Should delete the account abuse', async function () { | |
721 | this.timeout(10000) | |
722 | ||
0c1a77e9 | 723 | await commands[1].delete({ abuseId: abuseServer2.id }) |
310b5219 C |
724 | |
725 | await waitJobs(servers) | |
726 | ||
727 | { | |
0c1a77e9 C |
728 | const body = await commands[1].getAdminList({ filter: 'account' }) |
729 | expect(body.total).to.equal(0) | |
730 | expect(body.data.length).to.equal(0) | |
310b5219 C |
731 | } |
732 | ||
733 | { | |
0c1a77e9 C |
734 | const body = await commands[0].getAdminList({ filter: 'account' }) |
735 | expect(body.total).to.equal(2) | |
310b5219 | 736 | |
0c1a77e9 | 737 | abuseServer1 = body.data[0] |
310b5219 C |
738 | } |
739 | }) | |
740 | }) | |
4f32032f | 741 | |
310b5219 | 742 | describe('Common actions on abuses', function () { |
4f32032f | 743 | |
310b5219 | 744 | it('Should update the state of an abuse', async function () { |
0c1a77e9 | 745 | await commands[0].update({ abuseId: abuseServer1.id, body: { state: AbuseState.REJECTED } }) |
4f32032f | 746 | |
0c1a77e9 C |
747 | const body = await commands[0].getAdminList({ id: abuseServer1.id }) |
748 | expect(body.data[0].state.id).to.equal(AbuseState.REJECTED) | |
310b5219 | 749 | }) |
4f32032f | 750 | |
310b5219 | 751 | it('Should add a moderation comment', async function () { |
0c1a77e9 | 752 | await commands[0].update({ abuseId: abuseServer1.id, body: { state: AbuseState.ACCEPTED, moderationComment: 'Valid' } }) |
4f32032f | 753 | |
0c1a77e9 C |
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') | |
310b5219 | 757 | }) |
4f32032f C |
758 | }) |
759 | ||
edbc9325 C |
760 | describe('My abuses', async function () { |
761 | let abuseId1: number | |
762 | let userAccessToken: string | |
763 | ||
764 | before(async function () { | |
89d241a7 | 765 | userAccessToken = await servers[0].users.generateUserAndToken('user_42') |
edbc9325 | 766 | |
83903cb6 | 767 | await commands[0].report({ token: userAccessToken, videoId: servers[0].store.videoCreated.id, reason: 'user reason 1' }) |
edbc9325 | 768 | |
83903cb6 | 769 | const videoId = await servers[0].videos.getId({ uuid: servers[1].store.videoCreated.uuid }) |
0c1a77e9 | 770 | await commands[0].report({ token: userAccessToken, videoId, reason: 'user reason 2' }) |
edbc9325 C |
771 | }) |
772 | ||
773 | it('Should correctly list my abuses', async function () { | |
774 | { | |
0c1a77e9 C |
775 | const body = await commands[0].getUserList({ token: userAccessToken, start: 0, count: 5, sort: 'createdAt' }) |
776 | expect(body.total).to.equal(2) | |
edbc9325 | 777 | |
0c1a77e9 | 778 | const abuses = body.data |
edbc9325 C |
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 | { | |
0c1a77e9 C |
786 | const body = await commands[0].getUserList({ token: userAccessToken, start: 1, count: 1, sort: 'createdAt' }) |
787 | expect(body.total).to.equal(2) | |
edbc9325 | 788 | |
0c1a77e9 | 789 | const abuses: UserAbuse[] = body.data |
edbc9325 C |
790 | expect(abuses[0].reason).to.equal('user reason 2') |
791 | } | |
792 | ||
793 | { | |
0c1a77e9 C |
794 | const body = await commands[0].getUserList({ token: userAccessToken, start: 1, count: 1, sort: '-createdAt' }) |
795 | expect(body.total).to.equal(2) | |
edbc9325 | 796 | |
0c1a77e9 | 797 | const abuses: UserAbuse[] = body.data |
edbc9325 C |
798 | expect(abuses[0].reason).to.equal('user reason 1') |
799 | } | |
800 | }) | |
801 | ||
802 | it('Should correctly filter my abuses by id', async function () { | |
0c1a77e9 C |
803 | const body = await commands[0].getUserList({ token: userAccessToken, id: abuseId1 }) |
804 | expect(body.total).to.equal(1) | |
edbc9325 | 805 | |
0c1a77e9 | 806 | const abuses: UserAbuse[] = body.data |
edbc9325 C |
807 | expect(abuses[0].reason).to.equal('user reason 1') |
808 | }) | |
809 | ||
810 | it('Should correctly filter my abuses by search', async function () { | |
0c1a77e9 C |
811 | const body = await commands[0].getUserList({ token: userAccessToken, search: 'server 2' }) |
812 | expect(body.total).to.equal(1) | |
edbc9325 | 813 | |
0c1a77e9 | 814 | const abuses: UserAbuse[] = body.data |
edbc9325 C |
815 | expect(abuses[0].reason).to.equal('user reason 2') |
816 | }) | |
817 | ||
818 | it('Should correctly filter my abuses by state', async function () { | |
0c1a77e9 | 819 | await commands[0].update({ abuseId: abuseId1, body: { state: AbuseState.REJECTED } }) |
edbc9325 | 820 | |
0c1a77e9 C |
821 | const body = await commands[0].getUserList({ token: userAccessToken, state: AbuseState.REJECTED }) |
822 | expect(body.total).to.equal(1) | |
edbc9325 | 823 | |
0c1a77e9 | 824 | const abuses: UserAbuse[] = body.data |
edbc9325 C |
825 | expect(abuses[0].reason).to.equal('user reason 1') |
826 | }) | |
827 | }) | |
828 | ||
829 | describe('Abuse messages', async function () { | |
830 | let abuseId: number | |
0c1a77e9 | 831 | let userToken: string |
edbc9325 C |
832 | let abuseMessageUserId: number |
833 | let abuseMessageModerationId: number | |
834 | ||
835 | before(async function () { | |
89d241a7 | 836 | userToken = await servers[0].users.generateUserAndToken('user_43') |
edbc9325 | 837 | |
83903cb6 | 838 | const body = await commands[0].report({ token: userToken, videoId: servers[0].store.videoCreated.id, reason: 'user 43 reason 1' }) |
0c1a77e9 | 839 | abuseId = body.abuse.id |
edbc9325 C |
840 | }) |
841 | ||
842 | it('Should create some messages on the abuse', async function () { | |
0c1a77e9 C |
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' }) | |
edbc9325 C |
847 | }) |
848 | ||
849 | it('Should have the correct messages count when listing abuses', async function () { | |
850 | const results = await Promise.all([ | |
0c1a77e9 C |
851 | commands[0].getAdminList({ start: 0, count: 50 }), |
852 | commands[0].getUserList({ token: userToken, start: 0, count: 50 }) | |
edbc9325 C |
853 | ]) |
854 | ||
0c1a77e9 C |
855 | for (const body of results) { |
856 | const abuses = body.data | |
edbc9325 C |
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([ | |
0c1a77e9 C |
864 | commands[0].listMessages({ abuseId }), |
865 | commands[0].listMessages({ token: userToken, abuseId }) | |
edbc9325 C |
866 | ]) |
867 | ||
0c1a77e9 C |
868 | for (const body of results) { |
869 | expect(body.total).to.equal(4) | |
edbc9325 | 870 | |
0c1a77e9 | 871 | const abuseMessages: AbuseMessage[] = body.data |
edbc9325 C |
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 () { | |
0c1a77e9 C |
895 | await commands[0].deleteMessage({ abuseId, messageId: abuseMessageModerationId }) |
896 | await commands[0].deleteMessage({ token: userToken, abuseId, messageId: abuseMessageUserId }) | |
edbc9325 C |
897 | |
898 | const results = await Promise.all([ | |
0c1a77e9 C |
899 | commands[0].listMessages({ abuseId }), |
900 | commands[0].listMessages({ token: userToken, abuseId }) | |
edbc9325 C |
901 | ]) |
902 | ||
0c1a77e9 C |
903 | for (const body of results) { |
904 | expect(body.total).to.equal(2) | |
edbc9325 | 905 | |
0c1a77e9 | 906 | const abuseMessages: AbuseMessage[] = body.data |
edbc9325 C |
907 | expect(abuseMessages[0].message).to.equal('message 2') |
908 | expect(abuseMessages[1].message).to.equal('message 4') | |
909 | } | |
910 | }) | |
911 | }) | |
912 | ||
4f32032f C |
913 | after(async function () { |
914 | await cleanupTests(servers) | |
915 | }) | |
916 | }) |