]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/tests/api/server/config.ts
Shorter server command names
[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'
65e6e260 5import { HttpStatusCode } from '@shared/core-utils'
0e1dc3e7 6import {
7c3b7976 7 cleanupTests,
7c3b7976 8 flushAndRunServer,
a1587156 9 killallServers,
8155db66 10 makeGetRequest,
a1587156 11 parallelTests,
a1587156
C
12 reRunServer,
13 ServerInfo,
d23dd9fb 14 setAccessTokensToServers
65e6e260
C
15} from '@shared/extra-utils'
16import { CustomConfig } from '@shared/models'
0e1dc3e7 17
5bcfd029
C
18const expect = chai.expect
19
48f07b4a 20function checkInitialConfig (server: ServerInfo, data: CustomConfig) {
40e87e9e
C
21 expect(data.instance.name).to.equal('PeerTube')
22 expect(data.instance.shortDescription).to.equal(
482fa503 23 'PeerTube, an ActivityPub-federated video streaming platform using P2P directly in your web browser.'
40e87e9e
C
24 )
25 expect(data.instance.description).to.equal('Welcome to this PeerTube instance!')
ccc00cb2 26
40e87e9e 27 expect(data.instance.terms).to.equal('No terms for now.')
8ae03c37 28 expect(data.instance.creationReason).to.be.empty
ccc00cb2
C
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
be04c6fd 34 expect(data.instance.hardwareInformation).to.be.empty
ccc00cb2
C
35
36 expect(data.instance.languages).to.have.lengthOf(0)
37 expect(data.instance.categories).to.have.lengthOf(0)
38
40e87e9e 39 expect(data.instance.defaultClientRoute).to.equal('/videos/trending')
f8802489 40 expect(data.instance.isNSFW).to.be.false
40e87e9e
C
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
a4101923 44
40e87e9e
C
45 expect(data.services.twitter.username).to.equal('@Chocobozzz')
46 expect(data.services.twitter.whitelisted).to.be.false
a4101923 47
40e87e9e
C
48 expect(data.cache.previews.size).to.equal(1)
49 expect(data.cache.captions.size).to.equal(1)
b3d5cb92 50 expect(data.cache.torrents.size).to.equal(1)
a4101923 51
40e87e9e
C
52 expect(data.signup.enabled).to.be.true
53 expect(data.signup.limit).to.equal(4)
1f256e7d 54 expect(data.signup.minimumAge).to.equal(16)
d9eaee39 55 expect(data.signup.requiresEmailVerification).to.be.false
a4101923 56
48f07b4a 57 expect(data.admin.email).to.equal('admin' + server.internalServerNumber + '@example.com')
a4101923
C
58 expect(data.contactForm.enabled).to.be.true
59
40e87e9e 60 expect(data.user.videoQuota).to.equal(5242880)
9ee92651 61 expect(data.user.videoQuotaDaily).to.equal(-1)
c6c0fa6c 62
40e87e9e 63 expect(data.transcoding.enabled).to.be.false
14e2014a 64 expect(data.transcoding.allowAdditionalExtensions).to.be.false
536598cf 65 expect(data.transcoding.allowAudioFiles).to.be.false
40e87e9e 66 expect(data.transcoding.threads).to.equal(2)
9129b769 67 expect(data.transcoding.concurrency).to.equal(2)
1896bca0 68 expect(data.transcoding.profile).to.equal('default')
40e87e9e
C
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
b7085c71 74 expect(data.transcoding.resolutions['1440p']).to.be.true
db714ab4 75 expect(data.transcoding.resolutions['2160p']).to.be.true
d7a25329 76 expect(data.transcoding.webtorrent.enabled).to.be.true
09209296
C
77 expect(data.transcoding.hls.enabled).to.be.true
78
c6c0fa6c 79 expect(data.live.enabled).to.be.false
c655c9ef 80 expect(data.live.allowReplay).to.be.false
c9bc850e 81 expect(data.live.maxDuration).to.equal(-1)
a056ca48
C
82 expect(data.live.maxInstanceLives).to.equal(20)
83 expect(data.live.maxUserLives).to.equal(3)
c6c0fa6c
C
84 expect(data.live.transcoding.enabled).to.be.false
85 expect(data.live.transcoding.threads).to.equal(2)
1896bca0 86 expect(data.live.transcoding.profile).to.equal('default')
c6c0fa6c
C
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
b7085c71 92 expect(data.live.transcoding.resolutions['1440p']).to.be.false
c6c0fa6c
C
93 expect(data.live.transcoding.resolutions['2160p']).to.be.false
94
9129b769 95 expect(data.import.videos.concurrency).to.equal(2)
5d08a6a7 96 expect(data.import.videos.http.enabled).to.be.true
a84b8fa5 97 expect(data.import.videos.torrent.enabled).to.be.true
7ccddd7b 98 expect(data.autoBlacklist.videos.ofUsers.enabled).to.be.false
5b9c965d
C
99
100 expect(data.followers.instance.enabled).to.be.true
14893eb7 101 expect(data.followers.instance.manualApproval).to.be.false
8424c402
C
102
103 expect(data.followings.instance.autoFollowBack.enabled).to.be.false
104 expect(data.followings.instance.autoFollowIndex.enabled).to.be.false
c9215a1b 105 expect(data.followings.instance.autoFollowIndex.indexUrl).to.equal('')
72c33e71
C
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
40e87e9e
C
111}
112
113function 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')
ccc00cb2 117
40e87e9e 118 expect(data.instance.terms).to.equal('my super terms')
8ae03c37 119 expect(data.instance.creationReason).to.equal('my super creation reason')
ccc00cb2
C
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')
be04c6fd 125 expect(data.instance.hardwareInformation).to.equal('2vCore 3GB RAM')
ccc00cb2
C
126
127 expect(data.instance.languages).to.deep.equal([ 'en', 'es' ])
128 expect(data.instance.categories).to.deep.equal([ 1, 2 ])
129
40e87e9e 130 expect(data.instance.defaultClientRoute).to.equal('/videos/recently-added')
f8802489 131 expect(data.instance.isNSFW).to.be.true
40e87e9e
C
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; }')
a4101923 135
40e87e9e
C
136 expect(data.services.twitter.username).to.equal('@Kuja')
137 expect(data.services.twitter.whitelisted).to.be.true
a4101923 138
40e87e9e
C
139 expect(data.cache.previews.size).to.equal(2)
140 expect(data.cache.captions.size).to.equal(3)
b3d5cb92 141 expect(data.cache.torrents.size).to.equal(4)
a4101923 142
40e87e9e
C
143 expect(data.signup.enabled).to.be.false
144 expect(data.signup.limit).to.equal(5)
576ad67a 145 expect(data.signup.requiresEmailVerification).to.be.false
1f256e7d 146 expect(data.signup.minimumAge).to.equal(10)
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)
9129b769 160 expect(data.transcoding.concurrency).to.equal(3)
14e2014a 161 expect(data.transcoding.allowAdditionalExtensions).to.be.true
536598cf 162 expect(data.transcoding.allowAudioFiles).to.be.true
1896bca0 163 expect(data.transcoding.profile).to.equal('vod_profile')
40e87e9e
C
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
db714ab4 169 expect(data.transcoding.resolutions['2160p']).to.be.false
09209296 170 expect(data.transcoding.hls.enabled).to.be.false
d7a25329 171 expect(data.transcoding.webtorrent.enabled).to.be.true
a4101923 172
c6c0fa6c 173 expect(data.live.enabled).to.be.true
c655c9ef 174 expect(data.live.allowReplay).to.be.true
fb719404 175 expect(data.live.maxDuration).to.equal(5000)
a056ca48
C
176 expect(data.live.maxInstanceLives).to.equal(-1)
177 expect(data.live.maxUserLives).to.equal(10)
c6c0fa6c
C
178 expect(data.live.transcoding.enabled).to.be.true
179 expect(data.live.transcoding.threads).to.equal(4)
1896bca0 180 expect(data.live.transcoding.profile).to.equal('live_profile')
c6c0fa6c
C
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
9129b769 188 expect(data.import.videos.concurrency).to.equal(4)
5d08a6a7 189 expect(data.import.videos.http.enabled).to.be.false
a84b8fa5 190 expect(data.import.videos.torrent.enabled).to.be.false
7ccddd7b 191 expect(data.autoBlacklist.videos.ofUsers.enabled).to.be.true
5b9c965d
C
192
193 expect(data.followers.instance.enabled).to.be.false
14893eb7 194 expect(data.followers.instance.manualApproval).to.be.true
8424c402
C
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')
72c33e71
C
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
40e87e9e
C
204}
205
0e1dc3e7 206describe('Test config', function () {
65e6e260 207 let server: ServerInfo = null
0e1dc3e7
C
208
209 before(async function () {
e212f887 210 this.timeout(30000)
48f07b4a 211
210feb6c 212 server = await flushAndRunServer(1)
fd206f0b 213 await setAccessTokensToServers([ server ])
0e1dc3e7
C
214 })
215
216 it('Should have a correct config on a server with registration enabled', async function () {
89d241a7 217 const data = await server.config.getConfig()
0e1dc3e7
C
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 () {
652b3056
C
223 this.timeout(5000)
224
47e0652b 225 await Promise.all([
89d241a7
C
226 server.users.register({ username: 'user1' }),
227 server.users.register({ username: 'user2' }),
228 server.users.register({ username: 'user3' })
47e0652b 229 ])
0e1dc3e7 230
89d241a7 231 const data = await server.config.getConfig()
0e1dc3e7
C
232
233 expect(data.signup.allowed).to.be.false
234 })
235
14e2014a 236 it('Should have the correct video allowed extensions', async function () {
89d241a7 237 const data = await server.config.getConfig()
14e2014a
C
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')
a4101923 243
89d241a7
C
244 await server.videos.upload({ attributes: { fixture: 'video_short.mkv' }, expectedStatus: HttpStatusCode.UNSUPPORTED_MEDIA_TYPE_415 })
245 await server.videos.upload({ attributes: { fixture: 'sample.ogg' }, expectedStatus: HttpStatusCode.UNSUPPORTED_MEDIA_TYPE_415 })
b345a804 246
a4101923 247 expect(data.contactForm.enabled).to.be.true
14e2014a
C
248 })
249
fd206f0b 250 it('Should get the customized configuration', async function () {
89d241a7 251 const data = await server.config.getCustomConfig()
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
b3d5cb92
C
300 },
301 torrents: {
302 size: 4
fd206f0b
C
303 }
304 },
305 signup: {
306 enabled: false,
d9eaee39 307 limit: 5,
1f256e7d
P
308 requiresEmailVerification: false,
309 minimumAge: 10
fd206f0b
C
310 },
311 admin: {
312 email: 'superadmin1@example.com'
313 },
a4101923
C
314 contactForm: {
315 enabled: false
316 },
fd206f0b 317 user: {
bee0abff
FA
318 videoQuota: 5242881,
319 videoQuotaDaily: 318742
fd206f0b
C
320 },
321 transcoding: {
322 enabled: true,
14e2014a 323 allowAdditionalExtensions: true,
536598cf 324 allowAudioFiles: true,
fd206f0b 325 threads: 1,
9129b769 326 concurrency: 3,
1896bca0 327 profile: 'vod_profile',
fd206f0b 328 resolutions: {
5c7d6508 329 '0p': false,
fd206f0b
C
330 '240p': false,
331 '360p': true,
332 '480p': true,
333 '720p': false,
db714ab4 334 '1080p': false,
b7085c71 335 '1440p': false,
db714ab4 336 '2160p': false
09209296 337 },
d7a25329
C
338 webtorrent: {
339 enabled: true
340 },
09209296
C
341 hls: {
342 enabled: false
fd206f0b 343 }
5d08a6a7 344 },
c6c0fa6c
C
345 live: {
346 enabled: true,
c655c9ef 347 allowReplay: true,
fb719404 348 maxDuration: 5000,
a056ca48
C
349 maxInstanceLives: -1,
350 maxUserLives: 10,
c6c0fa6c
C
351 transcoding: {
352 enabled: true,
353 threads: 4,
1896bca0 354 profile: 'live_profile',
c6c0fa6c
C
355 resolutions: {
356 '240p': true,
357 '360p': true,
358 '480p': true,
359 '720p': true,
360 '1080p': true,
b7085c71 361 '1440p': true,
c6c0fa6c
C
362 '2160p': true
363 }
364 }
365 },
5d08a6a7
C
366 import: {
367 videos: {
9129b769 368 concurrency: 4,
5d08a6a7
C
369 http: {
370 enabled: false
a84b8fa5
C
371 },
372 torrent: {
373 enabled: false
5d08a6a7
C
374 }
375 }
7ccddd7b 376 },
ba5d4a84
RK
377 trending: {
378 videos: {
379 algorithms: {
3d4e112d 380 enabled: [ 'best', 'hot', 'most-viewed', 'most-liked' ],
ba5d4a84
RK
381 default: 'hot'
382 }
383 }
384 },
7ccddd7b
JM
385 autoBlacklist: {
386 videos: {
387 ofUsers: {
388 enabled: true
389 }
390 }
5b9c965d
C
391 },
392 followers: {
393 instance: {
14893eb7
C
394 enabled: false,
395 manualApproval: true
5b9c965d 396 }
8424c402
C
397 },
398 followings: {
399 instance: {
400 autoFollowBack: {
401 enabled: true
402 },
403 autoFollowIndex: {
404 enabled: true,
405 indexUrl: 'https://updated.example.com'
406 }
407 }
72c33e71
C
408 },
409 broadcastMessage: {
410 enabled: true,
411 level: 'error',
412 message: 'super bad message',
413 dismissable: true
5fb2e288
C
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 }
fd206f0b
C
426 }
427 }
89d241a7 428 await server.config.updateCustomConfig({ newCustomConfig })
fd206f0b 429
89d241a7 430 const data = await server.config.getCustomConfig()
40e87e9e 431 checkUpdatedConfig(data)
fd206f0b
C
432 })
433
14e2014a 434 it('Should have the correct updated video allowed extensions', async function () {
30bc55c8
C
435 this.timeout(10000)
436
89d241a7 437 const data = await server.config.getConfig()
14e2014a 438
30bc55c8 439 expect(data.video.file.extensions).to.have.length.above(4)
14e2014a
C
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')
fccbbc1a 444 expect(data.video.file.extensions).to.contain('.wmv')
14e2014a 445 expect(data.video.file.extensions).to.contain('.mkv')
b345a804
C
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
89d241a7
C
450 await server.videos.upload({ attributes: { fixture: 'video_short.mkv' }, expectedStatus: HttpStatusCode.OK_200 })
451 await server.videos.upload({ attributes: { fixture: 'sample.ogg' }, expectedStatus: HttpStatusCode.OK_200 })
14e2014a
C
452 })
453
fd206f0b 454 it('Should have the configuration updated after a restart', async function () {
23e27dd5
C
455 this.timeout(10000)
456
9293139f 457 await killallServers([ server ])
fd206f0b
C
458
459 await reRunServer(server)
460
89d241a7 461 const data = await server.config.getCustomConfig()
fd206f0b 462
40e87e9e 463 checkUpdatedConfig(data)
fd206f0b
C
464 })
465
36f9424f 466 it('Should fetch the about information', async function () {
89d241a7 467 const data = await server.config.getAbout()
36f9424f
C
468
469 expect(data.instance.name).to.equal('PeerTube updated')
2e3a0215 470 expect(data.instance.shortDescription).to.equal('my short description')
36f9424f
C
471 expect(data.instance.description).to.equal('my super description')
472 expect(data.instance.terms).to.equal('my super terms')
be04c6fd
C
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 ])
36f9424f
C
484 })
485
fd206f0b 486 it('Should remove the custom configuration', async function () {
23e27dd5
C
487 this.timeout(10000)
488
89d241a7 489 await server.config.deleteCustomConfig()
fd206f0b 490
89d241a7 491 const data = await server.config.getCustomConfig()
48f07b4a 492 checkInitialConfig(server, data)
fd206f0b
C
493 })
494
8155db66
C
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
9293139f 508 await killallServers([ server ])
8155db66
C
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
7c3b7976
C
528 after(async function () {
529 await cleanupTests([ server ])
0e1dc3e7
C
530 })
531})