1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
4 import { AbuseCreate, AbuseState } from '@shared/models'
13 generateUserAccessToken,
21 setAccessTokensToServers,
26 } from '../../../../shared/extra-utils'
28 checkBadCountPagination,
29 checkBadSortPagination,
30 checkBadStartPagination
31 } from '../../../../shared/extra-utils/requests/check-api-params'
33 describe('Test abuses API validators', function () {
34 const basePath = '/api/v1/abuses/'
36 let server: ServerInfo
38 let userAccessToken = ''
39 let userAccessToken2 = ''
43 // ---------------------------------------------------------------
45 before(async function () {
48 server = await flushAndRunServer(1)
50 await setAccessTokensToServers([ server ])
52 const username = 'user1'
53 const password = 'my super password'
54 await createUser({ url: server.url, accessToken: server.accessToken, username: username, password: password })
55 userAccessToken = await userLogin(server, { username, password })
58 userAccessToken2 = await generateUserAccessToken(server, 'user_2')
61 const res = await uploadVideo(server.url, server.accessToken, {})
62 server.video = res.body.video
65 describe('When listing abuses for admins', function () {
68 it('Should fail with a bad start pagination', async function () {
69 await checkBadStartPagination(server.url, path, server.accessToken)
72 it('Should fail with a bad count pagination', async function () {
73 await checkBadCountPagination(server.url, path, server.accessToken)
76 it('Should fail with an incorrect sort', async function () {
77 await checkBadSortPagination(server.url, path, server.accessToken)
80 it('Should fail with a non authenticated user', async function () {
81 await makeGetRequest({
84 statusCodeExpected: 401
88 it('Should fail with a non admin user', async function () {
89 await makeGetRequest({
92 token: userAccessToken,
93 statusCodeExpected: 403
97 it('Should fail with a bad id filter', async function () {
98 await makeGetRequest({ url: server.url, path, token: server.accessToken, query: { id: 'toto' } })
101 it('Should fail with a bad filter', async function () {
102 await makeGetRequest({ url: server.url, path, token: server.accessToken, query: { filter: 'toto' } })
103 await makeGetRequest({ url: server.url, path, token: server.accessToken, query: { filter: 'videos' } })
106 it('Should fail with bad predefined reason', async function () {
107 await makeGetRequest({ url: server.url, path, token: server.accessToken, query: { predefinedReason: 'violentOrRepulsives' } })
110 it('Should fail with a bad state filter', async function () {
111 await makeGetRequest({ url: server.url, path, token: server.accessToken, query: { state: 'toto' } })
112 await makeGetRequest({ url: server.url, path, token: server.accessToken, query: { state: 0 } })
115 it('Should fail with a bad videoIs filter', async function () {
116 await makeGetRequest({ url: server.url, path, token: server.accessToken, query: { videoIs: 'toto' } })
119 it('Should succeed with the correct params', async function () {
122 predefinedReason: 'violentOrRepulsive',
128 await makeGetRequest({ url: server.url, path, token: server.accessToken, query, statusCodeExpected: 200 })
132 describe('When listing abuses for users', function () {
133 const path = '/api/v1/users/me/abuses'
135 it('Should fail with a bad start pagination', async function () {
136 await checkBadStartPagination(server.url, path, userAccessToken)
139 it('Should fail with a bad count pagination', async function () {
140 await checkBadCountPagination(server.url, path, userAccessToken)
143 it('Should fail with an incorrect sort', async function () {
144 await checkBadSortPagination(server.url, path, userAccessToken)
147 it('Should fail with a non authenticated user', async function () {
148 await makeGetRequest({
151 statusCodeExpected: 401
155 it('Should fail with a bad id filter', async function () {
156 await makeGetRequest({ url: server.url, path, token: userAccessToken, query: { id: 'toto' } })
159 it('Should fail with a bad state filter', async function () {
160 await makeGetRequest({ url: server.url, path, token: userAccessToken, query: { state: 'toto' } })
161 await makeGetRequest({ url: server.url, path, token: userAccessToken, query: { state: 0 } })
164 it('Should succeed with the correct params', async function () {
170 await makeGetRequest({ url: server.url, path, token: userAccessToken, query, statusCodeExpected: 200 })
174 describe('When reporting an abuse', function () {
175 const path = basePath
177 it('Should fail with nothing', async function () {
179 await makePostBodyRequest({ url: server.url, path, token: userAccessToken, fields })
182 it('Should fail with a wrong video', async function () {
183 const fields = { video: { id: 'blabla' }, reason: 'my super reason' }
184 await makePostBodyRequest({ url: server.url, path: path, token: userAccessToken, fields })
187 it('Should fail with an unknown video', async function () {
188 const fields = { video: { id: 42 }, reason: 'my super reason' }
189 await makePostBodyRequest({ url: server.url, path: path, token: userAccessToken, fields, statusCodeExpected: 404 })
192 it('Should fail with a wrong comment', async function () {
193 const fields = { comment: { id: 'blabla' }, reason: 'my super reason' }
194 await makePostBodyRequest({ url: server.url, path: path, token: userAccessToken, fields })
197 it('Should fail with an unknown comment', async function () {
198 const fields = { comment: { id: 42 }, reason: 'my super reason' }
199 await makePostBodyRequest({ url: server.url, path: path, token: userAccessToken, fields, statusCodeExpected: 404 })
202 it('Should fail with a wrong account', async function () {
203 const fields = { account: { id: 'blabla' }, reason: 'my super reason' }
204 await makePostBodyRequest({ url: server.url, path: path, token: userAccessToken, fields })
207 it('Should fail with an unknown account', async function () {
208 const fields = { account: { id: 42 }, reason: 'my super reason' }
209 await makePostBodyRequest({ url: server.url, path: path, token: userAccessToken, fields, statusCodeExpected: 404 })
212 it('Should fail with not account, comment or video', async function () {
213 const fields = { reason: 'my super reason' }
214 await makePostBodyRequest({ url: server.url, path: path, token: userAccessToken, fields, statusCodeExpected: 400 })
217 it('Should fail with a non authenticated user', async function () {
218 const fields = { video: { id: server.video.id }, reason: 'my super reason' }
220 await makePostBodyRequest({ url: server.url, path, token: 'hello', fields, statusCodeExpected: 401 })
223 it('Should fail with a reason too short', async function () {
224 const fields = { video: { id: server.video.id }, reason: 'h' }
226 await makePostBodyRequest({ url: server.url, path, token: userAccessToken, fields })
229 it('Should fail with a too big reason', async function () {
230 const fields = { video: { id: server.video.id }, reason: 'super'.repeat(605) }
232 await makePostBodyRequest({ url: server.url, path, token: userAccessToken, fields })
235 it('Should succeed with the correct parameters (basic)', async function () {
236 const fields: AbuseCreate = { video: { id: server.video.id }, reason: 'my super reason' }
238 const res = await makePostBodyRequest({ url: server.url, path, token: userAccessToken, fields, statusCodeExpected: 200 })
239 abuseId = res.body.abuse.id
242 it('Should fail with a wrong predefined reason', async function () {
243 const fields = { video: { id: server.video.id }, reason: 'my super reason', predefinedReasons: [ 'wrongPredefinedReason' ] }
245 await makePostBodyRequest({ url: server.url, path, token: userAccessToken, fields })
248 it('Should fail with negative timestamps', async function () {
249 const fields = { video: { id: server.video.id, startAt: -1 }, reason: 'my super reason' }
251 await makePostBodyRequest({ url: server.url, path, token: userAccessToken, fields })
254 it('Should fail mith misordered startAt/endAt', async function () {
255 const fields = { video: { id: server.video.id, startAt: 5, endAt: 1 }, reason: 'my super reason' }
257 await makePostBodyRequest({ url: server.url, path, token: userAccessToken, fields })
260 it('Should succeed with the corret parameters (advanced)', async function () {
261 const fields: AbuseCreate = {
267 reason: 'my super reason',
268 predefinedReasons: [ 'serverRules' ]
271 await makePostBodyRequest({ url: server.url, path, token: userAccessToken, fields, statusCodeExpected: 200 })
275 describe('When updating an abuse', function () {
277 it('Should fail with a non authenticated user', async function () {
278 await updateAbuse(server.url, 'blabla', abuseId, {}, 401)
281 it('Should fail with a non admin user', async function () {
282 await updateAbuse(server.url, userAccessToken, abuseId, {}, 403)
285 it('Should fail with a bad abuse id', async function () {
286 await updateAbuse(server.url, server.accessToken, 45, {}, 404)
289 it('Should fail with a bad state', async function () {
290 const body = { state: 5 }
291 await updateAbuse(server.url, server.accessToken, abuseId, body, 400)
294 it('Should fail with a bad moderation comment', async function () {
295 const body = { moderationComment: 'b'.repeat(3001) }
296 await updateAbuse(server.url, server.accessToken, abuseId, body, 400)
299 it('Should succeed with the correct params', async function () {
300 const body = { state: AbuseState.ACCEPTED }
301 await updateAbuse(server.url, server.accessToken, abuseId, body)
305 describe('When creating an abuse message', function () {
306 const message = 'my super message'
308 it('Should fail with an invalid abuse id', async function () {
309 await addAbuseMessage(server.url, userAccessToken2, 888, message, 404)
312 it('Should fail with a non authenticated user', async function () {
313 await addAbuseMessage(server.url, 'fake_token', abuseId, message, 401)
316 it('Should fail with an invalid logged in user', async function () {
317 await addAbuseMessage(server.url, userAccessToken2, abuseId, message, 403)
320 it('Should fail with an invalid message', async function () {
321 await addAbuseMessage(server.url, userAccessToken, abuseId, 'a'.repeat(5000), 400)
324 it('Should suceed with the correct params', async function () {
325 const res = await addAbuseMessage(server.url, userAccessToken, abuseId, message)
326 messageId = res.body.abuseMessage.id
330 describe('When listing abuse messages', function () {
332 it('Should fail with an invalid abuse id', async function () {
333 await listAbuseMessages(server.url, userAccessToken, 888, 404)
336 it('Should fail with a non authenticated user', async function () {
337 await listAbuseMessages(server.url, 'fake_token', abuseId, 401)
340 it('Should fail with an invalid logged in user', async function () {
341 await listAbuseMessages(server.url, userAccessToken2, abuseId, 403)
344 it('Should succeed with the correct params', async function () {
345 await listAbuseMessages(server.url, userAccessToken, abuseId)
349 describe('When deleting an abuse message', function () {
351 it('Should fail with an invalid abuse id', async function () {
352 await deleteAbuseMessage(server.url, userAccessToken, 888, messageId, 404)
355 it('Should fail with an invalid message id', async function () {
356 await deleteAbuseMessage(server.url, userAccessToken, abuseId, 888, 404)
359 it('Should fail with a non authenticated user', async function () {
360 await deleteAbuseMessage(server.url, 'fake_token', abuseId, messageId, 401)
363 it('Should fail with an invalid logged in user', async function () {
364 await deleteAbuseMessage(server.url, userAccessToken2, abuseId, messageId, 403)
367 it('Should succeed with the correct params', async function () {
368 await deleteAbuseMessage(server.url, userAccessToken, abuseId, messageId)
372 describe('When deleting a video abuse', function () {
374 it('Should fail with a non authenticated user', async function () {
375 await deleteAbuse(server.url, 'blabla', abuseId, 401)
378 it('Should fail with a non admin user', async function () {
379 await deleteAbuse(server.url, userAccessToken, abuseId, 403)
382 it('Should fail with a bad abuse id', async function () {
383 await deleteAbuse(server.url, server.accessToken, 45, 404)
386 it('Should succeed with the correct params', async function () {
387 await deleteAbuse(server.url, server.accessToken, abuseId)
391 describe('When trying to manage messages of a remote abuse', function () {
392 let remoteAbuseId: number
393 let anotherServer: ServerInfo
395 before(async function () {
398 anotherServer = await flushAndRunServer(2)
399 await setAccessTokensToServers([ anotherServer ])
401 await doubleFollow(anotherServer, server)
403 const server2VideoId = await getVideoIdFromUUID(anotherServer.url, server.video.uuid)
405 url: anotherServer.url,
406 token: anotherServer.accessToken,
407 reason: 'remote server',
408 videoId: server2VideoId
411 await waitJobs([ server, anotherServer ])
413 const res = await getAdminAbusesList({ url: server.url, token: server.accessToken, sort: '-createdAt' })
414 remoteAbuseId = res.body.data[0].id
417 it('Should fail when listing abuse messages of a remote abuse', async function () {
418 await listAbuseMessages(server.url, server.accessToken, remoteAbuseId, 400)
421 it('Should fail when creating abuse message of a remote abuse', async function () {
422 await addAbuseMessage(server.url, server.accessToken, remoteAbuseId, 'message', 400)
425 after(async function () {
426 await cleanupTests([ anotherServer ])
430 after(async function () {
431 await cleanupTests([ server ])