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