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