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