1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
3 import { expect } from 'chai'
4 import { parallelTests } from '@shared/core-utils'
5 import { CustomConfig, HttpStatusCode } from '@shared/models'
12 setAccessTokensToServers
13 } from '@shared/server-commands'
15 function checkInitialConfig (server: PeerTubeServer, data: CustomConfig) {
16 expect(data.instance.name).to.equal('PeerTube')
17 expect(data.instance.shortDescription).to.equal(
18 'PeerTube, an ActivityPub-federated video streaming platform using P2P directly in your web browser.'
20 expect(data.instance.description).to.equal('Welcome to this PeerTube instance!')
22 expect(data.instance.terms).to.equal('No terms for now.')
23 expect(data.instance.creationReason).to.be.empty
24 expect(data.instance.codeOfConduct).to.be.empty
25 expect(data.instance.moderationInformation).to.be.empty
26 expect(data.instance.administrator).to.be.empty
27 expect(data.instance.maintenanceLifetime).to.be.empty
28 expect(data.instance.businessModel).to.be.empty
29 expect(data.instance.hardwareInformation).to.be.empty
31 expect(data.instance.languages).to.have.lengthOf(0)
32 expect(data.instance.categories).to.have.lengthOf(0)
34 expect(data.instance.defaultClientRoute).to.equal('/videos/trending')
35 expect(data.instance.isNSFW).to.be.false
36 expect(data.instance.defaultNSFWPolicy).to.equal('display')
37 expect(data.instance.customizations.css).to.be.empty
38 expect(data.instance.customizations.javascript).to.be.empty
40 expect(data.services.twitter.username).to.equal('@Chocobozzz')
41 expect(data.services.twitter.whitelisted).to.be.false
43 expect(data.client.videos.miniature.preferAuthorDisplayName).to.be.false
44 expect(data.client.menu.login.redirectOnSingleExternalAuth).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.requiresApproval).to.be.false
54 expect(data.signup.requiresEmailVerification).to.be.false
56 expect(data.admin.email).to.equal('admin' + server.internalServerNumber + '@example.com')
57 expect(data.contactForm.enabled).to.be.true
59 expect(data.user.history.videos.enabled).to.be.true
60 expect(data.user.videoQuota).to.equal(5242880)
61 expect(data.user.videoQuotaDaily).to.equal(-1)
63 expect(data.videoChannels.maxPerUser).to.equal(20)
65 expect(data.transcoding.enabled).to.be.false
66 expect(data.transcoding.allowAdditionalExtensions).to.be.false
67 expect(data.transcoding.allowAudioFiles).to.be.false
68 expect(data.transcoding.threads).to.equal(2)
69 expect(data.transcoding.concurrency).to.equal(2)
70 expect(data.transcoding.profile).to.equal('default')
71 expect(data.transcoding.resolutions['144p']).to.be.false
72 expect(data.transcoding.resolutions['240p']).to.be.true
73 expect(data.transcoding.resolutions['360p']).to.be.true
74 expect(data.transcoding.resolutions['480p']).to.be.true
75 expect(data.transcoding.resolutions['720p']).to.be.true
76 expect(data.transcoding.resolutions['1080p']).to.be.true
77 expect(data.transcoding.resolutions['1440p']).to.be.true
78 expect(data.transcoding.resolutions['2160p']).to.be.true
79 expect(data.transcoding.alwaysTranscodeOriginalResolution).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
100 expect(data.live.transcoding.alwaysTranscodeOriginalResolution).to.be.true
102 expect(data.videoStudio.enabled).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.client.videos.miniature.preferAuthorDisplayName).to.be.true
149 expect(data.client.menu.login.redirectOnSingleExternalAuth).to.be.true
151 expect(data.cache.previews.size).to.equal(2)
152 expect(data.cache.captions.size).to.equal(3)
153 expect(data.cache.torrents.size).to.equal(4)
155 expect(data.signup.enabled).to.be.false
156 expect(data.signup.limit).to.equal(5)
157 expect(data.signup.requiresApproval).to.be.false
158 expect(data.signup.requiresEmailVerification).to.be.false
159 expect(data.signup.minimumAge).to.equal(10)
161 // We override admin email in parallel tests, so skip this exception
162 if (parallelTests() === false) {
163 expect(data.admin.email).to.equal('superadmin1@example.com')
166 expect(data.contactForm.enabled).to.be.false
168 expect(data.user.history.videos.enabled).to.be.false
169 expect(data.user.videoQuota).to.equal(5242881)
170 expect(data.user.videoQuotaDaily).to.equal(318742)
172 expect(data.videoChannels.maxPerUser).to.equal(24)
174 expect(data.transcoding.enabled).to.be.true
175 expect(data.transcoding.threads).to.equal(1)
176 expect(data.transcoding.concurrency).to.equal(3)
177 expect(data.transcoding.allowAdditionalExtensions).to.be.true
178 expect(data.transcoding.allowAudioFiles).to.be.true
179 expect(data.transcoding.profile).to.equal('vod_profile')
180 expect(data.transcoding.resolutions['144p']).to.be.false
181 expect(data.transcoding.resolutions['240p']).to.be.false
182 expect(data.transcoding.resolutions['360p']).to.be.true
183 expect(data.transcoding.resolutions['480p']).to.be.true
184 expect(data.transcoding.resolutions['720p']).to.be.false
185 expect(data.transcoding.resolutions['1080p']).to.be.false
186 expect(data.transcoding.resolutions['2160p']).to.be.false
187 expect(data.transcoding.alwaysTranscodeOriginalResolution).to.be.false
188 expect(data.transcoding.hls.enabled).to.be.false
189 expect(data.transcoding.webtorrent.enabled).to.be.true
191 expect(data.live.enabled).to.be.true
192 expect(data.live.allowReplay).to.be.true
193 expect(data.live.latencySetting.enabled).to.be.false
194 expect(data.live.maxDuration).to.equal(5000)
195 expect(data.live.maxInstanceLives).to.equal(-1)
196 expect(data.live.maxUserLives).to.equal(10)
197 expect(data.live.transcoding.enabled).to.be.true
198 expect(data.live.transcoding.threads).to.equal(4)
199 expect(data.live.transcoding.profile).to.equal('live_profile')
200 expect(data.live.transcoding.resolutions['144p']).to.be.true
201 expect(data.live.transcoding.resolutions['240p']).to.be.true
202 expect(data.live.transcoding.resolutions['360p']).to.be.true
203 expect(data.live.transcoding.resolutions['480p']).to.be.true
204 expect(data.live.transcoding.resolutions['720p']).to.be.true
205 expect(data.live.transcoding.resolutions['1080p']).to.be.true
206 expect(data.live.transcoding.resolutions['2160p']).to.be.true
207 expect(data.live.transcoding.alwaysTranscodeOriginalResolution).to.be.false
209 expect(data.videoStudio.enabled).to.be.true
211 expect(data.import.videos.concurrency).to.equal(4)
212 expect(data.import.videos.http.enabled).to.be.false
213 expect(data.import.videos.torrent.enabled).to.be.false
214 expect(data.autoBlacklist.videos.ofUsers.enabled).to.be.true
216 expect(data.followers.instance.enabled).to.be.false
217 expect(data.followers.instance.manualApproval).to.be.true
219 expect(data.followings.instance.autoFollowBack.enabled).to.be.true
220 expect(data.followings.instance.autoFollowIndex.enabled).to.be.true
221 expect(data.followings.instance.autoFollowIndex.indexUrl).to.equal('https://updated.example.com')
223 expect(data.broadcastMessage.enabled).to.be.true
224 expect(data.broadcastMessage.level).to.equal('error')
225 expect(data.broadcastMessage.message).to.equal('super bad message')
226 expect(data.broadcastMessage.dismissable).to.be.true
229 const newCustomConfig: CustomConfig = {
231 name: 'PeerTube updated',
232 shortDescription: 'my short description',
233 description: 'my super description',
234 terms: 'my super terms',
235 codeOfConduct: 'my super coc',
237 creationReason: 'my super creation reason',
238 moderationInformation: 'my super moderation information',
239 administrator: 'Kuja',
240 maintenanceLifetime: 'forever',
241 businessModel: 'my super business model',
242 hardwareInformation: '2vCore 3GB RAM',
244 languages: [ 'en', 'es' ],
245 categories: [ 1, 2 ],
248 defaultNSFWPolicy: 'blur' as 'blur',
250 defaultClientRoute: '/videos/recently-added',
253 javascript: 'alert("coucou")',
254 css: 'body { background-color: red; }'
269 preferAuthorDisplayName: true
274 redirectOnSingleExternalAuth: true
292 requiresApproval: false,
293 requiresEmailVerification: false,
297 email: 'superadmin1@example.com'
309 videoQuotaDaily: 318742
316 allowAdditionalExtensions: true,
317 allowAudioFiles: true,
320 profile: 'vod_profile',
332 alwaysTranscodeOriginalResolution: false,
347 maxInstanceLives: -1,
352 profile: 'live_profile',
363 alwaysTranscodeOriginalResolution: false
379 videoChannelSynchronization: {
387 enabled: [ 'hot', 'most-viewed', 'most-liked' ],
412 indexUrl: 'https://updated.example.com'
419 message: 'super bad message',
429 url: 'https://search.joinpeertube.org',
430 disableLocalSearch: true,
431 isDefaultSearch: true
436 describe('Test static config', function () {
437 let server: PeerTubeServer = null
439 before(async function () {
442 server = await createSingleServer(1, { webadmin: { configuration: { edition: { allowed: false } } } })
443 await setAccessTokensToServers([ server ])
446 it('Should tell the client that edits are not allowed', async function () {
447 const data = await server.config.getConfig()
449 expect(data.webadmin.configuration.edition.allowed).to.be.false
452 it('Should error when client tries to update', async function () {
453 await server.config.updateCustomConfig({ newCustomConfig, expectedStatus: 405 })
456 after(async function () {
457 await cleanupTests([ server ])
461 describe('Test config', function () {
462 let server: PeerTubeServer = null
464 before(async function () {
467 server = await createSingleServer(1)
468 await setAccessTokensToServers([ server ])
471 it('Should have a correct config on a server with registration enabled', async function () {
472 const data = await server.config.getConfig()
474 expect(data.signup.allowed).to.be.true
477 it('Should have a correct config on a server with registration enabled and a users limit', async function () {
481 server.registrations.register({ username: 'user1' }),
482 server.registrations.register({ username: 'user2' }),
483 server.registrations.register({ username: 'user3' })
486 const data = await server.config.getConfig()
488 expect(data.signup.allowed).to.be.false
491 it('Should have the correct video allowed extensions', async function () {
492 const data = await server.config.getConfig()
494 expect(data.video.file.extensions).to.have.lengthOf(3)
495 expect(data.video.file.extensions).to.contain('.mp4')
496 expect(data.video.file.extensions).to.contain('.webm')
497 expect(data.video.file.extensions).to.contain('.ogv')
499 await server.videos.upload({ attributes: { fixture: 'video_short.mkv' }, expectedStatus: HttpStatusCode.UNSUPPORTED_MEDIA_TYPE_415 })
500 await server.videos.upload({ attributes: { fixture: 'sample.ogg' }, expectedStatus: HttpStatusCode.UNSUPPORTED_MEDIA_TYPE_415 })
502 expect(data.contactForm.enabled).to.be.true
505 it('Should get the customized configuration', async function () {
506 const data = await server.config.getCustomConfig()
508 checkInitialConfig(server, data)
511 it('Should update the customized configuration', async function () {
512 await server.config.updateCustomConfig({ newCustomConfig })
514 const data = await server.config.getCustomConfig()
515 checkUpdatedConfig(data)
518 it('Should have the correct updated video allowed extensions', async function () {
521 const data = await server.config.getConfig()
523 expect(data.video.file.extensions).to.have.length.above(4)
524 expect(data.video.file.extensions).to.contain('.mp4')
525 expect(data.video.file.extensions).to.contain('.webm')
526 expect(data.video.file.extensions).to.contain('.ogv')
527 expect(data.video.file.extensions).to.contain('.flv')
528 expect(data.video.file.extensions).to.contain('.wmv')
529 expect(data.video.file.extensions).to.contain('.mkv')
530 expect(data.video.file.extensions).to.contain('.mp3')
531 expect(data.video.file.extensions).to.contain('.ogg')
532 expect(data.video.file.extensions).to.contain('.flac')
534 await server.videos.upload({ attributes: { fixture: 'video_short.mkv' }, expectedStatus: HttpStatusCode.OK_200 })
535 await server.videos.upload({ attributes: { fixture: 'sample.ogg' }, expectedStatus: HttpStatusCode.OK_200 })
538 it('Should have the configuration updated after a restart', async function () {
541 await killallServers([ server ])
545 const data = await server.config.getCustomConfig()
547 checkUpdatedConfig(data)
550 it('Should fetch the about information', async function () {
551 const data = await server.config.getAbout()
553 expect(data.instance.name).to.equal('PeerTube updated')
554 expect(data.instance.shortDescription).to.equal('my short description')
555 expect(data.instance.description).to.equal('my super description')
556 expect(data.instance.terms).to.equal('my super terms')
557 expect(data.instance.codeOfConduct).to.equal('my super coc')
559 expect(data.instance.creationReason).to.equal('my super creation reason')
560 expect(data.instance.moderationInformation).to.equal('my super moderation information')
561 expect(data.instance.administrator).to.equal('Kuja')
562 expect(data.instance.maintenanceLifetime).to.equal('forever')
563 expect(data.instance.businessModel).to.equal('my super business model')
564 expect(data.instance.hardwareInformation).to.equal('2vCore 3GB RAM')
566 expect(data.instance.languages).to.deep.equal([ 'en', 'es' ])
567 expect(data.instance.categories).to.deep.equal([ 1, 2 ])
570 it('Should remove the custom configuration', async function () {
571 await server.config.deleteCustomConfig()
573 const data = await server.config.getCustomConfig()
574 checkInitialConfig(server, data)
577 it('Should enable/disable security headers', async function () {
581 const res = await makeGetRequest({
583 path: '/api/v1/config',
587 expect(res.headers['x-frame-options']).to.exist
588 expect(res.headers['x-powered-by']).to.equal('PeerTube')
591 await killallServers([ server ])
595 frameguard: { enabled: false },
596 powered_by_header: { enabled: false }
599 await server.run(config)
602 const res = await makeGetRequest({
604 path: '/api/v1/config',
608 expect(res.headers['x-frame-options']).to.not.exist
609 expect(res.headers['x-powered-by']).to.not.exist
613 after(async function () {
614 await cleanupTests([ server ])