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