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)
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.live.enabled).to.be.false
82 expect(data.live.allowReplay).to.be.true
83 expect(data.live.maxDuration).to.equal(1000 * 3600 * 5)
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.resolutions['240p']).to.be.false
89 expect(data.live.transcoding.resolutions['360p']).to.be.false
90 expect(data.live.transcoding.resolutions['480p']).to.be.false
91 expect(data.live.transcoding.resolutions['720p']).to.be.false
92 expect(data.live.transcoding.resolutions['1080p']).to.be.false
93 expect(data.live.transcoding.resolutions['2160p']).to.be.false
95 expect(data.import.videos.http.enabled).to.be.true
96 expect(data.import.videos.torrent.enabled).to.be.true
97 expect(data.autoBlacklist.videos.ofUsers.enabled).to.be.false
99 expect(data.followers.instance.enabled).to.be.true
100 expect(data.followers.instance.manualApproval).to.be.false
102 expect(data.followings.instance.autoFollowBack.enabled).to.be.false
103 expect(data.followings.instance.autoFollowIndex.enabled).to.be.false
104 expect(data.followings.instance.autoFollowIndex.indexUrl).to.equal('')
106 expect(data.broadcastMessage.enabled).to.be.false
107 expect(data.broadcastMessage.level).to.equal('info')
108 expect(data.broadcastMessage.message).to.equal('')
109 expect(data.broadcastMessage.dismissable).to.be.false
112 function checkUpdatedConfig (data: CustomConfig) {
113 expect(data.instance.name).to.equal('PeerTube updated')
114 expect(data.instance.shortDescription).to.equal('my short description')
115 expect(data.instance.description).to.equal('my super description')
117 expect(data.instance.terms).to.equal('my super terms')
118 expect(data.instance.creationReason).to.equal('my super creation reason')
119 expect(data.instance.codeOfConduct).to.equal('my super coc')
120 expect(data.instance.moderationInformation).to.equal('my super moderation information')
121 expect(data.instance.administrator).to.equal('Kuja')
122 expect(data.instance.maintenanceLifetime).to.equal('forever')
123 expect(data.instance.businessModel).to.equal('my super business model')
124 expect(data.instance.hardwareInformation).to.equal('2vCore 3GB RAM')
126 expect(data.instance.languages).to.deep.equal([ 'en', 'es' ])
127 expect(data.instance.categories).to.deep.equal([ 1, 2 ])
129 expect(data.instance.defaultClientRoute).to.equal('/videos/recently-added')
130 expect(data.instance.isNSFW).to.be.true
131 expect(data.instance.defaultNSFWPolicy).to.equal('blur')
132 expect(data.instance.customizations.javascript).to.equal('alert("coucou")')
133 expect(data.instance.customizations.css).to.equal('body { background-color: red; }')
135 expect(data.services.twitter.username).to.equal('@Kuja')
136 expect(data.services.twitter.whitelisted).to.be.true
138 expect(data.cache.previews.size).to.equal(2)
139 expect(data.cache.captions.size).to.equal(3)
141 expect(data.signup.enabled).to.be.false
142 expect(data.signup.limit).to.equal(5)
143 expect(data.signup.requiresEmailVerification).to.be.false
145 // We override admin email in parallel tests, so skip this exception
146 if (parallelTests() === false) {
147 expect(data.admin.email).to.equal('superadmin1@example.com')
150 expect(data.contactForm.enabled).to.be.false
152 expect(data.user.videoQuota).to.equal(5242881)
153 expect(data.user.videoQuotaDaily).to.equal(318742)
155 expect(data.transcoding.enabled).to.be.true
156 expect(data.transcoding.threads).to.equal(1)
157 expect(data.transcoding.allowAdditionalExtensions).to.be.true
158 expect(data.transcoding.allowAudioFiles).to.be.true
159 expect(data.transcoding.resolutions['240p']).to.be.false
160 expect(data.transcoding.resolutions['360p']).to.be.true
161 expect(data.transcoding.resolutions['480p']).to.be.true
162 expect(data.transcoding.resolutions['720p']).to.be.false
163 expect(data.transcoding.resolutions['1080p']).to.be.false
164 expect(data.transcoding.resolutions['2160p']).to.be.false
165 expect(data.transcoding.hls.enabled).to.be.false
166 expect(data.transcoding.webtorrent.enabled).to.be.true
168 expect(data.live.enabled).to.be.true
169 expect(data.live.allowReplay).to.be.false
170 expect(data.live.maxDuration).to.equal(5000)
171 expect(data.live.maxInstanceLives).to.equal(-1)
172 expect(data.live.maxUserLives).to.equal(10)
173 expect(data.live.transcoding.enabled).to.be.true
174 expect(data.live.transcoding.threads).to.equal(4)
175 expect(data.live.transcoding.resolutions['240p']).to.be.true
176 expect(data.live.transcoding.resolutions['360p']).to.be.true
177 expect(data.live.transcoding.resolutions['480p']).to.be.true
178 expect(data.live.transcoding.resolutions['720p']).to.be.true
179 expect(data.live.transcoding.resolutions['1080p']).to.be.true
180 expect(data.live.transcoding.resolutions['2160p']).to.be.true
182 expect(data.import.videos.http.enabled).to.be.false
183 expect(data.import.videos.torrent.enabled).to.be.false
184 expect(data.autoBlacklist.videos.ofUsers.enabled).to.be.true
186 expect(data.followers.instance.enabled).to.be.false
187 expect(data.followers.instance.manualApproval).to.be.true
189 expect(data.followings.instance.autoFollowBack.enabled).to.be.true
190 expect(data.followings.instance.autoFollowIndex.enabled).to.be.true
191 expect(data.followings.instance.autoFollowIndex.indexUrl).to.equal('https://updated.example.com')
193 expect(data.broadcastMessage.enabled).to.be.true
194 expect(data.broadcastMessage.level).to.equal('error')
195 expect(data.broadcastMessage.message).to.equal('super bad message')
196 expect(data.broadcastMessage.dismissable).to.be.true
199 describe('Test config', function () {
202 before(async function () {
205 server = await flushAndRunServer(1)
206 await setAccessTokensToServers([ server ])
209 it('Should have a correct config on a server with registration enabled', async function () {
210 const res = await getConfig(server.url)
211 const data: ServerConfig = res.body
213 expect(data.signup.allowed).to.be.true
216 it('Should have a correct config on a server with registration enabled and a users limit', async function () {
220 registerUser(server.url, 'user1', 'super password'),
221 registerUser(server.url, 'user2', 'super password'),
222 registerUser(server.url, 'user3', 'super password')
225 const res = await getConfig(server.url)
226 const data: ServerConfig = res.body
228 expect(data.signup.allowed).to.be.false
231 it('Should have the correct video allowed extensions', async function () {
232 const res = await getConfig(server.url)
233 const data: ServerConfig = res.body
235 expect(data.video.file.extensions).to.have.lengthOf(3)
236 expect(data.video.file.extensions).to.contain('.mp4')
237 expect(data.video.file.extensions).to.contain('.webm')
238 expect(data.video.file.extensions).to.contain('.ogv')
240 await uploadVideo(server.url, server.accessToken, { fixture: 'video_short.mkv' }, 400)
241 await uploadVideo(server.url, server.accessToken, { fixture: 'sample.ogg' }, 400)
243 expect(data.contactForm.enabled).to.be.true
246 it('Should get the customized configuration', async function () {
247 const res = await getCustomConfig(server.url, server.accessToken)
248 const data = res.body as CustomConfig
250 checkInitialConfig(server, data)
253 it('Should update the customized configuration', async function () {
254 const newCustomConfig: CustomConfig = {
256 name: 'PeerTube updated',
257 shortDescription: 'my short description',
258 description: 'my super description',
259 terms: 'my super terms',
260 codeOfConduct: 'my super coc',
262 creationReason: 'my super creation reason',
263 moderationInformation: 'my super moderation information',
264 administrator: 'Kuja',
265 maintenanceLifetime: 'forever',
266 businessModel: 'my super business model',
267 hardwareInformation: '2vCore 3GB RAM',
269 languages: [ 'en', 'es' ],
270 categories: [ 1, 2 ],
272 defaultClientRoute: '/videos/recently-added',
274 defaultNSFWPolicy: 'blur' as 'blur',
276 javascript: 'alert("coucou")',
277 css: 'body { background-color: red; }'
300 requiresEmailVerification: false
303 email: 'superadmin1@example.com'
310 videoQuotaDaily: 318742
314 allowAdditionalExtensions: true,
315 allowAudioFiles: true,
337 maxInstanceLives: -1,
382 indexUrl: 'https://updated.example.com'
389 message: 'super bad message',
399 url: 'https://search.joinpeertube.org',
400 disableLocalSearch: true,
401 isDefaultSearch: true
405 await updateCustomConfig(server.url, server.accessToken, newCustomConfig)
407 const res = await getCustomConfig(server.url, server.accessToken)
408 const data = res.body
410 checkUpdatedConfig(data)
413 it('Should have the correct updated video allowed extensions', async function () {
416 const res = await getConfig(server.url)
417 const data: ServerConfig = res.body
419 expect(data.video.file.extensions).to.have.length.above(4)
420 expect(data.video.file.extensions).to.contain('.mp4')
421 expect(data.video.file.extensions).to.contain('.webm')
422 expect(data.video.file.extensions).to.contain('.ogv')
423 expect(data.video.file.extensions).to.contain('.flv')
424 expect(data.video.file.extensions).to.contain('.wmv')
425 expect(data.video.file.extensions).to.contain('.mkv')
426 expect(data.video.file.extensions).to.contain('.mp3')
427 expect(data.video.file.extensions).to.contain('.ogg')
428 expect(data.video.file.extensions).to.contain('.flac')
430 await uploadVideo(server.url, server.accessToken, { fixture: 'video_short.mkv' }, 200)
431 await uploadVideo(server.url, server.accessToken, { fixture: 'sample.ogg' }, 200)
434 it('Should have the configuration updated after a restart', async function () {
437 killallServers([ server ])
439 await reRunServer(server)
441 const res = await getCustomConfig(server.url, server.accessToken)
442 const data = res.body
444 checkUpdatedConfig(data)
447 it('Should fetch the about information', async function () {
448 const res = await getAbout(server.url)
449 const data: About = res.body
451 expect(data.instance.name).to.equal('PeerTube updated')
452 expect(data.instance.shortDescription).to.equal('my short description')
453 expect(data.instance.description).to.equal('my super description')
454 expect(data.instance.terms).to.equal('my super terms')
455 expect(data.instance.codeOfConduct).to.equal('my super coc')
457 expect(data.instance.creationReason).to.equal('my super creation reason')
458 expect(data.instance.moderationInformation).to.equal('my super moderation information')
459 expect(data.instance.administrator).to.equal('Kuja')
460 expect(data.instance.maintenanceLifetime).to.equal('forever')
461 expect(data.instance.businessModel).to.equal('my super business model')
462 expect(data.instance.hardwareInformation).to.equal('2vCore 3GB RAM')
464 expect(data.instance.languages).to.deep.equal([ 'en', 'es' ])
465 expect(data.instance.categories).to.deep.equal([ 1, 2 ])
468 it('Should remove the custom configuration', async function () {
471 await deleteCustomConfig(server.url, server.accessToken)
473 const res = await getCustomConfig(server.url, server.accessToken)
474 const data = res.body
476 checkInitialConfig(server, data)
479 after(async function () {
480 await cleanupTests([ server ])