1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
4 import * as chai from 'chai'
12 setAccessTokensToServers
13 } from '@shared/extra-utils'
14 import { CustomConfig, HttpStatusCode } from '@shared/models'
16 const expect = chai.expect
18 function checkInitialConfig (server: PeerTubeServer, data: CustomConfig) {
19 expect(data.instance.name).to.equal('PeerTube')
20 expect(data.instance.shortDescription).to.equal(
21 'PeerTube, an ActivityPub-federated video streaming platform using P2P directly in your web browser.'
23 expect(data.instance.description).to.equal('Welcome to this PeerTube instance!')
25 expect(data.instance.terms).to.equal('No terms for now.')
26 expect(data.instance.creationReason).to.be.empty
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
32 expect(data.instance.hardwareInformation).to.be.empty
34 expect(data.instance.languages).to.have.lengthOf(0)
35 expect(data.instance.categories).to.have.lengthOf(0)
37 expect(data.instance.defaultClientRoute).to.equal('/videos/trending')
38 expect(data.instance.isNSFW).to.be.false
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
43 expect(data.services.twitter.username).to.equal('@Chocobozzz')
44 expect(data.services.twitter.whitelisted).to.be.false
46 expect(data.cache.previews.size).to.equal(1)
47 expect(data.cache.captions.size).to.equal(1)
48 expect(data.cache.torrents.size).to.equal(1)
50 expect(data.signup.enabled).to.be.true
51 expect(data.signup.limit).to.equal(4)
52 expect(data.signup.minimumAge).to.equal(16)
53 expect(data.signup.requiresEmailVerification).to.be.false
55 expect(data.admin.email).to.equal('admin' + server.internalServerNumber + '@example.com')
56 expect(data.contactForm.enabled).to.be.true
58 expect(data.user.videoQuota).to.equal(5242880)
59 expect(data.user.videoQuotaDaily).to.equal(-1)
61 expect(data.videoChannels.maxPerUser).to.equal(20)
63 expect(data.transcoding.enabled).to.be.false
64 expect(data.transcoding.allowAdditionalExtensions).to.be.false
65 expect(data.transcoding.allowAudioFiles).to.be.false
66 expect(data.transcoding.threads).to.equal(2)
67 expect(data.transcoding.concurrency).to.equal(2)
68 expect(data.transcoding.profile).to.equal('default')
69 expect(data.transcoding.resolutions['240p']).to.be.true
70 expect(data.transcoding.resolutions['360p']).to.be.true
71 expect(data.transcoding.resolutions['480p']).to.be.true
72 expect(data.transcoding.resolutions['720p']).to.be.true
73 expect(data.transcoding.resolutions['1080p']).to.be.true
74 expect(data.transcoding.resolutions['1440p']).to.be.true
75 expect(data.transcoding.resolutions['2160p']).to.be.true
76 expect(data.transcoding.webtorrent.enabled).to.be.true
77 expect(data.transcoding.hls.enabled).to.be.true
79 expect(data.live.enabled).to.be.false
80 expect(data.live.allowReplay).to.be.false
81 expect(data.live.maxDuration).to.equal(-1)
82 expect(data.live.maxInstanceLives).to.equal(20)
83 expect(data.live.maxUserLives).to.equal(3)
84 expect(data.live.transcoding.enabled).to.be.false
85 expect(data.live.transcoding.threads).to.equal(2)
86 expect(data.live.transcoding.profile).to.equal('default')
87 expect(data.live.transcoding.resolutions['240p']).to.be.false
88 expect(data.live.transcoding.resolutions['360p']).to.be.false
89 expect(data.live.transcoding.resolutions['480p']).to.be.false
90 expect(data.live.transcoding.resolutions['720p']).to.be.false
91 expect(data.live.transcoding.resolutions['1080p']).to.be.false
92 expect(data.live.transcoding.resolutions['1440p']).to.be.false
93 expect(data.live.transcoding.resolutions['2160p']).to.be.false
95 expect(data.import.videos.concurrency).to.equal(2)
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
100 expect(data.followers.instance.enabled).to.be.true
101 expect(data.followers.instance.manualApproval).to.be.false
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('')
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
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')
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')
127 expect(data.instance.languages).to.deep.equal([ 'en', 'es' ])
128 expect(data.instance.categories).to.deep.equal([ 1, 2 ])
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; }')
136 expect(data.services.twitter.username).to.equal('@Kuja')
137 expect(data.services.twitter.whitelisted).to.be.true
139 expect(data.cache.previews.size).to.equal(2)
140 expect(data.cache.captions.size).to.equal(3)
141 expect(data.cache.torrents.size).to.equal(4)
143 expect(data.signup.enabled).to.be.false
144 expect(data.signup.limit).to.equal(5)
145 expect(data.signup.requiresEmailVerification).to.be.false
146 expect(data.signup.minimumAge).to.equal(10)
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')
153 expect(data.contactForm.enabled).to.be.false
155 expect(data.user.videoQuota).to.equal(5242881)
156 expect(data.user.videoQuotaDaily).to.equal(318742)
158 expect(data.videoChannels.maxPerUser).to.equal(24)
160 expect(data.transcoding.enabled).to.be.true
161 expect(data.transcoding.threads).to.equal(1)
162 expect(data.transcoding.concurrency).to.equal(3)
163 expect(data.transcoding.allowAdditionalExtensions).to.be.true
164 expect(data.transcoding.allowAudioFiles).to.be.true
165 expect(data.transcoding.profile).to.equal('vod_profile')
166 expect(data.transcoding.resolutions['240p']).to.be.false
167 expect(data.transcoding.resolutions['360p']).to.be.true
168 expect(data.transcoding.resolutions['480p']).to.be.true
169 expect(data.transcoding.resolutions['720p']).to.be.false
170 expect(data.transcoding.resolutions['1080p']).to.be.false
171 expect(data.transcoding.resolutions['2160p']).to.be.false
172 expect(data.transcoding.hls.enabled).to.be.false
173 expect(data.transcoding.webtorrent.enabled).to.be.true
175 expect(data.live.enabled).to.be.true
176 expect(data.live.allowReplay).to.be.true
177 expect(data.live.maxDuration).to.equal(5000)
178 expect(data.live.maxInstanceLives).to.equal(-1)
179 expect(data.live.maxUserLives).to.equal(10)
180 expect(data.live.transcoding.enabled).to.be.true
181 expect(data.live.transcoding.threads).to.equal(4)
182 expect(data.live.transcoding.profile).to.equal('live_profile')
183 expect(data.live.transcoding.resolutions['240p']).to.be.true
184 expect(data.live.transcoding.resolutions['360p']).to.be.true
185 expect(data.live.transcoding.resolutions['480p']).to.be.true
186 expect(data.live.transcoding.resolutions['720p']).to.be.true
187 expect(data.live.transcoding.resolutions['1080p']).to.be.true
188 expect(data.live.transcoding.resolutions['2160p']).to.be.true
190 expect(data.import.videos.concurrency).to.equal(4)
191 expect(data.import.videos.http.enabled).to.be.false
192 expect(data.import.videos.torrent.enabled).to.be.false
193 expect(data.autoBlacklist.videos.ofUsers.enabled).to.be.true
195 expect(data.followers.instance.enabled).to.be.false
196 expect(data.followers.instance.manualApproval).to.be.true
198 expect(data.followings.instance.autoFollowBack.enabled).to.be.true
199 expect(data.followings.instance.autoFollowIndex.enabled).to.be.true
200 expect(data.followings.instance.autoFollowIndex.indexUrl).to.equal('https://updated.example.com')
202 expect(data.broadcastMessage.enabled).to.be.true
203 expect(data.broadcastMessage.level).to.equal('error')
204 expect(data.broadcastMessage.message).to.equal('super bad message')
205 expect(data.broadcastMessage.dismissable).to.be.true
208 const newCustomConfig: CustomConfig = {
210 name: 'PeerTube updated',
211 shortDescription: 'my short description',
212 description: 'my super description',
213 terms: 'my super terms',
214 codeOfConduct: 'my super coc',
216 creationReason: 'my super creation reason',
217 moderationInformation: 'my super moderation information',
218 administrator: 'Kuja',
219 maintenanceLifetime: 'forever',
220 businessModel: 'my super business model',
221 hardwareInformation: '2vCore 3GB RAM',
223 languages: [ 'en', 'es' ],
224 categories: [ 1, 2 ],
227 defaultNSFWPolicy: 'blur' as 'blur',
229 defaultClientRoute: '/videos/recently-added',
232 javascript: 'alert("coucou")',
233 css: 'body { background-color: red; }'
259 requiresEmailVerification: false,
263 email: 'superadmin1@example.com'
270 videoQuotaDaily: 318742
277 allowAdditionalExtensions: true,
278 allowAudioFiles: true,
281 profile: 'vod_profile',
303 maxInstanceLives: -1,
308 profile: 'live_profile',
334 enabled: [ 'best', 'hot', 'most-viewed', 'most-liked' ],
359 indexUrl: 'https://updated.example.com'
366 message: 'super bad message',
376 url: 'https://search.joinpeertube.org',
377 disableLocalSearch: true,
378 isDefaultSearch: true
383 describe('Test static config', function () {
384 let server: PeerTubeServer = null
386 before(async function () {
389 server = await createSingleServer(1, { webadmin: { configuration: { edition: { allowed: false } } } })
390 await setAccessTokensToServers([ server ])
393 it('Should tell the client that edits are not allowed', async function () {
394 const data = await server.config.getConfig()
396 expect(data.webadmin.configuration.edition.allowed).to.be.false
399 it('Should error when client tries to update', async function () {
400 await server.config.updateCustomConfig({ newCustomConfig, expectedStatus: 405 })
403 after(async function () {
404 await cleanupTests([ server ])
408 describe('Test config', function () {
409 let server: PeerTubeServer = null
411 before(async function () {
414 server = await createSingleServer(1)
415 await setAccessTokensToServers([ server ])
418 it('Should have a correct config on a server with registration enabled', async function () {
419 const data = await server.config.getConfig()
421 expect(data.signup.allowed).to.be.true
424 it('Should have a correct config on a server with registration enabled and a users limit', async function () {
428 server.users.register({ username: 'user1' }),
429 server.users.register({ username: 'user2' }),
430 server.users.register({ username: 'user3' })
433 const data = await server.config.getConfig()
435 expect(data.signup.allowed).to.be.false
438 it('Should have the correct video allowed extensions', async function () {
439 const data = await server.config.getConfig()
441 expect(data.video.file.extensions).to.have.lengthOf(3)
442 expect(data.video.file.extensions).to.contain('.mp4')
443 expect(data.video.file.extensions).to.contain('.webm')
444 expect(data.video.file.extensions).to.contain('.ogv')
446 await server.videos.upload({ attributes: { fixture: 'video_short.mkv' }, expectedStatus: HttpStatusCode.UNSUPPORTED_MEDIA_TYPE_415 })
447 await server.videos.upload({ attributes: { fixture: 'sample.ogg' }, expectedStatus: HttpStatusCode.UNSUPPORTED_MEDIA_TYPE_415 })
449 expect(data.contactForm.enabled).to.be.true
452 it('Should get the customized configuration', async function () {
453 const data = await server.config.getCustomConfig()
455 checkInitialConfig(server, data)
458 it('Should update the customized configuration', async function () {
459 await server.config.updateCustomConfig({ newCustomConfig })
461 const data = await server.config.getCustomConfig()
462 checkUpdatedConfig(data)
465 it('Should have the correct updated video allowed extensions', async function () {
468 const data = await server.config.getConfig()
470 expect(data.video.file.extensions).to.have.length.above(4)
471 expect(data.video.file.extensions).to.contain('.mp4')
472 expect(data.video.file.extensions).to.contain('.webm')
473 expect(data.video.file.extensions).to.contain('.ogv')
474 expect(data.video.file.extensions).to.contain('.flv')
475 expect(data.video.file.extensions).to.contain('.wmv')
476 expect(data.video.file.extensions).to.contain('.mkv')
477 expect(data.video.file.extensions).to.contain('.mp3')
478 expect(data.video.file.extensions).to.contain('.ogg')
479 expect(data.video.file.extensions).to.contain('.flac')
481 await server.videos.upload({ attributes: { fixture: 'video_short.mkv' }, expectedStatus: HttpStatusCode.OK_200 })
482 await server.videos.upload({ attributes: { fixture: 'sample.ogg' }, expectedStatus: HttpStatusCode.OK_200 })
485 it('Should have the configuration updated after a restart', async function () {
488 await killallServers([ server ])
492 const data = await server.config.getCustomConfig()
494 checkUpdatedConfig(data)
497 it('Should fetch the about information', async function () {
498 const data = await server.config.getAbout()
500 expect(data.instance.name).to.equal('PeerTube updated')
501 expect(data.instance.shortDescription).to.equal('my short description')
502 expect(data.instance.description).to.equal('my super description')
503 expect(data.instance.terms).to.equal('my super terms')
504 expect(data.instance.codeOfConduct).to.equal('my super coc')
506 expect(data.instance.creationReason).to.equal('my super creation reason')
507 expect(data.instance.moderationInformation).to.equal('my super moderation information')
508 expect(data.instance.administrator).to.equal('Kuja')
509 expect(data.instance.maintenanceLifetime).to.equal('forever')
510 expect(data.instance.businessModel).to.equal('my super business model')
511 expect(data.instance.hardwareInformation).to.equal('2vCore 3GB RAM')
513 expect(data.instance.languages).to.deep.equal([ 'en', 'es' ])
514 expect(data.instance.categories).to.deep.equal([ 1, 2 ])
517 it('Should remove the custom configuration', async function () {
520 await server.config.deleteCustomConfig()
522 const data = await server.config.getCustomConfig()
523 checkInitialConfig(server, data)
526 it('Should enable frameguard', async function () {
530 const res = await makeGetRequest({
532 path: '/api/v1/config',
536 expect(res.headers['x-frame-options']).to.exist
539 await killallServers([ server ])
543 frameguard: { enabled: false }
546 await server.run(config)
549 const res = await makeGetRequest({
551 path: '/api/v1/config',
555 expect(res.headers['x-frame-options']).to.not.exist
559 after(async function () {
560 await cleanupTests([ server ])