]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/tests/api/server/config.ts
Handle oembed with params in URL
[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'
0e1dc3e7 5import {
7c3b7976 6 cleanupTests,
254d3579 7 createSingleServer,
a1587156 8 killallServers,
8155db66 9 makeGetRequest,
a1587156 10 parallelTests,
254d3579 11 PeerTubeServer,
d23dd9fb 12 setAccessTokensToServers
65e6e260 13} from '@shared/extra-utils'
4c7e60bc 14import { CustomConfig, HttpStatusCode } from '@shared/models'
0e1dc3e7 15
5bcfd029
C
16const expect = chai.expect
17
254d3579 18function checkInitialConfig (server: PeerTubeServer, data: CustomConfig) {
40e87e9e
C
19 expect(data.instance.name).to.equal('PeerTube')
20 expect(data.instance.shortDescription).to.equal(
482fa503 21 'PeerTube, an ActivityPub-federated video streaming platform using P2P directly in your web browser.'
40e87e9e
C
22 )
23 expect(data.instance.description).to.equal('Welcome to this PeerTube instance!')
ccc00cb2 24
40e87e9e 25 expect(data.instance.terms).to.equal('No terms for now.')
8ae03c37 26 expect(data.instance.creationReason).to.be.empty
ccc00cb2
C
27 expect(data.instance.codeOfConduct).to.be.empty
28 expect(data.instance.moderationInformation).to.be.empty
29 expect(data.instance.administrator).to.be.empty
30 expect(data.instance.maintenanceLifetime).to.be.empty
31 expect(data.instance.businessModel).to.be.empty
be04c6fd 32 expect(data.instance.hardwareInformation).to.be.empty
ccc00cb2
C
33
34 expect(data.instance.languages).to.have.lengthOf(0)
35 expect(data.instance.categories).to.have.lengthOf(0)
36
40e87e9e 37 expect(data.instance.defaultClientRoute).to.equal('/videos/trending')
f8802489 38 expect(data.instance.isNSFW).to.be.false
40e87e9e
C
39 expect(data.instance.defaultNSFWPolicy).to.equal('display')
40 expect(data.instance.customizations.css).to.be.empty
41 expect(data.instance.customizations.javascript).to.be.empty
a4101923 42
40e87e9e
C
43 expect(data.services.twitter.username).to.equal('@Chocobozzz')
44 expect(data.services.twitter.whitelisted).to.be.false
a4101923 45
40e87e9e
C
46 expect(data.cache.previews.size).to.equal(1)
47 expect(data.cache.captions.size).to.equal(1)
b3d5cb92 48 expect(data.cache.torrents.size).to.equal(1)
a4101923 49
40e87e9e
C
50 expect(data.signup.enabled).to.be.true
51 expect(data.signup.limit).to.equal(4)
1f256e7d 52 expect(data.signup.minimumAge).to.equal(16)
d9eaee39 53 expect(data.signup.requiresEmailVerification).to.be.false
a4101923 54
48f07b4a 55 expect(data.admin.email).to.equal('admin' + server.internalServerNumber + '@example.com')
a4101923
C
56 expect(data.contactForm.enabled).to.be.true
57
40e87e9e 58 expect(data.user.videoQuota).to.equal(5242880)
9ee92651 59 expect(data.user.videoQuotaDaily).to.equal(-1)
c6c0fa6c 60
40e87e9e 61 expect(data.transcoding.enabled).to.be.false
14e2014a 62 expect(data.transcoding.allowAdditionalExtensions).to.be.false
536598cf 63 expect(data.transcoding.allowAudioFiles).to.be.false
40e87e9e 64 expect(data.transcoding.threads).to.equal(2)
9129b769 65 expect(data.transcoding.concurrency).to.equal(2)
1896bca0 66 expect(data.transcoding.profile).to.equal('default')
40e87e9e
C
67 expect(data.transcoding.resolutions['240p']).to.be.true
68 expect(data.transcoding.resolutions['360p']).to.be.true
69 expect(data.transcoding.resolutions['480p']).to.be.true
70 expect(data.transcoding.resolutions['720p']).to.be.true
71 expect(data.transcoding.resolutions['1080p']).to.be.true
b7085c71 72 expect(data.transcoding.resolutions['1440p']).to.be.true
db714ab4 73 expect(data.transcoding.resolutions['2160p']).to.be.true
d7a25329 74 expect(data.transcoding.webtorrent.enabled).to.be.true
09209296
C
75 expect(data.transcoding.hls.enabled).to.be.true
76
c6c0fa6c 77 expect(data.live.enabled).to.be.false
c655c9ef 78 expect(data.live.allowReplay).to.be.false
c9bc850e 79 expect(data.live.maxDuration).to.equal(-1)
a056ca48
C
80 expect(data.live.maxInstanceLives).to.equal(20)
81 expect(data.live.maxUserLives).to.equal(3)
c6c0fa6c
C
82 expect(data.live.transcoding.enabled).to.be.false
83 expect(data.live.transcoding.threads).to.equal(2)
1896bca0 84 expect(data.live.transcoding.profile).to.equal('default')
c6c0fa6c
C
85 expect(data.live.transcoding.resolutions['240p']).to.be.false
86 expect(data.live.transcoding.resolutions['360p']).to.be.false
87 expect(data.live.transcoding.resolutions['480p']).to.be.false
88 expect(data.live.transcoding.resolutions['720p']).to.be.false
89 expect(data.live.transcoding.resolutions['1080p']).to.be.false
b7085c71 90 expect(data.live.transcoding.resolutions['1440p']).to.be.false
c6c0fa6c
C
91 expect(data.live.transcoding.resolutions['2160p']).to.be.false
92
9129b769 93 expect(data.import.videos.concurrency).to.equal(2)
5d08a6a7 94 expect(data.import.videos.http.enabled).to.be.true
a84b8fa5 95 expect(data.import.videos.torrent.enabled).to.be.true
7ccddd7b 96 expect(data.autoBlacklist.videos.ofUsers.enabled).to.be.false
5b9c965d
C
97
98 expect(data.followers.instance.enabled).to.be.true
14893eb7 99 expect(data.followers.instance.manualApproval).to.be.false
8424c402
C
100
101 expect(data.followings.instance.autoFollowBack.enabled).to.be.false
102 expect(data.followings.instance.autoFollowIndex.enabled).to.be.false
c9215a1b 103 expect(data.followings.instance.autoFollowIndex.indexUrl).to.equal('')
72c33e71
C
104
105 expect(data.broadcastMessage.enabled).to.be.false
106 expect(data.broadcastMessage.level).to.equal('info')
107 expect(data.broadcastMessage.message).to.equal('')
108 expect(data.broadcastMessage.dismissable).to.be.false
40e87e9e
C
109}
110
111function checkUpdatedConfig (data: CustomConfig) {
112 expect(data.instance.name).to.equal('PeerTube updated')
113 expect(data.instance.shortDescription).to.equal('my short description')
114 expect(data.instance.description).to.equal('my super description')
ccc00cb2 115
40e87e9e 116 expect(data.instance.terms).to.equal('my super terms')
8ae03c37 117 expect(data.instance.creationReason).to.equal('my super creation reason')
ccc00cb2
C
118 expect(data.instance.codeOfConduct).to.equal('my super coc')
119 expect(data.instance.moderationInformation).to.equal('my super moderation information')
120 expect(data.instance.administrator).to.equal('Kuja')
121 expect(data.instance.maintenanceLifetime).to.equal('forever')
122 expect(data.instance.businessModel).to.equal('my super business model')
be04c6fd 123 expect(data.instance.hardwareInformation).to.equal('2vCore 3GB RAM')
ccc00cb2
C
124
125 expect(data.instance.languages).to.deep.equal([ 'en', 'es' ])
126 expect(data.instance.categories).to.deep.equal([ 1, 2 ])
127
40e87e9e 128 expect(data.instance.defaultClientRoute).to.equal('/videos/recently-added')
f8802489 129 expect(data.instance.isNSFW).to.be.true
40e87e9e
C
130 expect(data.instance.defaultNSFWPolicy).to.equal('blur')
131 expect(data.instance.customizations.javascript).to.equal('alert("coucou")')
132 expect(data.instance.customizations.css).to.equal('body { background-color: red; }')
a4101923 133
40e87e9e
C
134 expect(data.services.twitter.username).to.equal('@Kuja')
135 expect(data.services.twitter.whitelisted).to.be.true
a4101923 136
40e87e9e
C
137 expect(data.cache.previews.size).to.equal(2)
138 expect(data.cache.captions.size).to.equal(3)
b3d5cb92 139 expect(data.cache.torrents.size).to.equal(4)
a4101923 140
40e87e9e
C
141 expect(data.signup.enabled).to.be.false
142 expect(data.signup.limit).to.equal(5)
576ad67a 143 expect(data.signup.requiresEmailVerification).to.be.false
1f256e7d 144 expect(data.signup.minimumAge).to.equal(10)
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)
9129b769 158 expect(data.transcoding.concurrency).to.equal(3)
14e2014a 159 expect(data.transcoding.allowAdditionalExtensions).to.be.true
536598cf 160 expect(data.transcoding.allowAudioFiles).to.be.true
1896bca0 161 expect(data.transcoding.profile).to.equal('vod_profile')
40e87e9e
C
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
db714ab4 167 expect(data.transcoding.resolutions['2160p']).to.be.false
09209296 168 expect(data.transcoding.hls.enabled).to.be.false
d7a25329 169 expect(data.transcoding.webtorrent.enabled).to.be.true
a4101923 170
c6c0fa6c 171 expect(data.live.enabled).to.be.true
c655c9ef 172 expect(data.live.allowReplay).to.be.true
fb719404 173 expect(data.live.maxDuration).to.equal(5000)
a056ca48
C
174 expect(data.live.maxInstanceLives).to.equal(-1)
175 expect(data.live.maxUserLives).to.equal(10)
c6c0fa6c
C
176 expect(data.live.transcoding.enabled).to.be.true
177 expect(data.live.transcoding.threads).to.equal(4)
1896bca0 178 expect(data.live.transcoding.profile).to.equal('live_profile')
c6c0fa6c
C
179 expect(data.live.transcoding.resolutions['240p']).to.be.true
180 expect(data.live.transcoding.resolutions['360p']).to.be.true
181 expect(data.live.transcoding.resolutions['480p']).to.be.true
182 expect(data.live.transcoding.resolutions['720p']).to.be.true
183 expect(data.live.transcoding.resolutions['1080p']).to.be.true
184 expect(data.live.transcoding.resolutions['2160p']).to.be.true
185
9129b769 186 expect(data.import.videos.concurrency).to.equal(4)
5d08a6a7 187 expect(data.import.videos.http.enabled).to.be.false
a84b8fa5 188 expect(data.import.videos.torrent.enabled).to.be.false
7ccddd7b 189 expect(data.autoBlacklist.videos.ofUsers.enabled).to.be.true
5b9c965d
C
190
191 expect(data.followers.instance.enabled).to.be.false
14893eb7 192 expect(data.followers.instance.manualApproval).to.be.true
8424c402
C
193
194 expect(data.followings.instance.autoFollowBack.enabled).to.be.true
195 expect(data.followings.instance.autoFollowIndex.enabled).to.be.true
196 expect(data.followings.instance.autoFollowIndex.indexUrl).to.equal('https://updated.example.com')
72c33e71
C
197
198 expect(data.broadcastMessage.enabled).to.be.true
199 expect(data.broadcastMessage.level).to.equal('error')
200 expect(data.broadcastMessage.message).to.equal('super bad message')
201 expect(data.broadcastMessage.dismissable).to.be.true
40e87e9e
C
202}
203
0e1dc3e7 204describe('Test config', function () {
254d3579 205 let server: PeerTubeServer = null
0e1dc3e7
C
206
207 before(async function () {
e212f887 208 this.timeout(30000)
48f07b4a 209
254d3579 210 server = await createSingleServer(1)
fd206f0b 211 await setAccessTokensToServers([ server ])
0e1dc3e7
C
212 })
213
214 it('Should have a correct config on a server with registration enabled', async function () {
89d241a7 215 const data = await server.config.getConfig()
0e1dc3e7
C
216
217 expect(data.signup.allowed).to.be.true
218 })
219
220 it('Should have a correct config on a server with registration enabled and a users limit', async function () {
652b3056
C
221 this.timeout(5000)
222
47e0652b 223 await Promise.all([
89d241a7
C
224 server.users.register({ username: 'user1' }),
225 server.users.register({ username: 'user2' }),
226 server.users.register({ username: 'user3' })
47e0652b 227 ])
0e1dc3e7 228
89d241a7 229 const data = await server.config.getConfig()
0e1dc3e7
C
230
231 expect(data.signup.allowed).to.be.false
232 })
233
14e2014a 234 it('Should have the correct video allowed extensions', async function () {
89d241a7 235 const data = await server.config.getConfig()
14e2014a
C
236
237 expect(data.video.file.extensions).to.have.lengthOf(3)
238 expect(data.video.file.extensions).to.contain('.mp4')
239 expect(data.video.file.extensions).to.contain('.webm')
240 expect(data.video.file.extensions).to.contain('.ogv')
a4101923 241
89d241a7
C
242 await server.videos.upload({ attributes: { fixture: 'video_short.mkv' }, expectedStatus: HttpStatusCode.UNSUPPORTED_MEDIA_TYPE_415 })
243 await server.videos.upload({ attributes: { fixture: 'sample.ogg' }, expectedStatus: HttpStatusCode.UNSUPPORTED_MEDIA_TYPE_415 })
b345a804 244
a4101923 245 expect(data.contactForm.enabled).to.be.true
14e2014a
C
246 })
247
fd206f0b 248 it('Should get the customized configuration', async function () {
89d241a7 249 const data = await server.config.getCustomConfig()
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
f8802489 273 isNSFW: true,
0883b324 274 defaultNSFWPolicy: 'blur' as 'blur',
3da68f0a
RK
275
276 defaultClientRoute: '/videos/recently-added',
3da68f0a 277
00b5556c
C
278 customizations: {
279 javascript: 'alert("coucou")',
280 css: 'body { background-color: red; }'
281 }
66b16caf 282 },
7cd4d2ba
C
283 theme: {
284 default: 'default'
285 },
8be1afa1
C
286 services: {
287 twitter: {
288 username: '@Kuja',
289 whitelisted: true
290 }
291 },
fd206f0b
C
292 cache: {
293 previews: {
294 size: 2
40e87e9e
C
295 },
296 captions: {
297 size: 3
b3d5cb92
C
298 },
299 torrents: {
300 size: 4
fd206f0b
C
301 }
302 },
303 signup: {
304 enabled: false,
d9eaee39 305 limit: 5,
1f256e7d
P
306 requiresEmailVerification: false,
307 minimumAge: 10
fd206f0b
C
308 },
309 admin: {
310 email: 'superadmin1@example.com'
311 },
a4101923
C
312 contactForm: {
313 enabled: false
314 },
fd206f0b 315 user: {
bee0abff
FA
316 videoQuota: 5242881,
317 videoQuotaDaily: 318742
fd206f0b
C
318 },
319 transcoding: {
320 enabled: true,
14e2014a 321 allowAdditionalExtensions: true,
536598cf 322 allowAudioFiles: true,
fd206f0b 323 threads: 1,
9129b769 324 concurrency: 3,
1896bca0 325 profile: 'vod_profile',
fd206f0b 326 resolutions: {
5c7d6508 327 '0p': false,
fd206f0b
C
328 '240p': false,
329 '360p': true,
330 '480p': true,
331 '720p': false,
db714ab4 332 '1080p': false,
b7085c71 333 '1440p': false,
db714ab4 334 '2160p': false
09209296 335 },
d7a25329
C
336 webtorrent: {
337 enabled: true
338 },
09209296
C
339 hls: {
340 enabled: false
fd206f0b 341 }
5d08a6a7 342 },
c6c0fa6c
C
343 live: {
344 enabled: true,
c655c9ef 345 allowReplay: true,
fb719404 346 maxDuration: 5000,
a056ca48
C
347 maxInstanceLives: -1,
348 maxUserLives: 10,
c6c0fa6c
C
349 transcoding: {
350 enabled: true,
351 threads: 4,
1896bca0 352 profile: 'live_profile',
c6c0fa6c
C
353 resolutions: {
354 '240p': true,
355 '360p': true,
356 '480p': true,
357 '720p': true,
358 '1080p': true,
b7085c71 359 '1440p': true,
c6c0fa6c
C
360 '2160p': true
361 }
362 }
363 },
5d08a6a7
C
364 import: {
365 videos: {
9129b769 366 concurrency: 4,
5d08a6a7
C
367 http: {
368 enabled: false
a84b8fa5
C
369 },
370 torrent: {
371 enabled: false
5d08a6a7
C
372 }
373 }
7ccddd7b 374 },
ba5d4a84
RK
375 trending: {
376 videos: {
377 algorithms: {
3d4e112d 378 enabled: [ 'best', 'hot', 'most-viewed', 'most-liked' ],
ba5d4a84
RK
379 default: 'hot'
380 }
381 }
382 },
7ccddd7b
JM
383 autoBlacklist: {
384 videos: {
385 ofUsers: {
386 enabled: true
387 }
388 }
5b9c965d
C
389 },
390 followers: {
391 instance: {
14893eb7
C
392 enabled: false,
393 manualApproval: true
5b9c965d 394 }
8424c402
C
395 },
396 followings: {
397 instance: {
398 autoFollowBack: {
399 enabled: true
400 },
401 autoFollowIndex: {
402 enabled: true,
403 indexUrl: 'https://updated.example.com'
404 }
405 }
72c33e71
C
406 },
407 broadcastMessage: {
408 enabled: true,
409 level: 'error',
410 message: 'super bad message',
411 dismissable: true
5fb2e288
C
412 },
413 search: {
414 remoteUri: {
415 anonymous: true,
416 users: true
417 },
418 searchIndex: {
419 enabled: true,
420 url: 'https://search.joinpeertube.org',
421 disableLocalSearch: true,
422 isDefaultSearch: true
423 }
fd206f0b
C
424 }
425 }
89d241a7 426 await server.config.updateCustomConfig({ newCustomConfig })
fd206f0b 427
89d241a7 428 const data = await server.config.getCustomConfig()
40e87e9e 429 checkUpdatedConfig(data)
fd206f0b
C
430 })
431
14e2014a 432 it('Should have the correct updated video allowed extensions', async function () {
30bc55c8
C
433 this.timeout(10000)
434
89d241a7 435 const data = await server.config.getConfig()
14e2014a 436
30bc55c8 437 expect(data.video.file.extensions).to.have.length.above(4)
14e2014a
C
438 expect(data.video.file.extensions).to.contain('.mp4')
439 expect(data.video.file.extensions).to.contain('.webm')
440 expect(data.video.file.extensions).to.contain('.ogv')
441 expect(data.video.file.extensions).to.contain('.flv')
fccbbc1a 442 expect(data.video.file.extensions).to.contain('.wmv')
14e2014a 443 expect(data.video.file.extensions).to.contain('.mkv')
b345a804
C
444 expect(data.video.file.extensions).to.contain('.mp3')
445 expect(data.video.file.extensions).to.contain('.ogg')
446 expect(data.video.file.extensions).to.contain('.flac')
447
89d241a7
C
448 await server.videos.upload({ attributes: { fixture: 'video_short.mkv' }, expectedStatus: HttpStatusCode.OK_200 })
449 await server.videos.upload({ attributes: { fixture: 'sample.ogg' }, expectedStatus: HttpStatusCode.OK_200 })
14e2014a
C
450 })
451
fd206f0b 452 it('Should have the configuration updated after a restart', async function () {
61e9908c 453 this.timeout(30000)
23e27dd5 454
9293139f 455 await killallServers([ server ])
fd206f0b 456
254d3579 457 await server.run()
fd206f0b 458
89d241a7 459 const data = await server.config.getCustomConfig()
fd206f0b 460
40e87e9e 461 checkUpdatedConfig(data)
fd206f0b
C
462 })
463
36f9424f 464 it('Should fetch the about information', async function () {
89d241a7 465 const data = await server.config.getAbout()
36f9424f
C
466
467 expect(data.instance.name).to.equal('PeerTube updated')
2e3a0215 468 expect(data.instance.shortDescription).to.equal('my short description')
36f9424f
C
469 expect(data.instance.description).to.equal('my super description')
470 expect(data.instance.terms).to.equal('my super terms')
be04c6fd
C
471 expect(data.instance.codeOfConduct).to.equal('my super coc')
472
473 expect(data.instance.creationReason).to.equal('my super creation reason')
474 expect(data.instance.moderationInformation).to.equal('my super moderation information')
475 expect(data.instance.administrator).to.equal('Kuja')
476 expect(data.instance.maintenanceLifetime).to.equal('forever')
477 expect(data.instance.businessModel).to.equal('my super business model')
478 expect(data.instance.hardwareInformation).to.equal('2vCore 3GB RAM')
479
480 expect(data.instance.languages).to.deep.equal([ 'en', 'es' ])
481 expect(data.instance.categories).to.deep.equal([ 1, 2 ])
36f9424f
C
482 })
483
fd206f0b 484 it('Should remove the custom configuration', async function () {
23e27dd5
C
485 this.timeout(10000)
486
89d241a7 487 await server.config.deleteCustomConfig()
fd206f0b 488
89d241a7 489 const data = await server.config.getCustomConfig()
48f07b4a 490 checkInitialConfig(server, data)
fd206f0b
C
491 })
492
8155db66
C
493 it('Should enable frameguard', async function () {
494 this.timeout(25000)
495
496 {
497 const res = await makeGetRequest({
498 url: server.url,
499 path: '/api/v1/config',
c0e8b12e 500 expectedStatus: 200
8155db66
C
501 })
502
503 expect(res.headers['x-frame-options']).to.exist
504 }
505
9293139f 506 await killallServers([ server ])
8155db66
C
507
508 const config = {
509 security: {
510 frameguard: { enabled: false }
511 }
512 }
254d3579 513 await server.run(config)
8155db66
C
514
515 {
516 const res = await makeGetRequest({
517 url: server.url,
518 path: '/api/v1/config',
c0e8b12e 519 expectedStatus: 200
8155db66
C
520 })
521
522 expect(res.headers['x-frame-options']).to.not.exist
523 }
524 })
525
7c3b7976
C
526 after(async function () {
527 await cleanupTests([ server ])
0e1dc3e7
C
528 })
529})