1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
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'
20 setAccessTokensToServers,
23 } from '../../../../shared/extra-utils'
24 import { ServerConfig } from '../../../../shared/models'
25 import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
27 const expect = chai.expect
29 function checkInitialConfig (server: ServerInfo, data: CustomConfig) {
30 expect(data.instance.name).to.equal('PeerTube')
31 expect(data.instance.shortDescription).to.equal(
32 'PeerTube, an ActivityPub-federated video streaming platform using P2P directly in your web browser.'
34 expect(data.instance.description).to.equal('Welcome to this PeerTube instance!')
36 expect(data.instance.terms).to.equal('No terms for now.')
37 expect(data.instance.creationReason).to.be.empty
38 expect(data.instance.codeOfConduct).to.be.empty
39 expect(data.instance.moderationInformation).to.be.empty
40 expect(data.instance.administrator).to.be.empty
41 expect(data.instance.maintenanceLifetime).to.be.empty
42 expect(data.instance.businessModel).to.be.empty
43 expect(data.instance.hardwareInformation).to.be.empty
45 expect(data.instance.languages).to.have.lengthOf(0)
46 expect(data.instance.categories).to.have.lengthOf(0)
48 expect(data.instance.defaultClientRoute).to.equal('/videos/trending')
49 expect(data.instance.isNSFW).to.be.false
50 expect(data.instance.defaultNSFWPolicy).to.equal('display')
51 expect(data.instance.customizations.css).to.be.empty
52 expect(data.instance.customizations.javascript).to.be.empty
54 expect(data.services.twitter.username).to.equal('@Chocobozzz')
55 expect(data.services.twitter.whitelisted).to.be.false
57 expect(data.cache.previews.size).to.equal(1)
58 expect(data.cache.captions.size).to.equal(1)
59 expect(data.cache.torrents.size).to.equal(1)
61 expect(data.signup.enabled).to.be.true
62 expect(data.signup.limit).to.equal(4)
63 expect(data.signup.minimumAge).to.equal(16)
64 expect(data.signup.requiresEmailVerification).to.be.false
66 expect(data.admin.email).to.equal('admin' + server.internalServerNumber + '@example.com')
67 expect(data.contactForm.enabled).to.be.true
69 expect(data.user.videoQuota).to.equal(5242880)
70 expect(data.user.videoQuotaDaily).to.equal(-1)
72 expect(data.transcoding.enabled).to.be.false
73 expect(data.transcoding.allowAdditionalExtensions).to.be.false
74 expect(data.transcoding.allowAudioFiles).to.be.false
75 expect(data.transcoding.threads).to.equal(2)
76 expect(data.transcoding.concurrency).to.equal(2)
77 expect(data.transcoding.profile).to.equal('default')
78 expect(data.transcoding.resolutions['240p']).to.be.true
79 expect(data.transcoding.resolutions['360p']).to.be.true
80 expect(data.transcoding.resolutions['480p']).to.be.true
81 expect(data.transcoding.resolutions['720p']).to.be.true
82 expect(data.transcoding.resolutions['1080p']).to.be.true
83 expect(data.transcoding.resolutions['1440p']).to.be.true
84 expect(data.transcoding.resolutions['2160p']).to.be.true
85 expect(data.transcoding.webtorrent.enabled).to.be.true
86 expect(data.transcoding.hls.enabled).to.be.true
88 expect(data.live.enabled).to.be.false
89 expect(data.live.allowReplay).to.be.false
90 expect(data.live.maxDuration).to.equal(-1)
91 expect(data.live.maxInstanceLives).to.equal(20)
92 expect(data.live.maxUserLives).to.equal(3)
93 expect(data.live.transcoding.enabled).to.be.false
94 expect(data.live.transcoding.threads).to.equal(2)
95 expect(data.live.transcoding.profile).to.equal('default')
96 expect(data.live.transcoding.resolutions['240p']).to.be.false
97 expect(data.live.transcoding.resolutions['360p']).to.be.false
98 expect(data.live.transcoding.resolutions['480p']).to.be.false
99 expect(data.live.transcoding.resolutions['720p']).to.be.false
100 expect(data.live.transcoding.resolutions['1080p']).to.be.false
101 expect(data.live.transcoding.resolutions['1440p']).to.be.false
102 expect(data.live.transcoding.resolutions['2160p']).to.be.false
104 expect(data.import.videos.concurrency).to.equal(2)
105 expect(data.import.videos.http.enabled).to.be.true
106 expect(data.import.videos.torrent.enabled).to.be.true
107 expect(data.autoBlacklist.videos.ofUsers.enabled).to.be.false
109 expect(data.followers.instance.enabled).to.be.true
110 expect(data.followers.instance.manualApproval).to.be.false
112 expect(data.followings.instance.autoFollowBack.enabled).to.be.false
113 expect(data.followings.instance.autoFollowIndex.enabled).to.be.false
114 expect(data.followings.instance.autoFollowIndex.indexUrl).to.equal('')
116 expect(data.broadcastMessage.enabled).to.be.false
117 expect(data.broadcastMessage.level).to.equal('info')
118 expect(data.broadcastMessage.message).to.equal('')
119 expect(data.broadcastMessage.dismissable).to.be.false
122 function checkUpdatedConfig (data: CustomConfig) {
123 expect(data.instance.name).to.equal('PeerTube updated')
124 expect(data.instance.shortDescription).to.equal('my short description')
125 expect(data.instance.description).to.equal('my super description')
127 expect(data.instance.terms).to.equal('my super terms')
128 expect(data.instance.creationReason).to.equal('my super creation reason')
129 expect(data.instance.codeOfConduct).to.equal('my super coc')
130 expect(data.instance.moderationInformation).to.equal('my super moderation information')
131 expect(data.instance.administrator).to.equal('Kuja')
132 expect(data.instance.maintenanceLifetime).to.equal('forever')
133 expect(data.instance.businessModel).to.equal('my super business model')
134 expect(data.instance.hardwareInformation).to.equal('2vCore 3GB RAM')
136 expect(data.instance.languages).to.deep.equal([ 'en', 'es' ])
137 expect(data.instance.categories).to.deep.equal([ 1, 2 ])
139 expect(data.instance.defaultClientRoute).to.equal('/videos/recently-added')
140 expect(data.instance.isNSFW).to.be.true
141 expect(data.instance.defaultNSFWPolicy).to.equal('blur')
142 expect(data.instance.customizations.javascript).to.equal('alert("coucou")')
143 expect(data.instance.customizations.css).to.equal('body { background-color: red; }')
145 expect(data.services.twitter.username).to.equal('@Kuja')
146 expect(data.services.twitter.whitelisted).to.be.true
148 expect(data.cache.previews.size).to.equal(2)
149 expect(data.cache.captions.size).to.equal(3)
150 expect(data.cache.torrents.size).to.equal(4)
152 expect(data.signup.enabled).to.be.false
153 expect(data.signup.limit).to.equal(5)
154 expect(data.signup.requiresEmailVerification).to.be.false
155 expect(data.signup.minimumAge).to.equal(10)
157 // We override admin email in parallel tests, so skip this exception
158 if (parallelTests() === false) {
159 expect(data.admin.email).to.equal('superadmin1@example.com')
162 expect(data.contactForm.enabled).to.be.false
164 expect(data.user.videoQuota).to.equal(5242881)
165 expect(data.user.videoQuotaDaily).to.equal(318742)
167 expect(data.transcoding.enabled).to.be.true
168 expect(data.transcoding.threads).to.equal(1)
169 expect(data.transcoding.concurrency).to.equal(3)
170 expect(data.transcoding.allowAdditionalExtensions).to.be.true
171 expect(data.transcoding.allowAudioFiles).to.be.true
172 expect(data.transcoding.profile).to.equal('vod_profile')
173 expect(data.transcoding.resolutions['240p']).to.be.false
174 expect(data.transcoding.resolutions['360p']).to.be.true
175 expect(data.transcoding.resolutions['480p']).to.be.true
176 expect(data.transcoding.resolutions['720p']).to.be.false
177 expect(data.transcoding.resolutions['1080p']).to.be.false
178 expect(data.transcoding.resolutions['2160p']).to.be.false
179 expect(data.transcoding.hls.enabled).to.be.false
180 expect(data.transcoding.webtorrent.enabled).to.be.true
182 expect(data.live.enabled).to.be.true
183 expect(data.live.allowReplay).to.be.true
184 expect(data.live.maxDuration).to.equal(5000)
185 expect(data.live.maxInstanceLives).to.equal(-1)
186 expect(data.live.maxUserLives).to.equal(10)
187 expect(data.live.transcoding.enabled).to.be.true
188 expect(data.live.transcoding.threads).to.equal(4)
189 expect(data.live.transcoding.profile).to.equal('live_profile')
190 expect(data.live.transcoding.resolutions['240p']).to.be.true
191 expect(data.live.transcoding.resolutions['360p']).to.be.true
192 expect(data.live.transcoding.resolutions['480p']).to.be.true
193 expect(data.live.transcoding.resolutions['720p']).to.be.true
194 expect(data.live.transcoding.resolutions['1080p']).to.be.true
195 expect(data.live.transcoding.resolutions['2160p']).to.be.true
197 expect(data.import.videos.concurrency).to.equal(4)
198 expect(data.import.videos.http.enabled).to.be.false
199 expect(data.import.videos.torrent.enabled).to.be.false
200 expect(data.autoBlacklist.videos.ofUsers.enabled).to.be.true
202 expect(data.followers.instance.enabled).to.be.false
203 expect(data.followers.instance.manualApproval).to.be.true
205 expect(data.followings.instance.autoFollowBack.enabled).to.be.true
206 expect(data.followings.instance.autoFollowIndex.enabled).to.be.true
207 expect(data.followings.instance.autoFollowIndex.indexUrl).to.equal('https://updated.example.com')
209 expect(data.broadcastMessage.enabled).to.be.true
210 expect(data.broadcastMessage.level).to.equal('error')
211 expect(data.broadcastMessage.message).to.equal('super bad message')
212 expect(data.broadcastMessage.dismissable).to.be.true
215 describe('Test config', function () {
218 before(async function () {
221 server = await flushAndRunServer(1)
222 await setAccessTokensToServers([ server ])
225 it('Should have a correct config on a server with registration enabled', async function () {
226 const res = await getConfig(server.url)
227 const data: ServerConfig = res.body
229 expect(data.signup.allowed).to.be.true
232 it('Should have a correct config on a server with registration enabled and a users limit', async function () {
236 registerUser(server.url, 'user1', 'super password'),
237 registerUser(server.url, 'user2', 'super password'),
238 registerUser(server.url, 'user3', 'super password')
241 const res = await getConfig(server.url)
242 const data: ServerConfig = res.body
244 expect(data.signup.allowed).to.be.false
247 it('Should have the correct video allowed extensions', async function () {
248 const res = await getConfig(server.url)
249 const data: ServerConfig = res.body
251 expect(data.video.file.extensions).to.have.lengthOf(3)
252 expect(data.video.file.extensions).to.contain('.mp4')
253 expect(data.video.file.extensions).to.contain('.webm')
254 expect(data.video.file.extensions).to.contain('.ogv')
256 await uploadVideo(server.url, server.accessToken, { fixture: 'video_short.mkv' }, HttpStatusCode.UNSUPPORTED_MEDIA_TYPE_415)
257 await uploadVideo(server.url, server.accessToken, { fixture: 'sample.ogg' }, HttpStatusCode.UNSUPPORTED_MEDIA_TYPE_415)
259 expect(data.contactForm.enabled).to.be.true
262 it('Should get the customized configuration', async function () {
263 const res = await getCustomConfig(server.url, server.accessToken)
264 const data = res.body as CustomConfig
266 checkInitialConfig(server, data)
269 it('Should update the customized configuration', async function () {
270 const newCustomConfig: CustomConfig = {
272 name: 'PeerTube updated',
273 shortDescription: 'my short description',
274 description: 'my super description',
275 terms: 'my super terms',
276 codeOfConduct: 'my super coc',
278 creationReason: 'my super creation reason',
279 moderationInformation: 'my super moderation information',
280 administrator: 'Kuja',
281 maintenanceLifetime: 'forever',
282 businessModel: 'my super business model',
283 hardwareInformation: '2vCore 3GB RAM',
285 languages: [ 'en', 'es' ],
286 categories: [ 1, 2 ],
289 defaultNSFWPolicy: 'blur' as 'blur',
291 defaultClientRoute: '/videos/recently-added',
294 javascript: 'alert("coucou")',
295 css: 'body { background-color: red; }'
321 requiresEmailVerification: false,
325 email: 'superadmin1@example.com'
332 videoQuotaDaily: 318742
336 allowAdditionalExtensions: true,
337 allowAudioFiles: true,
340 profile: 'vod_profile',
362 maxInstanceLives: -1,
367 profile: 'live_profile',
393 enabled: [ 'best', 'hot', 'most-viewed', 'most-liked' ],
418 indexUrl: 'https://updated.example.com'
425 message: 'super bad message',
435 url: 'https://search.joinpeertube.org',
436 disableLocalSearch: true,
437 isDefaultSearch: true
441 await updateCustomConfig(server.url, server.accessToken, newCustomConfig)
443 const res = await getCustomConfig(server.url, server.accessToken)
444 const data = res.body
446 checkUpdatedConfig(data)
449 it('Should have the correct updated video allowed extensions', async function () {
452 const res = await getConfig(server.url)
453 const data: ServerConfig = res.body
455 expect(data.video.file.extensions).to.have.length.above(4)
456 expect(data.video.file.extensions).to.contain('.mp4')
457 expect(data.video.file.extensions).to.contain('.webm')
458 expect(data.video.file.extensions).to.contain('.ogv')
459 expect(data.video.file.extensions).to.contain('.flv')
460 expect(data.video.file.extensions).to.contain('.wmv')
461 expect(data.video.file.extensions).to.contain('.mkv')
462 expect(data.video.file.extensions).to.contain('.mp3')
463 expect(data.video.file.extensions).to.contain('.ogg')
464 expect(data.video.file.extensions).to.contain('.flac')
466 await uploadVideo(server.url, server.accessToken, { fixture: 'video_short.mkv' }, HttpStatusCode.OK_200)
467 await uploadVideo(server.url, server.accessToken, { fixture: 'sample.ogg' }, HttpStatusCode.OK_200)
470 it('Should have the configuration updated after a restart', async function () {
473 killallServers([ server ])
475 await reRunServer(server)
477 const res = await getCustomConfig(server.url, server.accessToken)
478 const data = res.body
480 checkUpdatedConfig(data)
483 it('Should fetch the about information', async function () {
484 const res = await getAbout(server.url)
485 const data: About = res.body
487 expect(data.instance.name).to.equal('PeerTube updated')
488 expect(data.instance.shortDescription).to.equal('my short description')
489 expect(data.instance.description).to.equal('my super description')
490 expect(data.instance.terms).to.equal('my super terms')
491 expect(data.instance.codeOfConduct).to.equal('my super coc')
493 expect(data.instance.creationReason).to.equal('my super creation reason')
494 expect(data.instance.moderationInformation).to.equal('my super moderation information')
495 expect(data.instance.administrator).to.equal('Kuja')
496 expect(data.instance.maintenanceLifetime).to.equal('forever')
497 expect(data.instance.businessModel).to.equal('my super business model')
498 expect(data.instance.hardwareInformation).to.equal('2vCore 3GB RAM')
500 expect(data.instance.languages).to.deep.equal([ 'en', 'es' ])
501 expect(data.instance.categories).to.deep.equal([ 1, 2 ])
504 it('Should remove the custom configuration', async function () {
507 await deleteCustomConfig(server.url, server.accessToken)
509 const res = await getCustomConfig(server.url, server.accessToken)
510 const data = res.body
512 checkInitialConfig(server, data)
515 it('Should enable frameguard', async function () {
519 const res = await makeGetRequest({
521 path: '/api/v1/config',
522 statusCodeExpected: 200
525 expect(res.headers['x-frame-options']).to.exist
528 killallServers([ server ])
532 frameguard: { enabled: false }
535 server = await reRunServer(server, config)
538 const res = await makeGetRequest({
540 path: '/api/v1/config',
541 statusCodeExpected: 200
544 expect(res.headers['x-frame-options']).to.not.exist
548 after(async function () {
549 await cleanupTests([ server ])