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.maxDuration).to.equal(-1)
86 expect(data.live.maxInstanceLives).to.equal(20)
87 expect(data.live.maxUserLives).to.equal(3)
88 expect(data.live.transcoding.enabled).to.be.false
89 expect(data.live.transcoding.threads).to.equal(2)
90 expect(data.live.transcoding.profile).to.equal('default')
91 expect(data.live.transcoding.resolutions['144p']).to.be.false
92 expect(data.live.transcoding.resolutions['240p']).to.be.false
93 expect(data.live.transcoding.resolutions['360p']).to.be.false
94 expect(data.live.transcoding.resolutions['480p']).to.be.false
95 expect(data.live.transcoding.resolutions['720p']).to.be.false
96 expect(data.live.transcoding.resolutions['1080p']).to.be.false
97 expect(data.live.transcoding.resolutions['1440p']).to.be.false
98 expect(data.live.transcoding.resolutions['2160p']).to.be.false
100 expect(data.import.videos.concurrency).to.equal(2)
101 expect(data.import.videos.http.enabled).to.be.true
102 expect(data.import.videos.torrent.enabled).to.be.true
103 expect(data.autoBlacklist.videos.ofUsers.enabled).to.be.false
105 expect(data.followers.instance.enabled).to.be.true
106 expect(data.followers.instance.manualApproval).to.be.false
108 expect(data.followings.instance.autoFollowBack.enabled).to.be.false
109 expect(data.followings.instance.autoFollowIndex.enabled).to.be.false
110 expect(data.followings.instance.autoFollowIndex.indexUrl).to.equal('')
112 expect(data.broadcastMessage.enabled).to.be.false
113 expect(data.broadcastMessage.level).to.equal('info')
114 expect(data.broadcastMessage.message).to.equal('')
115 expect(data.broadcastMessage.dismissable).to.be.false
118 function checkUpdatedConfig (data: CustomConfig) {
119 expect(data.instance.name).to.equal('PeerTube updated')
120 expect(data.instance.shortDescription).to.equal('my short description')
121 expect(data.instance.description).to.equal('my super description')
123 expect(data.instance.terms).to.equal('my super terms')
124 expect(data.instance.creationReason).to.equal('my super creation reason')
125 expect(data.instance.codeOfConduct).to.equal('my super coc')
126 expect(data.instance.moderationInformation).to.equal('my super moderation information')
127 expect(data.instance.administrator).to.equal('Kuja')
128 expect(data.instance.maintenanceLifetime).to.equal('forever')
129 expect(data.instance.businessModel).to.equal('my super business model')
130 expect(data.instance.hardwareInformation).to.equal('2vCore 3GB RAM')
132 expect(data.instance.languages).to.deep.equal([ 'en', 'es' ])
133 expect(data.instance.categories).to.deep.equal([ 1, 2 ])
135 expect(data.instance.defaultClientRoute).to.equal('/videos/recently-added')
136 expect(data.instance.isNSFW).to.be.true
137 expect(data.instance.defaultNSFWPolicy).to.equal('blur')
138 expect(data.instance.customizations.javascript).to.equal('alert("coucou")')
139 expect(data.instance.customizations.css).to.equal('body { background-color: red; }')
141 expect(data.services.twitter.username).to.equal('@Kuja')
142 expect(data.services.twitter.whitelisted).to.be.true
144 expect(data.client.videos.miniature.preferAuthorDisplayName).to.be.true
145 expect(data.client.menu.login.redirectOnSingleExternalAuth).to.be.true
147 expect(data.cache.previews.size).to.equal(2)
148 expect(data.cache.captions.size).to.equal(3)
149 expect(data.cache.torrents.size).to.equal(4)
151 expect(data.signup.enabled).to.be.false
152 expect(data.signup.limit).to.equal(5)
153 expect(data.signup.requiresEmailVerification).to.be.false
154 expect(data.signup.minimumAge).to.equal(10)
156 // We override admin email in parallel tests, so skip this exception
157 if (parallelTests() === false) {
158 expect(data.admin.email).to.equal('superadmin1@example.com')
161 expect(data.contactForm.enabled).to.be.false
163 expect(data.user.videoQuota).to.equal(5242881)
164 expect(data.user.videoQuotaDaily).to.equal(318742)
166 expect(data.videoChannels.maxPerUser).to.equal(24)
168 expect(data.transcoding.enabled).to.be.true
169 expect(data.transcoding.threads).to.equal(1)
170 expect(data.transcoding.concurrency).to.equal(3)
171 expect(data.transcoding.allowAdditionalExtensions).to.be.true
172 expect(data.transcoding.allowAudioFiles).to.be.true
173 expect(data.transcoding.profile).to.equal('vod_profile')
174 expect(data.transcoding.resolutions['144p']).to.be.false
175 expect(data.transcoding.resolutions['240p']).to.be.false
176 expect(data.transcoding.resolutions['360p']).to.be.true
177 expect(data.transcoding.resolutions['480p']).to.be.true
178 expect(data.transcoding.resolutions['720p']).to.be.false
179 expect(data.transcoding.resolutions['1080p']).to.be.false
180 expect(data.transcoding.resolutions['2160p']).to.be.false
181 expect(data.transcoding.hls.enabled).to.be.false
182 expect(data.transcoding.webtorrent.enabled).to.be.true
184 expect(data.live.enabled).to.be.true
185 expect(data.live.allowReplay).to.be.true
186 expect(data.live.maxDuration).to.equal(5000)
187 expect(data.live.maxInstanceLives).to.equal(-1)
188 expect(data.live.maxUserLives).to.equal(10)
189 expect(data.live.transcoding.enabled).to.be.true
190 expect(data.live.transcoding.threads).to.equal(4)
191 expect(data.live.transcoding.profile).to.equal('live_profile')
192 expect(data.live.transcoding.resolutions['144p']).to.be.true
193 expect(data.live.transcoding.resolutions['240p']).to.be.true
194 expect(data.live.transcoding.resolutions['360p']).to.be.true
195 expect(data.live.transcoding.resolutions['480p']).to.be.true
196 expect(data.live.transcoding.resolutions['720p']).to.be.true
197 expect(data.live.transcoding.resolutions['1080p']).to.be.true
198 expect(data.live.transcoding.resolutions['2160p']).to.be.true
200 expect(data.import.videos.concurrency).to.equal(4)
201 expect(data.import.videos.http.enabled).to.be.false
202 expect(data.import.videos.torrent.enabled).to.be.false
203 expect(data.autoBlacklist.videos.ofUsers.enabled).to.be.true
205 expect(data.followers.instance.enabled).to.be.false
206 expect(data.followers.instance.manualApproval).to.be.true
208 expect(data.followings.instance.autoFollowBack.enabled).to.be.true
209 expect(data.followings.instance.autoFollowIndex.enabled).to.be.true
210 expect(data.followings.instance.autoFollowIndex.indexUrl).to.equal('https://updated.example.com')
212 expect(data.broadcastMessage.enabled).to.be.true
213 expect(data.broadcastMessage.level).to.equal('error')
214 expect(data.broadcastMessage.message).to.equal('super bad message')
215 expect(data.broadcastMessage.dismissable).to.be.true
218 const newCustomConfig: CustomConfig = {
220 name: 'PeerTube updated',
221 shortDescription: 'my short description',
222 description: 'my super description',
223 terms: 'my super terms',
224 codeOfConduct: 'my super coc',
226 creationReason: 'my super creation reason',
227 moderationInformation: 'my super moderation information',
228 administrator: 'Kuja',
229 maintenanceLifetime: 'forever',
230 businessModel: 'my super business model',
231 hardwareInformation: '2vCore 3GB RAM',
233 languages: [ 'en', 'es' ],
234 categories: [ 1, 2 ],
237 defaultNSFWPolicy: 'blur' as 'blur',
239 defaultClientRoute: '/videos/recently-added',
242 javascript: 'alert("coucou")',
243 css: 'body { background-color: red; }'
258 preferAuthorDisplayName: true
263 redirectOnSingleExternalAuth: true
281 requiresEmailVerification: false,
285 email: 'superadmin1@example.com'
292 videoQuotaDaily: 318742
299 allowAdditionalExtensions: true,
300 allowAudioFiles: true,
303 profile: 'vod_profile',
326 maxInstanceLives: -1,
331 profile: 'live_profile',
358 enabled: [ 'best', 'hot', 'most-viewed', 'most-liked' ],
383 indexUrl: 'https://updated.example.com'
390 message: 'super bad message',
400 url: 'https://search.joinpeertube.org',
401 disableLocalSearch: true,
402 isDefaultSearch: true
407 describe('Test static config', function () {
408 let server: PeerTubeServer = null
410 before(async function () {
413 server = await createSingleServer(1, { webadmin: { configuration: { edition: { allowed: false } } } })
414 await setAccessTokensToServers([ server ])
417 it('Should tell the client that edits are not allowed', async function () {
418 const data = await server.config.getConfig()
420 expect(data.webadmin.configuration.edition.allowed).to.be.false
423 it('Should error when client tries to update', async function () {
424 await server.config.updateCustomConfig({ newCustomConfig, expectedStatus: 405 })
427 after(async function () {
428 await cleanupTests([ server ])
432 describe('Test config', function () {
433 let server: PeerTubeServer = null
435 before(async function () {
438 server = await createSingleServer(1)
439 await setAccessTokensToServers([ server ])
442 it('Should have a correct config on a server with registration enabled', async function () {
443 const data = await server.config.getConfig()
445 expect(data.signup.allowed).to.be.true
448 it('Should have a correct config on a server with registration enabled and a users limit', async function () {
452 server.users.register({ username: 'user1' }),
453 server.users.register({ username: 'user2' }),
454 server.users.register({ username: 'user3' })
457 const data = await server.config.getConfig()
459 expect(data.signup.allowed).to.be.false
462 it('Should have the correct video allowed extensions', async function () {
463 const data = await server.config.getConfig()
465 expect(data.video.file.extensions).to.have.lengthOf(3)
466 expect(data.video.file.extensions).to.contain('.mp4')
467 expect(data.video.file.extensions).to.contain('.webm')
468 expect(data.video.file.extensions).to.contain('.ogv')
470 await server.videos.upload({ attributes: { fixture: 'video_short.mkv' }, expectedStatus: HttpStatusCode.UNSUPPORTED_MEDIA_TYPE_415 })
471 await server.videos.upload({ attributes: { fixture: 'sample.ogg' }, expectedStatus: HttpStatusCode.UNSUPPORTED_MEDIA_TYPE_415 })
473 expect(data.contactForm.enabled).to.be.true
476 it('Should get the customized configuration', async function () {
477 const data = await server.config.getCustomConfig()
479 checkInitialConfig(server, data)
482 it('Should update the customized configuration', async function () {
483 await server.config.updateCustomConfig({ newCustomConfig })
485 const data = await server.config.getCustomConfig()
486 checkUpdatedConfig(data)
489 it('Should have the correct updated video allowed extensions', async function () {
492 const data = await server.config.getConfig()
494 expect(data.video.file.extensions).to.have.length.above(4)
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')
498 expect(data.video.file.extensions).to.contain('.flv')
499 expect(data.video.file.extensions).to.contain('.wmv')
500 expect(data.video.file.extensions).to.contain('.mkv')
501 expect(data.video.file.extensions).to.contain('.mp3')
502 expect(data.video.file.extensions).to.contain('.ogg')
503 expect(data.video.file.extensions).to.contain('.flac')
505 await server.videos.upload({ attributes: { fixture: 'video_short.mkv' }, expectedStatus: HttpStatusCode.OK_200 })
506 await server.videos.upload({ attributes: { fixture: 'sample.ogg' }, expectedStatus: HttpStatusCode.OK_200 })
509 it('Should have the configuration updated after a restart', async function () {
512 await killallServers([ server ])
516 const data = await server.config.getCustomConfig()
518 checkUpdatedConfig(data)
521 it('Should fetch the about information', async function () {
522 const data = await server.config.getAbout()
524 expect(data.instance.name).to.equal('PeerTube updated')
525 expect(data.instance.shortDescription).to.equal('my short description')
526 expect(data.instance.description).to.equal('my super description')
527 expect(data.instance.terms).to.equal('my super terms')
528 expect(data.instance.codeOfConduct).to.equal('my super coc')
530 expect(data.instance.creationReason).to.equal('my super creation reason')
531 expect(data.instance.moderationInformation).to.equal('my super moderation information')
532 expect(data.instance.administrator).to.equal('Kuja')
533 expect(data.instance.maintenanceLifetime).to.equal('forever')
534 expect(data.instance.businessModel).to.equal('my super business model')
535 expect(data.instance.hardwareInformation).to.equal('2vCore 3GB RAM')
537 expect(data.instance.languages).to.deep.equal([ 'en', 'es' ])
538 expect(data.instance.categories).to.deep.equal([ 1, 2 ])
541 it('Should remove the custom configuration', async function () {
544 await server.config.deleteCustomConfig()
546 const data = await server.config.getCustomConfig()
547 checkInitialConfig(server, data)
550 it('Should enable frameguard', async function () {
554 const res = await makeGetRequest({
556 path: '/api/v1/config',
560 expect(res.headers['x-frame-options']).to.exist
563 await killallServers([ server ])
567 frameguard: { enabled: false }
570 await server.run(config)
573 const res = await makeGetRequest({
575 path: '/api/v1/config',
579 expect(res.headers['x-frame-options']).to.not.exist
583 after(async function () {
584 await cleanupTests([ server ])