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