]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/tests/api/check-params/config.ts
Made the video channels limit (per user) server-wide configurable (#4491)
[github/Chocobozzz/PeerTube.git] / server / tests / api / check-params / config.ts
CommitLineData
a1587156 1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
fd206f0b 2
fd206f0b 3import 'mocha'
6c5065a0 4import { omit } from 'lodash'
fd206f0b 5import {
8424c402 6 cleanupTests,
254d3579 7 createSingleServer,
8424c402
C
8 makeDeleteRequest,
9 makeGetRequest,
10 makePutBodyRequest,
254d3579 11 PeerTubeServer,
41d1d075 12 setAccessTokensToServers
6c5065a0 13} from '@shared/extra-utils'
4c7e60bc 14import { CustomConfig, HttpStatusCode } from '@shared/models'
fd206f0b
C
15
16describe('Test config API validators', function () {
17 const path = '/api/v1/config/custom'
254d3579 18 let server: PeerTubeServer
fd206f0b
C
19 let userAccessToken: string
20 const updateParams: CustomConfig = {
66b16caf
C
21 instance: {
22 name: 'PeerTube updated',
2e3a0215 23 shortDescription: 'my short description',
66b16caf 24 description: 'my super description',
00b5556c 25 terms: 'my super terms',
ccc00cb2
C
26 codeOfConduct: 'my super coc',
27
8ae03c37 28 creationReason: 'my super reason',
ccc00cb2
C
29 moderationInformation: 'my super moderation information',
30 administrator: 'Kuja',
31 maintenanceLifetime: 'forever',
32 businessModel: 'my super business model',
be04c6fd 33 hardwareInformation: '2vCore 3GB RAM',
ccc00cb2
C
34
35 languages: [ 'en', 'es' ],
36 categories: [ 1, 2 ],
37
f8802489 38 isNSFW: true,
0883b324 39 defaultNSFWPolicy: 'blur',
3da68f0a
RK
40
41 defaultClientRoute: '/videos/recently-added',
3da68f0a 42
00b5556c
C
43 customizations: {
44 javascript: 'alert("coucou")',
45 css: 'body { background-color: red; }'
46 }
66b16caf 47 },
7cd4d2ba
C
48 theme: {
49 default: 'default'
50 },
8be1afa1
C
51 services: {
52 twitter: {
53 username: '@MySuperUsername',
54 whitelisted: true
55 }
56 },
fd206f0b
C
57 cache: {
58 previews: {
59 size: 2
40e87e9e
C
60 },
61 captions: {
62 size: 3
b3d5cb92
C
63 },
64 torrents: {
65 size: 4
fd206f0b
C
66 }
67 },
68 signup: {
69 enabled: false,
d9eaee39 70 limit: 5,
1f256e7d
P
71 requiresEmailVerification: false,
72 minimumAge: 16
fd206f0b
C
73 },
74 admin: {
75 email: 'superadmin1@example.com'
76 },
a4101923
C
77 contactForm: {
78 enabled: false
79 },
fd206f0b 80 user: {
bee0abff
FA
81 videoQuota: 5242881,
82 videoQuotaDaily: 318742
fd206f0b 83 },
754b6f5f
FC
84 videoChannels: {
85 maxPerUser: 20
86 },
fd206f0b
C
87 transcoding: {
88 enabled: true,
14e2014a 89 allowAdditionalExtensions: true,
536598cf 90 allowAudioFiles: true,
9129b769 91 concurrency: 1,
fd206f0b 92 threads: 1,
1896bca0 93 profile: 'vod_profile',
fd206f0b 94 resolutions: {
5c7d6508 95 '0p': false,
fd206f0b
C
96 '240p': false,
97 '360p': true,
98 '480p': true,
99 '720p': false,
db714ab4 100 '1080p': false,
b7085c71 101 '1440p': false,
db714ab4 102 '2160p': false
09209296 103 },
d7a25329
C
104 webtorrent: {
105 enabled: true
106 },
09209296
C
107 hls: {
108 enabled: false
fd206f0b 109 }
5d08a6a7 110 },
c6c0fa6c
C
111 live: {
112 enabled: true,
113
fb719404 114 allowReplay: false,
c9bc850e 115 maxDuration: 30,
a056ca48
C
116 maxInstanceLives: -1,
117 maxUserLives: 50,
fb719404 118
c6c0fa6c
C
119 transcoding: {
120 enabled: true,
121 threads: 4,
1896bca0 122 profile: 'live_profile',
c6c0fa6c
C
123 resolutions: {
124 '240p': true,
125 '360p': true,
126 '480p': true,
127 '720p': true,
128 '1080p': true,
b7085c71 129 '1440p': true,
c6c0fa6c
C
130 '2160p': true
131 }
132 }
133 },
5d08a6a7
C
134 import: {
135 videos: {
9129b769 136 concurrency: 1,
5d08a6a7
C
137 http: {
138 enabled: false
a84b8fa5
C
139 },
140 torrent: {
141 enabled: false
5d08a6a7
C
142 }
143 }
7ccddd7b 144 },
ba5d4a84
RK
145 trending: {
146 videos: {
147 algorithms: {
3d4e112d 148 enabled: [ 'best', 'hot', 'most-viewed', 'most-liked' ],
ba5d4a84
RK
149 default: 'most-viewed'
150 }
151 }
152 },
7ccddd7b
JM
153 autoBlacklist: {
154 videos: {
155 ofUsers: {
156 enabled: false
157 }
158 }
5b9c965d
C
159 },
160 followers: {
161 instance: {
14893eb7
C
162 enabled: false,
163 manualApproval: true
5b9c965d 164 }
8424c402
C
165 },
166 followings: {
167 instance: {
168 autoFollowBack: {
169 enabled: true
170 },
171 autoFollowIndex: {
172 enabled: true,
173 indexUrl: 'https://index.example.com'
174 }
175 }
72c33e71
C
176 },
177 broadcastMessage: {
178 enabled: true,
179 dismissable: true,
180 message: 'super message',
181 level: 'warning'
5fb2e288
C
182 },
183 search: {
184 remoteUri: {
185 users: true,
186 anonymous: true
187 },
188 searchIndex: {
189 enabled: true,
190 url: 'https://search.joinpeertube.org',
191 disableLocalSearch: true,
192 isDefaultSearch: true
193 }
fd206f0b
C
194 }
195 }
196
197 // ---------------------------------------------------------------
198
199 before(async function () {
e212f887 200 this.timeout(30000)
fd206f0b 201
254d3579 202 server = await createSingleServer(1)
fd206f0b
C
203
204 await setAccessTokensToServers([ server ])
205
206 const user = {
207 username: 'user1',
208 password: 'password'
209 }
89d241a7
C
210 await server.users.create({ username: user.username, password: user.password })
211 userAccessToken = await server.login.getAccessToken(user)
fd206f0b
C
212 })
213
214 describe('When getting the configuration', function () {
215 it('Should fail without token', async function () {
216 await makeGetRequest({
217 url: server.url,
218 path,
c0e8b12e 219 expectedStatus: HttpStatusCode.UNAUTHORIZED_401
fd206f0b
C
220 })
221 })
222
223 it('Should fail if the user is not an administrator', async function () {
224 await makeGetRequest({
225 url: server.url,
226 path,
227 token: userAccessToken,
c0e8b12e 228 expectedStatus: HttpStatusCode.FORBIDDEN_403
fd206f0b
C
229 })
230 })
231 })
232
233 describe('When updating the configuration', function () {
234 it('Should fail without token', async function () {
235 await makePutBodyRequest({
236 url: server.url,
237 path,
238 fields: updateParams,
c0e8b12e 239 expectedStatus: HttpStatusCode.UNAUTHORIZED_401
fd206f0b
C
240 })
241 })
242
243 it('Should fail if the user is not an administrator', async function () {
244 await makePutBodyRequest({
245 url: server.url,
246 path,
247 fields: updateParams,
248 token: userAccessToken,
c0e8b12e 249 expectedStatus: HttpStatusCode.FORBIDDEN_403
fd206f0b
C
250 })
251 })
252
253 it('Should fail if it misses a key', async function () {
254 const newUpdateParams = omit(updateParams, 'admin.email')
255
256 await makePutBodyRequest({
257 url: server.url,
258 path,
0883b324
C
259 fields: newUpdateParams,
260 token: server.accessToken,
c0e8b12e 261 expectedStatus: HttpStatusCode.BAD_REQUEST_400
0883b324
C
262 })
263 })
264
265 it('Should fail with a bad default NSFW policy', async function () {
6c5065a0
C
266 const newUpdateParams = {
267 ...updateParams,
268
0883b324
C
269 instance: {
270 defaultNSFWPolicy: 'hello'
271 }
6c5065a0 272 }
0883b324
C
273
274 await makePutBodyRequest({
275 url: server.url,
276 path,
576ad67a
JM
277 fields: newUpdateParams,
278 token: server.accessToken,
c0e8b12e 279 expectedStatus: HttpStatusCode.BAD_REQUEST_400
576ad67a
JM
280 })
281 })
282
283 it('Should fail if email disabled and signup requires email verification', async function () {
7c3b7976 284 // opposite scenario - success when enable enabled - covered via tests/api/users/user-verification.ts
6c5065a0
C
285 const newUpdateParams = {
286 ...updateParams,
287
576ad67a
JM
288 signup: {
289 enabled: true,
290 limit: 5,
291 requiresEmailVerification: true
292 }
6c5065a0 293 }
576ad67a
JM
294
295 await makePutBodyRequest({
296 url: server.url,
297 path,
fd206f0b
C
298 fields: newUpdateParams,
299 token: server.accessToken,
c0e8b12e 300 expectedStatus: HttpStatusCode.BAD_REQUEST_400
fd206f0b
C
301 })
302 })
303
d7a25329 304 it('Should fail with a disabled webtorrent & hls transcoding', async function () {
6c5065a0
C
305 const newUpdateParams = {
306 ...updateParams,
307
d7a25329
C
308 transcoding: {
309 hls: {
310 enabled: false
311 },
312 webtorrent: {
313 enabled: false
314 }
315 }
6c5065a0 316 }
d7a25329
C
317
318 await makePutBodyRequest({
319 url: server.url,
320 path,
321 fields: newUpdateParams,
322 token: server.accessToken,
c0e8b12e 323 expectedStatus: HttpStatusCode.BAD_REQUEST_400
d7a25329
C
324 })
325 })
326
fd206f0b
C
327 it('Should success with the correct parameters', async function () {
328 await makePutBodyRequest({
329 url: server.url,
330 path,
331 fields: updateParams,
332 token: server.accessToken,
c0e8b12e 333 expectedStatus: HttpStatusCode.OK_200
fd206f0b
C
334 })
335 })
336 })
337
338 describe('When deleting the configuration', function () {
339 it('Should fail without token', async function () {
340 await makeDeleteRequest({
341 url: server.url,
342 path,
c0e8b12e 343 expectedStatus: HttpStatusCode.UNAUTHORIZED_401
fd206f0b
C
344 })
345 })
346
347 it('Should fail if the user is not an administrator', async function () {
348 await makeDeleteRequest({
349 url: server.url,
350 path,
351 token: userAccessToken,
c0e8b12e 352 expectedStatus: HttpStatusCode.FORBIDDEN_403
fd206f0b
C
353 })
354 })
355 })
356
7c3b7976
C
357 after(async function () {
358 await cleanupTests([ server ])
fd206f0b
C
359 })
360})