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