1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
4 import * as chai from 'chai'
5 import { About } from '../../../../shared/models/server/about.model'
6 import { CustomConfig } from '../../../../shared/models/server/custom-config.model'
19 setAccessTokensToServers,
22 } from '../../../../shared/extra-utils'
23 import { ServerConfig } from '../../../../shared/models'
24 import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
26 const expect = chai.expect
28 function checkInitialConfig (server: ServerInfo, data: CustomConfig) {
29 expect(data.instance.name).to.equal('PeerTube')
30 expect(data.instance.shortDescription).to.equal(
31 'PeerTube, an ActivityPub-federated video streaming platform using P2P directly in your web browser.'
33 expect(data.instance.description).to.equal('Welcome to this PeerTube instance!')
35 expect(data.instance.terms).to.equal('No terms for now.')
36 expect(data.instance.creationReason).to.be.empty
37 expect(data.instance.codeOfConduct).to.be.empty
38 expect(data.instance.moderationInformation).to.be.empty
39 expect(data.instance.administrator).to.be.empty
40 expect(data.instance.maintenanceLifetime).to.be.empty
41 expect(data.instance.businessModel).to.be.empty
42 expect(data.instance.hardwareInformation).to.be.empty
44 expect(data.instance.languages).to.have.lengthOf(0)
45 expect(data.instance.categories).to.have.lengthOf(0)
47 expect(data.instance.defaultClientRoute).to.equal('/videos/trending')
48 expect(data.instance.isNSFW).to.be.false
49 expect(data.instance.defaultNSFWPolicy).to.equal('display')
50 expect(data.instance.customizations.css).to.be.empty
51 expect(data.instance.customizations.javascript).to.be.empty
53 expect(data.services.twitter.username).to.equal('@Chocobozzz')
54 expect(data.services.twitter.whitelisted).to.be.false
56 expect(data.cache.previews.size).to.equal(1)
57 expect(data.cache.captions.size).to.equal(1)
59 expect(data.signup.enabled).to.be.true
60 expect(data.signup.limit).to.equal(4)
61 expect(data.signup.requiresEmailVerification).to.be.false
63 expect(data.admin.email).to.equal('admin' + server.internalServerNumber + '@example.com')
64 expect(data.contactForm.enabled).to.be.true
66 expect(data.user.videoQuota).to.equal(5242880)
67 expect(data.user.videoQuotaDaily).to.equal(-1)
69 expect(data.transcoding.enabled).to.be.false
70 expect(data.transcoding.allowAdditionalExtensions).to.be.false
71 expect(data.transcoding.allowAudioFiles).to.be.false
72 expect(data.transcoding.threads).to.equal(2)
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['2160p']).to.be.true
79 expect(data.transcoding.webtorrent.enabled).to.be.true
80 expect(data.transcoding.hls.enabled).to.be.true
82 expect(data.live.enabled).to.be.false
83 expect(data.live.allowReplay).to.be.false
84 expect(data.live.maxDuration).to.be.null
85 expect(data.live.maxInstanceLives).to.equal(20)
86 expect(data.live.maxUserLives).to.equal(3)
87 expect(data.live.transcoding.enabled).to.be.false
88 expect(data.live.transcoding.threads).to.equal(2)
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['2160p']).to.be.false
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)
142 expect(data.signup.enabled).to.be.false
143 expect(data.signup.limit).to.equal(5)
144 expect(data.signup.requiresEmailVerification).to.be.false
146 // We override admin email in parallel tests, so skip this exception
147 if (parallelTests() === false) {
148 expect(data.admin.email).to.equal('superadmin1@example.com')
151 expect(data.contactForm.enabled).to.be.false
153 expect(data.user.videoQuota).to.equal(5242881)
154 expect(data.user.videoQuotaDaily).to.equal(318742)
156 expect(data.transcoding.enabled).to.be.true
157 expect(data.transcoding.threads).to.equal(1)
158 expect(data.transcoding.allowAdditionalExtensions).to.be.true
159 expect(data.transcoding.allowAudioFiles).to.be.true
160 expect(data.transcoding.resolutions['240p']).to.be.false
161 expect(data.transcoding.resolutions['360p']).to.be.true
162 expect(data.transcoding.resolutions['480p']).to.be.true
163 expect(data.transcoding.resolutions['720p']).to.be.false
164 expect(data.transcoding.resolutions['1080p']).to.be.false
165 expect(data.transcoding.resolutions['2160p']).to.be.false
166 expect(data.transcoding.hls.enabled).to.be.false
167 expect(data.transcoding.webtorrent.enabled).to.be.true
169 expect(data.live.enabled).to.be.true
170 expect(data.live.allowReplay).to.be.true
171 expect(data.live.maxDuration).to.equal(5000)
172 expect(data.live.maxInstanceLives).to.equal(-1)
173 expect(data.live.maxUserLives).to.equal(10)
174 expect(data.live.transcoding.enabled).to.be.true
175 expect(data.live.transcoding.threads).to.equal(4)
176 expect(data.live.transcoding.resolutions['240p']).to.be.true
177 expect(data.live.transcoding.resolutions['360p']).to.be.true
178 expect(data.live.transcoding.resolutions['480p']).to.be.true
179 expect(data.live.transcoding.resolutions['720p']).to.be.true
180 expect(data.live.transcoding.resolutions['1080p']).to.be.true
181 expect(data.live.transcoding.resolutions['2160p']).to.be.true
183 expect(data.import.videos.http.enabled).to.be.false
184 expect(data.import.videos.torrent.enabled).to.be.false
185 expect(data.autoBlacklist.videos.ofUsers.enabled).to.be.true
187 expect(data.followers.instance.enabled).to.be.false
188 expect(data.followers.instance.manualApproval).to.be.true
190 expect(data.followings.instance.autoFollowBack.enabled).to.be.true
191 expect(data.followings.instance.autoFollowIndex.enabled).to.be.true
192 expect(data.followings.instance.autoFollowIndex.indexUrl).to.equal('https://updated.example.com')
194 expect(data.broadcastMessage.enabled).to.be.true
195 expect(data.broadcastMessage.level).to.equal('error')
196 expect(data.broadcastMessage.message).to.equal('super bad message')
197 expect(data.broadcastMessage.dismissable).to.be.true
200 describe('Test config', function () {
203 before(async function () {
206 server = await flushAndRunServer(1)
207 await setAccessTokensToServers([ server ])
210 it('Should have a correct config on a server with registration enabled', async function () {
211 const res = await getConfig(server.url)
212 const data: ServerConfig = res.body
214 expect(data.signup.allowed).to.be.true
217 it('Should have a correct config on a server with registration enabled and a users limit', async function () {
221 registerUser(server.url, 'user1', 'super password'),
222 registerUser(server.url, 'user2', 'super password'),
223 registerUser(server.url, 'user3', 'super password')
226 const res = await getConfig(server.url)
227 const data: ServerConfig = res.body
229 expect(data.signup.allowed).to.be.false
232 it('Should have the correct video allowed extensions', async function () {
233 const res = await getConfig(server.url)
234 const data: ServerConfig = res.body
236 expect(data.video.file.extensions).to.have.lengthOf(3)
237 expect(data.video.file.extensions).to.contain('.mp4')
238 expect(data.video.file.extensions).to.contain('.webm')
239 expect(data.video.file.extensions).to.contain('.ogv')
241 await uploadVideo(server.url, server.accessToken, { fixture: 'video_short.mkv' }, HttpStatusCode.UNSUPPORTED_MEDIA_TYPE_415)
242 await uploadVideo(server.url, server.accessToken, { fixture: 'sample.ogg' }, HttpStatusCode.UNSUPPORTED_MEDIA_TYPE_415)
244 expect(data.contactForm.enabled).to.be.true
247 it('Should get the customized configuration', async function () {
248 const res = await getCustomConfig(server.url, server.accessToken)
249 const data = res.body as CustomConfig
251 checkInitialConfig(server, data)
254 it('Should update the customized configuration', async function () {
255 const newCustomConfig: CustomConfig = {
257 name: 'PeerTube updated',
258 shortDescription: 'my short description',
259 description: 'my super description',
260 terms: 'my super terms',
261 codeOfConduct: 'my super coc',
263 creationReason: 'my super creation reason',
264 moderationInformation: 'my super moderation information',
265 administrator: 'Kuja',
266 maintenanceLifetime: 'forever',
267 businessModel: 'my super business model',
268 hardwareInformation: '2vCore 3GB RAM',
270 languages: [ 'en', 'es' ],
271 categories: [ 1, 2 ],
273 defaultClientRoute: '/videos/recently-added',
275 defaultNSFWPolicy: 'blur' as 'blur',
277 javascript: 'alert("coucou")',
278 css: 'body { background-color: red; }'
301 requiresEmailVerification: false
304 email: 'superadmin1@example.com'
311 videoQuotaDaily: 318742
315 allowAdditionalExtensions: true,
316 allowAudioFiles: true,
338 maxInstanceLives: -1,
383 indexUrl: 'https://updated.example.com'
390 message: 'super bad message',
400 url: 'https://search.joinpeertube.org',
401 disableLocalSearch: true,
402 isDefaultSearch: true
406 await updateCustomConfig(server.url, server.accessToken, newCustomConfig)
408 const res = await getCustomConfig(server.url, server.accessToken)
409 const data = res.body
411 checkUpdatedConfig(data)
414 it('Should have the correct updated video allowed extensions', async function () {
417 const res = await getConfig(server.url)
418 const data: ServerConfig = res.body
420 expect(data.video.file.extensions).to.have.length.above(4)
421 expect(data.video.file.extensions).to.contain('.mp4')
422 expect(data.video.file.extensions).to.contain('.webm')
423 expect(data.video.file.extensions).to.contain('.ogv')
424 expect(data.video.file.extensions).to.contain('.flv')
425 expect(data.video.file.extensions).to.contain('.wmv')
426 expect(data.video.file.extensions).to.contain('.mkv')
427 expect(data.video.file.extensions).to.contain('.mp3')
428 expect(data.video.file.extensions).to.contain('.ogg')
429 expect(data.video.file.extensions).to.contain('.flac')
431 await uploadVideo(server.url, server.accessToken, { fixture: 'video_short.mkv' }, HttpStatusCode.OK_200)
432 await uploadVideo(server.url, server.accessToken, { fixture: 'sample.ogg' }, HttpStatusCode.OK_200)
435 it('Should have the configuration updated after a restart', async function () {
438 killallServers([ server ])
440 await reRunServer(server)
442 const res = await getCustomConfig(server.url, server.accessToken)
443 const data = res.body
445 checkUpdatedConfig(data)
448 it('Should fetch the about information', async function () {
449 const res = await getAbout(server.url)
450 const data: About = res.body
452 expect(data.instance.name).to.equal('PeerTube updated')
453 expect(data.instance.shortDescription).to.equal('my short description')
454 expect(data.instance.description).to.equal('my super description')
455 expect(data.instance.terms).to.equal('my super terms')
456 expect(data.instance.codeOfConduct).to.equal('my super coc')
458 expect(data.instance.creationReason).to.equal('my super creation reason')
459 expect(data.instance.moderationInformation).to.equal('my super moderation information')
460 expect(data.instance.administrator).to.equal('Kuja')
461 expect(data.instance.maintenanceLifetime).to.equal('forever')
462 expect(data.instance.businessModel).to.equal('my super business model')
463 expect(data.instance.hardwareInformation).to.equal('2vCore 3GB RAM')
465 expect(data.instance.languages).to.deep.equal([ 'en', 'es' ])
466 expect(data.instance.categories).to.deep.equal([ 1, 2 ])
469 it('Should remove the custom configuration', async function () {
472 await deleteCustomConfig(server.url, server.accessToken)
474 const res = await getCustomConfig(server.url, server.accessToken)
475 const data = res.body
477 checkInitialConfig(server, data)
480 after(async function () {
481 await cleanupTests([ server ])