1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
4 import * as chai from 'chai'
5 import { parallelTests } from '@shared/core-utils'
6 import { CustomConfig, HttpStatusCode } from '@shared/models'
13 setAccessTokensToServers
14 } from '@shared/server-commands'
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.client.videos.miniature.preferAuthorDisplayName).to.be.false
47 expect(data.client.menu.login.redirectOnSingleExternalAuth).to.be.false
49 expect(data.cache.previews.size).to.equal(1)
50 expect(data.cache.captions.size).to.equal(1)
51 expect(data.cache.torrents.size).to.equal(1)
53 expect(data.signup.enabled).to.be.true
54 expect(data.signup.limit).to.equal(4)
55 expect(data.signup.minimumAge).to.equal(16)
56 expect(data.signup.requiresEmailVerification).to.be.false
58 expect(data.admin.email).to.equal('admin' + server.internalServerNumber + '@example.com')
59 expect(data.contactForm.enabled).to.be.true
61 expect(data.user.videoQuota).to.equal(5242880)
62 expect(data.user.videoQuotaDaily).to.equal(-1)
64 expect(data.videoChannels.maxPerUser).to.equal(20)
66 expect(data.transcoding.enabled).to.be.false
67 expect(data.transcoding.allowAdditionalExtensions).to.be.false
68 expect(data.transcoding.allowAudioFiles).to.be.false
69 expect(data.transcoding.threads).to.equal(2)
70 expect(data.transcoding.concurrency).to.equal(2)
71 expect(data.transcoding.profile).to.equal('default')
72 expect(data.transcoding.resolutions['144p']).to.be.false
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
78 expect(data.transcoding.resolutions['1440p']).to.be.true
79 expect(data.transcoding.resolutions['2160p']).to.be.true
80 expect(data.transcoding.webtorrent.enabled).to.be.true
81 expect(data.transcoding.hls.enabled).to.be.true
83 expect(data.live.enabled).to.be.false
84 expect(data.live.allowReplay).to.be.false
85 expect(data.live.latencySetting.enabled).to.be.true
86 expect(data.live.maxDuration).to.equal(-1)
87 expect(data.live.maxInstanceLives).to.equal(20)
88 expect(data.live.maxUserLives).to.equal(3)
89 expect(data.live.transcoding.enabled).to.be.false
90 expect(data.live.transcoding.threads).to.equal(2)
91 expect(data.live.transcoding.profile).to.equal('default')
92 expect(data.live.transcoding.resolutions['144p']).to.be.false
93 expect(data.live.transcoding.resolutions['240p']).to.be.false
94 expect(data.live.transcoding.resolutions['360p']).to.be.false
95 expect(data.live.transcoding.resolutions['480p']).to.be.false
96 expect(data.live.transcoding.resolutions['720p']).to.be.false
97 expect(data.live.transcoding.resolutions['1080p']).to.be.false
98 expect(data.live.transcoding.resolutions['1440p']).to.be.false
99 expect(data.live.transcoding.resolutions['2160p']).to.be.false
101 expect(data.videoStudio.enabled).to.be.false
103 expect(data.import.videos.concurrency).to.equal(2)
104 expect(data.import.videos.http.enabled).to.be.true
105 expect(data.import.videos.torrent.enabled).to.be.true
106 expect(data.autoBlacklist.videos.ofUsers.enabled).to.be.false
108 expect(data.followers.instance.enabled).to.be.true
109 expect(data.followers.instance.manualApproval).to.be.false
111 expect(data.followings.instance.autoFollowBack.enabled).to.be.false
112 expect(data.followings.instance.autoFollowIndex.enabled).to.be.false
113 expect(data.followings.instance.autoFollowIndex.indexUrl).to.equal('')
115 expect(data.broadcastMessage.enabled).to.be.false
116 expect(data.broadcastMessage.level).to.equal('info')
117 expect(data.broadcastMessage.message).to.equal('')
118 expect(data.broadcastMessage.dismissable).to.be.false
121 function checkUpdatedConfig (data: CustomConfig) {
122 expect(data.instance.name).to.equal('PeerTube updated')
123 expect(data.instance.shortDescription).to.equal('my short description')
124 expect(data.instance.description).to.equal('my super description')
126 expect(data.instance.terms).to.equal('my super terms')
127 expect(data.instance.creationReason).to.equal('my super creation reason')
128 expect(data.instance.codeOfConduct).to.equal('my super coc')
129 expect(data.instance.moderationInformation).to.equal('my super moderation information')
130 expect(data.instance.administrator).to.equal('Kuja')
131 expect(data.instance.maintenanceLifetime).to.equal('forever')
132 expect(data.instance.businessModel).to.equal('my super business model')
133 expect(data.instance.hardwareInformation).to.equal('2vCore 3GB RAM')
135 expect(data.instance.languages).to.deep.equal([ 'en', 'es' ])
136 expect(data.instance.categories).to.deep.equal([ 1, 2 ])
138 expect(data.instance.defaultClientRoute).to.equal('/videos/recently-added')
139 expect(data.instance.isNSFW).to.be.true
140 expect(data.instance.defaultNSFWPolicy).to.equal('blur')
141 expect(data.instance.customizations.javascript).to.equal('alert("coucou")')
142 expect(data.instance.customizations.css).to.equal('body { background-color: red; }')
144 expect(data.services.twitter.username).to.equal('@Kuja')
145 expect(data.services.twitter.whitelisted).to.be.true
147 expect(data.client.videos.miniature.preferAuthorDisplayName).to.be.true
148 expect(data.client.menu.login.redirectOnSingleExternalAuth).to.be.true
150 expect(data.cache.previews.size).to.equal(2)
151 expect(data.cache.captions.size).to.equal(3)
152 expect(data.cache.torrents.size).to.equal(4)
154 expect(data.signup.enabled).to.be.false
155 expect(data.signup.limit).to.equal(5)
156 expect(data.signup.requiresEmailVerification).to.be.false
157 expect(data.signup.minimumAge).to.equal(10)
159 // We override admin email in parallel tests, so skip this exception
160 if (parallelTests() === false) {
161 expect(data.admin.email).to.equal('superadmin1@example.com')
164 expect(data.contactForm.enabled).to.be.false
166 expect(data.user.videoQuota).to.equal(5242881)
167 expect(data.user.videoQuotaDaily).to.equal(318742)
169 expect(data.videoChannels.maxPerUser).to.equal(24)
171 expect(data.transcoding.enabled).to.be.true
172 expect(data.transcoding.threads).to.equal(1)
173 expect(data.transcoding.concurrency).to.equal(3)
174 expect(data.transcoding.allowAdditionalExtensions).to.be.true
175 expect(data.transcoding.allowAudioFiles).to.be.true
176 expect(data.transcoding.profile).to.equal('vod_profile')
177 expect(data.transcoding.resolutions['144p']).to.be.false
178 expect(data.transcoding.resolutions['240p']).to.be.false
179 expect(data.transcoding.resolutions['360p']).to.be.true
180 expect(data.transcoding.resolutions['480p']).to.be.true
181 expect(data.transcoding.resolutions['720p']).to.be.false
182 expect(data.transcoding.resolutions['1080p']).to.be.false
183 expect(data.transcoding.resolutions['2160p']).to.be.false
184 expect(data.transcoding.hls.enabled).to.be.false
185 expect(data.transcoding.webtorrent.enabled).to.be.true
187 expect(data.live.enabled).to.be.true
188 expect(data.live.allowReplay).to.be.true
189 expect(data.live.latencySetting.enabled).to.be.false
190 expect(data.live.maxDuration).to.equal(5000)
191 expect(data.live.maxInstanceLives).to.equal(-1)
192 expect(data.live.maxUserLives).to.equal(10)
193 expect(data.live.transcoding.enabled).to.be.true
194 expect(data.live.transcoding.threads).to.equal(4)
195 expect(data.live.transcoding.profile).to.equal('live_profile')
196 expect(data.live.transcoding.resolutions['144p']).to.be.true
197 expect(data.live.transcoding.resolutions['240p']).to.be.true
198 expect(data.live.transcoding.resolutions['360p']).to.be.true
199 expect(data.live.transcoding.resolutions['480p']).to.be.true
200 expect(data.live.transcoding.resolutions['720p']).to.be.true
201 expect(data.live.transcoding.resolutions['1080p']).to.be.true
202 expect(data.live.transcoding.resolutions['2160p']).to.be.true
204 expect(data.videoStudio.enabled).to.be.true
206 expect(data.import.videos.concurrency).to.equal(4)
207 expect(data.import.videos.http.enabled).to.be.false
208 expect(data.import.videos.torrent.enabled).to.be.false
209 expect(data.autoBlacklist.videos.ofUsers.enabled).to.be.true
211 expect(data.followers.instance.enabled).to.be.false
212 expect(data.followers.instance.manualApproval).to.be.true
214 expect(data.followings.instance.autoFollowBack.enabled).to.be.true
215 expect(data.followings.instance.autoFollowIndex.enabled).to.be.true
216 expect(data.followings.instance.autoFollowIndex.indexUrl).to.equal('https://updated.example.com')
218 expect(data.broadcastMessage.enabled).to.be.true
219 expect(data.broadcastMessage.level).to.equal('error')
220 expect(data.broadcastMessage.message).to.equal('super bad message')
221 expect(data.broadcastMessage.dismissable).to.be.true
224 const newCustomConfig: CustomConfig = {
226 name: 'PeerTube updated',
227 shortDescription: 'my short description',
228 description: 'my super description',
229 terms: 'my super terms',
230 codeOfConduct: 'my super coc',
232 creationReason: 'my super creation reason',
233 moderationInformation: 'my super moderation information',
234 administrator: 'Kuja',
235 maintenanceLifetime: 'forever',
236 businessModel: 'my super business model',
237 hardwareInformation: '2vCore 3GB RAM',
239 languages: [ 'en', 'es' ],
240 categories: [ 1, 2 ],
243 defaultNSFWPolicy: 'blur' as 'blur',
245 defaultClientRoute: '/videos/recently-added',
248 javascript: 'alert("coucou")',
249 css: 'body { background-color: red; }'
264 preferAuthorDisplayName: true
269 redirectOnSingleExternalAuth: true
287 requiresEmailVerification: false,
291 email: 'superadmin1@example.com'
298 videoQuotaDaily: 318742
305 allowAdditionalExtensions: true,
306 allowAudioFiles: true,
309 profile: 'vod_profile',
335 maxInstanceLives: -1,
340 profile: 'live_profile',
370 enabled: [ 'hot', 'most-viewed', 'most-liked' ],
395 indexUrl: 'https://updated.example.com'
402 message: 'super bad message',
412 url: 'https://search.joinpeertube.org',
413 disableLocalSearch: true,
414 isDefaultSearch: true
419 describe('Test static config', function () {
420 let server: PeerTubeServer = null
422 before(async function () {
425 server = await createSingleServer(1, { webadmin: { configuration: { edition: { allowed: false } } } })
426 await setAccessTokensToServers([ server ])
429 it('Should tell the client that edits are not allowed', async function () {
430 const data = await server.config.getConfig()
432 expect(data.webadmin.configuration.edition.allowed).to.be.false
435 it('Should error when client tries to update', async function () {
436 await server.config.updateCustomConfig({ newCustomConfig, expectedStatus: 405 })
439 after(async function () {
440 await cleanupTests([ server ])
444 describe('Test config', function () {
445 let server: PeerTubeServer = null
447 before(async function () {
450 server = await createSingleServer(1)
451 await setAccessTokensToServers([ server ])
454 it('Should have a correct config on a server with registration enabled', async function () {
455 const data = await server.config.getConfig()
457 expect(data.signup.allowed).to.be.true
460 it('Should have a correct config on a server with registration enabled and a users limit', async function () {
464 server.users.register({ username: 'user1' }),
465 server.users.register({ username: 'user2' }),
466 server.users.register({ username: 'user3' })
469 const data = await server.config.getConfig()
471 expect(data.signup.allowed).to.be.false
474 it('Should have the correct video allowed extensions', async function () {
475 const data = await server.config.getConfig()
477 expect(data.video.file.extensions).to.have.lengthOf(3)
478 expect(data.video.file.extensions).to.contain('.mp4')
479 expect(data.video.file.extensions).to.contain('.webm')
480 expect(data.video.file.extensions).to.contain('.ogv')
482 await server.videos.upload({ attributes: { fixture: 'video_short.mkv' }, expectedStatus: HttpStatusCode.UNSUPPORTED_MEDIA_TYPE_415 })
483 await server.videos.upload({ attributes: { fixture: 'sample.ogg' }, expectedStatus: HttpStatusCode.UNSUPPORTED_MEDIA_TYPE_415 })
485 expect(data.contactForm.enabled).to.be.true
488 it('Should get the customized configuration', async function () {
489 const data = await server.config.getCustomConfig()
491 checkInitialConfig(server, data)
494 it('Should update the customized configuration', async function () {
495 await server.config.updateCustomConfig({ newCustomConfig })
497 const data = await server.config.getCustomConfig()
498 checkUpdatedConfig(data)
501 it('Should have the correct updated video allowed extensions', async function () {
504 const data = await server.config.getConfig()
506 expect(data.video.file.extensions).to.have.length.above(4)
507 expect(data.video.file.extensions).to.contain('.mp4')
508 expect(data.video.file.extensions).to.contain('.webm')
509 expect(data.video.file.extensions).to.contain('.ogv')
510 expect(data.video.file.extensions).to.contain('.flv')
511 expect(data.video.file.extensions).to.contain('.wmv')
512 expect(data.video.file.extensions).to.contain('.mkv')
513 expect(data.video.file.extensions).to.contain('.mp3')
514 expect(data.video.file.extensions).to.contain('.ogg')
515 expect(data.video.file.extensions).to.contain('.flac')
517 await server.videos.upload({ attributes: { fixture: 'video_short.mkv' }, expectedStatus: HttpStatusCode.OK_200 })
518 await server.videos.upload({ attributes: { fixture: 'sample.ogg' }, expectedStatus: HttpStatusCode.OK_200 })
521 it('Should have the configuration updated after a restart', async function () {
524 await killallServers([ server ])
528 const data = await server.config.getCustomConfig()
530 checkUpdatedConfig(data)
533 it('Should fetch the about information', async function () {
534 const data = await server.config.getAbout()
536 expect(data.instance.name).to.equal('PeerTube updated')
537 expect(data.instance.shortDescription).to.equal('my short description')
538 expect(data.instance.description).to.equal('my super description')
539 expect(data.instance.terms).to.equal('my super terms')
540 expect(data.instance.codeOfConduct).to.equal('my super coc')
542 expect(data.instance.creationReason).to.equal('my super creation reason')
543 expect(data.instance.moderationInformation).to.equal('my super moderation information')
544 expect(data.instance.administrator).to.equal('Kuja')
545 expect(data.instance.maintenanceLifetime).to.equal('forever')
546 expect(data.instance.businessModel).to.equal('my super business model')
547 expect(data.instance.hardwareInformation).to.equal('2vCore 3GB RAM')
549 expect(data.instance.languages).to.deep.equal([ 'en', 'es' ])
550 expect(data.instance.categories).to.deep.equal([ 1, 2 ])
553 it('Should remove the custom configuration', async function () {
556 await server.config.deleteCustomConfig()
558 const data = await server.config.getCustomConfig()
559 checkInitialConfig(server, data)
562 it('Should enable frameguard', async function () {
566 const res = await makeGetRequest({
568 path: '/api/v1/config',
572 expect(res.headers['x-frame-options']).to.exist
575 await killallServers([ server ])
579 frameguard: { enabled: false }
582 await server.run(config)
585 const res = await makeGetRequest({
587 path: '/api/v1/config',
591 expect(res.headers['x-frame-options']).to.not.exist
595 after(async function () {
596 await cleanupTests([ server ])