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