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'
25 const expect = chai.expect
27 function checkInitialConfig (server: ServerInfo, data: CustomConfig) {
28 expect(data.instance.name).to.equal('PeerTube')
29 expect(data.instance.shortDescription).to.equal(
30 'PeerTube, an ActivityPub-federated video streaming platform using P2P directly in your web browser.'
32 expect(data.instance.description).to.equal('Welcome to this PeerTube instance!')
34 expect(data.instance.terms).to.equal('No terms for now.')
35 expect(data.instance.creationReason).to.be.empty
36 expect(data.instance.codeOfConduct).to.be.empty
37 expect(data.instance.moderationInformation).to.be.empty
38 expect(data.instance.administrator).to.be.empty
39 expect(data.instance.maintenanceLifetime).to.be.empty
40 expect(data.instance.businessModel).to.be.empty
41 expect(data.instance.hardwareInformation).to.be.empty
43 expect(data.instance.languages).to.have.lengthOf(0)
44 expect(data.instance.categories).to.have.lengthOf(0)
46 expect(data.instance.defaultClientRoute).to.equal('/videos/trending')
47 expect(data.instance.isNSFW).to.be.false
48 expect(data.instance.defaultNSFWPolicy).to.equal('display')
49 expect(data.instance.customizations.css).to.be.empty
50 expect(data.instance.customizations.javascript).to.be.empty
52 expect(data.services.twitter.username).to.equal('@Chocobozzz')
53 expect(data.services.twitter.whitelisted).to.be.false
55 expect(data.cache.previews.size).to.equal(1)
56 expect(data.cache.captions.size).to.equal(1)
58 expect(data.signup.enabled).to.be.true
59 expect(data.signup.limit).to.equal(4)
60 expect(data.signup.requiresEmailVerification).to.be.false
62 expect(data.admin.email).to.equal('admin' + server.internalServerNumber + '@example.com')
63 expect(data.contactForm.enabled).to.be.true
65 expect(data.user.videoQuota).to.equal(5242880)
66 expect(data.user.videoQuotaDaily).to.equal(-1)
67 expect(data.transcoding.enabled).to.be.false
68 expect(data.transcoding.allowAdditionalExtensions).to.be.false
69 expect(data.transcoding.allowAudioFiles).to.be.false
70 expect(data.transcoding.threads).to.equal(2)
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['2160p']).to.be.true
77 expect(data.transcoding.webtorrent.enabled).to.be.true
78 expect(data.transcoding.hls.enabled).to.be.true
80 expect(data.import.videos.http.enabled).to.be.true
81 expect(data.import.videos.torrent.enabled).to.be.true
82 expect(data.autoBlacklist.videos.ofUsers.enabled).to.be.false
84 expect(data.followers.instance.enabled).to.be.true
85 expect(data.followers.instance.manualApproval).to.be.false
87 expect(data.followings.instance.autoFollowBack.enabled).to.be.false
88 expect(data.followings.instance.autoFollowIndex.enabled).to.be.false
89 expect(data.followings.instance.autoFollowIndex.indexUrl).to.equal('')
91 expect(data.broadcastMessage.enabled).to.be.false
92 expect(data.broadcastMessage.level).to.equal('info')
93 expect(data.broadcastMessage.message).to.equal('')
94 expect(data.broadcastMessage.dismissable).to.be.false
97 function checkUpdatedConfig (data: CustomConfig) {
98 expect(data.instance.name).to.equal('PeerTube updated')
99 expect(data.instance.shortDescription).to.equal('my short description')
100 expect(data.instance.description).to.equal('my super description')
102 expect(data.instance.terms).to.equal('my super terms')
103 expect(data.instance.creationReason).to.equal('my super creation reason')
104 expect(data.instance.codeOfConduct).to.equal('my super coc')
105 expect(data.instance.moderationInformation).to.equal('my super moderation information')
106 expect(data.instance.administrator).to.equal('Kuja')
107 expect(data.instance.maintenanceLifetime).to.equal('forever')
108 expect(data.instance.businessModel).to.equal('my super business model')
109 expect(data.instance.hardwareInformation).to.equal('2vCore 3GB RAM')
111 expect(data.instance.languages).to.deep.equal([ 'en', 'es' ])
112 expect(data.instance.categories).to.deep.equal([ 1, 2 ])
114 expect(data.instance.defaultClientRoute).to.equal('/videos/recently-added')
115 expect(data.instance.isNSFW).to.be.true
116 expect(data.instance.defaultNSFWPolicy).to.equal('blur')
117 expect(data.instance.customizations.javascript).to.equal('alert("coucou")')
118 expect(data.instance.customizations.css).to.equal('body { background-color: red; }')
120 expect(data.services.twitter.username).to.equal('@Kuja')
121 expect(data.services.twitter.whitelisted).to.be.true
123 expect(data.cache.previews.size).to.equal(2)
124 expect(data.cache.captions.size).to.equal(3)
126 expect(data.signup.enabled).to.be.false
127 expect(data.signup.limit).to.equal(5)
128 expect(data.signup.requiresEmailVerification).to.be.false
130 // We override admin email in parallel tests, so skip this exception
131 if (parallelTests() === false) {
132 expect(data.admin.email).to.equal('superadmin1@example.com')
135 expect(data.contactForm.enabled).to.be.false
137 expect(data.user.videoQuota).to.equal(5242881)
138 expect(data.user.videoQuotaDaily).to.equal(318742)
140 expect(data.transcoding.enabled).to.be.true
141 expect(data.transcoding.threads).to.equal(1)
142 expect(data.transcoding.allowAdditionalExtensions).to.be.true
143 expect(data.transcoding.allowAudioFiles).to.be.true
144 expect(data.transcoding.resolutions['240p']).to.be.false
145 expect(data.transcoding.resolutions['360p']).to.be.true
146 expect(data.transcoding.resolutions['480p']).to.be.true
147 expect(data.transcoding.resolutions['720p']).to.be.false
148 expect(data.transcoding.resolutions['1080p']).to.be.false
149 expect(data.transcoding.resolutions['2160p']).to.be.false
150 expect(data.transcoding.hls.enabled).to.be.false
151 expect(data.transcoding.webtorrent.enabled).to.be.true
153 expect(data.import.videos.http.enabled).to.be.false
154 expect(data.import.videos.torrent.enabled).to.be.false
155 expect(data.autoBlacklist.videos.ofUsers.enabled).to.be.true
157 expect(data.followers.instance.enabled).to.be.false
158 expect(data.followers.instance.manualApproval).to.be.true
160 expect(data.followings.instance.autoFollowBack.enabled).to.be.true
161 expect(data.followings.instance.autoFollowIndex.enabled).to.be.true
162 expect(data.followings.instance.autoFollowIndex.indexUrl).to.equal('https://updated.example.com')
164 expect(data.broadcastMessage.enabled).to.be.true
165 expect(data.broadcastMessage.level).to.equal('error')
166 expect(data.broadcastMessage.message).to.equal('super bad message')
167 expect(data.broadcastMessage.dismissable).to.be.true
170 describe('Test config', function () {
173 before(async function () {
176 server = await flushAndRunServer(1)
177 await setAccessTokensToServers([ server ])
180 it('Should have a correct config on a server with registration enabled', async function () {
181 const res = await getConfig(server.url)
182 const data: ServerConfig = res.body
184 expect(data.signup.allowed).to.be.true
187 it('Should have a correct config on a server with registration enabled and a users limit', async function () {
191 registerUser(server.url, 'user1', 'super password'),
192 registerUser(server.url, 'user2', 'super password'),
193 registerUser(server.url, 'user3', 'super password')
196 const res = await getConfig(server.url)
197 const data: ServerConfig = res.body
199 expect(data.signup.allowed).to.be.false
202 it('Should have the correct video allowed extensions', async function () {
203 const res = await getConfig(server.url)
204 const data: ServerConfig = res.body
206 expect(data.video.file.extensions).to.have.lengthOf(3)
207 expect(data.video.file.extensions).to.contain('.mp4')
208 expect(data.video.file.extensions).to.contain('.webm')
209 expect(data.video.file.extensions).to.contain('.ogv')
211 await uploadVideo(server.url, server.accessToken, { fixture: 'video_short.mkv' }, 400)
212 await uploadVideo(server.url, server.accessToken, { fixture: 'sample.ogg' }, 400)
214 expect(data.contactForm.enabled).to.be.true
217 it('Should get the customized configuration', async function () {
218 const res = await getCustomConfig(server.url, server.accessToken)
219 const data = res.body as CustomConfig
221 checkInitialConfig(server, data)
224 it('Should update the customized configuration', async function () {
225 const newCustomConfig: CustomConfig = {
227 name: 'PeerTube updated',
228 shortDescription: 'my short description',
229 description: 'my super description',
230 terms: 'my super terms',
231 codeOfConduct: 'my super coc',
233 creationReason: 'my super creation reason',
234 moderationInformation: 'my super moderation information',
235 administrator: 'Kuja',
236 maintenanceLifetime: 'forever',
237 businessModel: 'my super business model',
238 hardwareInformation: '2vCore 3GB RAM',
240 languages: [ 'en', 'es' ],
241 categories: [ 1, 2 ],
243 defaultClientRoute: '/videos/recently-added',
245 defaultNSFWPolicy: 'blur' as 'blur',
247 javascript: 'alert("coucou")',
248 css: 'body { background-color: red; }'
271 requiresEmailVerification: false
274 email: 'superadmin1@example.com'
281 videoQuotaDaily: 318742
285 allowAdditionalExtensions: true,
286 allowAudioFiles: true,
334 indexUrl: 'https://updated.example.com'
341 message: 'super bad message',
351 url: 'https://search.joinpeertube.org',
352 disableLocalSearch: true,
353 isDefaultSearch: true
357 await updateCustomConfig(server.url, server.accessToken, newCustomConfig)
359 const res = await getCustomConfig(server.url, server.accessToken)
360 const data = res.body
362 checkUpdatedConfig(data)
365 it('Should have the correct updated video allowed extensions', async function () {
366 const res = await getConfig(server.url)
367 const data: ServerConfig = res.body
369 expect(data.video.file.extensions).to.have.length.above(3)
370 expect(data.video.file.extensions).to.contain('.mp4')
371 expect(data.video.file.extensions).to.contain('.webm')
372 expect(data.video.file.extensions).to.contain('.ogv')
373 expect(data.video.file.extensions).to.contain('.flv')
374 expect(data.video.file.extensions).to.contain('.wmv')
375 expect(data.video.file.extensions).to.contain('.mkv')
376 expect(data.video.file.extensions).to.contain('.mp3')
377 expect(data.video.file.extensions).to.contain('.ogg')
378 expect(data.video.file.extensions).to.contain('.flac')
380 await uploadVideo(server.url, server.accessToken, { fixture: 'video_short.mkv' }, 200)
381 await uploadVideo(server.url, server.accessToken, { fixture: 'sample.ogg' }, 200)
384 it('Should have the configuration updated after a restart', async function () {
387 killallServers([ server ])
389 await reRunServer(server)
391 const res = await getCustomConfig(server.url, server.accessToken)
392 const data = res.body
394 checkUpdatedConfig(data)
397 it('Should fetch the about information', async function () {
398 const res = await getAbout(server.url)
399 const data: About = res.body
401 expect(data.instance.name).to.equal('PeerTube updated')
402 expect(data.instance.shortDescription).to.equal('my short description')
403 expect(data.instance.description).to.equal('my super description')
404 expect(data.instance.terms).to.equal('my super terms')
405 expect(data.instance.codeOfConduct).to.equal('my super coc')
407 expect(data.instance.creationReason).to.equal('my super creation reason')
408 expect(data.instance.moderationInformation).to.equal('my super moderation information')
409 expect(data.instance.administrator).to.equal('Kuja')
410 expect(data.instance.maintenanceLifetime).to.equal('forever')
411 expect(data.instance.businessModel).to.equal('my super business model')
412 expect(data.instance.hardwareInformation).to.equal('2vCore 3GB RAM')
414 expect(data.instance.languages).to.deep.equal([ 'en', 'es' ])
415 expect(data.instance.categories).to.deep.equal([ 1, 2 ])
418 it('Should remove the custom configuration', async function () {
421 await deleteCustomConfig(server.url, server.accessToken)
423 const res = await getCustomConfig(server.url, server.accessToken)
424 const data = res.body
426 checkInitialConfig(server, data)
429 after(async function () {
430 await cleanupTests([ server ])