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