]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/tests/api/server/config.ts
Made the video channels limit (per user) server-wide configurable (#4491)
[github/Chocobozzz/PeerTube.git] / server / tests / api / server / config.ts
CommitLineData
a1587156 1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
0e1dc3e7
C
2
3import 'mocha'
4import * as chai from 'chai'
0e1dc3e7 5import {
7c3b7976 6 cleanupTests,
254d3579 7 createSingleServer,
a1587156 8 killallServers,
8155db66 9 makeGetRequest,
a1587156 10 parallelTests,
254d3579 11 PeerTubeServer,
d23dd9fb 12 setAccessTokensToServers
65e6e260 13} from '@shared/extra-utils'
4c7e60bc 14import { CustomConfig, HttpStatusCode } from '@shared/models'
0e1dc3e7 15
5bcfd029
C
16const expect = chai.expect
17
254d3579 18function checkInitialConfig (server: PeerTubeServer, data: CustomConfig) {
40e87e9e
C
19 expect(data.instance.name).to.equal('PeerTube')
20 expect(data.instance.shortDescription).to.equal(
482fa503 21 'PeerTube, an ActivityPub-federated video streaming platform using P2P directly in your web browser.'
40e87e9e
C
22 )
23 expect(data.instance.description).to.equal('Welcome to this PeerTube instance!')
ccc00cb2 24
40e87e9e 25 expect(data.instance.terms).to.equal('No terms for now.')
8ae03c37 26 expect(data.instance.creationReason).to.be.empty
ccc00cb2
C
27 expect(data.instance.codeOfConduct).to.be.empty
28 expect(data.instance.moderationInformation).to.be.empty
29 expect(data.instance.administrator).to.be.empty
30 expect(data.instance.maintenanceLifetime).to.be.empty
31 expect(data.instance.businessModel).to.be.empty
be04c6fd 32 expect(data.instance.hardwareInformation).to.be.empty
ccc00cb2
C
33
34 expect(data.instance.languages).to.have.lengthOf(0)
35 expect(data.instance.categories).to.have.lengthOf(0)
36
40e87e9e 37 expect(data.instance.defaultClientRoute).to.equal('/videos/trending')
f8802489 38 expect(data.instance.isNSFW).to.be.false
40e87e9e
C
39 expect(data.instance.defaultNSFWPolicy).to.equal('display')
40 expect(data.instance.customizations.css).to.be.empty
41 expect(data.instance.customizations.javascript).to.be.empty
a4101923 42
40e87e9e
C
43 expect(data.services.twitter.username).to.equal('@Chocobozzz')
44 expect(data.services.twitter.whitelisted).to.be.false
a4101923 45
40e87e9e
C
46 expect(data.cache.previews.size).to.equal(1)
47 expect(data.cache.captions.size).to.equal(1)
b3d5cb92 48 expect(data.cache.torrents.size).to.equal(1)
a4101923 49
40e87e9e
C
50 expect(data.signup.enabled).to.be.true
51 expect(data.signup.limit).to.equal(4)
1f256e7d 52 expect(data.signup.minimumAge).to.equal(16)
d9eaee39 53 expect(data.signup.requiresEmailVerification).to.be.false
a4101923 54
48f07b4a 55 expect(data.admin.email).to.equal('admin' + server.internalServerNumber + '@example.com')
a4101923
C
56 expect(data.contactForm.enabled).to.be.true
57
40e87e9e 58 expect(data.user.videoQuota).to.equal(5242880)
9ee92651 59 expect(data.user.videoQuotaDaily).to.equal(-1)
c6c0fa6c 60
754b6f5f
FC
61 expect(data.videoChannels.maxPerUser).to.equal(20)
62
40e87e9e 63 expect(data.transcoding.enabled).to.be.false
14e2014a 64 expect(data.transcoding.allowAdditionalExtensions).to.be.false
536598cf 65 expect(data.transcoding.allowAudioFiles).to.be.false
40e87e9e 66 expect(data.transcoding.threads).to.equal(2)
9129b769 67 expect(data.transcoding.concurrency).to.equal(2)
1896bca0 68 expect(data.transcoding.profile).to.equal('default')
40e87e9e
C
69 expect(data.transcoding.resolutions['240p']).to.be.true
70 expect(data.transcoding.resolutions['360p']).to.be.true
71 expect(data.transcoding.resolutions['480p']).to.be.true
72 expect(data.transcoding.resolutions['720p']).to.be.true
73 expect(data.transcoding.resolutions['1080p']).to.be.true
b7085c71 74 expect(data.transcoding.resolutions['1440p']).to.be.true
db714ab4 75 expect(data.transcoding.resolutions['2160p']).to.be.true
d7a25329 76 expect(data.transcoding.webtorrent.enabled).to.be.true
09209296
C
77 expect(data.transcoding.hls.enabled).to.be.true
78
c6c0fa6c 79 expect(data.live.enabled).to.be.false
c655c9ef 80 expect(data.live.allowReplay).to.be.false
c9bc850e 81 expect(data.live.maxDuration).to.equal(-1)
a056ca48
C
82 expect(data.live.maxInstanceLives).to.equal(20)
83 expect(data.live.maxUserLives).to.equal(3)
c6c0fa6c
C
84 expect(data.live.transcoding.enabled).to.be.false
85 expect(data.live.transcoding.threads).to.equal(2)
1896bca0 86 expect(data.live.transcoding.profile).to.equal('default')
c6c0fa6c
C
87 expect(data.live.transcoding.resolutions['240p']).to.be.false
88 expect(data.live.transcoding.resolutions['360p']).to.be.false
89 expect(data.live.transcoding.resolutions['480p']).to.be.false
90 expect(data.live.transcoding.resolutions['720p']).to.be.false
91 expect(data.live.transcoding.resolutions['1080p']).to.be.false
b7085c71 92 expect(data.live.transcoding.resolutions['1440p']).to.be.false
c6c0fa6c
C
93 expect(data.live.transcoding.resolutions['2160p']).to.be.false
94
9129b769 95 expect(data.import.videos.concurrency).to.equal(2)
5d08a6a7 96 expect(data.import.videos.http.enabled).to.be.true
a84b8fa5 97 expect(data.import.videos.torrent.enabled).to.be.true
7ccddd7b 98 expect(data.autoBlacklist.videos.ofUsers.enabled).to.be.false
5b9c965d
C
99
100 expect(data.followers.instance.enabled).to.be.true
14893eb7 101 expect(data.followers.instance.manualApproval).to.be.false
8424c402
C
102
103 expect(data.followings.instance.autoFollowBack.enabled).to.be.false
104 expect(data.followings.instance.autoFollowIndex.enabled).to.be.false
c9215a1b 105 expect(data.followings.instance.autoFollowIndex.indexUrl).to.equal('')
72c33e71
C
106
107 expect(data.broadcastMessage.enabled).to.be.false
108 expect(data.broadcastMessage.level).to.equal('info')
109 expect(data.broadcastMessage.message).to.equal('')
110 expect(data.broadcastMessage.dismissable).to.be.false
40e87e9e
C
111}
112
113function checkUpdatedConfig (data: CustomConfig) {
114 expect(data.instance.name).to.equal('PeerTube updated')
115 expect(data.instance.shortDescription).to.equal('my short description')
116 expect(data.instance.description).to.equal('my super description')
ccc00cb2 117
40e87e9e 118 expect(data.instance.terms).to.equal('my super terms')
8ae03c37 119 expect(data.instance.creationReason).to.equal('my super creation reason')
ccc00cb2
C
120 expect(data.instance.codeOfConduct).to.equal('my super coc')
121 expect(data.instance.moderationInformation).to.equal('my super moderation information')
122 expect(data.instance.administrator).to.equal('Kuja')
123 expect(data.instance.maintenanceLifetime).to.equal('forever')
124 expect(data.instance.businessModel).to.equal('my super business model')
be04c6fd 125 expect(data.instance.hardwareInformation).to.equal('2vCore 3GB RAM')
ccc00cb2
C
126
127 expect(data.instance.languages).to.deep.equal([ 'en', 'es' ])
128 expect(data.instance.categories).to.deep.equal([ 1, 2 ])
129
40e87e9e 130 expect(data.instance.defaultClientRoute).to.equal('/videos/recently-added')
f8802489 131 expect(data.instance.isNSFW).to.be.true
40e87e9e
C
132 expect(data.instance.defaultNSFWPolicy).to.equal('blur')
133 expect(data.instance.customizations.javascript).to.equal('alert("coucou")')
134 expect(data.instance.customizations.css).to.equal('body { background-color: red; }')
a4101923 135
40e87e9e
C
136 expect(data.services.twitter.username).to.equal('@Kuja')
137 expect(data.services.twitter.whitelisted).to.be.true
a4101923 138
40e87e9e
C
139 expect(data.cache.previews.size).to.equal(2)
140 expect(data.cache.captions.size).to.equal(3)
b3d5cb92 141 expect(data.cache.torrents.size).to.equal(4)
a4101923 142
40e87e9e
C
143 expect(data.signup.enabled).to.be.false
144 expect(data.signup.limit).to.equal(5)
576ad67a 145 expect(data.signup.requiresEmailVerification).to.be.false
1f256e7d 146 expect(data.signup.minimumAge).to.equal(10)
a4101923 147
48f07b4a
C
148 // We override admin email in parallel tests, so skip this exception
149 if (parallelTests() === false) {
150 expect(data.admin.email).to.equal('superadmin1@example.com')
151 }
152
a4101923
C
153 expect(data.contactForm.enabled).to.be.false
154
40e87e9e 155 expect(data.user.videoQuota).to.equal(5242881)
bee0abff 156 expect(data.user.videoQuotaDaily).to.equal(318742)
a4101923 157
754b6f5f
FC
158 expect(data.videoChannels.maxPerUser).to.equal(24)
159
40e87e9e
C
160 expect(data.transcoding.enabled).to.be.true
161 expect(data.transcoding.threads).to.equal(1)
9129b769 162 expect(data.transcoding.concurrency).to.equal(3)
14e2014a 163 expect(data.transcoding.allowAdditionalExtensions).to.be.true
536598cf 164 expect(data.transcoding.allowAudioFiles).to.be.true
1896bca0 165 expect(data.transcoding.profile).to.equal('vod_profile')
40e87e9e
C
166 expect(data.transcoding.resolutions['240p']).to.be.false
167 expect(data.transcoding.resolutions['360p']).to.be.true
168 expect(data.transcoding.resolutions['480p']).to.be.true
169 expect(data.transcoding.resolutions['720p']).to.be.false
170 expect(data.transcoding.resolutions['1080p']).to.be.false
db714ab4 171 expect(data.transcoding.resolutions['2160p']).to.be.false
09209296 172 expect(data.transcoding.hls.enabled).to.be.false
d7a25329 173 expect(data.transcoding.webtorrent.enabled).to.be.true
a4101923 174
c6c0fa6c 175 expect(data.live.enabled).to.be.true
c655c9ef 176 expect(data.live.allowReplay).to.be.true
fb719404 177 expect(data.live.maxDuration).to.equal(5000)
a056ca48
C
178 expect(data.live.maxInstanceLives).to.equal(-1)
179 expect(data.live.maxUserLives).to.equal(10)
c6c0fa6c
C
180 expect(data.live.transcoding.enabled).to.be.true
181 expect(data.live.transcoding.threads).to.equal(4)
1896bca0 182 expect(data.live.transcoding.profile).to.equal('live_profile')
c6c0fa6c
C
183 expect(data.live.transcoding.resolutions['240p']).to.be.true
184 expect(data.live.transcoding.resolutions['360p']).to.be.true
185 expect(data.live.transcoding.resolutions['480p']).to.be.true
186 expect(data.live.transcoding.resolutions['720p']).to.be.true
187 expect(data.live.transcoding.resolutions['1080p']).to.be.true
188 expect(data.live.transcoding.resolutions['2160p']).to.be.true
189
9129b769 190 expect(data.import.videos.concurrency).to.equal(4)
5d08a6a7 191 expect(data.import.videos.http.enabled).to.be.false
a84b8fa5 192 expect(data.import.videos.torrent.enabled).to.be.false
7ccddd7b 193 expect(data.autoBlacklist.videos.ofUsers.enabled).to.be.true
5b9c965d
C
194
195 expect(data.followers.instance.enabled).to.be.false
14893eb7 196 expect(data.followers.instance.manualApproval).to.be.true
8424c402
C
197
198 expect(data.followings.instance.autoFollowBack.enabled).to.be.true
199 expect(data.followings.instance.autoFollowIndex.enabled).to.be.true
200 expect(data.followings.instance.autoFollowIndex.indexUrl).to.equal('https://updated.example.com')
72c33e71
C
201
202 expect(data.broadcastMessage.enabled).to.be.true
203 expect(data.broadcastMessage.level).to.equal('error')
204 expect(data.broadcastMessage.message).to.equal('super bad message')
205 expect(data.broadcastMessage.dismissable).to.be.true
40e87e9e
C
206}
207
8d8a037e
JB
208const newCustomConfig: CustomConfig = {
209 instance: {
210 name: 'PeerTube updated',
211 shortDescription: 'my short description',
212 description: 'my super description',
213 terms: 'my super terms',
214 codeOfConduct: 'my super coc',
215
216 creationReason: 'my super creation reason',
217 moderationInformation: 'my super moderation information',
218 administrator: 'Kuja',
219 maintenanceLifetime: 'forever',
220 businessModel: 'my super business model',
221 hardwareInformation: '2vCore 3GB RAM',
222
223 languages: [ 'en', 'es' ],
224 categories: [ 1, 2 ],
225
226 isNSFW: true,
227 defaultNSFWPolicy: 'blur' as 'blur',
228
229 defaultClientRoute: '/videos/recently-added',
230
231 customizations: {
232 javascript: 'alert("coucou")',
233 css: 'body { background-color: red; }'
234 }
235 },
236 theme: {
237 default: 'default'
238 },
239 services: {
240 twitter: {
241 username: '@Kuja',
242 whitelisted: true
243 }
244 },
245 cache: {
246 previews: {
247 size: 2
248 },
249 captions: {
250 size: 3
251 },
252 torrents: {
253 size: 4
254 }
255 },
256 signup: {
257 enabled: false,
258 limit: 5,
259 requiresEmailVerification: false,
260 minimumAge: 10
261 },
262 admin: {
263 email: 'superadmin1@example.com'
264 },
265 contactForm: {
266 enabled: false
267 },
268 user: {
269 videoQuota: 5242881,
270 videoQuotaDaily: 318742
271 },
754b6f5f
FC
272 videoChannels: {
273 maxPerUser: 24
274 },
8d8a037e
JB
275 transcoding: {
276 enabled: true,
277 allowAdditionalExtensions: true,
278 allowAudioFiles: true,
279 threads: 1,
280 concurrency: 3,
281 profile: 'vod_profile',
282 resolutions: {
283 '0p': false,
284 '240p': false,
285 '360p': true,
286 '480p': true,
287 '720p': false,
288 '1080p': false,
289 '1440p': false,
290 '2160p': false
291 },
292 webtorrent: {
293 enabled: true
294 },
295 hls: {
296 enabled: false
297 }
298 },
299 live: {
300 enabled: true,
301 allowReplay: true,
302 maxDuration: 5000,
303 maxInstanceLives: -1,
304 maxUserLives: 10,
305 transcoding: {
306 enabled: true,
307 threads: 4,
308 profile: 'live_profile',
309 resolutions: {
310 '240p': true,
311 '360p': true,
312 '480p': true,
313 '720p': true,
314 '1080p': true,
315 '1440p': true,
316 '2160p': true
317 }
318 }
319 },
320 import: {
321 videos: {
322 concurrency: 4,
323 http: {
324 enabled: false
325 },
326 torrent: {
327 enabled: false
328 }
329 }
330 },
331 trending: {
332 videos: {
333 algorithms: {
334 enabled: [ 'best', 'hot', 'most-viewed', 'most-liked' ],
335 default: 'hot'
336 }
337 }
338 },
339 autoBlacklist: {
340 videos: {
341 ofUsers: {
342 enabled: true
343 }
344 }
345 },
346 followers: {
347 instance: {
348 enabled: false,
349 manualApproval: true
350 }
351 },
352 followings: {
353 instance: {
354 autoFollowBack: {
355 enabled: true
356 },
357 autoFollowIndex: {
358 enabled: true,
359 indexUrl: 'https://updated.example.com'
360 }
361 }
362 },
363 broadcastMessage: {
364 enabled: true,
365 level: 'error',
366 message: 'super bad message',
367 dismissable: true
368 },
369 search: {
370 remoteUri: {
371 anonymous: true,
372 users: true
373 },
374 searchIndex: {
375 enabled: true,
376 url: 'https://search.joinpeertube.org',
377 disableLocalSearch: true,
378 isDefaultSearch: true
379 }
380 }
381}
382
383describe('Test static config', function () {
384 let server: PeerTubeServer = null
385
386 before(async function () {
387 this.timeout(30000)
388
cf0c8ee5 389 server = await createSingleServer(1, { webadmin: { configuration: { edition: { allowed: false } } } })
8d8a037e
JB
390 await setAccessTokensToServers([ server ])
391 })
392
393 it('Should tell the client that edits are not allowed', async function () {
394 const data = await server.config.getConfig()
395
cf0c8ee5 396 expect(data.webadmin.configuration.edition.allowed).to.be.false
8d8a037e
JB
397 })
398
399 it('Should error when client tries to update', async function () {
400 await server.config.updateCustomConfig({ newCustomConfig, expectedStatus: 405 })
401 })
f87d82b9
C
402
403 after(async function () {
404 await cleanupTests([ server ])
405 })
8d8a037e
JB
406})
407
0e1dc3e7 408describe('Test config', function () {
254d3579 409 let server: PeerTubeServer = null
0e1dc3e7
C
410
411 before(async function () {
e212f887 412 this.timeout(30000)
48f07b4a 413
254d3579 414 server = await createSingleServer(1)
fd206f0b 415 await setAccessTokensToServers([ server ])
0e1dc3e7
C
416 })
417
418 it('Should have a correct config on a server with registration enabled', async function () {
89d241a7 419 const data = await server.config.getConfig()
0e1dc3e7
C
420
421 expect(data.signup.allowed).to.be.true
422 })
423
424 it('Should have a correct config on a server with registration enabled and a users limit', async function () {
652b3056
C
425 this.timeout(5000)
426
47e0652b 427 await Promise.all([
89d241a7
C
428 server.users.register({ username: 'user1' }),
429 server.users.register({ username: 'user2' }),
430 server.users.register({ username: 'user3' })
47e0652b 431 ])
0e1dc3e7 432
89d241a7 433 const data = await server.config.getConfig()
0e1dc3e7
C
434
435 expect(data.signup.allowed).to.be.false
436 })
437
14e2014a 438 it('Should have the correct video allowed extensions', async function () {
89d241a7 439 const data = await server.config.getConfig()
14e2014a
C
440
441 expect(data.video.file.extensions).to.have.lengthOf(3)
442 expect(data.video.file.extensions).to.contain('.mp4')
443 expect(data.video.file.extensions).to.contain('.webm')
444 expect(data.video.file.extensions).to.contain('.ogv')
a4101923 445
89d241a7
C
446 await server.videos.upload({ attributes: { fixture: 'video_short.mkv' }, expectedStatus: HttpStatusCode.UNSUPPORTED_MEDIA_TYPE_415 })
447 await server.videos.upload({ attributes: { fixture: 'sample.ogg' }, expectedStatus: HttpStatusCode.UNSUPPORTED_MEDIA_TYPE_415 })
b345a804 448
a4101923 449 expect(data.contactForm.enabled).to.be.true
14e2014a
C
450 })
451
fd206f0b 452 it('Should get the customized configuration', async function () {
89d241a7 453 const data = await server.config.getCustomConfig()
fd206f0b 454
48f07b4a 455 checkInitialConfig(server, data)
fd206f0b
C
456 })
457
458 it('Should update the customized configuration', async function () {
89d241a7 459 await server.config.updateCustomConfig({ newCustomConfig })
fd206f0b 460
89d241a7 461 const data = await server.config.getCustomConfig()
40e87e9e 462 checkUpdatedConfig(data)
fd206f0b
C
463 })
464
14e2014a 465 it('Should have the correct updated video allowed extensions', async function () {
30bc55c8
C
466 this.timeout(10000)
467
89d241a7 468 const data = await server.config.getConfig()
14e2014a 469
30bc55c8 470 expect(data.video.file.extensions).to.have.length.above(4)
14e2014a
C
471 expect(data.video.file.extensions).to.contain('.mp4')
472 expect(data.video.file.extensions).to.contain('.webm')
473 expect(data.video.file.extensions).to.contain('.ogv')
474 expect(data.video.file.extensions).to.contain('.flv')
fccbbc1a 475 expect(data.video.file.extensions).to.contain('.wmv')
14e2014a 476 expect(data.video.file.extensions).to.contain('.mkv')
b345a804
C
477 expect(data.video.file.extensions).to.contain('.mp3')
478 expect(data.video.file.extensions).to.contain('.ogg')
479 expect(data.video.file.extensions).to.contain('.flac')
480
89d241a7
C
481 await server.videos.upload({ attributes: { fixture: 'video_short.mkv' }, expectedStatus: HttpStatusCode.OK_200 })
482 await server.videos.upload({ attributes: { fixture: 'sample.ogg' }, expectedStatus: HttpStatusCode.OK_200 })
14e2014a
C
483 })
484
fd206f0b 485 it('Should have the configuration updated after a restart', async function () {
61e9908c 486 this.timeout(30000)
23e27dd5 487
9293139f 488 await killallServers([ server ])
fd206f0b 489
254d3579 490 await server.run()
fd206f0b 491
89d241a7 492 const data = await server.config.getCustomConfig()
fd206f0b 493
40e87e9e 494 checkUpdatedConfig(data)
fd206f0b
C
495 })
496
36f9424f 497 it('Should fetch the about information', async function () {
89d241a7 498 const data = await server.config.getAbout()
36f9424f
C
499
500 expect(data.instance.name).to.equal('PeerTube updated')
2e3a0215 501 expect(data.instance.shortDescription).to.equal('my short description')
36f9424f
C
502 expect(data.instance.description).to.equal('my super description')
503 expect(data.instance.terms).to.equal('my super terms')
be04c6fd
C
504 expect(data.instance.codeOfConduct).to.equal('my super coc')
505
506 expect(data.instance.creationReason).to.equal('my super creation reason')
507 expect(data.instance.moderationInformation).to.equal('my super moderation information')
508 expect(data.instance.administrator).to.equal('Kuja')
509 expect(data.instance.maintenanceLifetime).to.equal('forever')
510 expect(data.instance.businessModel).to.equal('my super business model')
511 expect(data.instance.hardwareInformation).to.equal('2vCore 3GB RAM')
512
513 expect(data.instance.languages).to.deep.equal([ 'en', 'es' ])
514 expect(data.instance.categories).to.deep.equal([ 1, 2 ])
36f9424f
C
515 })
516
fd206f0b 517 it('Should remove the custom configuration', async function () {
23e27dd5
C
518 this.timeout(10000)
519
89d241a7 520 await server.config.deleteCustomConfig()
fd206f0b 521
89d241a7 522 const data = await server.config.getCustomConfig()
48f07b4a 523 checkInitialConfig(server, data)
fd206f0b
C
524 })
525
8155db66
C
526 it('Should enable frameguard', async function () {
527 this.timeout(25000)
528
529 {
530 const res = await makeGetRequest({
531 url: server.url,
532 path: '/api/v1/config',
c0e8b12e 533 expectedStatus: 200
8155db66
C
534 })
535
536 expect(res.headers['x-frame-options']).to.exist
537 }
538
9293139f 539 await killallServers([ server ])
8155db66
C
540
541 const config = {
542 security: {
543 frameguard: { enabled: false }
544 }
545 }
254d3579 546 await server.run(config)
8155db66
C
547
548 {
549 const res = await makeGetRequest({
550 url: server.url,
551 path: '/api/v1/config',
c0e8b12e 552 expectedStatus: 200
8155db66
C
553 })
554
555 expect(res.headers['x-frame-options']).to.not.exist
556 }
557 })
558
7c3b7976
C
559 after(async function () {
560 await cleanupTests([ server ])
0e1dc3e7
C
561 })
562})