]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/tests/api/server/config.ts
Use a profile manager for transcoding
[github/Chocobozzz/PeerTube.git] / server / tests / api / server / config.ts
CommitLineData
a1587156 1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
0e1dc3e7
C
2
3import 'mocha'
4import * as chai from 'chai'
09cababd
C
5import { About } from '../../../../shared/models/server/about.model'
6import { CustomConfig } from '../../../../shared/models/server/custom-config.model'
0e1dc3e7 7import {
7c3b7976 8 cleanupTests,
9639bd17 9 deleteCustomConfig,
7c3b7976 10 flushAndRunServer,
9639bd17 11 getAbout,
5bcfd029
C
12 getConfig,
13 getCustomConfig,
a1587156
C
14 killallServers,
15 parallelTests,
5bcfd029 16 registerUser,
a1587156
C
17 reRunServer,
18 ServerInfo,
5bcfd029 19 setAccessTokensToServers,
a1587156
C
20 updateCustomConfig,
21 uploadVideo
94565d52 22} from '../../../../shared/extra-utils'
14e2014a 23import { ServerConfig } from '../../../../shared/models'
f2eb23cd 24import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
0e1dc3e7 25
5bcfd029
C
26const expect = chai.expect
27
48f07b4a 28function checkInitialConfig (server: ServerInfo, data: CustomConfig) {
40e87e9e
C
29 expect(data.instance.name).to.equal('PeerTube')
30 expect(data.instance.shortDescription).to.equal(
482fa503 31 'PeerTube, an ActivityPub-federated video streaming platform using P2P directly in your web browser.'
40e87e9e
C
32 )
33 expect(data.instance.description).to.equal('Welcome to this PeerTube instance!')
ccc00cb2 34
40e87e9e 35 expect(data.instance.terms).to.equal('No terms for now.')
8ae03c37 36 expect(data.instance.creationReason).to.be.empty
ccc00cb2
C
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
be04c6fd 42 expect(data.instance.hardwareInformation).to.be.empty
ccc00cb2
C
43
44 expect(data.instance.languages).to.have.lengthOf(0)
45 expect(data.instance.categories).to.have.lengthOf(0)
46
40e87e9e 47 expect(data.instance.defaultClientRoute).to.equal('/videos/trending')
f8802489 48 expect(data.instance.isNSFW).to.be.false
40e87e9e
C
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
a4101923 52
40e87e9e
C
53 expect(data.services.twitter.username).to.equal('@Chocobozzz')
54 expect(data.services.twitter.whitelisted).to.be.false
a4101923 55
40e87e9e
C
56 expect(data.cache.previews.size).to.equal(1)
57 expect(data.cache.captions.size).to.equal(1)
a4101923 58
40e87e9e
C
59 expect(data.signup.enabled).to.be.true
60 expect(data.signup.limit).to.equal(4)
d9eaee39 61 expect(data.signup.requiresEmailVerification).to.be.false
a4101923 62
48f07b4a 63 expect(data.admin.email).to.equal('admin' + server.internalServerNumber + '@example.com')
a4101923
C
64 expect(data.contactForm.enabled).to.be.true
65
40e87e9e 66 expect(data.user.videoQuota).to.equal(5242880)
9ee92651 67 expect(data.user.videoQuotaDaily).to.equal(-1)
c6c0fa6c 68
40e87e9e 69 expect(data.transcoding.enabled).to.be.false
14e2014a 70 expect(data.transcoding.allowAdditionalExtensions).to.be.false
536598cf 71 expect(data.transcoding.allowAudioFiles).to.be.false
40e87e9e
C
72 expect(data.transcoding.threads).to.equal(2)
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
b7085c71 78 expect(data.transcoding.resolutions['1440p']).to.be.true
db714ab4 79 expect(data.transcoding.resolutions['2160p']).to.be.true
d7a25329 80 expect(data.transcoding.webtorrent.enabled).to.be.true
09209296
C
81 expect(data.transcoding.hls.enabled).to.be.true
82
c6c0fa6c 83 expect(data.live.enabled).to.be.false
c655c9ef 84 expect(data.live.allowReplay).to.be.false
c9bc850e 85 expect(data.live.maxDuration).to.equal(-1)
a056ca48
C
86 expect(data.live.maxInstanceLives).to.equal(20)
87 expect(data.live.maxUserLives).to.equal(3)
c6c0fa6c
C
88 expect(data.live.transcoding.enabled).to.be.false
89 expect(data.live.transcoding.threads).to.equal(2)
90 expect(data.live.transcoding.resolutions['240p']).to.be.false
91 expect(data.live.transcoding.resolutions['360p']).to.be.false
92 expect(data.live.transcoding.resolutions['480p']).to.be.false
93 expect(data.live.transcoding.resolutions['720p']).to.be.false
94 expect(data.live.transcoding.resolutions['1080p']).to.be.false
b7085c71 95 expect(data.live.transcoding.resolutions['1440p']).to.be.false
c6c0fa6c
C
96 expect(data.live.transcoding.resolutions['2160p']).to.be.false
97
5d08a6a7 98 expect(data.import.videos.http.enabled).to.be.true
a84b8fa5 99 expect(data.import.videos.torrent.enabled).to.be.true
7ccddd7b 100 expect(data.autoBlacklist.videos.ofUsers.enabled).to.be.false
5b9c965d
C
101
102 expect(data.followers.instance.enabled).to.be.true
14893eb7 103 expect(data.followers.instance.manualApproval).to.be.false
8424c402
C
104
105 expect(data.followings.instance.autoFollowBack.enabled).to.be.false
106 expect(data.followings.instance.autoFollowIndex.enabled).to.be.false
c9215a1b 107 expect(data.followings.instance.autoFollowIndex.indexUrl).to.equal('')
72c33e71
C
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
40e87e9e
C
113}
114
115function 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')
ccc00cb2 119
40e87e9e 120 expect(data.instance.terms).to.equal('my super terms')
8ae03c37 121 expect(data.instance.creationReason).to.equal('my super creation reason')
ccc00cb2
C
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')
be04c6fd 127 expect(data.instance.hardwareInformation).to.equal('2vCore 3GB RAM')
ccc00cb2
C
128
129 expect(data.instance.languages).to.deep.equal([ 'en', 'es' ])
130 expect(data.instance.categories).to.deep.equal([ 1, 2 ])
131
40e87e9e 132 expect(data.instance.defaultClientRoute).to.equal('/videos/recently-added')
f8802489 133 expect(data.instance.isNSFW).to.be.true
40e87e9e
C
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; }')
a4101923 137
40e87e9e
C
138 expect(data.services.twitter.username).to.equal('@Kuja')
139 expect(data.services.twitter.whitelisted).to.be.true
a4101923 140
40e87e9e
C
141 expect(data.cache.previews.size).to.equal(2)
142 expect(data.cache.captions.size).to.equal(3)
a4101923 143
40e87e9e
C
144 expect(data.signup.enabled).to.be.false
145 expect(data.signup.limit).to.equal(5)
576ad67a 146 expect(data.signup.requiresEmailVerification).to.be.false
a4101923 147
48f07b4a
C
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
a4101923
C
153 expect(data.contactForm.enabled).to.be.false
154
40e87e9e 155 expect(data.user.videoQuota).to.equal(5242881)
bee0abff 156 expect(data.user.videoQuotaDaily).to.equal(318742)
a4101923 157
40e87e9e
C
158 expect(data.transcoding.enabled).to.be.true
159 expect(data.transcoding.threads).to.equal(1)
14e2014a 160 expect(data.transcoding.allowAdditionalExtensions).to.be.true
536598cf 161 expect(data.transcoding.allowAudioFiles).to.be.true
40e87e9e
C
162 expect(data.transcoding.resolutions['240p']).to.be.false
163 expect(data.transcoding.resolutions['360p']).to.be.true
164 expect(data.transcoding.resolutions['480p']).to.be.true
165 expect(data.transcoding.resolutions['720p']).to.be.false
166 expect(data.transcoding.resolutions['1080p']).to.be.false
db714ab4 167 expect(data.transcoding.resolutions['2160p']).to.be.false
09209296 168 expect(data.transcoding.hls.enabled).to.be.false
d7a25329 169 expect(data.transcoding.webtorrent.enabled).to.be.true
a4101923 170
c6c0fa6c 171 expect(data.live.enabled).to.be.true
c655c9ef 172 expect(data.live.allowReplay).to.be.true
fb719404 173 expect(data.live.maxDuration).to.equal(5000)
a056ca48
C
174 expect(data.live.maxInstanceLives).to.equal(-1)
175 expect(data.live.maxUserLives).to.equal(10)
c6c0fa6c
C
176 expect(data.live.transcoding.enabled).to.be.true
177 expect(data.live.transcoding.threads).to.equal(4)
178 expect(data.live.transcoding.resolutions['240p']).to.be.true
179 expect(data.live.transcoding.resolutions['360p']).to.be.true
180 expect(data.live.transcoding.resolutions['480p']).to.be.true
181 expect(data.live.transcoding.resolutions['720p']).to.be.true
182 expect(data.live.transcoding.resolutions['1080p']).to.be.true
183 expect(data.live.transcoding.resolutions['2160p']).to.be.true
184
5d08a6a7 185 expect(data.import.videos.http.enabled).to.be.false
a84b8fa5 186 expect(data.import.videos.torrent.enabled).to.be.false
7ccddd7b 187 expect(data.autoBlacklist.videos.ofUsers.enabled).to.be.true
5b9c965d
C
188
189 expect(data.followers.instance.enabled).to.be.false
14893eb7 190 expect(data.followers.instance.manualApproval).to.be.true
8424c402
C
191
192 expect(data.followings.instance.autoFollowBack.enabled).to.be.true
193 expect(data.followings.instance.autoFollowIndex.enabled).to.be.true
194 expect(data.followings.instance.autoFollowIndex.indexUrl).to.equal('https://updated.example.com')
72c33e71
C
195
196 expect(data.broadcastMessage.enabled).to.be.true
197 expect(data.broadcastMessage.level).to.equal('error')
198 expect(data.broadcastMessage.message).to.equal('super bad message')
199 expect(data.broadcastMessage.dismissable).to.be.true
40e87e9e
C
200}
201
0e1dc3e7
C
202describe('Test config', function () {
203 let server = null
204
205 before(async function () {
e212f887 206 this.timeout(30000)
48f07b4a 207
210feb6c 208 server = await flushAndRunServer(1)
fd206f0b 209 await setAccessTokensToServers([ server ])
0e1dc3e7
C
210 })
211
212 it('Should have a correct config on a server with registration enabled', async function () {
213 const res = await getConfig(server.url)
14e2014a 214 const data: ServerConfig = res.body
0e1dc3e7
C
215
216 expect(data.signup.allowed).to.be.true
217 })
218
219 it('Should have a correct config on a server with registration enabled and a users limit', async function () {
652b3056
C
220 this.timeout(5000)
221
47e0652b
C
222 await Promise.all([
223 registerUser(server.url, 'user1', 'super password'),
224 registerUser(server.url, 'user2', 'super password'),
225 registerUser(server.url, 'user3', 'super password')
226 ])
0e1dc3e7
C
227
228 const res = await getConfig(server.url)
14e2014a 229 const data: ServerConfig = res.body
0e1dc3e7
C
230
231 expect(data.signup.allowed).to.be.false
232 })
233
14e2014a
C
234 it('Should have the correct video allowed extensions', async function () {
235 const res = await getConfig(server.url)
236 const data: ServerConfig = res.body
237
238 expect(data.video.file.extensions).to.have.lengthOf(3)
239 expect(data.video.file.extensions).to.contain('.mp4')
240 expect(data.video.file.extensions).to.contain('.webm')
241 expect(data.video.file.extensions).to.contain('.ogv')
a4101923 242
f2eb23cd
RK
243 await uploadVideo(server.url, server.accessToken, { fixture: 'video_short.mkv' }, HttpStatusCode.UNSUPPORTED_MEDIA_TYPE_415)
244 await uploadVideo(server.url, server.accessToken, { fixture: 'sample.ogg' }, HttpStatusCode.UNSUPPORTED_MEDIA_TYPE_415)
b345a804 245
a4101923 246 expect(data.contactForm.enabled).to.be.true
14e2014a
C
247 })
248
fd206f0b
C
249 it('Should get the customized configuration', async function () {
250 const res = await getCustomConfig(server.url, server.accessToken)
00b5556c 251 const data = res.body as CustomConfig
fd206f0b 252
48f07b4a 253 checkInitialConfig(server, data)
fd206f0b
C
254 })
255
256 it('Should update the customized configuration', async function () {
40e87e9e 257 const newCustomConfig: CustomConfig = {
66b16caf
C
258 instance: {
259 name: 'PeerTube updated',
2e3a0215 260 shortDescription: 'my short description',
66b16caf 261 description: 'my super description',
00b5556c 262 terms: 'my super terms',
ccc00cb2
C
263 codeOfConduct: 'my super coc',
264
8ae03c37 265 creationReason: 'my super creation reason',
ccc00cb2
C
266 moderationInformation: 'my super moderation information',
267 administrator: 'Kuja',
268 maintenanceLifetime: 'forever',
269 businessModel: 'my super business model',
be04c6fd 270 hardwareInformation: '2vCore 3GB RAM',
ccc00cb2
C
271
272 languages: [ 'en', 'es' ],
273 categories: [ 1, 2 ],
274
f8802489 275 isNSFW: true,
0883b324 276 defaultNSFWPolicy: 'blur' as 'blur',
3da68f0a
RK
277
278 defaultClientRoute: '/videos/recently-added',
3da68f0a 279
00b5556c
C
280 customizations: {
281 javascript: 'alert("coucou")',
282 css: 'body { background-color: red; }'
283 }
66b16caf 284 },
7cd4d2ba
C
285 theme: {
286 default: 'default'
287 },
8be1afa1
C
288 services: {
289 twitter: {
290 username: '@Kuja',
291 whitelisted: true
292 }
293 },
fd206f0b
C
294 cache: {
295 previews: {
296 size: 2
40e87e9e
C
297 },
298 captions: {
299 size: 3
fd206f0b
C
300 }
301 },
302 signup: {
303 enabled: false,
d9eaee39 304 limit: 5,
576ad67a 305 requiresEmailVerification: false
fd206f0b
C
306 },
307 admin: {
308 email: 'superadmin1@example.com'
309 },
a4101923
C
310 contactForm: {
311 enabled: false
312 },
fd206f0b 313 user: {
bee0abff
FA
314 videoQuota: 5242881,
315 videoQuotaDaily: 318742
fd206f0b
C
316 },
317 transcoding: {
318 enabled: true,
14e2014a 319 allowAdditionalExtensions: true,
536598cf 320 allowAudioFiles: true,
fd206f0b
C
321 threads: 1,
322 resolutions: {
5c7d6508 323 '0p': false,
fd206f0b
C
324 '240p': false,
325 '360p': true,
326 '480p': true,
327 '720p': false,
db714ab4 328 '1080p': false,
b7085c71 329 '1440p': false,
db714ab4 330 '2160p': false
09209296 331 },
d7a25329
C
332 webtorrent: {
333 enabled: true
334 },
09209296
C
335 hls: {
336 enabled: false
fd206f0b 337 }
5d08a6a7 338 },
c6c0fa6c
C
339 live: {
340 enabled: true,
c655c9ef 341 allowReplay: true,
fb719404 342 maxDuration: 5000,
a056ca48
C
343 maxInstanceLives: -1,
344 maxUserLives: 10,
c6c0fa6c
C
345 transcoding: {
346 enabled: true,
347 threads: 4,
348 resolutions: {
349 '240p': true,
350 '360p': true,
351 '480p': true,
352 '720p': true,
353 '1080p': true,
b7085c71 354 '1440p': true,
c6c0fa6c
C
355 '2160p': true
356 }
357 }
358 },
5d08a6a7
C
359 import: {
360 videos: {
361 http: {
362 enabled: false
a84b8fa5
C
363 },
364 torrent: {
365 enabled: false
5d08a6a7
C
366 }
367 }
7ccddd7b 368 },
ba5d4a84
RK
369 trending: {
370 videos: {
371 algorithms: {
372 enabled: [ 'hot', 'most-viewed', 'most-liked' ],
373 default: 'hot'
374 }
375 }
376 },
7ccddd7b
JM
377 autoBlacklist: {
378 videos: {
379 ofUsers: {
380 enabled: true
381 }
382 }
5b9c965d
C
383 },
384 followers: {
385 instance: {
14893eb7
C
386 enabled: false,
387 manualApproval: true
5b9c965d 388 }
8424c402
C
389 },
390 followings: {
391 instance: {
392 autoFollowBack: {
393 enabled: true
394 },
395 autoFollowIndex: {
396 enabled: true,
397 indexUrl: 'https://updated.example.com'
398 }
399 }
72c33e71
C
400 },
401 broadcastMessage: {
402 enabled: true,
403 level: 'error',
404 message: 'super bad message',
405 dismissable: true
5fb2e288
C
406 },
407 search: {
408 remoteUri: {
409 anonymous: true,
410 users: true
411 },
412 searchIndex: {
413 enabled: true,
414 url: 'https://search.joinpeertube.org',
415 disableLocalSearch: true,
416 isDefaultSearch: true
417 }
fd206f0b
C
418 }
419 }
420 await updateCustomConfig(server.url, server.accessToken, newCustomConfig)
421
422 const res = await getCustomConfig(server.url, server.accessToken)
423 const data = res.body
424
40e87e9e 425 checkUpdatedConfig(data)
fd206f0b
C
426 })
427
14e2014a 428 it('Should have the correct updated video allowed extensions', async function () {
30bc55c8
C
429 this.timeout(10000)
430
14e2014a
C
431 const res = await getConfig(server.url)
432 const data: ServerConfig = res.body
433
30bc55c8 434 expect(data.video.file.extensions).to.have.length.above(4)
14e2014a
C
435 expect(data.video.file.extensions).to.contain('.mp4')
436 expect(data.video.file.extensions).to.contain('.webm')
437 expect(data.video.file.extensions).to.contain('.ogv')
438 expect(data.video.file.extensions).to.contain('.flv')
fccbbc1a 439 expect(data.video.file.extensions).to.contain('.wmv')
14e2014a 440 expect(data.video.file.extensions).to.contain('.mkv')
b345a804
C
441 expect(data.video.file.extensions).to.contain('.mp3')
442 expect(data.video.file.extensions).to.contain('.ogg')
443 expect(data.video.file.extensions).to.contain('.flac')
444
f2eb23cd
RK
445 await uploadVideo(server.url, server.accessToken, { fixture: 'video_short.mkv' }, HttpStatusCode.OK_200)
446 await uploadVideo(server.url, server.accessToken, { fixture: 'sample.ogg' }, HttpStatusCode.OK_200)
14e2014a
C
447 })
448
fd206f0b 449 it('Should have the configuration updated after a restart', async function () {
23e27dd5
C
450 this.timeout(10000)
451
fd206f0b
C
452 killallServers([ server ])
453
454 await reRunServer(server)
455
456 const res = await getCustomConfig(server.url, server.accessToken)
457 const data = res.body
458
40e87e9e 459 checkUpdatedConfig(data)
fd206f0b
C
460 })
461
36f9424f
C
462 it('Should fetch the about information', async function () {
463 const res = await getAbout(server.url)
464 const data: About = res.body
465
466 expect(data.instance.name).to.equal('PeerTube updated')
2e3a0215 467 expect(data.instance.shortDescription).to.equal('my short description')
36f9424f
C
468 expect(data.instance.description).to.equal('my super description')
469 expect(data.instance.terms).to.equal('my super terms')
be04c6fd
C
470 expect(data.instance.codeOfConduct).to.equal('my super coc')
471
472 expect(data.instance.creationReason).to.equal('my super creation reason')
473 expect(data.instance.moderationInformation).to.equal('my super moderation information')
474 expect(data.instance.administrator).to.equal('Kuja')
475 expect(data.instance.maintenanceLifetime).to.equal('forever')
476 expect(data.instance.businessModel).to.equal('my super business model')
477 expect(data.instance.hardwareInformation).to.equal('2vCore 3GB RAM')
478
479 expect(data.instance.languages).to.deep.equal([ 'en', 'es' ])
480 expect(data.instance.categories).to.deep.equal([ 1, 2 ])
36f9424f
C
481 })
482
fd206f0b 483 it('Should remove the custom configuration', async function () {
23e27dd5
C
484 this.timeout(10000)
485
fd206f0b
C
486 await deleteCustomConfig(server.url, server.accessToken)
487
488 const res = await getCustomConfig(server.url, server.accessToken)
489 const data = res.body
490
48f07b4a 491 checkInitialConfig(server, data)
fd206f0b
C
492 })
493
7c3b7976
C
494 after(async function () {
495 await cleanupTests([ server ])
0e1dc3e7
C
496 })
497})