1 /* tslint:disable:no-unused-expression */
8 flushAndRunMultipleServers,
10 getBlacklistedVideosList,
11 getBlacklistedVideosListWithTypeFilter,
17 removeVideoFromBlacklist,
19 setAccessTokensToServers,
22 } from '../../../../shared/utils'
24 checkBadCountPagination,
25 checkBadSortPagination,
26 checkBadStartPagination
27 } from '../../../../shared/utils/requests/check-api-params'
28 import { VideoDetails, VideoBlacklistType } from '../../../../shared/models/videos'
29 import { expect } from 'chai'
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 () {
44 servers = await flushAndRunMultipleServers(2)
46 await setAccessTokensToServers(servers)
47 await doubleFollow(servers[0], servers[1])
50 const username = 'user1'
51 const password = 'my super password'
52 await createUser(servers[0].url, servers[0].accessToken, username, password)
53 userAccessToken1 = await userLogin(servers[0], { username, password })
57 const username = 'user2'
58 const password = 'my super password'
59 await createUser(servers[0].url, servers[0].accessToken, username, password)
60 userAccessToken2 = await userLogin(servers[0], { username, password })
64 const res = await uploadVideo(servers[0].url, userAccessToken1, {})
65 servers[0].video = res.body.video
69 const res = await uploadVideo(servers[0].url, servers[0].accessToken, {})
70 notBlacklistedVideoId = res.body.video.uuid
74 const res = await uploadVideo(servers[1].url, servers[1].accessToken, {})
75 remoteVideoUUID = res.body.video.uuid
78 await waitJobs(servers)
81 describe('When adding a video in blacklist', function () {
82 const basePath = '/api/v1/videos/'
84 it('Should fail with nothing', async function () {
85 const path = basePath + servers[0].video + '/blacklist'
87 await makePostBodyRequest({ url: servers[0].url, path, token: servers[0].accessToken, fields })
90 it('Should fail with a wrong video', async function () {
91 const wrongPath = '/api/v1/videos/blabla/blacklist'
93 await makePostBodyRequest({ url: servers[0].url, path: wrongPath, token: servers[0].accessToken, fields })
96 it('Should fail with a non authenticated user', async function () {
97 const path = basePath + servers[0].video + '/blacklist'
99 await makePostBodyRequest({ url: servers[0].url, path, token: 'hello', fields, statusCodeExpected: 401 })
102 it('Should fail with a non admin user', async function () {
103 const path = basePath + servers[0].video + '/blacklist'
105 await makePostBodyRequest({ url: servers[0].url, path, token: userAccessToken2, fields, statusCodeExpected: 403 })
108 it('Should fail with an invalid reason', async function () {
109 const path = basePath + servers[0].video.uuid + '/blacklist'
110 const fields = { reason: 'a'.repeat(305) }
112 await makePostBodyRequest({ url: servers[0].url, path, token: servers[0].accessToken, fields })
115 it('Should fail to unfederate a remote video', async function () {
116 const path = basePath + remoteVideoUUID + '/blacklist'
117 const fields = { unfederate: true }
119 await makePostBodyRequest({ url: servers[0].url, path, token: servers[0].accessToken, fields, statusCodeExpected: 409 })
122 it('Should succeed with the correct params', async function () {
123 const path = basePath + servers[0].video.uuid + '/blacklist'
126 await makePostBodyRequest({ url: servers[0].url, path, token: servers[0].accessToken, fields, statusCodeExpected: 204 })
130 describe('When updating a video in blacklist', function () {
131 const basePath = '/api/v1/videos/'
133 it('Should fail with a wrong video', async function () {
134 const wrongPath = '/api/v1/videos/blabla/blacklist'
136 await makePutBodyRequest({ url: servers[0].url, path: wrongPath, token: servers[0].accessToken, fields })
139 it('Should fail with a video not blacklisted', async function () {
140 const path = '/api/v1/videos/' + notBlacklistedVideoId + '/blacklist'
142 await makePutBodyRequest({ url: servers[0].url, path, token: servers[0].accessToken, fields, statusCodeExpected: 404 })
145 it('Should fail with a non authenticated user', async function () {
146 const path = basePath + servers[0].video + '/blacklist'
148 await makePutBodyRequest({ url: servers[0].url, path, token: 'hello', fields, statusCodeExpected: 401 })
151 it('Should fail with a non admin user', async function () {
152 const path = basePath + servers[0].video + '/blacklist'
154 await makePutBodyRequest({ url: servers[0].url, path, token: userAccessToken2, fields, statusCodeExpected: 403 })
157 it('Should fail with an invalid reason', async function () {
158 const path = basePath + servers[0].video.uuid + '/blacklist'
159 const fields = { reason: 'a'.repeat(305) }
161 await makePutBodyRequest({ url: servers[0].url, path, token: servers[0].accessToken, fields })
164 it('Should succeed with the correct params', async function () {
165 const path = basePath + servers[0].video.uuid + '/blacklist'
166 const fields = { reason: 'hello' }
168 await makePutBodyRequest({ url: servers[0].url, path, token: servers[0].accessToken, fields, statusCodeExpected: 204 })
172 describe('When getting blacklisted video', function () {
174 it('Should fail with a non authenticated user', async function () {
175 await getVideo(servers[0].url, servers[0].video.uuid, 401)
178 it('Should fail with another user', async function () {
179 await getVideoWithToken(servers[0].url, userAccessToken2, servers[0].video.uuid, 403)
182 it('Should succeed with the owner authenticated user', async function () {
183 const res = await getVideoWithToken(servers[0].url, userAccessToken1, servers[0].video.uuid, 200)
184 const video: VideoDetails = res.body
186 expect(video.blacklisted).to.be.true
189 it('Should succeed with an admin', async function () {
190 const res = await getVideoWithToken(servers[0].url, servers[0].accessToken, servers[0].video.uuid, 200)
191 const video: VideoDetails = res.body
193 expect(video.blacklisted).to.be.true
197 describe('When removing a video in blacklist', function () {
198 it('Should fail with a non authenticated user', async function () {
199 await removeVideoFromBlacklist(servers[0].url, 'fake token', servers[0].video.uuid, 401)
202 it('Should fail with a non admin user', async function () {
203 await removeVideoFromBlacklist(servers[0].url, userAccessToken2, servers[0].video.uuid, 403)
206 it('Should fail with an incorrect id', async function () {
207 await removeVideoFromBlacklist(servers[0].url, servers[0].accessToken, 'hello', 400)
210 it('Should fail with a not blacklisted video', async function () {
211 // The video was not added to the blacklist so it should fail
212 await removeVideoFromBlacklist(servers[0].url, servers[0].accessToken, notBlacklistedVideoId, 404)
215 it('Should succeed with the correct params', async function () {
216 await removeVideoFromBlacklist(servers[0].url, servers[0].accessToken, servers[0].video.uuid, 204)
220 describe('When listing videos in blacklist', function () {
221 const basePath = '/api/v1/videos/blacklist/'
223 it('Should fail with a non authenticated user', async function () {
224 await getBlacklistedVideosList(servers[0].url, 'fake token', 401)
227 it('Should fail with a non admin user', async function () {
228 await getBlacklistedVideosList(servers[0].url, userAccessToken2, 403)
231 it('Should fail with a bad start pagination', async function () {
232 await checkBadStartPagination(servers[0].url, basePath, servers[0].accessToken)
235 it('Should fail with a bad count pagination', async function () {
236 await checkBadCountPagination(servers[0].url, basePath, servers[0].accessToken)
239 it('Should fail with an incorrect sort', async function () {
240 await checkBadSortPagination(servers[0].url, basePath, servers[0].accessToken)
243 it('Should fail with an invalid type', async function () {
244 await getBlacklistedVideosListWithTypeFilter(servers[0].url, servers[0].accessToken, 0, 400)
247 it('Should succeed with the correct parameters', async function () {
248 await getBlacklistedVideosListWithTypeFilter(servers[0].url, servers[0].accessToken, VideoBlacklistType.MANUAL)
252 after(async function () {
253 killallServers(servers)
255 // Keep the logs if the test failed