]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/tests/api/check-params/video-blacklist.ts
Use test wrapper exit function
[github/Chocobozzz/PeerTube.git] / server / tests / api / check-params / video-blacklist.ts
CommitLineData
792dbaf0
GS
1/* tslint:disable:no-unused-expression */
2
3import 'mocha'
792dbaf0
GS
4
5import {
7c3b7976 6 cleanupTests,
26b7305a 7 createUser,
5abb9fbb
C
8 doubleFollow,
9 flushAndRunMultipleServers,
26b7305a 10 flushTests,
5abb9fbb
C
11 getBlacklistedVideosList,
12 getVideo,
13 getVideoWithToken,
26b7305a
C
14 killallServers,
15 makePostBodyRequest,
16 makePutBodyRequest,
17 removeVideoFromBlacklist,
26b7305a
C
18 ServerInfo,
19 setAccessTokensToServers,
20 uploadVideo,
5abb9fbb 21 userLogin, waitJobs
94565d52 22} from '../../../../shared/extra-utils'
9639bd17 23import {
24 checkBadCountPagination,
25 checkBadSortPagination,
26 checkBadStartPagination
94565d52 27} from '../../../../shared/extra-utils/requests/check-api-params'
7ccddd7b 28import { VideoDetails, VideoBlacklistType } from '../../../../shared/models/videos'
e5e7f7fe 29import { expect } from 'chai'
792dbaf0
GS
30
31describe('Test video blacklist API validators', function () {
5abb9fbb 32 let servers: ServerInfo[]
26b7305a 33 let notBlacklistedVideoId: number
5abb9fbb 34 let remoteVideoUUID: string
e5e7f7fe
C
35 let userAccessToken1 = ''
36 let userAccessToken2 = ''
792dbaf0
GS
37
38 // ---------------------------------------------------------------
39
40 before(async function () {
41 this.timeout(120000)
42
5abb9fbb 43 servers = await flushAndRunMultipleServers(2)
792dbaf0 44
5abb9fbb
C
45 await setAccessTokensToServers(servers)
46 await doubleFollow(servers[0], servers[1])
792dbaf0 47
e5e7f7fe
C
48 {
49 const username = 'user1'
50 const password = 'my super password'
1eddc9a7 51 await createUser({ url: servers[ 0 ].url, accessToken: servers[ 0 ].accessToken, username: username, password: password })
5abb9fbb 52 userAccessToken1 = await userLogin(servers[0], { username, password })
e5e7f7fe 53 }
792dbaf0 54
26b7305a 55 {
e5e7f7fe
C
56 const username = 'user2'
57 const password = 'my super password'
1eddc9a7 58 await createUser({ url: servers[ 0 ].url, accessToken: servers[ 0 ].accessToken, username: username, password: password })
5abb9fbb 59 userAccessToken2 = await userLogin(servers[0], { username, password })
e5e7f7fe
C
60 }
61
62 {
5abb9fbb
C
63 const res = await uploadVideo(servers[0].url, userAccessToken1, {})
64 servers[0].video = res.body.video
26b7305a
C
65 }
66
67 {
5abb9fbb 68 const res = await uploadVideo(servers[0].url, servers[0].accessToken, {})
26b7305a
C
69 notBlacklistedVideoId = res.body.video.uuid
70 }
5abb9fbb
C
71
72 {
73 const res = await uploadVideo(servers[1].url, servers[1].accessToken, {})
74 remoteVideoUUID = res.body.video.uuid
75 }
76
77 await waitJobs(servers)
792dbaf0
GS
78 })
79
80 describe('When adding a video in blacklist', function () {
81 const basePath = '/api/v1/videos/'
82
83 it('Should fail with nothing', async function () {
5abb9fbb 84 const path = basePath + servers[0].video + '/blacklist'
792dbaf0 85 const fields = {}
5abb9fbb 86 await makePostBodyRequest({ url: servers[0].url, path, token: servers[0].accessToken, fields })
792dbaf0
GS
87 })
88
89 it('Should fail with a wrong video', async function () {
90 const wrongPath = '/api/v1/videos/blabla/blacklist'
91 const fields = {}
5abb9fbb 92 await makePostBodyRequest({ url: servers[0].url, path: wrongPath, token: servers[0].accessToken, fields })
792dbaf0
GS
93 })
94
95 it('Should fail with a non authenticated user', async function () {
5abb9fbb 96 const path = basePath + servers[0].video + '/blacklist'
11ba2ab3 97 const fields = {}
5abb9fbb 98 await makePostBodyRequest({ url: servers[0].url, path, token: 'hello', fields, statusCodeExpected: 401 })
792dbaf0
GS
99 })
100
101 it('Should fail with a non admin user', async function () {
5abb9fbb 102 const path = basePath + servers[0].video + '/blacklist'
11ba2ab3 103 const fields = {}
5abb9fbb 104 await makePostBodyRequest({ url: servers[0].url, path, token: userAccessToken2, fields, statusCodeExpected: 403 })
792dbaf0
GS
105 })
106
26b7305a 107 it('Should fail with an invalid reason', async function () {
5abb9fbb 108 const path = basePath + servers[0].video.uuid + '/blacklist'
26b7305a
C
109 const fields = { reason: 'a'.repeat(305) }
110
5abb9fbb
C
111 await makePostBodyRequest({ url: servers[0].url, path, token: servers[0].accessToken, fields })
112 })
113
114 it('Should fail to unfederate a remote video', async function () {
115 const path = basePath + remoteVideoUUID + '/blacklist'
116 const fields = { unfederate: true }
117
118 await makePostBodyRequest({ url: servers[0].url, path, token: servers[0].accessToken, fields, statusCodeExpected: 409 })
26b7305a
C
119 })
120
121 it('Should succeed with the correct params', async function () {
5abb9fbb 122 const path = basePath + servers[0].video.uuid + '/blacklist'
26b7305a
C
123 const fields = { }
124
5abb9fbb 125 await makePostBodyRequest({ url: servers[0].url, path, token: servers[0].accessToken, fields, statusCodeExpected: 204 })
26b7305a
C
126 })
127 })
128
129 describe('When updating a video in blacklist', function () {
130 const basePath = '/api/v1/videos/'
131
132 it('Should fail with a wrong video', async function () {
133 const wrongPath = '/api/v1/videos/blabla/blacklist'
134 const fields = {}
5abb9fbb 135 await makePutBodyRequest({ url: servers[0].url, path: wrongPath, token: servers[0].accessToken, fields })
26b7305a
C
136 })
137
138 it('Should fail with a video not blacklisted', async function () {
139 const path = '/api/v1/videos/' + notBlacklistedVideoId + '/blacklist'
140 const fields = {}
5abb9fbb 141 await makePutBodyRequest({ url: servers[0].url, path, token: servers[0].accessToken, fields, statusCodeExpected: 404 })
26b7305a
C
142 })
143
144 it('Should fail with a non authenticated user', async function () {
5abb9fbb 145 const path = basePath + servers[0].video + '/blacklist'
26b7305a 146 const fields = {}
5abb9fbb 147 await makePutBodyRequest({ url: servers[0].url, path, token: 'hello', fields, statusCodeExpected: 401 })
26b7305a
C
148 })
149
150 it('Should fail with a non admin user', async function () {
5abb9fbb 151 const path = basePath + servers[0].video + '/blacklist'
11ba2ab3 152 const fields = {}
5abb9fbb 153 await makePutBodyRequest({ url: servers[0].url, path, token: userAccessToken2, fields, statusCodeExpected: 403 })
26b7305a
C
154 })
155
156 it('Should fail with an invalid reason', async function () {
5abb9fbb 157 const path = basePath + servers[0].video.uuid + '/blacklist'
26b7305a
C
158 const fields = { reason: 'a'.repeat(305) }
159
5abb9fbb 160 await makePutBodyRequest({ url: servers[0].url, path, token: servers[0].accessToken, fields })
26b7305a
C
161 })
162
163 it('Should succeed with the correct params', async function () {
5abb9fbb 164 const path = basePath + servers[0].video.uuid + '/blacklist'
26b7305a
C
165 const fields = { reason: 'hello' }
166
5abb9fbb 167 await makePutBodyRequest({ url: servers[0].url, path, token: servers[0].accessToken, fields, statusCodeExpected: 204 })
792dbaf0
GS
168 })
169 })
170
e5e7f7fe
C
171 describe('When getting blacklisted video', function () {
172
173 it('Should fail with a non authenticated user', async function () {
5abb9fbb 174 await getVideo(servers[0].url, servers[0].video.uuid, 401)
e5e7f7fe
C
175 })
176
177 it('Should fail with another user', async function () {
5abb9fbb 178 await getVideoWithToken(servers[0].url, userAccessToken2, servers[0].video.uuid, 403)
e5e7f7fe
C
179 })
180
181 it('Should succeed with the owner authenticated user', async function () {
5abb9fbb 182 const res = await getVideoWithToken(servers[0].url, userAccessToken1, servers[0].video.uuid, 200)
e5e7f7fe
C
183 const video: VideoDetails = res.body
184
185 expect(video.blacklisted).to.be.true
186 })
187
188 it('Should succeed with an admin', async function () {
5abb9fbb 189 const res = await getVideoWithToken(servers[0].url, servers[0].accessToken, servers[0].video.uuid, 200)
e5e7f7fe
C
190 const video: VideoDetails = res.body
191
192 expect(video.blacklisted).to.be.true
193 })
194 })
195
792dbaf0 196 describe('When removing a video in blacklist', function () {
792dbaf0 197 it('Should fail with a non authenticated user', async function () {
5abb9fbb 198 await removeVideoFromBlacklist(servers[0].url, 'fake token', servers[0].video.uuid, 401)
792dbaf0
GS
199 })
200
201 it('Should fail with a non admin user', async function () {
5abb9fbb 202 await removeVideoFromBlacklist(servers[0].url, userAccessToken2, servers[0].video.uuid, 403)
792dbaf0
GS
203 })
204
205 it('Should fail with an incorrect id', async function () {
5abb9fbb 206 await removeVideoFromBlacklist(servers[0].url, servers[0].accessToken, 'hello', 400)
792dbaf0
GS
207 })
208
209 it('Should fail with a not blacklisted video', async function () {
210 // The video was not added to the blacklist so it should fail
5abb9fbb 211 await removeVideoFromBlacklist(servers[0].url, servers[0].accessToken, notBlacklistedVideoId, 404)
26b7305a
C
212 })
213
214 it('Should succeed with the correct params', async function () {
5abb9fbb 215 await removeVideoFromBlacklist(servers[0].url, servers[0].accessToken, servers[0].video.uuid, 204)
792dbaf0
GS
216 })
217 })
218
219 describe('When listing videos in blacklist', function () {
35bf0c83 220 const basePath = '/api/v1/videos/blacklist/'
792dbaf0
GS
221
222 it('Should fail with a non authenticated user', async function () {
1eddc9a7 223 await getBlacklistedVideosList({ url: servers[0].url, token: 'fake token', specialStatus: 401 })
792dbaf0
GS
224 })
225
226 it('Should fail with a non admin user', async function () {
1eddc9a7 227 await getBlacklistedVideosList({ url: servers[0].url, token: userAccessToken2, specialStatus: 403 })
792dbaf0
GS
228 })
229
230 it('Should fail with a bad start pagination', async function () {
5abb9fbb 231 await checkBadStartPagination(servers[0].url, basePath, servers[0].accessToken)
792dbaf0
GS
232 })
233
234 it('Should fail with a bad count pagination', async function () {
5abb9fbb 235 await checkBadCountPagination(servers[0].url, basePath, servers[0].accessToken)
792dbaf0
GS
236 })
237
238 it('Should fail with an incorrect sort', async function () {
5abb9fbb 239 await checkBadSortPagination(servers[0].url, basePath, servers[0].accessToken)
792dbaf0 240 })
7ccddd7b
JM
241
242 it('Should fail with an invalid type', async function () {
1eddc9a7 243 await getBlacklistedVideosList({ url: servers[0].url, token: servers[0].accessToken, type: 0, specialStatus: 400 })
7ccddd7b
JM
244 })
245
246 it('Should succeed with the correct parameters', async function () {
1eddc9a7 247 await getBlacklistedVideosList({ url: servers[0].url, token: servers[0].accessToken, type: VideoBlacklistType.MANUAL })
7ccddd7b 248 })
792dbaf0
GS
249 })
250
7c3b7976
C
251 after(async function () {
252 await cleanupTests(servers)
792dbaf0
GS
253 })
254})