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'
29 import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
31 describe('Test video blacklist API validators', function () {
32 let servers: ServerInfo[]
33 let notBlacklistedVideoId: number
34 let remoteVideoUUID: string
35 let userAccessToken1 = ''
36 let userAccessToken2 = ''
38 // ---------------------------------------------------------------
40 before(async function () {
43 servers = await flushAndRunMultipleServers(2)
45 await setAccessTokensToServers(servers)
46 await doubleFollow(servers[0], servers[1])
49 const username = 'user1'
50 const password = 'my super password'
51 await createUser({ url: servers[0].url, accessToken: servers[0].accessToken, username: username, password: password })
52 userAccessToken1 = await userLogin(servers[0], { username, password })
56 const username = 'user2'
57 const password = 'my super password'
58 await createUser({ url: servers[0].url, accessToken: servers[0].accessToken, username: username, password: password })
59 userAccessToken2 = await userLogin(servers[0], { username, password })
63 const res = await uploadVideo(servers[0].url, userAccessToken1, {})
64 servers[0].video = res.body.video
68 const res = await uploadVideo(servers[0].url, servers[0].accessToken, {})
69 notBlacklistedVideoId = res.body.video.uuid
73 const res = await uploadVideo(servers[1].url, servers[1].accessToken, {})
74 remoteVideoUUID = res.body.video.uuid
77 await waitJobs(servers)
80 describe('When adding a video in blacklist', function () {
81 const basePath = '/api/v1/videos/'
83 it('Should fail with nothing', async function () {
84 const path = basePath + servers[0].video + '/blacklist'
86 await makePostBodyRequest({ url: servers[0].url, path, token: servers[0].accessToken, fields })
89 it('Should fail with a wrong video', async function () {
90 const wrongPath = '/api/v1/videos/blabla/blacklist'
92 await makePostBodyRequest({ url: servers[0].url, path: wrongPath, token: servers[0].accessToken, fields })
95 it('Should fail with a non authenticated user', async function () {
96 const path = basePath + servers[0].video + '/blacklist'
98 await makePostBodyRequest({ url: servers[0].url, path, token: 'hello', fields, statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 })
101 it('Should fail with a non admin user', async function () {
102 const path = basePath + servers[0].video + '/blacklist'
104 await makePostBodyRequest({
107 token: userAccessToken2,
109 statusCodeExpected: HttpStatusCode.FORBIDDEN_403
113 it('Should fail with an invalid reason', async function () {
114 const path = basePath + servers[0].video.uuid + '/blacklist'
115 const fields = { reason: 'a'.repeat(305) }
117 await makePostBodyRequest({ url: servers[0].url, path, token: servers[0].accessToken, fields })
120 it('Should fail to unfederate a remote video', async function () {
121 const path = basePath + remoteVideoUUID + '/blacklist'
122 const fields = { unfederate: true }
124 await makePostBodyRequest({
127 token: servers[0].accessToken,
129 statusCodeExpected: HttpStatusCode.CONFLICT_409
133 it('Should succeed with the correct params', async function () {
134 const path = basePath + servers[0].video.uuid + '/blacklist'
137 await makePostBodyRequest({
140 token: servers[0].accessToken,
142 statusCodeExpected: HttpStatusCode.NO_CONTENT_204
147 describe('When updating a video in blacklist', function () {
148 const basePath = '/api/v1/videos/'
150 it('Should fail with a wrong video', async function () {
151 const wrongPath = '/api/v1/videos/blabla/blacklist'
153 await makePutBodyRequest({ url: servers[0].url, path: wrongPath, token: servers[0].accessToken, fields })
156 it('Should fail with a video not blacklisted', async function () {
157 const path = '/api/v1/videos/' + notBlacklistedVideoId + '/blacklist'
159 await makePutBodyRequest({
162 token: servers[0].accessToken,
164 statusCodeExpected: HttpStatusCode.NOT_FOUND_404
168 it('Should fail with a non authenticated user', async function () {
169 const path = basePath + servers[0].video + '/blacklist'
171 await makePutBodyRequest({ url: servers[0].url, path, token: 'hello', fields, statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 })
174 it('Should fail with a non admin user', async function () {
175 const path = basePath + servers[0].video + '/blacklist'
177 await makePutBodyRequest({
180 token: userAccessToken2,
182 statusCodeExpected: HttpStatusCode.FORBIDDEN_403
186 it('Should fail with an invalid reason', async function () {
187 const path = basePath + servers[0].video.uuid + '/blacklist'
188 const fields = { reason: 'a'.repeat(305) }
190 await makePutBodyRequest({ url: servers[0].url, path, token: servers[0].accessToken, fields })
193 it('Should succeed with the correct params', async function () {
194 const path = basePath + servers[0].video.shortUUID + '/blacklist'
195 const fields = { reason: 'hello' }
197 await makePutBodyRequest({
200 token: servers[0].accessToken,
202 statusCodeExpected: HttpStatusCode.NO_CONTENT_204
207 describe('When getting blacklisted video', function () {
209 it('Should fail with a non authenticated user', async function () {
210 await getVideo(servers[0].url, servers[0].video.uuid, HttpStatusCode.UNAUTHORIZED_401)
213 it('Should fail with another user', async function () {
214 await getVideoWithToken(servers[0].url, userAccessToken2, servers[0].video.uuid, HttpStatusCode.FORBIDDEN_403)
217 it('Should succeed with the owner authenticated user', async function () {
218 const res = await getVideoWithToken(servers[0].url, userAccessToken1, servers[0].video.uuid, HttpStatusCode.OK_200)
219 const video: VideoDetails = res.body
221 expect(video.blacklisted).to.be.true
224 it('Should succeed with an admin', async function () {
225 const video = servers[0].video
227 for (const id of [ video.id, video.uuid, video.shortUUID ]) {
228 const res = await getVideoWithToken(servers[0].url, servers[0].accessToken, id, HttpStatusCode.OK_200)
229 const video: VideoDetails = res.body
231 expect(video.blacklisted).to.be.true
236 describe('When removing a video in blacklist', function () {
237 it('Should fail with a non authenticated user', async function () {
238 await removeVideoFromBlacklist(servers[0].url, 'fake token', servers[0].video.uuid, HttpStatusCode.UNAUTHORIZED_401)
241 it('Should fail with a non admin user', async function () {
242 await removeVideoFromBlacklist(servers[0].url, userAccessToken2, servers[0].video.uuid, HttpStatusCode.FORBIDDEN_403)
245 it('Should fail with an incorrect id', async function () {
246 await removeVideoFromBlacklist(servers[0].url, servers[0].accessToken, 'hello', HttpStatusCode.BAD_REQUEST_400)
249 it('Should fail with a not blacklisted video', async function () {
250 // The video was not added to the blacklist so it should fail
251 await removeVideoFromBlacklist(servers[0].url, servers[0].accessToken, notBlacklistedVideoId, HttpStatusCode.NOT_FOUND_404)
254 it('Should succeed with the correct params', async function () {
255 await removeVideoFromBlacklist(servers[0].url, servers[0].accessToken, servers[0].video.uuid, HttpStatusCode.NO_CONTENT_204)
259 describe('When listing videos in blacklist', function () {
260 const basePath = '/api/v1/videos/blacklist/'
262 it('Should fail with a non authenticated user', async function () {
263 await getBlacklistedVideosList({ url: servers[0].url, token: 'fake token', specialStatus: HttpStatusCode.UNAUTHORIZED_401 })
266 it('Should fail with a non admin user', async function () {
267 await getBlacklistedVideosList({ url: servers[0].url, token: userAccessToken2, specialStatus: HttpStatusCode.FORBIDDEN_403 })
270 it('Should fail with a bad start pagination', async function () {
271 await checkBadStartPagination(servers[0].url, basePath, servers[0].accessToken)
274 it('Should fail with a bad count pagination', async function () {
275 await checkBadCountPagination(servers[0].url, basePath, servers[0].accessToken)
278 it('Should fail with an incorrect sort', async function () {
279 await checkBadSortPagination(servers[0].url, basePath, servers[0].accessToken)
282 it('Should fail with an invalid type', async function () {
283 await getBlacklistedVideosList({
285 token: servers[0].accessToken,
287 specialStatus: HttpStatusCode.BAD_REQUEST_400
291 it('Should succeed with the correct parameters', async function () {
292 await getBlacklistedVideosList({ url: servers[0].url, token: servers[0].accessToken, type: VideoBlacklistType.MANUAL })
296 after(async function () {
297 await cleanupTests(servers)