1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
9 flushAndRunMultipleServers,
10 getBlacklistedVideosList,
15 removeVideoFromBlacklist,
17 setAccessTokensToServers,
21 } from '../../../../shared/extra-utils'
23 checkBadCountPagination,
24 checkBadSortPagination,
25 checkBadStartPagination
26 } from '../../../../shared/extra-utils/requests/check-api-params'
27 import { VideoBlacklistType, VideoDetails } from '../../../../shared/models/videos'
28 import { expect } from 'chai'
30 describe('Test video blacklist API validators', function () {
31 let servers: ServerInfo[]
32 let notBlacklistedVideoId: number
33 let remoteVideoUUID: string
34 let userAccessToken1 = ''
35 let userAccessToken2 = ''
37 // ---------------------------------------------------------------
39 before(async function () {
42 servers = await flushAndRunMultipleServers(2)
44 await setAccessTokensToServers(servers)
45 await doubleFollow(servers[0], servers[1])
48 const username = 'user1'
49 const password = 'my super password'
50 await createUser({ url: servers[0].url, accessToken: servers[0].accessToken, username: username, password: password })
51 userAccessToken1 = await userLogin(servers[0], { username, password })
55 const username = 'user2'
56 const password = 'my super password'
57 await createUser({ url: servers[0].url, accessToken: servers[0].accessToken, username: username, password: password })
58 userAccessToken2 = await userLogin(servers[0], { username, password })
62 const res = await uploadVideo(servers[0].url, userAccessToken1, {})
63 servers[0].video = res.body.video
67 const res = await uploadVideo(servers[0].url, servers[0].accessToken, {})
68 notBlacklistedVideoId = res.body.video.uuid
72 const res = await uploadVideo(servers[1].url, servers[1].accessToken, {})
73 remoteVideoUUID = res.body.video.uuid
76 await waitJobs(servers)
79 describe('When adding a video in blacklist', function () {
80 const basePath = '/api/v1/videos/'
82 it('Should fail with nothing', async function () {
83 const path = basePath + servers[0].video + '/blacklist'
85 await makePostBodyRequest({ url: servers[0].url, path, token: servers[0].accessToken, fields })
88 it('Should fail with a wrong video', async function () {
89 const wrongPath = '/api/v1/videos/blabla/blacklist'
91 await makePostBodyRequest({ url: servers[0].url, path: wrongPath, token: servers[0].accessToken, fields })
94 it('Should fail with a non authenticated user', async function () {
95 const path = basePath + servers[0].video + '/blacklist'
97 await makePostBodyRequest({ url: servers[0].url, path, token: 'hello', fields, statusCodeExpected: 401 })
100 it('Should fail with a non admin user', async function () {
101 const path = basePath + servers[0].video + '/blacklist'
103 await makePostBodyRequest({ url: servers[0].url, path, token: userAccessToken2, fields, statusCodeExpected: 403 })
106 it('Should fail with an invalid reason', async function () {
107 const path = basePath + servers[0].video.uuid + '/blacklist'
108 const fields = { reason: 'a'.repeat(305) }
110 await makePostBodyRequest({ url: servers[0].url, path, token: servers[0].accessToken, fields })
113 it('Should fail to unfederate a remote video', async function () {
114 const path = basePath + remoteVideoUUID + '/blacklist'
115 const fields = { unfederate: true }
117 await makePostBodyRequest({ url: servers[0].url, path, token: servers[0].accessToken, fields, statusCodeExpected: 409 })
120 it('Should succeed with the correct params', async function () {
121 const path = basePath + servers[0].video.uuid + '/blacklist'
124 await makePostBodyRequest({ url: servers[0].url, path, token: servers[0].accessToken, fields, statusCodeExpected: 204 })
128 describe('When updating a video in blacklist', function () {
129 const basePath = '/api/v1/videos/'
131 it('Should fail with a wrong video', async function () {
132 const wrongPath = '/api/v1/videos/blabla/blacklist'
134 await makePutBodyRequest({ url: servers[0].url, path: wrongPath, token: servers[0].accessToken, fields })
137 it('Should fail with a video not blacklisted', async function () {
138 const path = '/api/v1/videos/' + notBlacklistedVideoId + '/blacklist'
140 await makePutBodyRequest({ url: servers[0].url, path, token: servers[0].accessToken, fields, statusCodeExpected: 404 })
143 it('Should fail with a non authenticated user', async function () {
144 const path = basePath + servers[0].video + '/blacklist'
146 await makePutBodyRequest({ url: servers[0].url, path, token: 'hello', fields, statusCodeExpected: 401 })
149 it('Should fail with a non admin user', async function () {
150 const path = basePath + servers[0].video + '/blacklist'
152 await makePutBodyRequest({ url: servers[0].url, path, token: userAccessToken2, fields, statusCodeExpected: 403 })
155 it('Should fail with an invalid reason', async function () {
156 const path = basePath + servers[0].video.uuid + '/blacklist'
157 const fields = { reason: 'a'.repeat(305) }
159 await makePutBodyRequest({ url: servers[0].url, path, token: servers[0].accessToken, fields })
162 it('Should succeed with the correct params', async function () {
163 const path = basePath + servers[0].video.uuid + '/blacklist'
164 const fields = { reason: 'hello' }
166 await makePutBodyRequest({ url: servers[0].url, path, token: servers[0].accessToken, fields, statusCodeExpected: 204 })
170 describe('When getting blacklisted video', function () {
172 it('Should fail with a non authenticated user', async function () {
173 await getVideo(servers[0].url, servers[0].video.uuid, 401)
176 it('Should fail with another user', async function () {
177 await getVideoWithToken(servers[0].url, userAccessToken2, servers[0].video.uuid, 403)
180 it('Should succeed with the owner authenticated user', async function () {
181 const res = await getVideoWithToken(servers[0].url, userAccessToken1, servers[0].video.uuid, 200)
182 const video: VideoDetails = res.body
184 expect(video.blacklisted).to.be.true
187 it('Should succeed with an admin', async function () {
188 const res = await getVideoWithToken(servers[0].url, servers[0].accessToken, servers[0].video.uuid, 200)
189 const video: VideoDetails = res.body
191 expect(video.blacklisted).to.be.true
195 describe('When removing a video in blacklist', function () {
196 it('Should fail with a non authenticated user', async function () {
197 await removeVideoFromBlacklist(servers[0].url, 'fake token', servers[0].video.uuid, 401)
200 it('Should fail with a non admin user', async function () {
201 await removeVideoFromBlacklist(servers[0].url, userAccessToken2, servers[0].video.uuid, 403)
204 it('Should fail with an incorrect id', async function () {
205 await removeVideoFromBlacklist(servers[0].url, servers[0].accessToken, 'hello', 400)
208 it('Should fail with a not blacklisted video', async function () {
209 // The video was not added to the blacklist so it should fail
210 await removeVideoFromBlacklist(servers[0].url, servers[0].accessToken, notBlacklistedVideoId, 404)
213 it('Should succeed with the correct params', async function () {
214 await removeVideoFromBlacklist(servers[0].url, servers[0].accessToken, servers[0].video.uuid, 204)
218 describe('When listing videos in blacklist', function () {
219 const basePath = '/api/v1/videos/blacklist/'
221 it('Should fail with a non authenticated user', async function () {
222 await getBlacklistedVideosList({ url: servers[0].url, token: 'fake token', specialStatus: 401 })
225 it('Should fail with a non admin user', async function () {
226 await getBlacklistedVideosList({ url: servers[0].url, token: userAccessToken2, specialStatus: 403 })
229 it('Should fail with a bad start pagination', async function () {
230 await checkBadStartPagination(servers[0].url, basePath, servers[0].accessToken)
233 it('Should fail with a bad count pagination', async function () {
234 await checkBadCountPagination(servers[0].url, basePath, servers[0].accessToken)
237 it('Should fail with an incorrect sort', async function () {
238 await checkBadSortPagination(servers[0].url, basePath, servers[0].accessToken)
241 it('Should fail with an invalid type', async function () {
242 await getBlacklistedVideosList({ url: servers[0].url, token: servers[0].accessToken, type: 0, specialStatus: 400 })
245 it('Should succeed with the correct parameters', async function () {
246 await getBlacklistedVideosList({ url: servers[0].url, token: servers[0].accessToken, type: VideoBlacklistType.MANUAL })
250 after(async function () {
251 await cleanupTests(servers)