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