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