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