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