1 /* tslint:disable:no-unused-expression */
8 flushAndRunMultipleServers,
10 getBlacklistedVideosList,
16 removeVideoFromBlacklist,
18 setAccessTokensToServers,
21 } from '../../../../shared/extra-utils'
23 checkBadCountPagination,
24 checkBadSortPagination,
25 checkBadStartPagination
26 } from '../../../../shared/extra-utils/requests/check-api-params'
27 import { VideoDetails, VideoBlacklistType } 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 () {
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: 401 })
101 it('Should fail with a non admin user', async function () {
102 const path = basePath + servers[0].video + '/blacklist'
104 await makePostBodyRequest({ url: servers[0].url, path, token: userAccessToken2, fields, statusCodeExpected: 403 })
107 it('Should fail with an invalid reason', async function () {
108 const path = basePath + servers[0].video.uuid + '/blacklist'
109 const fields = { reason: 'a'.repeat(305) }
111 await makePostBodyRequest({ url: servers[0].url, path, token: servers[0].accessToken, fields })
114 it('Should fail to unfederate a remote video', async function () {
115 const path = basePath + remoteVideoUUID + '/blacklist'
116 const fields = { unfederate: true }
118 await makePostBodyRequest({ url: servers[0].url, path, token: servers[0].accessToken, fields, statusCodeExpected: 409 })
121 it('Should succeed with the correct params', async function () {
122 const path = basePath + servers[0].video.uuid + '/blacklist'
125 await makePostBodyRequest({ url: servers[0].url, path, token: servers[0].accessToken, fields, statusCodeExpected: 204 })
129 describe('When updating a video in blacklist', function () {
130 const basePath = '/api/v1/videos/'
132 it('Should fail with a wrong video', async function () {
133 const wrongPath = '/api/v1/videos/blabla/blacklist'
135 await makePutBodyRequest({ url: servers[0].url, path: wrongPath, token: servers[0].accessToken, fields })
138 it('Should fail with a video not blacklisted', async function () {
139 const path = '/api/v1/videos/' + notBlacklistedVideoId + '/blacklist'
141 await makePutBodyRequest({ url: servers[0].url, path, token: servers[0].accessToken, fields, statusCodeExpected: 404 })
144 it('Should fail with a non authenticated user', async function () {
145 const path = basePath + servers[0].video + '/blacklist'
147 await makePutBodyRequest({ url: servers[0].url, path, token: 'hello', fields, statusCodeExpected: 401 })
150 it('Should fail with a non admin user', async function () {
151 const path = basePath + servers[0].video + '/blacklist'
153 await makePutBodyRequest({ url: servers[0].url, path, token: userAccessToken2, fields, statusCodeExpected: 403 })
156 it('Should fail with an invalid reason', async function () {
157 const path = basePath + servers[0].video.uuid + '/blacklist'
158 const fields = { reason: 'a'.repeat(305) }
160 await makePutBodyRequest({ url: servers[0].url, path, token: servers[0].accessToken, fields })
163 it('Should succeed with the correct params', async function () {
164 const path = basePath + servers[0].video.uuid + '/blacklist'
165 const fields = { reason: 'hello' }
167 await makePutBodyRequest({ url: servers[0].url, path, token: servers[0].accessToken, fields, statusCodeExpected: 204 })
171 describe('When getting blacklisted video', function () {
173 it('Should fail with a non authenticated user', async function () {
174 await getVideo(servers[0].url, servers[0].video.uuid, 401)
177 it('Should fail with another user', async function () {
178 await getVideoWithToken(servers[0].url, userAccessToken2, servers[0].video.uuid, 403)
181 it('Should succeed with the owner authenticated user', async function () {
182 const res = await getVideoWithToken(servers[0].url, userAccessToken1, servers[0].video.uuid, 200)
183 const video: VideoDetails = res.body
185 expect(video.blacklisted).to.be.true
188 it('Should succeed with an admin', async function () {
189 const res = await getVideoWithToken(servers[0].url, servers[0].accessToken, servers[0].video.uuid, 200)
190 const video: VideoDetails = res.body
192 expect(video.blacklisted).to.be.true
196 describe('When removing a video in blacklist', function () {
197 it('Should fail with a non authenticated user', async function () {
198 await removeVideoFromBlacklist(servers[0].url, 'fake token', servers[0].video.uuid, 401)
201 it('Should fail with a non admin user', async function () {
202 await removeVideoFromBlacklist(servers[0].url, userAccessToken2, servers[0].video.uuid, 403)
205 it('Should fail with an incorrect id', async function () {
206 await removeVideoFromBlacklist(servers[0].url, servers[0].accessToken, 'hello', 400)
209 it('Should fail with a not blacklisted video', async function () {
210 // The video was not added to the blacklist so it should fail
211 await removeVideoFromBlacklist(servers[0].url, servers[0].accessToken, notBlacklistedVideoId, 404)
214 it('Should succeed with the correct params', async function () {
215 await removeVideoFromBlacklist(servers[0].url, servers[0].accessToken, servers[0].video.uuid, 204)
219 describe('When listing videos in blacklist', function () {
220 const basePath = '/api/v1/videos/blacklist/'
222 it('Should fail with a non authenticated user', async function () {
223 await getBlacklistedVideosList({ url: servers[0].url, token: 'fake token', specialStatus: 401 })
226 it('Should fail with a non admin user', async function () {
227 await getBlacklistedVideosList({ url: servers[0].url, token: userAccessToken2, specialStatus: 403 })
230 it('Should fail with a bad start pagination', async function () {
231 await checkBadStartPagination(servers[0].url, basePath, servers[0].accessToken)
234 it('Should fail with a bad count pagination', async function () {
235 await checkBadCountPagination(servers[0].url, basePath, servers[0].accessToken)
238 it('Should fail with an incorrect sort', async function () {
239 await checkBadSortPagination(servers[0].url, basePath, servers[0].accessToken)
242 it('Should fail with an invalid type', async function () {
243 await getBlacklistedVideosList({ url: servers[0].url, token: servers[0].accessToken, type: 0, specialStatus: 400 })
246 it('Should succeed with the correct parameters', async function () {
247 await getBlacklistedVideosList({ url: servers[0].url, token: servers[0].accessToken, type: VideoBlacklistType.MANUAL })
251 after(async function () {
252 killallServers(servers)
254 // Keep the logs if the test failed