]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/tests/api/server/config.ts
eb51d8909c1f1284327f67173ebd26d0242fdf94
[github/Chocobozzz/PeerTube.git] / server / tests / api / server / config.ts
1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2
3 import 'mocha'
4 import * as chai from 'chai'
5 import { About } from '../../../../shared/models/server/about.model'
6 import { CustomConfig } from '../../../../shared/models/server/custom-config.model'
7 import {
8 cleanupTests,
9 deleteCustomConfig,
10 flushAndRunServer,
11 getAbout,
12 getConfig,
13 getCustomConfig,
14 killallServers,
15 parallelTests,
16 registerUser,
17 reRunServer,
18 ServerInfo,
19 setAccessTokensToServers,
20 updateCustomConfig,
21 uploadVideo
22 } from '../../../../shared/extra-utils'
23 import { ServerConfig } from '../../../../shared/models'
24
25 const expect = chai.expect
26
27 function checkInitialConfig (server: ServerInfo, data: CustomConfig) {
28 expect(data.instance.name).to.equal('PeerTube')
29 expect(data.instance.shortDescription).to.equal(
30 'PeerTube, an ActivityPub-federated video streaming platform using P2P directly in your web browser.'
31 )
32 expect(data.instance.description).to.equal('Welcome to this PeerTube instance!')
33
34 expect(data.instance.terms).to.equal('No terms for now.')
35 expect(data.instance.creationReason).to.be.empty
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
41 expect(data.instance.hardwareInformation).to.be.empty
42
43 expect(data.instance.languages).to.have.lengthOf(0)
44 expect(data.instance.categories).to.have.lengthOf(0)
45
46 expect(data.instance.defaultClientRoute).to.equal('/videos/trending')
47 expect(data.instance.isNSFW).to.be.false
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
51
52 expect(data.services.twitter.username).to.equal('@Chocobozzz')
53 expect(data.services.twitter.whitelisted).to.be.false
54
55 expect(data.cache.previews.size).to.equal(1)
56 expect(data.cache.captions.size).to.equal(1)
57
58 expect(data.signup.enabled).to.be.true
59 expect(data.signup.limit).to.equal(4)
60 expect(data.signup.requiresEmailVerification).to.be.false
61
62 expect(data.admin.email).to.equal('admin' + server.internalServerNumber + '@example.com')
63 expect(data.contactForm.enabled).to.be.true
64
65 expect(data.user.videoQuota).to.equal(5242880)
66 expect(data.user.videoQuotaDaily).to.equal(-1)
67
68 expect(data.transcoding.enabled).to.be.false
69 expect(data.transcoding.allowAdditionalExtensions).to.be.false
70 expect(data.transcoding.allowAudioFiles).to.be.false
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
77 expect(data.transcoding.resolutions['2160p']).to.be.true
78 expect(data.transcoding.webtorrent.enabled).to.be.true
79 expect(data.transcoding.hls.enabled).to.be.true
80
81 expect(data.live.enabled).to.be.false
82 expect(data.live.allowReplay).to.be.false
83 expect(data.live.maxDuration).to.be.null
84 expect(data.live.maxInstanceLives).to.equal(20)
85 expect(data.live.maxUserLives).to.equal(3)
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
95 expect(data.import.videos.http.enabled).to.be.true
96 expect(data.import.videos.torrent.enabled).to.be.true
97 expect(data.autoBlacklist.videos.ofUsers.enabled).to.be.false
98
99 expect(data.followers.instance.enabled).to.be.true
100 expect(data.followers.instance.manualApproval).to.be.false
101
102 expect(data.followings.instance.autoFollowBack.enabled).to.be.false
103 expect(data.followings.instance.autoFollowIndex.enabled).to.be.false
104 expect(data.followings.instance.autoFollowIndex.indexUrl).to.equal('')
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
110 }
111
112 function 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')
116
117 expect(data.instance.terms).to.equal('my super terms')
118 expect(data.instance.creationReason).to.equal('my super creation reason')
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')
124 expect(data.instance.hardwareInformation).to.equal('2vCore 3GB RAM')
125
126 expect(data.instance.languages).to.deep.equal([ 'en', 'es' ])
127 expect(data.instance.categories).to.deep.equal([ 1, 2 ])
128
129 expect(data.instance.defaultClientRoute).to.equal('/videos/recently-added')
130 expect(data.instance.isNSFW).to.be.true
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; }')
134
135 expect(data.services.twitter.username).to.equal('@Kuja')
136 expect(data.services.twitter.whitelisted).to.be.true
137
138 expect(data.cache.previews.size).to.equal(2)
139 expect(data.cache.captions.size).to.equal(3)
140
141 expect(data.signup.enabled).to.be.false
142 expect(data.signup.limit).to.equal(5)
143 expect(data.signup.requiresEmailVerification).to.be.false
144
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
150 expect(data.contactForm.enabled).to.be.false
151
152 expect(data.user.videoQuota).to.equal(5242881)
153 expect(data.user.videoQuotaDaily).to.equal(318742)
154
155 expect(data.transcoding.enabled).to.be.true
156 expect(data.transcoding.threads).to.equal(1)
157 expect(data.transcoding.allowAdditionalExtensions).to.be.true
158 expect(data.transcoding.allowAudioFiles).to.be.true
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
164 expect(data.transcoding.resolutions['2160p']).to.be.false
165 expect(data.transcoding.hls.enabled).to.be.false
166 expect(data.transcoding.webtorrent.enabled).to.be.true
167
168 expect(data.live.enabled).to.be.true
169 expect(data.live.allowReplay).to.be.true
170 expect(data.live.maxDuration).to.equal(5000)
171 expect(data.live.maxInstanceLives).to.equal(-1)
172 expect(data.live.maxUserLives).to.equal(10)
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
182 expect(data.import.videos.http.enabled).to.be.false
183 expect(data.import.videos.torrent.enabled).to.be.false
184 expect(data.autoBlacklist.videos.ofUsers.enabled).to.be.true
185
186 expect(data.followers.instance.enabled).to.be.false
187 expect(data.followers.instance.manualApproval).to.be.true
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')
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
197 }
198
199 describe('Test config', function () {
200 let server = null
201
202 before(async function () {
203 this.timeout(30000)
204
205 server = await flushAndRunServer(1)
206 await setAccessTokensToServers([ server ])
207 })
208
209 it('Should have a correct config on a server with registration enabled', async function () {
210 const res = await getConfig(server.url)
211 const data: ServerConfig = res.body
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 () {
217 this.timeout(5000)
218
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 ])
224
225 const res = await getConfig(server.url)
226 const data: ServerConfig = res.body
227
228 expect(data.signup.allowed).to.be.false
229 })
230
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')
239
240 await uploadVideo(server.url, server.accessToken, { fixture: 'video_short.mkv' }, 400)
241 await uploadVideo(server.url, server.accessToken, { fixture: 'sample.ogg' }, 400)
242
243 expect(data.contactForm.enabled).to.be.true
244 })
245
246 it('Should get the customized configuration', async function () {
247 const res = await getCustomConfig(server.url, server.accessToken)
248 const data = res.body as CustomConfig
249
250 checkInitialConfig(server, data)
251 })
252
253 it('Should update the customized configuration', async function () {
254 const newCustomConfig: CustomConfig = {
255 instance: {
256 name: 'PeerTube updated',
257 shortDescription: 'my short description',
258 description: 'my super description',
259 terms: 'my super terms',
260 codeOfConduct: 'my super coc',
261
262 creationReason: 'my super creation reason',
263 moderationInformation: 'my super moderation information',
264 administrator: 'Kuja',
265 maintenanceLifetime: 'forever',
266 businessModel: 'my super business model',
267 hardwareInformation: '2vCore 3GB RAM',
268
269 languages: [ 'en', 'es' ],
270 categories: [ 1, 2 ],
271
272 defaultClientRoute: '/videos/recently-added',
273 isNSFW: true,
274 defaultNSFWPolicy: 'blur' as 'blur',
275 customizations: {
276 javascript: 'alert("coucou")',
277 css: 'body { background-color: red; }'
278 }
279 },
280 theme: {
281 default: 'default'
282 },
283 services: {
284 twitter: {
285 username: '@Kuja',
286 whitelisted: true
287 }
288 },
289 cache: {
290 previews: {
291 size: 2
292 },
293 captions: {
294 size: 3
295 }
296 },
297 signup: {
298 enabled: false,
299 limit: 5,
300 requiresEmailVerification: false
301 },
302 admin: {
303 email: 'superadmin1@example.com'
304 },
305 contactForm: {
306 enabled: false
307 },
308 user: {
309 videoQuota: 5242881,
310 videoQuotaDaily: 318742
311 },
312 transcoding: {
313 enabled: true,
314 allowAdditionalExtensions: true,
315 allowAudioFiles: true,
316 threads: 1,
317 resolutions: {
318 '0p': false,
319 '240p': false,
320 '360p': true,
321 '480p': true,
322 '720p': false,
323 '1080p': false,
324 '2160p': false
325 },
326 webtorrent: {
327 enabled: true
328 },
329 hls: {
330 enabled: false
331 }
332 },
333 live: {
334 enabled: true,
335 allowReplay: true,
336 maxDuration: 5000,
337 maxInstanceLives: -1,
338 maxUserLives: 10,
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 },
352 import: {
353 videos: {
354 http: {
355 enabled: false
356 },
357 torrent: {
358 enabled: false
359 }
360 }
361 },
362 autoBlacklist: {
363 videos: {
364 ofUsers: {
365 enabled: true
366 }
367 }
368 },
369 followers: {
370 instance: {
371 enabled: false,
372 manualApproval: true
373 }
374 },
375 followings: {
376 instance: {
377 autoFollowBack: {
378 enabled: true
379 },
380 autoFollowIndex: {
381 enabled: true,
382 indexUrl: 'https://updated.example.com'
383 }
384 }
385 },
386 broadcastMessage: {
387 enabled: true,
388 level: 'error',
389 message: 'super bad message',
390 dismissable: true
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 }
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
410 checkUpdatedConfig(data)
411 })
412
413 it('Should have the correct updated video allowed extensions', async function () {
414 this.timeout(10000)
415
416 const res = await getConfig(server.url)
417 const data: ServerConfig = res.body
418
419 expect(data.video.file.extensions).to.have.length.above(4)
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')
424 expect(data.video.file.extensions).to.contain('.wmv')
425 expect(data.video.file.extensions).to.contain('.mkv')
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)
432 })
433
434 it('Should have the configuration updated after a restart', async function () {
435 this.timeout(10000)
436
437 killallServers([ server ])
438
439 await reRunServer(server)
440
441 const res = await getCustomConfig(server.url, server.accessToken)
442 const data = res.body
443
444 checkUpdatedConfig(data)
445 })
446
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')
452 expect(data.instance.shortDescription).to.equal('my short description')
453 expect(data.instance.description).to.equal('my super description')
454 expect(data.instance.terms).to.equal('my super terms')
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 ])
466 })
467
468 it('Should remove the custom configuration', async function () {
469 this.timeout(10000)
470
471 await deleteCustomConfig(server.url, server.accessToken)
472
473 const res = await getCustomConfig(server.url, server.accessToken)
474 const data = res.body
475
476 checkInitialConfig(server, data)
477 })
478
479 after(async function () {
480 await cleanupTests([ server ])
481 })
482 })