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