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