]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/tests/api/server/config.ts
Fix live tests
[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'
f2eb23cd 24import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
0e1dc3e7 25
5bcfd029
C
26const expect = chai.expect
27
48f07b4a 28function checkInitialConfig (server: ServerInfo, data: CustomConfig) {
40e87e9e
C
29 expect(data.instance.name).to.equal('PeerTube')
30 expect(data.instance.shortDescription).to.equal(
482fa503 31 'PeerTube, an ActivityPub-federated video streaming platform using P2P directly in your web browser.'
40e87e9e
C
32 )
33 expect(data.instance.description).to.equal('Welcome to this PeerTube instance!')
ccc00cb2 34
40e87e9e 35 expect(data.instance.terms).to.equal('No terms for now.')
8ae03c37 36 expect(data.instance.creationReason).to.be.empty
ccc00cb2
C
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
be04c6fd 42 expect(data.instance.hardwareInformation).to.be.empty
ccc00cb2
C
43
44 expect(data.instance.languages).to.have.lengthOf(0)
45 expect(data.instance.categories).to.have.lengthOf(0)
46
40e87e9e 47 expect(data.instance.defaultClientRoute).to.equal('/videos/trending')
f8802489 48 expect(data.instance.isNSFW).to.be.false
40e87e9e
C
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
a4101923 52
40e87e9e
C
53 expect(data.services.twitter.username).to.equal('@Chocobozzz')
54 expect(data.services.twitter.whitelisted).to.be.false
a4101923 55
40e87e9e
C
56 expect(data.cache.previews.size).to.equal(1)
57 expect(data.cache.captions.size).to.equal(1)
a4101923 58
40e87e9e
C
59 expect(data.signup.enabled).to.be.true
60 expect(data.signup.limit).to.equal(4)
d9eaee39 61 expect(data.signup.requiresEmailVerification).to.be.false
a4101923 62
48f07b4a 63 expect(data.admin.email).to.equal('admin' + server.internalServerNumber + '@example.com')
a4101923
C
64 expect(data.contactForm.enabled).to.be.true
65
40e87e9e 66 expect(data.user.videoQuota).to.equal(5242880)
9ee92651 67 expect(data.user.videoQuotaDaily).to.equal(-1)
c6c0fa6c 68
40e87e9e 69 expect(data.transcoding.enabled).to.be.false
14e2014a 70 expect(data.transcoding.allowAdditionalExtensions).to.be.false
536598cf 71 expect(data.transcoding.allowAudioFiles).to.be.false
40e87e9e
C
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
db714ab4 78 expect(data.transcoding.resolutions['2160p']).to.be.true
d7a25329 79 expect(data.transcoding.webtorrent.enabled).to.be.true
09209296
C
80 expect(data.transcoding.hls.enabled).to.be.true
81
c6c0fa6c 82 expect(data.live.enabled).to.be.false
c655c9ef 83 expect(data.live.allowReplay).to.be.false
8e2392e5 84 expect(data.live.maxDuration).to.be.null
a056ca48
C
85 expect(data.live.maxInstanceLives).to.equal(20)
86 expect(data.live.maxUserLives).to.equal(3)
c6c0fa6c
C
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
5d08a6a7 96 expect(data.import.videos.http.enabled).to.be.true
a84b8fa5 97 expect(data.import.videos.torrent.enabled).to.be.true
7ccddd7b 98 expect(data.autoBlacklist.videos.ofUsers.enabled).to.be.false
5b9c965d
C
99
100 expect(data.followers.instance.enabled).to.be.true
14893eb7 101 expect(data.followers.instance.manualApproval).to.be.false
8424c402
C
102
103 expect(data.followings.instance.autoFollowBack.enabled).to.be.false
104 expect(data.followings.instance.autoFollowIndex.enabled).to.be.false
c9215a1b 105 expect(data.followings.instance.autoFollowIndex.indexUrl).to.equal('')
72c33e71
C
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
40e87e9e
C
111}
112
113function 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')
ccc00cb2 117
40e87e9e 118 expect(data.instance.terms).to.equal('my super terms')
8ae03c37 119 expect(data.instance.creationReason).to.equal('my super creation reason')
ccc00cb2
C
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')
be04c6fd 125 expect(data.instance.hardwareInformation).to.equal('2vCore 3GB RAM')
ccc00cb2
C
126
127 expect(data.instance.languages).to.deep.equal([ 'en', 'es' ])
128 expect(data.instance.categories).to.deep.equal([ 1, 2 ])
129
40e87e9e 130 expect(data.instance.defaultClientRoute).to.equal('/videos/recently-added')
f8802489 131 expect(data.instance.isNSFW).to.be.true
40e87e9e
C
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; }')
a4101923 135
40e87e9e
C
136 expect(data.services.twitter.username).to.equal('@Kuja')
137 expect(data.services.twitter.whitelisted).to.be.true
a4101923 138
40e87e9e
C
139 expect(data.cache.previews.size).to.equal(2)
140 expect(data.cache.captions.size).to.equal(3)
a4101923 141
40e87e9e
C
142 expect(data.signup.enabled).to.be.false
143 expect(data.signup.limit).to.equal(5)
576ad67a 144 expect(data.signup.requiresEmailVerification).to.be.false
a4101923 145
48f07b4a
C
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
a4101923
C
151 expect(data.contactForm.enabled).to.be.false
152
40e87e9e 153 expect(data.user.videoQuota).to.equal(5242881)
bee0abff 154 expect(data.user.videoQuotaDaily).to.equal(318742)
a4101923 155
40e87e9e
C
156 expect(data.transcoding.enabled).to.be.true
157 expect(data.transcoding.threads).to.equal(1)
14e2014a 158 expect(data.transcoding.allowAdditionalExtensions).to.be.true
536598cf 159 expect(data.transcoding.allowAudioFiles).to.be.true
40e87e9e
C
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
db714ab4 165 expect(data.transcoding.resolutions['2160p']).to.be.false
09209296 166 expect(data.transcoding.hls.enabled).to.be.false
d7a25329 167 expect(data.transcoding.webtorrent.enabled).to.be.true
a4101923 168
c6c0fa6c 169 expect(data.live.enabled).to.be.true
c655c9ef 170 expect(data.live.allowReplay).to.be.true
fb719404 171 expect(data.live.maxDuration).to.equal(5000)
a056ca48
C
172 expect(data.live.maxInstanceLives).to.equal(-1)
173 expect(data.live.maxUserLives).to.equal(10)
c6c0fa6c
C
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
5d08a6a7 183 expect(data.import.videos.http.enabled).to.be.false
a84b8fa5 184 expect(data.import.videos.torrent.enabled).to.be.false
7ccddd7b 185 expect(data.autoBlacklist.videos.ofUsers.enabled).to.be.true
5b9c965d
C
186
187 expect(data.followers.instance.enabled).to.be.false
14893eb7 188 expect(data.followers.instance.manualApproval).to.be.true
8424c402
C
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')
72c33e71
C
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
40e87e9e
C
198}
199
0e1dc3e7
C
200describe('Test config', function () {
201 let server = null
202
203 before(async function () {
e212f887 204 this.timeout(30000)
48f07b4a 205
210feb6c 206 server = await flushAndRunServer(1)
fd206f0b 207 await setAccessTokensToServers([ server ])
0e1dc3e7
C
208 })
209
210 it('Should have a correct config on a server with registration enabled', async function () {
211 const res = await getConfig(server.url)
14e2014a 212 const data: ServerConfig = res.body
0e1dc3e7
C
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 () {
652b3056
C
218 this.timeout(5000)
219
47e0652b
C
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 ])
0e1dc3e7
C
225
226 const res = await getConfig(server.url)
14e2014a 227 const data: ServerConfig = res.body
0e1dc3e7
C
228
229 expect(data.signup.allowed).to.be.false
230 })
231
14e2014a
C
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')
a4101923 240
f2eb23cd
RK
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)
b345a804 243
a4101923 244 expect(data.contactForm.enabled).to.be.true
14e2014a
C
245 })
246
fd206f0b
C
247 it('Should get the customized configuration', async function () {
248 const res = await getCustomConfig(server.url, server.accessToken)
00b5556c 249 const data = res.body as CustomConfig
fd206f0b 250
48f07b4a 251 checkInitialConfig(server, data)
fd206f0b
C
252 })
253
254 it('Should update the customized configuration', async function () {
40e87e9e 255 const newCustomConfig: CustomConfig = {
66b16caf
C
256 instance: {
257 name: 'PeerTube updated',
2e3a0215 258 shortDescription: 'my short description',
66b16caf 259 description: 'my super description',
00b5556c 260 terms: 'my super terms',
ccc00cb2
C
261 codeOfConduct: 'my super coc',
262
8ae03c37 263 creationReason: 'my super creation reason',
ccc00cb2
C
264 moderationInformation: 'my super moderation information',
265 administrator: 'Kuja',
266 maintenanceLifetime: 'forever',
267 businessModel: 'my super business model',
be04c6fd 268 hardwareInformation: '2vCore 3GB RAM',
ccc00cb2
C
269
270 languages: [ 'en', 'es' ],
271 categories: [ 1, 2 ],
272
901637bb 273 defaultClientRoute: '/videos/recently-added',
f8802489 274 isNSFW: true,
0883b324 275 defaultNSFWPolicy: 'blur' as 'blur',
00b5556c
C
276 customizations: {
277 javascript: 'alert("coucou")',
278 css: 'body { background-color: red; }'
279 }
66b16caf 280 },
7cd4d2ba
C
281 theme: {
282 default: 'default'
283 },
8be1afa1
C
284 services: {
285 twitter: {
286 username: '@Kuja',
287 whitelisted: true
288 }
289 },
fd206f0b
C
290 cache: {
291 previews: {
292 size: 2
40e87e9e
C
293 },
294 captions: {
295 size: 3
fd206f0b
C
296 }
297 },
298 signup: {
299 enabled: false,
d9eaee39 300 limit: 5,
576ad67a 301 requiresEmailVerification: false
fd206f0b
C
302 },
303 admin: {
304 email: 'superadmin1@example.com'
305 },
a4101923
C
306 contactForm: {
307 enabled: false
308 },
fd206f0b 309 user: {
bee0abff
FA
310 videoQuota: 5242881,
311 videoQuotaDaily: 318742
fd206f0b
C
312 },
313 transcoding: {
314 enabled: true,
14e2014a 315 allowAdditionalExtensions: true,
536598cf 316 allowAudioFiles: true,
fd206f0b
C
317 threads: 1,
318 resolutions: {
5c7d6508 319 '0p': false,
fd206f0b
C
320 '240p': false,
321 '360p': true,
322 '480p': true,
323 '720p': false,
db714ab4
C
324 '1080p': false,
325 '2160p': false
09209296 326 },
d7a25329
C
327 webtorrent: {
328 enabled: true
329 },
09209296
C
330 hls: {
331 enabled: false
fd206f0b 332 }
5d08a6a7 333 },
c6c0fa6c
C
334 live: {
335 enabled: true,
c655c9ef 336 allowReplay: true,
fb719404 337 maxDuration: 5000,
a056ca48
C
338 maxInstanceLives: -1,
339 maxUserLives: 10,
c6c0fa6c
C
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 },
5d08a6a7
C
353 import: {
354 videos: {
355 http: {
356 enabled: false
a84b8fa5
C
357 },
358 torrent: {
359 enabled: false
5d08a6a7
C
360 }
361 }
7ccddd7b
JM
362 },
363 autoBlacklist: {
364 videos: {
365 ofUsers: {
366 enabled: true
367 }
368 }
5b9c965d
C
369 },
370 followers: {
371 instance: {
14893eb7
C
372 enabled: false,
373 manualApproval: true
5b9c965d 374 }
8424c402
C
375 },
376 followings: {
377 instance: {
378 autoFollowBack: {
379 enabled: true
380 },
381 autoFollowIndex: {
382 enabled: true,
383 indexUrl: 'https://updated.example.com'
384 }
385 }
72c33e71
C
386 },
387 broadcastMessage: {
388 enabled: true,
389 level: 'error',
390 message: 'super bad message',
391 dismissable: true
5fb2e288
C
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 }
fd206f0b
C
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
40e87e9e 411 checkUpdatedConfig(data)
fd206f0b
C
412 })
413
14e2014a 414 it('Should have the correct updated video allowed extensions', async function () {
30bc55c8
C
415 this.timeout(10000)
416
14e2014a
C
417 const res = await getConfig(server.url)
418 const data: ServerConfig = res.body
419
30bc55c8 420 expect(data.video.file.extensions).to.have.length.above(4)
14e2014a
C
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')
fccbbc1a 425 expect(data.video.file.extensions).to.contain('.wmv')
14e2014a 426 expect(data.video.file.extensions).to.contain('.mkv')
b345a804
C
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
f2eb23cd
RK
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)
14e2014a
C
433 })
434
fd206f0b 435 it('Should have the configuration updated after a restart', async function () {
23e27dd5
C
436 this.timeout(10000)
437
fd206f0b
C
438 killallServers([ server ])
439
440 await reRunServer(server)
441
442 const res = await getCustomConfig(server.url, server.accessToken)
443 const data = res.body
444
40e87e9e 445 checkUpdatedConfig(data)
fd206f0b
C
446 })
447
36f9424f
C
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')
2e3a0215 453 expect(data.instance.shortDescription).to.equal('my short description')
36f9424f
C
454 expect(data.instance.description).to.equal('my super description')
455 expect(data.instance.terms).to.equal('my super terms')
be04c6fd
C
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 ])
36f9424f
C
467 })
468
fd206f0b 469 it('Should remove the custom configuration', async function () {
23e27dd5
C
470 this.timeout(10000)
471
fd206f0b
C
472 await deleteCustomConfig(server.url, server.accessToken)
473
474 const res = await getCustomConfig(server.url, server.accessToken)
475 const data = res.body
476
48f07b4a 477 checkInitialConfig(server, data)
fd206f0b
C
478 })
479
7c3b7976
C
480 after(async function () {
481 await cleanupTests([ server ])
0e1dc3e7
C
482 })
483})