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