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'
15 setAccessTokensToServers,
17 } from '@shared/extra-utils'
18 import { CustomConfig } from '@shared/models'
20 const expect = chai.expect
22 function checkInitialConfig (server: ServerInfo, data: CustomConfig) {
23 expect(data.instance.name).to.equal('PeerTube')
24 expect(data.instance.shortDescription).to.equal(
25 'PeerTube, an ActivityPub-federated video streaming platform using P2P directly in your web browser.'
27 expect(data.instance.description).to.equal('Welcome to this PeerTube instance!')
29 expect(data.instance.terms).to.equal('No terms for now.')
30 expect(data.instance.creationReason).to.be.empty
31 expect(data.instance.codeOfConduct).to.be.empty
32 expect(data.instance.moderationInformation).to.be.empty
33 expect(data.instance.administrator).to.be.empty
34 expect(data.instance.maintenanceLifetime).to.be.empty
35 expect(data.instance.businessModel).to.be.empty
36 expect(data.instance.hardwareInformation).to.be.empty
38 expect(data.instance.languages).to.have.lengthOf(0)
39 expect(data.instance.categories).to.have.lengthOf(0)
41 expect(data.instance.defaultClientRoute).to.equal('/videos/trending')
42 expect(data.instance.isNSFW).to.be.false
43 expect(data.instance.defaultNSFWPolicy).to.equal('display')
44 expect(data.instance.customizations.css).to.be.empty
45 expect(data.instance.customizations.javascript).to.be.empty
47 expect(data.services.twitter.username).to.equal('@Chocobozzz')
48 expect(data.services.twitter.whitelisted).to.be.false
50 expect(data.cache.previews.size).to.equal(1)
51 expect(data.cache.captions.size).to.equal(1)
52 expect(data.cache.torrents.size).to.equal(1)
54 expect(data.signup.enabled).to.be.true
55 expect(data.signup.limit).to.equal(4)
56 expect(data.signup.minimumAge).to.equal(16)
57 expect(data.signup.requiresEmailVerification).to.be.false
59 expect(data.admin.email).to.equal('admin' + server.internalServerNumber + '@example.com')
60 expect(data.contactForm.enabled).to.be.true
62 expect(data.user.videoQuota).to.equal(5242880)
63 expect(data.user.videoQuotaDaily).to.equal(-1)
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['240p']).to.be.true
72 expect(data.transcoding.resolutions['360p']).to.be.true
73 expect(data.transcoding.resolutions['480p']).to.be.true
74 expect(data.transcoding.resolutions['720p']).to.be.true
75 expect(data.transcoding.resolutions['1080p']).to.be.true
76 expect(data.transcoding.resolutions['1440p']).to.be.true
77 expect(data.transcoding.resolutions['2160p']).to.be.true
78 expect(data.transcoding.webtorrent.enabled).to.be.true
79 expect(data.transcoding.hls.enabled).to.be.true
81 expect(data.live.enabled).to.be.false
82 expect(data.live.allowReplay).to.be.false
83 expect(data.live.maxDuration).to.equal(-1)
84 expect(data.live.maxInstanceLives).to.equal(20)
85 expect(data.live.maxUserLives).to.equal(3)
86 expect(data.live.transcoding.enabled).to.be.false
87 expect(data.live.transcoding.threads).to.equal(2)
88 expect(data.live.transcoding.profile).to.equal('default')
89 expect(data.live.transcoding.resolutions['240p']).to.be.false
90 expect(data.live.transcoding.resolutions['360p']).to.be.false
91 expect(data.live.transcoding.resolutions['480p']).to.be.false
92 expect(data.live.transcoding.resolutions['720p']).to.be.false
93 expect(data.live.transcoding.resolutions['1080p']).to.be.false
94 expect(data.live.transcoding.resolutions['1440p']).to.be.false
95 expect(data.live.transcoding.resolutions['2160p']).to.be.false
97 expect(data.import.videos.concurrency).to.equal(2)
98 expect(data.import.videos.http.enabled).to.be.true
99 expect(data.import.videos.torrent.enabled).to.be.true
100 expect(data.autoBlacklist.videos.ofUsers.enabled).to.be.false
102 expect(data.followers.instance.enabled).to.be.true
103 expect(data.followers.instance.manualApproval).to.be.false
105 expect(data.followings.instance.autoFollowBack.enabled).to.be.false
106 expect(data.followings.instance.autoFollowIndex.enabled).to.be.false
107 expect(data.followings.instance.autoFollowIndex.indexUrl).to.equal('')
109 expect(data.broadcastMessage.enabled).to.be.false
110 expect(data.broadcastMessage.level).to.equal('info')
111 expect(data.broadcastMessage.message).to.equal('')
112 expect(data.broadcastMessage.dismissable).to.be.false
115 function checkUpdatedConfig (data: CustomConfig) {
116 expect(data.instance.name).to.equal('PeerTube updated')
117 expect(data.instance.shortDescription).to.equal('my short description')
118 expect(data.instance.description).to.equal('my super description')
120 expect(data.instance.terms).to.equal('my super terms')
121 expect(data.instance.creationReason).to.equal('my super creation reason')
122 expect(data.instance.codeOfConduct).to.equal('my super coc')
123 expect(data.instance.moderationInformation).to.equal('my super moderation information')
124 expect(data.instance.administrator).to.equal('Kuja')
125 expect(data.instance.maintenanceLifetime).to.equal('forever')
126 expect(data.instance.businessModel).to.equal('my super business model')
127 expect(data.instance.hardwareInformation).to.equal('2vCore 3GB RAM')
129 expect(data.instance.languages).to.deep.equal([ 'en', 'es' ])
130 expect(data.instance.categories).to.deep.equal([ 1, 2 ])
132 expect(data.instance.defaultClientRoute).to.equal('/videos/recently-added')
133 expect(data.instance.isNSFW).to.be.true
134 expect(data.instance.defaultNSFWPolicy).to.equal('blur')
135 expect(data.instance.customizations.javascript).to.equal('alert("coucou")')
136 expect(data.instance.customizations.css).to.equal('body { background-color: red; }')
138 expect(data.services.twitter.username).to.equal('@Kuja')
139 expect(data.services.twitter.whitelisted).to.be.true
141 expect(data.cache.previews.size).to.equal(2)
142 expect(data.cache.captions.size).to.equal(3)
143 expect(data.cache.torrents.size).to.equal(4)
145 expect(data.signup.enabled).to.be.false
146 expect(data.signup.limit).to.equal(5)
147 expect(data.signup.requiresEmailVerification).to.be.false
148 expect(data.signup.minimumAge).to.equal(10)
150 // We override admin email in parallel tests, so skip this exception
151 if (parallelTests() === false) {
152 expect(data.admin.email).to.equal('superadmin1@example.com')
155 expect(data.contactForm.enabled).to.be.false
157 expect(data.user.videoQuota).to.equal(5242881)
158 expect(data.user.videoQuotaDaily).to.equal(318742)
160 expect(data.transcoding.enabled).to.be.true
161 expect(data.transcoding.threads).to.equal(1)
162 expect(data.transcoding.concurrency).to.equal(3)
163 expect(data.transcoding.allowAdditionalExtensions).to.be.true
164 expect(data.transcoding.allowAudioFiles).to.be.true
165 expect(data.transcoding.profile).to.equal('vod_profile')
166 expect(data.transcoding.resolutions['240p']).to.be.false
167 expect(data.transcoding.resolutions['360p']).to.be.true
168 expect(data.transcoding.resolutions['480p']).to.be.true
169 expect(data.transcoding.resolutions['720p']).to.be.false
170 expect(data.transcoding.resolutions['1080p']).to.be.false
171 expect(data.transcoding.resolutions['2160p']).to.be.false
172 expect(data.transcoding.hls.enabled).to.be.false
173 expect(data.transcoding.webtorrent.enabled).to.be.true
175 expect(data.live.enabled).to.be.true
176 expect(data.live.allowReplay).to.be.true
177 expect(data.live.maxDuration).to.equal(5000)
178 expect(data.live.maxInstanceLives).to.equal(-1)
179 expect(data.live.maxUserLives).to.equal(10)
180 expect(data.live.transcoding.enabled).to.be.true
181 expect(data.live.transcoding.threads).to.equal(4)
182 expect(data.live.transcoding.profile).to.equal('live_profile')
183 expect(data.live.transcoding.resolutions['240p']).to.be.true
184 expect(data.live.transcoding.resolutions['360p']).to.be.true
185 expect(data.live.transcoding.resolutions['480p']).to.be.true
186 expect(data.live.transcoding.resolutions['720p']).to.be.true
187 expect(data.live.transcoding.resolutions['1080p']).to.be.true
188 expect(data.live.transcoding.resolutions['2160p']).to.be.true
190 expect(data.import.videos.concurrency).to.equal(4)
191 expect(data.import.videos.http.enabled).to.be.false
192 expect(data.import.videos.torrent.enabled).to.be.false
193 expect(data.autoBlacklist.videos.ofUsers.enabled).to.be.true
195 expect(data.followers.instance.enabled).to.be.false
196 expect(data.followers.instance.manualApproval).to.be.true
198 expect(data.followings.instance.autoFollowBack.enabled).to.be.true
199 expect(data.followings.instance.autoFollowIndex.enabled).to.be.true
200 expect(data.followings.instance.autoFollowIndex.indexUrl).to.equal('https://updated.example.com')
202 expect(data.broadcastMessage.enabled).to.be.true
203 expect(data.broadcastMessage.level).to.equal('error')
204 expect(data.broadcastMessage.message).to.equal('super bad message')
205 expect(data.broadcastMessage.dismissable).to.be.true
208 describe('Test config', function () {
209 let server: ServerInfo = null
211 before(async function () {
214 server = await flushAndRunServer(1)
215 await setAccessTokensToServers([ server ])
218 it('Should have a correct config on a server with registration enabled', async function () {
219 const data = await server.configCommand.getConfig()
221 expect(data.signup.allowed).to.be.true
224 it('Should have a correct config on a server with registration enabled and a users limit', async function () {
228 registerUser(server.url, 'user1', 'super password'),
229 registerUser(server.url, 'user2', 'super password'),
230 registerUser(server.url, 'user3', 'super password')
233 const data = await server.configCommand.getConfig()
235 expect(data.signup.allowed).to.be.false
238 it('Should have the correct video allowed extensions', async function () {
239 const data = await server.configCommand.getConfig()
241 expect(data.video.file.extensions).to.have.lengthOf(3)
242 expect(data.video.file.extensions).to.contain('.mp4')
243 expect(data.video.file.extensions).to.contain('.webm')
244 expect(data.video.file.extensions).to.contain('.ogv')
246 await uploadVideo(server.url, server.accessToken, { fixture: 'video_short.mkv' }, HttpStatusCode.UNSUPPORTED_MEDIA_TYPE_415)
247 await uploadVideo(server.url, server.accessToken, { fixture: 'sample.ogg' }, HttpStatusCode.UNSUPPORTED_MEDIA_TYPE_415)
249 expect(data.contactForm.enabled).to.be.true
252 it('Should get the customized configuration', async function () {
253 const data = await server.configCommand.getCustomConfig()
255 checkInitialConfig(server, data)
258 it('Should update the customized configuration', async function () {
259 const newCustomConfig: CustomConfig = {
261 name: 'PeerTube updated',
262 shortDescription: 'my short description',
263 description: 'my super description',
264 terms: 'my super terms',
265 codeOfConduct: 'my super coc',
267 creationReason: 'my super creation reason',
268 moderationInformation: 'my super moderation information',
269 administrator: 'Kuja',
270 maintenanceLifetime: 'forever',
271 businessModel: 'my super business model',
272 hardwareInformation: '2vCore 3GB RAM',
274 languages: [ 'en', 'es' ],
275 categories: [ 1, 2 ],
278 defaultNSFWPolicy: 'blur' as 'blur',
280 defaultClientRoute: '/videos/recently-added',
283 javascript: 'alert("coucou")',
284 css: 'body { background-color: red; }'
310 requiresEmailVerification: false,
314 email: 'superadmin1@example.com'
321 videoQuotaDaily: 318742
325 allowAdditionalExtensions: true,
326 allowAudioFiles: true,
329 profile: 'vod_profile',
351 maxInstanceLives: -1,
356 profile: 'live_profile',
382 enabled: [ 'best', 'hot', 'most-viewed', 'most-liked' ],
407 indexUrl: 'https://updated.example.com'
414 message: 'super bad message',
424 url: 'https://search.joinpeertube.org',
425 disableLocalSearch: true,
426 isDefaultSearch: true
430 await server.configCommand.updateCustomConfig({ newCustomConfig })
432 const data = await server.configCommand.getCustomConfig()
433 checkUpdatedConfig(data)
436 it('Should have the correct updated video allowed extensions', async function () {
439 const data = await server.configCommand.getConfig()
441 expect(data.video.file.extensions).to.have.length.above(4)
442 expect(data.video.file.extensions).to.contain('.mp4')
443 expect(data.video.file.extensions).to.contain('.webm')
444 expect(data.video.file.extensions).to.contain('.ogv')
445 expect(data.video.file.extensions).to.contain('.flv')
446 expect(data.video.file.extensions).to.contain('.wmv')
447 expect(data.video.file.extensions).to.contain('.mkv')
448 expect(data.video.file.extensions).to.contain('.mp3')
449 expect(data.video.file.extensions).to.contain('.ogg')
450 expect(data.video.file.extensions).to.contain('.flac')
452 await uploadVideo(server.url, server.accessToken, { fixture: 'video_short.mkv' }, HttpStatusCode.OK_200)
453 await uploadVideo(server.url, server.accessToken, { fixture: 'sample.ogg' }, HttpStatusCode.OK_200)
456 it('Should have the configuration updated after a restart', async function () {
459 killallServers([ server ])
461 await reRunServer(server)
463 const data = await server.configCommand.getCustomConfig()
465 checkUpdatedConfig(data)
468 it('Should fetch the about information', async function () {
469 const data = await server.configCommand.getAbout()
471 expect(data.instance.name).to.equal('PeerTube updated')
472 expect(data.instance.shortDescription).to.equal('my short description')
473 expect(data.instance.description).to.equal('my super description')
474 expect(data.instance.terms).to.equal('my super terms')
475 expect(data.instance.codeOfConduct).to.equal('my super coc')
477 expect(data.instance.creationReason).to.equal('my super creation reason')
478 expect(data.instance.moderationInformation).to.equal('my super moderation information')
479 expect(data.instance.administrator).to.equal('Kuja')
480 expect(data.instance.maintenanceLifetime).to.equal('forever')
481 expect(data.instance.businessModel).to.equal('my super business model')
482 expect(data.instance.hardwareInformation).to.equal('2vCore 3GB RAM')
484 expect(data.instance.languages).to.deep.equal([ 'en', 'es' ])
485 expect(data.instance.categories).to.deep.equal([ 1, 2 ])
488 it('Should remove the custom configuration', async function () {
491 await server.configCommand.deleteCustomConfig()
493 const data = await server.configCommand.getCustomConfig()
494 checkInitialConfig(server, data)
497 it('Should enable frameguard', async function () {
501 const res = await makeGetRequest({
503 path: '/api/v1/config',
504 statusCodeExpected: 200
507 expect(res.headers['x-frame-options']).to.exist
510 killallServers([ server ])
514 frameguard: { enabled: false }
517 server = await reRunServer(server, config)
520 const res = await makeGetRequest({
522 path: '/api/v1/config',
523 statusCodeExpected: 200
526 expect(res.headers['x-frame-options']).to.not.exist
530 after(async function () {
531 await cleanupTests([ server ])