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['144p']).to.be.false
70 expect(data.transcoding.resolutions['240p']).to.be.true
71 expect(data.transcoding.resolutions['360p']).to.be.true
72 expect(data.transcoding.resolutions['480p']).to.be.true
73 expect(data.transcoding.resolutions['720p']).to.be.true
74 expect(data.transcoding.resolutions['1080p']).to.be.true
75 expect(data.transcoding.resolutions['1440p']).to.be.true
76 expect(data.transcoding.resolutions['2160p']).to.be.true
77 expect(data.transcoding.webtorrent.enabled).to.be.true
78 expect(data.transcoding.hls.enabled).to.be.true
80 expect(data.live.enabled).to.be.false
81 expect(data.live.allowReplay).to.be.false
82 expect(data.live.maxDuration).to.equal(-1)
83 expect(data.live.maxInstanceLives).to.equal(20)
84 expect(data.live.maxUserLives).to.equal(3)
85 expect(data.live.transcoding.enabled).to.be.false
86 expect(data.live.transcoding.threads).to.equal(2)
87 expect(data.live.transcoding.profile).to.equal('default')
88 expect(data.live.transcoding.resolutions['144p']).to.be.false
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['1440p']).to.be.false
95 expect(data.live.transcoding.resolutions['2160p']).to.be.false
97 expect(data.import.videos.concurrency).to.equal(2)
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
102 expect(data.followers.instance.enabled).to.be.true
103 expect(data.followers.instance.manualApproval).to.be.false
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('')
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
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')
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')
129 expect(data.instance.languages).to.deep.equal([ 'en', 'es' ])
130 expect(data.instance.categories).to.deep.equal([ 1, 2 ])
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; }')
138 expect(data.services.twitter.username).to.equal('@Kuja')
139 expect(data.services.twitter.whitelisted).to.be.true
141 expect(data.cache.previews.size).to.equal(2)
142 expect(data.cache.captions.size).to.equal(3)
143 expect(data.cache.torrents.size).to.equal(4)
145 expect(data.signup.enabled).to.be.false
146 expect(data.signup.limit).to.equal(5)
147 expect(data.signup.requiresEmailVerification).to.be.false
148 expect(data.signup.minimumAge).to.equal(10)
150 // We override admin email in parallel tests, so skip this exception
151 if (parallelTests() === false) {
152 expect(data.admin.email).to.equal('superadmin1@example.com')
155 expect(data.contactForm.enabled).to.be.false
157 expect(data.user.videoQuota).to.equal(5242881)
158 expect(data.user.videoQuotaDaily).to.equal(318742)
160 expect(data.videoChannels.maxPerUser).to.equal(24)
162 expect(data.transcoding.enabled).to.be.true
163 expect(data.transcoding.threads).to.equal(1)
164 expect(data.transcoding.concurrency).to.equal(3)
165 expect(data.transcoding.allowAdditionalExtensions).to.be.true
166 expect(data.transcoding.allowAudioFiles).to.be.true
167 expect(data.transcoding.profile).to.equal('vod_profile')
168 expect(data.transcoding.resolutions['144p']).to.be.false
169 expect(data.transcoding.resolutions['240p']).to.be.false
170 expect(data.transcoding.resolutions['360p']).to.be.true
171 expect(data.transcoding.resolutions['480p']).to.be.true
172 expect(data.transcoding.resolutions['720p']).to.be.false
173 expect(data.transcoding.resolutions['1080p']).to.be.false
174 expect(data.transcoding.resolutions['2160p']).to.be.false
175 expect(data.transcoding.hls.enabled).to.be.false
176 expect(data.transcoding.webtorrent.enabled).to.be.true
178 expect(data.live.enabled).to.be.true
179 expect(data.live.allowReplay).to.be.true
180 expect(data.live.maxDuration).to.equal(5000)
181 expect(data.live.maxInstanceLives).to.equal(-1)
182 expect(data.live.maxUserLives).to.equal(10)
183 expect(data.live.transcoding.enabled).to.be.true
184 expect(data.live.transcoding.threads).to.equal(4)
185 expect(data.live.transcoding.profile).to.equal('live_profile')
186 expect(data.live.transcoding.resolutions['144p']).to.be.true
187 expect(data.live.transcoding.resolutions['240p']).to.be.true
188 expect(data.live.transcoding.resolutions['360p']).to.be.true
189 expect(data.live.transcoding.resolutions['480p']).to.be.true
190 expect(data.live.transcoding.resolutions['720p']).to.be.true
191 expect(data.live.transcoding.resolutions['1080p']).to.be.true
192 expect(data.live.transcoding.resolutions['2160p']).to.be.true
194 expect(data.import.videos.concurrency).to.equal(4)
195 expect(data.import.videos.http.enabled).to.be.false
196 expect(data.import.videos.torrent.enabled).to.be.false
197 expect(data.autoBlacklist.videos.ofUsers.enabled).to.be.true
199 expect(data.followers.instance.enabled).to.be.false
200 expect(data.followers.instance.manualApproval).to.be.true
202 expect(data.followings.instance.autoFollowBack.enabled).to.be.true
203 expect(data.followings.instance.autoFollowIndex.enabled).to.be.true
204 expect(data.followings.instance.autoFollowIndex.indexUrl).to.equal('https://updated.example.com')
206 expect(data.broadcastMessage.enabled).to.be.true
207 expect(data.broadcastMessage.level).to.equal('error')
208 expect(data.broadcastMessage.message).to.equal('super bad message')
209 expect(data.broadcastMessage.dismissable).to.be.true
212 const newCustomConfig: CustomConfig = {
214 name: 'PeerTube updated',
215 shortDescription: 'my short description',
216 description: 'my super description',
217 terms: 'my super terms',
218 codeOfConduct: 'my super coc',
220 creationReason: 'my super creation reason',
221 moderationInformation: 'my super moderation information',
222 administrator: 'Kuja',
223 maintenanceLifetime: 'forever',
224 businessModel: 'my super business model',
225 hardwareInformation: '2vCore 3GB RAM',
227 languages: [ 'en', 'es' ],
228 categories: [ 1, 2 ],
231 defaultNSFWPolicy: 'blur' as 'blur',
233 defaultClientRoute: '/videos/recently-added',
236 javascript: 'alert("coucou")',
237 css: 'body { background-color: red; }'
263 requiresEmailVerification: false,
267 email: 'superadmin1@example.com'
274 videoQuotaDaily: 318742
281 allowAdditionalExtensions: true,
282 allowAudioFiles: true,
285 profile: 'vod_profile',
308 maxInstanceLives: -1,
313 profile: 'live_profile',
340 enabled: [ 'best', 'hot', 'most-viewed', 'most-liked' ],
365 indexUrl: 'https://updated.example.com'
372 message: 'super bad message',
382 url: 'https://search.joinpeertube.org',
383 disableLocalSearch: true,
384 isDefaultSearch: true
389 describe('Test static config', function () {
390 let server: PeerTubeServer = null
392 before(async function () {
395 server = await createSingleServer(1, { webadmin: { configuration: { edition: { allowed: false } } } })
396 await setAccessTokensToServers([ server ])
399 it('Should tell the client that edits are not allowed', async function () {
400 const data = await server.config.getConfig()
402 expect(data.webadmin.configuration.edition.allowed).to.be.false
405 it('Should error when client tries to update', async function () {
406 await server.config.updateCustomConfig({ newCustomConfig, expectedStatus: 405 })
409 after(async function () {
410 await cleanupTests([ server ])
414 describe('Test config', function () {
415 let server: PeerTubeServer = null
417 before(async function () {
420 server = await createSingleServer(1)
421 await setAccessTokensToServers([ server ])
424 it('Should have a correct config on a server with registration enabled', async function () {
425 const data = await server.config.getConfig()
427 expect(data.signup.allowed).to.be.true
430 it('Should have a correct config on a server with registration enabled and a users limit', async function () {
434 server.users.register({ username: 'user1' }),
435 server.users.register({ username: 'user2' }),
436 server.users.register({ username: 'user3' })
439 const data = await server.config.getConfig()
441 expect(data.signup.allowed).to.be.false
444 it('Should have the correct video allowed extensions', async function () {
445 const data = await server.config.getConfig()
447 expect(data.video.file.extensions).to.have.lengthOf(3)
448 expect(data.video.file.extensions).to.contain('.mp4')
449 expect(data.video.file.extensions).to.contain('.webm')
450 expect(data.video.file.extensions).to.contain('.ogv')
452 await server.videos.upload({ attributes: { fixture: 'video_short.mkv' }, expectedStatus: HttpStatusCode.UNSUPPORTED_MEDIA_TYPE_415 })
453 await server.videos.upload({ attributes: { fixture: 'sample.ogg' }, expectedStatus: HttpStatusCode.UNSUPPORTED_MEDIA_TYPE_415 })
455 expect(data.contactForm.enabled).to.be.true
458 it('Should get the customized configuration', async function () {
459 const data = await server.config.getCustomConfig()
461 checkInitialConfig(server, data)
464 it('Should update the customized configuration', async function () {
465 await server.config.updateCustomConfig({ newCustomConfig })
467 const data = await server.config.getCustomConfig()
468 checkUpdatedConfig(data)
471 it('Should have the correct updated video allowed extensions', async function () {
474 const data = await server.config.getConfig()
476 expect(data.video.file.extensions).to.have.length.above(4)
477 expect(data.video.file.extensions).to.contain('.mp4')
478 expect(data.video.file.extensions).to.contain('.webm')
479 expect(data.video.file.extensions).to.contain('.ogv')
480 expect(data.video.file.extensions).to.contain('.flv')
481 expect(data.video.file.extensions).to.contain('.wmv')
482 expect(data.video.file.extensions).to.contain('.mkv')
483 expect(data.video.file.extensions).to.contain('.mp3')
484 expect(data.video.file.extensions).to.contain('.ogg')
485 expect(data.video.file.extensions).to.contain('.flac')
487 await server.videos.upload({ attributes: { fixture: 'video_short.mkv' }, expectedStatus: HttpStatusCode.OK_200 })
488 await server.videos.upload({ attributes: { fixture: 'sample.ogg' }, expectedStatus: HttpStatusCode.OK_200 })
491 it('Should have the configuration updated after a restart', async function () {
494 await killallServers([ server ])
498 const data = await server.config.getCustomConfig()
500 checkUpdatedConfig(data)
503 it('Should fetch the about information', async function () {
504 const data = await server.config.getAbout()
506 expect(data.instance.name).to.equal('PeerTube updated')
507 expect(data.instance.shortDescription).to.equal('my short description')
508 expect(data.instance.description).to.equal('my super description')
509 expect(data.instance.terms).to.equal('my super terms')
510 expect(data.instance.codeOfConduct).to.equal('my super coc')
512 expect(data.instance.creationReason).to.equal('my super creation reason')
513 expect(data.instance.moderationInformation).to.equal('my super moderation information')
514 expect(data.instance.administrator).to.equal('Kuja')
515 expect(data.instance.maintenanceLifetime).to.equal('forever')
516 expect(data.instance.businessModel).to.equal('my super business model')
517 expect(data.instance.hardwareInformation).to.equal('2vCore 3GB RAM')
519 expect(data.instance.languages).to.deep.equal([ 'en', 'es' ])
520 expect(data.instance.categories).to.deep.equal([ 1, 2 ])
523 it('Should remove the custom configuration', async function () {
526 await server.config.deleteCustomConfig()
528 const data = await server.config.getCustomConfig()
529 checkInitialConfig(server, data)
532 it('Should enable frameguard', async function () {
536 const res = await makeGetRequest({
538 path: '/api/v1/config',
542 expect(res.headers['x-frame-options']).to.exist
545 await killallServers([ server ])
549 frameguard: { enabled: false }
552 await server.run(config)
555 const res = await makeGetRequest({
557 path: '/api/v1/config',
561 expect(res.headers['x-frame-options']).to.not.exist
565 after(async function () {
566 await cleanupTests([ server ])