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