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