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, a federated (ActivityPub) video streaming platform using P2P (BitTorrent) directly in the web browser ' +
31 'with WebTorrent and Angular.'
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)
68 expect(data.transcoding.enabled).to.be.false
69 expect(data.transcoding.allowAdditionalExtensions).to.be.false
70 expect(data.transcoding.allowAudioFiles).to.be.false
71 expect(data.transcoding.threads).to.equal(2)
72 expect(data.transcoding.resolutions['240p']).to.be.true
73 expect(data.transcoding.resolutions['360p']).to.be.true
74 expect(data.transcoding.resolutions['480p']).to.be.true
75 expect(data.transcoding.resolutions['720p']).to.be.true
76 expect(data.transcoding.resolutions['1080p']).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.import.videos.http.enabled).to.be.true
82 expect(data.import.videos.torrent.enabled).to.be.true
83 expect(data.autoBlacklist.videos.ofUsers.enabled).to.be.false
85 expect(data.followers.instance.enabled).to.be.true
86 expect(data.followers.instance.manualApproval).to.be.false
88 expect(data.followings.instance.autoFollowBack.enabled).to.be.false
89 expect(data.followings.instance.autoFollowIndex.enabled).to.be.false
90 expect(data.followings.instance.autoFollowIndex.indexUrl).to.equal('https://instances.joinpeertube.org')
93 function checkUpdatedConfig (data: CustomConfig) {
94 expect(data.instance.name).to.equal('PeerTube updated')
95 expect(data.instance.shortDescription).to.equal('my short description')
96 expect(data.instance.description).to.equal('my super description')
98 expect(data.instance.terms).to.equal('my super terms')
99 expect(data.instance.creationReason).to.equal('my super creation reason')
100 expect(data.instance.codeOfConduct).to.equal('my super coc')
101 expect(data.instance.moderationInformation).to.equal('my super moderation information')
102 expect(data.instance.administrator).to.equal('Kuja')
103 expect(data.instance.maintenanceLifetime).to.equal('forever')
104 expect(data.instance.businessModel).to.equal('my super business model')
105 expect(data.instance.hardwareInformation).to.equal('2vCore 3GB RAM')
107 expect(data.instance.languages).to.deep.equal([ 'en', 'es' ])
108 expect(data.instance.categories).to.deep.equal([ 1, 2 ])
110 expect(data.instance.defaultClientRoute).to.equal('/videos/recently-added')
111 expect(data.instance.isNSFW).to.be.true
112 expect(data.instance.defaultNSFWPolicy).to.equal('blur')
113 expect(data.instance.customizations.javascript).to.equal('alert("coucou")')
114 expect(data.instance.customizations.css).to.equal('body { background-color: red; }')
116 expect(data.services.twitter.username).to.equal('@Kuja')
117 expect(data.services.twitter.whitelisted).to.be.true
119 expect(data.cache.previews.size).to.equal(2)
120 expect(data.cache.captions.size).to.equal(3)
122 expect(data.signup.enabled).to.be.false
123 expect(data.signup.limit).to.equal(5)
124 expect(data.signup.requiresEmailVerification).to.be.false
126 // We override admin email in parallel tests, so skip this exception
127 if (parallelTests() === false) {
128 expect(data.admin.email).to.equal('superadmin1@example.com')
131 expect(data.contactForm.enabled).to.be.false
133 expect(data.user.videoQuota).to.equal(5242881)
134 expect(data.user.videoQuotaDaily).to.equal(318742)
136 expect(data.transcoding.enabled).to.be.true
137 expect(data.transcoding.threads).to.equal(1)
138 expect(data.transcoding.allowAdditionalExtensions).to.be.true
139 expect(data.transcoding.allowAudioFiles).to.be.true
140 expect(data.transcoding.resolutions['240p']).to.be.false
141 expect(data.transcoding.resolutions['360p']).to.be.true
142 expect(data.transcoding.resolutions['480p']).to.be.true
143 expect(data.transcoding.resolutions['720p']).to.be.false
144 expect(data.transcoding.resolutions['1080p']).to.be.false
145 expect(data.transcoding.resolutions['2160p']).to.be.false
146 expect(data.transcoding.hls.enabled).to.be.false
147 expect(data.transcoding.webtorrent.enabled).to.be.true
149 expect(data.import.videos.http.enabled).to.be.false
150 expect(data.import.videos.torrent.enabled).to.be.false
151 expect(data.autoBlacklist.videos.ofUsers.enabled).to.be.true
153 expect(data.followers.instance.enabled).to.be.false
154 expect(data.followers.instance.manualApproval).to.be.true
156 expect(data.followings.instance.autoFollowBack.enabled).to.be.true
157 expect(data.followings.instance.autoFollowIndex.enabled).to.be.true
158 expect(data.followings.instance.autoFollowIndex.indexUrl).to.equal('https://updated.example.com')
161 describe('Test config', function () {
164 before(async function () {
167 server = await flushAndRunServer(1)
168 await setAccessTokensToServers([ server ])
171 it('Should have a correct config on a server with registration enabled', async function () {
172 const res = await getConfig(server.url)
173 const data: ServerConfig = res.body
175 expect(data.signup.allowed).to.be.true
178 it('Should have a correct config on a server with registration enabled and a users limit', async function () {
182 registerUser(server.url, 'user1', 'super password'),
183 registerUser(server.url, 'user2', 'super password'),
184 registerUser(server.url, 'user3', 'super password')
187 const res = await getConfig(server.url)
188 const data: ServerConfig = res.body
190 expect(data.signup.allowed).to.be.false
193 it('Should have the correct video allowed extensions', async function () {
194 const res = await getConfig(server.url)
195 const data: ServerConfig = res.body
197 expect(data.video.file.extensions).to.have.lengthOf(3)
198 expect(data.video.file.extensions).to.contain('.mp4')
199 expect(data.video.file.extensions).to.contain('.webm')
200 expect(data.video.file.extensions).to.contain('.ogv')
202 await uploadVideo(server.url, server.accessToken, { fixture: 'video_short.mkv' }, 400)
203 await uploadVideo(server.url, server.accessToken, { fixture: 'sample.ogg' }, 400)
205 expect(data.contactForm.enabled).to.be.true
208 it('Should get the customized configuration', async function () {
209 const res = await getCustomConfig(server.url, server.accessToken)
210 const data = res.body as CustomConfig
212 checkInitialConfig(server, data)
215 it('Should update the customized configuration', async function () {
216 const newCustomConfig: CustomConfig = {
218 name: 'PeerTube updated',
219 shortDescription: 'my short description',
220 description: 'my super description',
221 terms: 'my super terms',
222 codeOfConduct: 'my super coc',
224 creationReason: 'my super creation reason',
225 moderationInformation: 'my super moderation information',
226 administrator: 'Kuja',
227 maintenanceLifetime: 'forever',
228 businessModel: 'my super business model',
229 hardwareInformation: '2vCore 3GB RAM',
231 languages: [ 'en', 'es' ],
232 categories: [ 1, 2 ],
234 defaultClientRoute: '/videos/recently-added',
236 defaultNSFWPolicy: 'blur' as 'blur',
238 javascript: 'alert("coucou")',
239 css: 'body { background-color: red; }'
262 requiresEmailVerification: false
265 email: 'superadmin1@example.com'
272 videoQuotaDaily: 318742
276 allowAdditionalExtensions: true,
277 allowAudioFiles: true,
325 indexUrl: 'https://updated.example.com'
330 await updateCustomConfig(server.url, server.accessToken, newCustomConfig)
332 const res = await getCustomConfig(server.url, server.accessToken)
333 const data = res.body
335 checkUpdatedConfig(data)
338 it('Should have the correct updated video allowed extensions', async function () {
339 const res = await getConfig(server.url)
340 const data: ServerConfig = res.body
342 expect(data.video.file.extensions).to.have.length.above(3)
343 expect(data.video.file.extensions).to.contain('.mp4')
344 expect(data.video.file.extensions).to.contain('.webm')
345 expect(data.video.file.extensions).to.contain('.ogv')
346 expect(data.video.file.extensions).to.contain('.flv')
347 expect(data.video.file.extensions).to.contain('.mkv')
348 expect(data.video.file.extensions).to.contain('.mp3')
349 expect(data.video.file.extensions).to.contain('.ogg')
350 expect(data.video.file.extensions).to.contain('.flac')
352 await uploadVideo(server.url, server.accessToken, { fixture: 'video_short.mkv' }, 200)
353 await uploadVideo(server.url, server.accessToken, { fixture: 'sample.ogg' }, 200)
356 it('Should have the configuration updated after a restart', async function () {
359 killallServers([ server ])
361 await reRunServer(server)
363 const res = await getCustomConfig(server.url, server.accessToken)
364 const data = res.body
366 checkUpdatedConfig(data)
369 it('Should fetch the about information', async function () {
370 const res = await getAbout(server.url)
371 const data: About = res.body
373 expect(data.instance.name).to.equal('PeerTube updated')
374 expect(data.instance.shortDescription).to.equal('my short description')
375 expect(data.instance.description).to.equal('my super description')
376 expect(data.instance.terms).to.equal('my super terms')
377 expect(data.instance.codeOfConduct).to.equal('my super coc')
379 expect(data.instance.creationReason).to.equal('my super creation reason')
380 expect(data.instance.moderationInformation).to.equal('my super moderation information')
381 expect(data.instance.administrator).to.equal('Kuja')
382 expect(data.instance.maintenanceLifetime).to.equal('forever')
383 expect(data.instance.businessModel).to.equal('my super business model')
384 expect(data.instance.hardwareInformation).to.equal('2vCore 3GB RAM')
386 expect(data.instance.languages).to.deep.equal([ 'en', 'es' ])
387 expect(data.instance.categories).to.deep.equal([ 1, 2 ])
390 it('Should remove the custom configuration', async function () {
393 await deleteCustomConfig(server.url, server.accessToken)
395 const res = await getCustomConfig(server.url, server.accessToken)
396 const data = res.body
398 checkInitialConfig(server, data)
401 after(async function () {
402 await cleanupTests([ server ])