]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/tests/api/server/config.ts
Support transcoding options/encoders by plugins
[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 { About } from '../../../../shared/models/server/about.model'
6 import { CustomConfig } from '../../../../shared/models/server/custom-config.model'
7 import {
8 cleanupTests,
9 deleteCustomConfig,
10 flushAndRunServer,
11 getAbout,
12 getConfig,
13 getCustomConfig,
14 killallServers,
15 parallelTests,
16 registerUser,
17 reRunServer,
18 ServerInfo,
19 setAccessTokensToServers,
20 updateCustomConfig,
21 uploadVideo
22 } from '../../../../shared/extra-utils'
23 import { ServerConfig } from '../../../../shared/models'
24 import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
25
26 const expect = chai.expect
27
28 function checkInitialConfig (server: ServerInfo, data: CustomConfig) {
29 expect(data.instance.name).to.equal('PeerTube')
30 expect(data.instance.shortDescription).to.equal(
31 'PeerTube, an ActivityPub-federated video streaming platform using P2P directly in your web browser.'
32 )
33 expect(data.instance.description).to.equal('Welcome to this PeerTube instance!')
34
35 expect(data.instance.terms).to.equal('No terms for now.')
36 expect(data.instance.creationReason).to.be.empty
37 expect(data.instance.codeOfConduct).to.be.empty
38 expect(data.instance.moderationInformation).to.be.empty
39 expect(data.instance.administrator).to.be.empty
40 expect(data.instance.maintenanceLifetime).to.be.empty
41 expect(data.instance.businessModel).to.be.empty
42 expect(data.instance.hardwareInformation).to.be.empty
43
44 expect(data.instance.languages).to.have.lengthOf(0)
45 expect(data.instance.categories).to.have.lengthOf(0)
46
47 expect(data.instance.defaultClientRoute).to.equal('/videos/trending')
48 expect(data.instance.isNSFW).to.be.false
49 expect(data.instance.defaultNSFWPolicy).to.equal('display')
50 expect(data.instance.customizations.css).to.be.empty
51 expect(data.instance.customizations.javascript).to.be.empty
52
53 expect(data.services.twitter.username).to.equal('@Chocobozzz')
54 expect(data.services.twitter.whitelisted).to.be.false
55
56 expect(data.cache.previews.size).to.equal(1)
57 expect(data.cache.captions.size).to.equal(1)
58
59 expect(data.signup.enabled).to.be.true
60 expect(data.signup.limit).to.equal(4)
61 expect(data.signup.requiresEmailVerification).to.be.false
62
63 expect(data.admin.email).to.equal('admin' + server.internalServerNumber + '@example.com')
64 expect(data.contactForm.enabled).to.be.true
65
66 expect(data.user.videoQuota).to.equal(5242880)
67 expect(data.user.videoQuotaDaily).to.equal(-1)
68
69 expect(data.transcoding.enabled).to.be.false
70 expect(data.transcoding.allowAdditionalExtensions).to.be.false
71 expect(data.transcoding.allowAudioFiles).to.be.false
72 expect(data.transcoding.threads).to.equal(2)
73 expect(data.transcoding.profile).to.equal('default')
74 expect(data.transcoding.resolutions['240p']).to.be.true
75 expect(data.transcoding.resolutions['360p']).to.be.true
76 expect(data.transcoding.resolutions['480p']).to.be.true
77 expect(data.transcoding.resolutions['720p']).to.be.true
78 expect(data.transcoding.resolutions['1080p']).to.be.true
79 expect(data.transcoding.resolutions['1440p']).to.be.true
80 expect(data.transcoding.resolutions['2160p']).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.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['240p']).to.be.false
93 expect(data.live.transcoding.resolutions['360p']).to.be.false
94 expect(data.live.transcoding.resolutions['480p']).to.be.false
95 expect(data.live.transcoding.resolutions['720p']).to.be.false
96 expect(data.live.transcoding.resolutions['1080p']).to.be.false
97 expect(data.live.transcoding.resolutions['1440p']).to.be.false
98 expect(data.live.transcoding.resolutions['2160p']).to.be.false
99
100 expect(data.import.videos.http.enabled).to.be.true
101 expect(data.import.videos.torrent.enabled).to.be.true
102 expect(data.autoBlacklist.videos.ofUsers.enabled).to.be.false
103
104 expect(data.followers.instance.enabled).to.be.true
105 expect(data.followers.instance.manualApproval).to.be.false
106
107 expect(data.followings.instance.autoFollowBack.enabled).to.be.false
108 expect(data.followings.instance.autoFollowIndex.enabled).to.be.false
109 expect(data.followings.instance.autoFollowIndex.indexUrl).to.equal('')
110
111 expect(data.broadcastMessage.enabled).to.be.false
112 expect(data.broadcastMessage.level).to.equal('info')
113 expect(data.broadcastMessage.message).to.equal('')
114 expect(data.broadcastMessage.dismissable).to.be.false
115 }
116
117 function checkUpdatedConfig (data: CustomConfig) {
118 expect(data.instance.name).to.equal('PeerTube updated')
119 expect(data.instance.shortDescription).to.equal('my short description')
120 expect(data.instance.description).to.equal('my super description')
121
122 expect(data.instance.terms).to.equal('my super terms')
123 expect(data.instance.creationReason).to.equal('my super creation reason')
124 expect(data.instance.codeOfConduct).to.equal('my super coc')
125 expect(data.instance.moderationInformation).to.equal('my super moderation information')
126 expect(data.instance.administrator).to.equal('Kuja')
127 expect(data.instance.maintenanceLifetime).to.equal('forever')
128 expect(data.instance.businessModel).to.equal('my super business model')
129 expect(data.instance.hardwareInformation).to.equal('2vCore 3GB RAM')
130
131 expect(data.instance.languages).to.deep.equal([ 'en', 'es' ])
132 expect(data.instance.categories).to.deep.equal([ 1, 2 ])
133
134 expect(data.instance.defaultClientRoute).to.equal('/videos/recently-added')
135 expect(data.instance.isNSFW).to.be.true
136 expect(data.instance.defaultNSFWPolicy).to.equal('blur')
137 expect(data.instance.customizations.javascript).to.equal('alert("coucou")')
138 expect(data.instance.customizations.css).to.equal('body { background-color: red; }')
139
140 expect(data.services.twitter.username).to.equal('@Kuja')
141 expect(data.services.twitter.whitelisted).to.be.true
142
143 expect(data.cache.previews.size).to.equal(2)
144 expect(data.cache.captions.size).to.equal(3)
145
146 expect(data.signup.enabled).to.be.false
147 expect(data.signup.limit).to.equal(5)
148 expect(data.signup.requiresEmailVerification).to.be.false
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.transcoding.enabled).to.be.true
161 expect(data.transcoding.threads).to.equal(1)
162 expect(data.transcoding.allowAdditionalExtensions).to.be.true
163 expect(data.transcoding.allowAudioFiles).to.be.true
164 expect(data.transcoding.profile).to.equal('vod_profile')
165 expect(data.transcoding.resolutions['240p']).to.be.false
166 expect(data.transcoding.resolutions['360p']).to.be.true
167 expect(data.transcoding.resolutions['480p']).to.be.true
168 expect(data.transcoding.resolutions['720p']).to.be.false
169 expect(data.transcoding.resolutions['1080p']).to.be.false
170 expect(data.transcoding.resolutions['2160p']).to.be.false
171 expect(data.transcoding.hls.enabled).to.be.false
172 expect(data.transcoding.webtorrent.enabled).to.be.true
173
174 expect(data.live.enabled).to.be.true
175 expect(data.live.allowReplay).to.be.true
176 expect(data.live.maxDuration).to.equal(5000)
177 expect(data.live.maxInstanceLives).to.equal(-1)
178 expect(data.live.maxUserLives).to.equal(10)
179 expect(data.live.transcoding.enabled).to.be.true
180 expect(data.live.transcoding.threads).to.equal(4)
181 expect(data.live.transcoding.profile).to.equal('live_profile')
182 expect(data.live.transcoding.resolutions['240p']).to.be.true
183 expect(data.live.transcoding.resolutions['360p']).to.be.true
184 expect(data.live.transcoding.resolutions['480p']).to.be.true
185 expect(data.live.transcoding.resolutions['720p']).to.be.true
186 expect(data.live.transcoding.resolutions['1080p']).to.be.true
187 expect(data.live.transcoding.resolutions['2160p']).to.be.true
188
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 = 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 res = await getConfig(server.url)
218 const data: ServerConfig = res.body
219
220 expect(data.signup.allowed).to.be.true
221 })
222
223 it('Should have a correct config on a server with registration enabled and a users limit', async function () {
224 this.timeout(5000)
225
226 await Promise.all([
227 registerUser(server.url, 'user1', 'super password'),
228 registerUser(server.url, 'user2', 'super password'),
229 registerUser(server.url, 'user3', 'super password')
230 ])
231
232 const res = await getConfig(server.url)
233 const data: ServerConfig = res.body
234
235 expect(data.signup.allowed).to.be.false
236 })
237
238 it('Should have the correct video allowed extensions', async function () {
239 const res = await getConfig(server.url)
240 const data: ServerConfig = res.body
241
242 expect(data.video.file.extensions).to.have.lengthOf(3)
243 expect(data.video.file.extensions).to.contain('.mp4')
244 expect(data.video.file.extensions).to.contain('.webm')
245 expect(data.video.file.extensions).to.contain('.ogv')
246
247 await uploadVideo(server.url, server.accessToken, { fixture: 'video_short.mkv' }, HttpStatusCode.UNSUPPORTED_MEDIA_TYPE_415)
248 await uploadVideo(server.url, server.accessToken, { fixture: 'sample.ogg' }, HttpStatusCode.UNSUPPORTED_MEDIA_TYPE_415)
249
250 expect(data.contactForm.enabled).to.be.true
251 })
252
253 it('Should get the customized configuration', async function () {
254 const res = await getCustomConfig(server.url, server.accessToken)
255 const data = res.body as CustomConfig
256
257 checkInitialConfig(server, data)
258 })
259
260 it('Should update the customized configuration', async function () {
261 const newCustomConfig: CustomConfig = {
262 instance: {
263 name: 'PeerTube updated',
264 shortDescription: 'my short description',
265 description: 'my super description',
266 terms: 'my super terms',
267 codeOfConduct: 'my super coc',
268
269 creationReason: 'my super creation reason',
270 moderationInformation: 'my super moderation information',
271 administrator: 'Kuja',
272 maintenanceLifetime: 'forever',
273 businessModel: 'my super business model',
274 hardwareInformation: '2vCore 3GB RAM',
275
276 languages: [ 'en', 'es' ],
277 categories: [ 1, 2 ],
278
279 isNSFW: true,
280 defaultNSFWPolicy: 'blur' as 'blur',
281
282 defaultClientRoute: '/videos/recently-added',
283
284 customizations: {
285 javascript: 'alert("coucou")',
286 css: 'body { background-color: red; }'
287 }
288 },
289 theme: {
290 default: 'default'
291 },
292 services: {
293 twitter: {
294 username: '@Kuja',
295 whitelisted: true
296 }
297 },
298 cache: {
299 previews: {
300 size: 2
301 },
302 captions: {
303 size: 3
304 }
305 },
306 signup: {
307 enabled: false,
308 limit: 5,
309 requiresEmailVerification: false
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 profile: 'vod_profile',
327 resolutions: {
328 '0p': false,
329 '240p': false,
330 '360p': true,
331 '480p': true,
332 '720p': false,
333 '1080p': false,
334 '1440p': false,
335 '2160p': false
336 },
337 webtorrent: {
338 enabled: true
339 },
340 hls: {
341 enabled: false
342 }
343 },
344 live: {
345 enabled: true,
346 allowReplay: true,
347 maxDuration: 5000,
348 maxInstanceLives: -1,
349 maxUserLives: 10,
350 transcoding: {
351 enabled: true,
352 threads: 4,
353 profile: 'live_profile',
354 resolutions: {
355 '240p': true,
356 '360p': true,
357 '480p': true,
358 '720p': true,
359 '1080p': true,
360 '1440p': true,
361 '2160p': true
362 }
363 }
364 },
365 import: {
366 videos: {
367 http: {
368 enabled: false
369 },
370 torrent: {
371 enabled: false
372 }
373 }
374 },
375 trending: {
376 videos: {
377 algorithms: {
378 enabled: [ 'hot', 'most-viewed', 'most-liked' ],
379 default: 'hot'
380 }
381 }
382 },
383 autoBlacklist: {
384 videos: {
385 ofUsers: {
386 enabled: true
387 }
388 }
389 },
390 followers: {
391 instance: {
392 enabled: false,
393 manualApproval: true
394 }
395 },
396 followings: {
397 instance: {
398 autoFollowBack: {
399 enabled: true
400 },
401 autoFollowIndex: {
402 enabled: true,
403 indexUrl: 'https://updated.example.com'
404 }
405 }
406 },
407 broadcastMessage: {
408 enabled: true,
409 level: 'error',
410 message: 'super bad message',
411 dismissable: true
412 },
413 search: {
414 remoteUri: {
415 anonymous: true,
416 users: true
417 },
418 searchIndex: {
419 enabled: true,
420 url: 'https://search.joinpeertube.org',
421 disableLocalSearch: true,
422 isDefaultSearch: true
423 }
424 }
425 }
426 await updateCustomConfig(server.url, server.accessToken, newCustomConfig)
427
428 const res = await getCustomConfig(server.url, server.accessToken)
429 const data = res.body
430
431 checkUpdatedConfig(data)
432 })
433
434 it('Should have the correct updated video allowed extensions', async function () {
435 this.timeout(10000)
436
437 const res = await getConfig(server.url)
438 const data: ServerConfig = res.body
439
440 expect(data.video.file.extensions).to.have.length.above(4)
441 expect(data.video.file.extensions).to.contain('.mp4')
442 expect(data.video.file.extensions).to.contain('.webm')
443 expect(data.video.file.extensions).to.contain('.ogv')
444 expect(data.video.file.extensions).to.contain('.flv')
445 expect(data.video.file.extensions).to.contain('.wmv')
446 expect(data.video.file.extensions).to.contain('.mkv')
447 expect(data.video.file.extensions).to.contain('.mp3')
448 expect(data.video.file.extensions).to.contain('.ogg')
449 expect(data.video.file.extensions).to.contain('.flac')
450
451 await uploadVideo(server.url, server.accessToken, { fixture: 'video_short.mkv' }, HttpStatusCode.OK_200)
452 await uploadVideo(server.url, server.accessToken, { fixture: 'sample.ogg' }, HttpStatusCode.OK_200)
453 })
454
455 it('Should have the configuration updated after a restart', async function () {
456 this.timeout(10000)
457
458 killallServers([ server ])
459
460 await reRunServer(server)
461
462 const res = await getCustomConfig(server.url, server.accessToken)
463 const data = res.body
464
465 checkUpdatedConfig(data)
466 })
467
468 it('Should fetch the about information', async function () {
469 const res = await getAbout(server.url)
470 const data: About = res.body
471
472 expect(data.instance.name).to.equal('PeerTube updated')
473 expect(data.instance.shortDescription).to.equal('my short description')
474 expect(data.instance.description).to.equal('my super description')
475 expect(data.instance.terms).to.equal('my super terms')
476 expect(data.instance.codeOfConduct).to.equal('my super coc')
477
478 expect(data.instance.creationReason).to.equal('my super creation reason')
479 expect(data.instance.moderationInformation).to.equal('my super moderation information')
480 expect(data.instance.administrator).to.equal('Kuja')
481 expect(data.instance.maintenanceLifetime).to.equal('forever')
482 expect(data.instance.businessModel).to.equal('my super business model')
483 expect(data.instance.hardwareInformation).to.equal('2vCore 3GB RAM')
484
485 expect(data.instance.languages).to.deep.equal([ 'en', 'es' ])
486 expect(data.instance.categories).to.deep.equal([ 1, 2 ])
487 })
488
489 it('Should remove the custom configuration', async function () {
490 this.timeout(10000)
491
492 await deleteCustomConfig(server.url, server.accessToken)
493
494 const res = await getCustomConfig(server.url, server.accessToken)
495 const data = res.body
496
497 checkInitialConfig(server, data)
498 })
499
500 after(async function () {
501 await cleanupTests([ server ])
502 })
503 })