1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
4 import * as chai from 'chai'
5 import { HttpStatusCode } from '@shared/core-utils'
14 setAccessTokensToServers
15 } from '@shared/extra-utils'
16 import { CustomConfig } from '@shared/models'
18 const expect = chai.expect
20 function checkInitialConfig (server: ServerInfo, data: CustomConfig) {
21 expect(data.instance.name).to.equal('PeerTube')
22 expect(data.instance.shortDescription).to.equal(
23 'PeerTube, an ActivityPub-federated video streaming platform using P2P directly in your web browser.'
25 expect(data.instance.description).to.equal('Welcome to this PeerTube instance!')
27 expect(data.instance.terms).to.equal('No terms for now.')
28 expect(data.instance.creationReason).to.be.empty
29 expect(data.instance.codeOfConduct).to.be.empty
30 expect(data.instance.moderationInformation).to.be.empty
31 expect(data.instance.administrator).to.be.empty
32 expect(data.instance.maintenanceLifetime).to.be.empty
33 expect(data.instance.businessModel).to.be.empty
34 expect(data.instance.hardwareInformation).to.be.empty
36 expect(data.instance.languages).to.have.lengthOf(0)
37 expect(data.instance.categories).to.have.lengthOf(0)
39 expect(data.instance.defaultClientRoute).to.equal('/videos/trending')
40 expect(data.instance.isNSFW).to.be.false
41 expect(data.instance.defaultNSFWPolicy).to.equal('display')
42 expect(data.instance.customizations.css).to.be.empty
43 expect(data.instance.customizations.javascript).to.be.empty
45 expect(data.services.twitter.username).to.equal('@Chocobozzz')
46 expect(data.services.twitter.whitelisted).to.be.false
48 expect(data.cache.previews.size).to.equal(1)
49 expect(data.cache.captions.size).to.equal(1)
50 expect(data.cache.torrents.size).to.equal(1)
52 expect(data.signup.enabled).to.be.true
53 expect(data.signup.limit).to.equal(4)
54 expect(data.signup.minimumAge).to.equal(16)
55 expect(data.signup.requiresEmailVerification).to.be.false
57 expect(data.admin.email).to.equal('admin' + server.internalServerNumber + '@example.com')
58 expect(data.contactForm.enabled).to.be.true
60 expect(data.user.videoQuota).to.equal(5242880)
61 expect(data.user.videoQuotaDaily).to.equal(-1)
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['240p']).to.be.true
70 expect(data.transcoding.resolutions['360p']).to.be.true
71 expect(data.transcoding.resolutions['480p']).to.be.true
72 expect(data.transcoding.resolutions['720p']).to.be.true
73 expect(data.transcoding.resolutions['1080p']).to.be.true
74 expect(data.transcoding.resolutions['1440p']).to.be.true
75 expect(data.transcoding.resolutions['2160p']).to.be.true
76 expect(data.transcoding.webtorrent.enabled).to.be.true
77 expect(data.transcoding.hls.enabled).to.be.true
79 expect(data.live.enabled).to.be.false
80 expect(data.live.allowReplay).to.be.false
81 expect(data.live.maxDuration).to.equal(-1)
82 expect(data.live.maxInstanceLives).to.equal(20)
83 expect(data.live.maxUserLives).to.equal(3)
84 expect(data.live.transcoding.enabled).to.be.false
85 expect(data.live.transcoding.threads).to.equal(2)
86 expect(data.live.transcoding.profile).to.equal('default')
87 expect(data.live.transcoding.resolutions['240p']).to.be.false
88 expect(data.live.transcoding.resolutions['360p']).to.be.false
89 expect(data.live.transcoding.resolutions['480p']).to.be.false
90 expect(data.live.transcoding.resolutions['720p']).to.be.false
91 expect(data.live.transcoding.resolutions['1080p']).to.be.false
92 expect(data.live.transcoding.resolutions['1440p']).to.be.false
93 expect(data.live.transcoding.resolutions['2160p']).to.be.false
95 expect(data.import.videos.concurrency).to.equal(2)
96 expect(data.import.videos.http.enabled).to.be.true
97 expect(data.import.videos.torrent.enabled).to.be.true
98 expect(data.autoBlacklist.videos.ofUsers.enabled).to.be.false
100 expect(data.followers.instance.enabled).to.be.true
101 expect(data.followers.instance.manualApproval).to.be.false
103 expect(data.followings.instance.autoFollowBack.enabled).to.be.false
104 expect(data.followings.instance.autoFollowIndex.enabled).to.be.false
105 expect(data.followings.instance.autoFollowIndex.indexUrl).to.equal('')
107 expect(data.broadcastMessage.enabled).to.be.false
108 expect(data.broadcastMessage.level).to.equal('info')
109 expect(data.broadcastMessage.message).to.equal('')
110 expect(data.broadcastMessage.dismissable).to.be.false
113 function checkUpdatedConfig (data: CustomConfig) {
114 expect(data.instance.name).to.equal('PeerTube updated')
115 expect(data.instance.shortDescription).to.equal('my short description')
116 expect(data.instance.description).to.equal('my super description')
118 expect(data.instance.terms).to.equal('my super terms')
119 expect(data.instance.creationReason).to.equal('my super creation reason')
120 expect(data.instance.codeOfConduct).to.equal('my super coc')
121 expect(data.instance.moderationInformation).to.equal('my super moderation information')
122 expect(data.instance.administrator).to.equal('Kuja')
123 expect(data.instance.maintenanceLifetime).to.equal('forever')
124 expect(data.instance.businessModel).to.equal('my super business model')
125 expect(data.instance.hardwareInformation).to.equal('2vCore 3GB RAM')
127 expect(data.instance.languages).to.deep.equal([ 'en', 'es' ])
128 expect(data.instance.categories).to.deep.equal([ 1, 2 ])
130 expect(data.instance.defaultClientRoute).to.equal('/videos/recently-added')
131 expect(data.instance.isNSFW).to.be.true
132 expect(data.instance.defaultNSFWPolicy).to.equal('blur')
133 expect(data.instance.customizations.javascript).to.equal('alert("coucou")')
134 expect(data.instance.customizations.css).to.equal('body { background-color: red; }')
136 expect(data.services.twitter.username).to.equal('@Kuja')
137 expect(data.services.twitter.whitelisted).to.be.true
139 expect(data.cache.previews.size).to.equal(2)
140 expect(data.cache.captions.size).to.equal(3)
141 expect(data.cache.torrents.size).to.equal(4)
143 expect(data.signup.enabled).to.be.false
144 expect(data.signup.limit).to.equal(5)
145 expect(data.signup.requiresEmailVerification).to.be.false
146 expect(data.signup.minimumAge).to.equal(10)
148 // We override admin email in parallel tests, so skip this exception
149 if (parallelTests() === false) {
150 expect(data.admin.email).to.equal('superadmin1@example.com')
153 expect(data.contactForm.enabled).to.be.false
155 expect(data.user.videoQuota).to.equal(5242881)
156 expect(data.user.videoQuotaDaily).to.equal(318742)
158 expect(data.transcoding.enabled).to.be.true
159 expect(data.transcoding.threads).to.equal(1)
160 expect(data.transcoding.concurrency).to.equal(3)
161 expect(data.transcoding.allowAdditionalExtensions).to.be.true
162 expect(data.transcoding.allowAudioFiles).to.be.true
163 expect(data.transcoding.profile).to.equal('vod_profile')
164 expect(data.transcoding.resolutions['240p']).to.be.false
165 expect(data.transcoding.resolutions['360p']).to.be.true
166 expect(data.transcoding.resolutions['480p']).to.be.true
167 expect(data.transcoding.resolutions['720p']).to.be.false
168 expect(data.transcoding.resolutions['1080p']).to.be.false
169 expect(data.transcoding.resolutions['2160p']).to.be.false
170 expect(data.transcoding.hls.enabled).to.be.false
171 expect(data.transcoding.webtorrent.enabled).to.be.true
173 expect(data.live.enabled).to.be.true
174 expect(data.live.allowReplay).to.be.true
175 expect(data.live.maxDuration).to.equal(5000)
176 expect(data.live.maxInstanceLives).to.equal(-1)
177 expect(data.live.maxUserLives).to.equal(10)
178 expect(data.live.transcoding.enabled).to.be.true
179 expect(data.live.transcoding.threads).to.equal(4)
180 expect(data.live.transcoding.profile).to.equal('live_profile')
181 expect(data.live.transcoding.resolutions['240p']).to.be.true
182 expect(data.live.transcoding.resolutions['360p']).to.be.true
183 expect(data.live.transcoding.resolutions['480p']).to.be.true
184 expect(data.live.transcoding.resolutions['720p']).to.be.true
185 expect(data.live.transcoding.resolutions['1080p']).to.be.true
186 expect(data.live.transcoding.resolutions['2160p']).to.be.true
188 expect(data.import.videos.concurrency).to.equal(4)
189 expect(data.import.videos.http.enabled).to.be.false
190 expect(data.import.videos.torrent.enabled).to.be.false
191 expect(data.autoBlacklist.videos.ofUsers.enabled).to.be.true
193 expect(data.followers.instance.enabled).to.be.false
194 expect(data.followers.instance.manualApproval).to.be.true
196 expect(data.followings.instance.autoFollowBack.enabled).to.be.true
197 expect(data.followings.instance.autoFollowIndex.enabled).to.be.true
198 expect(data.followings.instance.autoFollowIndex.indexUrl).to.equal('https://updated.example.com')
200 expect(data.broadcastMessage.enabled).to.be.true
201 expect(data.broadcastMessage.level).to.equal('error')
202 expect(data.broadcastMessage.message).to.equal('super bad message')
203 expect(data.broadcastMessage.dismissable).to.be.true
206 describe('Test config', function () {
207 let server: ServerInfo = null
209 before(async function () {
212 server = await flushAndRunServer(1)
213 await setAccessTokensToServers([ server ])
216 it('Should have a correct config on a server with registration enabled', async function () {
217 const data = await server.configCommand.getConfig()
219 expect(data.signup.allowed).to.be.true
222 it('Should have a correct config on a server with registration enabled and a users limit', async function () {
226 server.usersCommand.register({ username: 'user1' }),
227 server.usersCommand.register({ username: 'user2' }),
228 server.usersCommand.register({ username: 'user3' })
231 const data = await server.configCommand.getConfig()
233 expect(data.signup.allowed).to.be.false
236 it('Should have the correct video allowed extensions', async function () {
237 const data = await server.configCommand.getConfig()
239 expect(data.video.file.extensions).to.have.lengthOf(3)
240 expect(data.video.file.extensions).to.contain('.mp4')
241 expect(data.video.file.extensions).to.contain('.webm')
242 expect(data.video.file.extensions).to.contain('.ogv')
244 await server.videosCommand.upload({ attributes: { fixture: 'video_short.mkv' }, expectedStatus: HttpStatusCode.UNSUPPORTED_MEDIA_TYPE_415 })
245 await server.videosCommand.upload({ attributes: { fixture: 'sample.ogg' }, expectedStatus: HttpStatusCode.UNSUPPORTED_MEDIA_TYPE_415 })
247 expect(data.contactForm.enabled).to.be.true
250 it('Should get the customized configuration', async function () {
251 const data = await server.configCommand.getCustomConfig()
253 checkInitialConfig(server, data)
256 it('Should update the customized configuration', async function () {
257 const newCustomConfig: CustomConfig = {
259 name: 'PeerTube updated',
260 shortDescription: 'my short description',
261 description: 'my super description',
262 terms: 'my super terms',
263 codeOfConduct: 'my super coc',
265 creationReason: 'my super creation reason',
266 moderationInformation: 'my super moderation information',
267 administrator: 'Kuja',
268 maintenanceLifetime: 'forever',
269 businessModel: 'my super business model',
270 hardwareInformation: '2vCore 3GB RAM',
272 languages: [ 'en', 'es' ],
273 categories: [ 1, 2 ],
276 defaultNSFWPolicy: 'blur' as 'blur',
278 defaultClientRoute: '/videos/recently-added',
281 javascript: 'alert("coucou")',
282 css: 'body { background-color: red; }'
308 requiresEmailVerification: false,
312 email: 'superadmin1@example.com'
319 videoQuotaDaily: 318742
323 allowAdditionalExtensions: true,
324 allowAudioFiles: true,
327 profile: 'vod_profile',
349 maxInstanceLives: -1,
354 profile: 'live_profile',
380 enabled: [ 'best', 'hot', 'most-viewed', 'most-liked' ],
405 indexUrl: 'https://updated.example.com'
412 message: 'super bad message',
422 url: 'https://search.joinpeertube.org',
423 disableLocalSearch: true,
424 isDefaultSearch: true
428 await server.configCommand.updateCustomConfig({ newCustomConfig })
430 const data = await server.configCommand.getCustomConfig()
431 checkUpdatedConfig(data)
434 it('Should have the correct updated video allowed extensions', async function () {
437 const data = await server.configCommand.getConfig()
439 expect(data.video.file.extensions).to.have.length.above(4)
440 expect(data.video.file.extensions).to.contain('.mp4')
441 expect(data.video.file.extensions).to.contain('.webm')
442 expect(data.video.file.extensions).to.contain('.ogv')
443 expect(data.video.file.extensions).to.contain('.flv')
444 expect(data.video.file.extensions).to.contain('.wmv')
445 expect(data.video.file.extensions).to.contain('.mkv')
446 expect(data.video.file.extensions).to.contain('.mp3')
447 expect(data.video.file.extensions).to.contain('.ogg')
448 expect(data.video.file.extensions).to.contain('.flac')
450 await server.videosCommand.upload({ attributes: { fixture: 'video_short.mkv' }, expectedStatus: HttpStatusCode.OK_200 })
451 await server.videosCommand.upload({ attributes: { fixture: 'sample.ogg' }, expectedStatus: HttpStatusCode.OK_200 })
454 it('Should have the configuration updated after a restart', async function () {
457 await killallServers([ server ])
459 await reRunServer(server)
461 const data = await server.configCommand.getCustomConfig()
463 checkUpdatedConfig(data)
466 it('Should fetch the about information', async function () {
467 const data = await server.configCommand.getAbout()
469 expect(data.instance.name).to.equal('PeerTube updated')
470 expect(data.instance.shortDescription).to.equal('my short description')
471 expect(data.instance.description).to.equal('my super description')
472 expect(data.instance.terms).to.equal('my super terms')
473 expect(data.instance.codeOfConduct).to.equal('my super coc')
475 expect(data.instance.creationReason).to.equal('my super creation reason')
476 expect(data.instance.moderationInformation).to.equal('my super moderation information')
477 expect(data.instance.administrator).to.equal('Kuja')
478 expect(data.instance.maintenanceLifetime).to.equal('forever')
479 expect(data.instance.businessModel).to.equal('my super business model')
480 expect(data.instance.hardwareInformation).to.equal('2vCore 3GB RAM')
482 expect(data.instance.languages).to.deep.equal([ 'en', 'es' ])
483 expect(data.instance.categories).to.deep.equal([ 1, 2 ])
486 it('Should remove the custom configuration', async function () {
489 await server.configCommand.deleteCustomConfig()
491 const data = await server.configCommand.getCustomConfig()
492 checkInitialConfig(server, data)
495 it('Should enable frameguard', async function () {
499 const res = await makeGetRequest({
501 path: '/api/v1/config',
502 statusCodeExpected: 200
505 expect(res.headers['x-frame-options']).to.exist
508 await killallServers([ server ])
512 frameguard: { enabled: false }
515 server = await reRunServer(server, config)
518 const res = await makeGetRequest({
520 path: '/api/v1/config',
521 statusCodeExpected: 200
524 expect(res.headers['x-frame-options']).to.not.exist
528 after(async function () {
529 await cleanupTests([ server ])