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)
58 expect(data.cache.torrents.size).to.equal(1)
60 expect(data.signup.enabled).to.be.true
61 expect(data.signup.limit).to.equal(4)
62 expect(data.signup.requiresEmailVerification).to.be.false
64 expect(data.admin.email).to.equal('admin' + server.internalServerNumber + '@example.com')
65 expect(data.contactForm.enabled).to.be.true
67 expect(data.user.videoQuota).to.equal(5242880)
68 expect(data.user.videoQuotaDaily).to.equal(-1)
70 expect(data.transcoding.enabled).to.be.false
71 expect(data.transcoding.allowAdditionalExtensions).to.be.false
72 expect(data.transcoding.allowAudioFiles).to.be.false
73 expect(data.transcoding.threads).to.equal(2)
74 expect(data.transcoding.concurrency).to.equal(2)
75 expect(data.transcoding.profile).to.equal('default')
76 expect(data.transcoding.resolutions['240p']).to.be.true
77 expect(data.transcoding.resolutions['360p']).to.be.true
78 expect(data.transcoding.resolutions['480p']).to.be.true
79 expect(data.transcoding.resolutions['720p']).to.be.true
80 expect(data.transcoding.resolutions['1080p']).to.be.true
81 expect(data.transcoding.resolutions['1440p']).to.be.true
82 expect(data.transcoding.resolutions['2160p']).to.be.true
83 expect(data.transcoding.webtorrent.enabled).to.be.true
84 expect(data.transcoding.hls.enabled).to.be.true
86 expect(data.live.enabled).to.be.false
87 expect(data.live.allowReplay).to.be.false
88 expect(data.live.maxDuration).to.equal(-1)
89 expect(data.live.maxInstanceLives).to.equal(20)
90 expect(data.live.maxUserLives).to.equal(3)
91 expect(data.live.transcoding.enabled).to.be.false
92 expect(data.live.transcoding.threads).to.equal(2)
93 expect(data.live.transcoding.profile).to.equal('default')
94 expect(data.live.transcoding.resolutions['240p']).to.be.false
95 expect(data.live.transcoding.resolutions['360p']).to.be.false
96 expect(data.live.transcoding.resolutions['480p']).to.be.false
97 expect(data.live.transcoding.resolutions['720p']).to.be.false
98 expect(data.live.transcoding.resolutions['1080p']).to.be.false
99 expect(data.live.transcoding.resolutions['1440p']).to.be.false
100 expect(data.live.transcoding.resolutions['2160p']).to.be.false
102 expect(data.import.videos.concurrency).to.equal(2)
103 expect(data.import.videos.http.enabled).to.be.true
104 expect(data.import.videos.torrent.enabled).to.be.true
105 expect(data.autoBlacklist.videos.ofUsers.enabled).to.be.false
107 expect(data.followers.instance.enabled).to.be.true
108 expect(data.followers.instance.manualApproval).to.be.false
110 expect(data.followings.instance.autoFollowBack.enabled).to.be.false
111 expect(data.followings.instance.autoFollowIndex.enabled).to.be.false
112 expect(data.followings.instance.autoFollowIndex.indexUrl).to.equal('')
114 expect(data.broadcastMessage.enabled).to.be.false
115 expect(data.broadcastMessage.level).to.equal('info')
116 expect(data.broadcastMessage.message).to.equal('')
117 expect(data.broadcastMessage.dismissable).to.be.false
120 function checkUpdatedConfig (data: CustomConfig) {
121 expect(data.instance.name).to.equal('PeerTube updated')
122 expect(data.instance.shortDescription).to.equal('my short description')
123 expect(data.instance.description).to.equal('my super description')
125 expect(data.instance.terms).to.equal('my super terms')
126 expect(data.instance.creationReason).to.equal('my super creation reason')
127 expect(data.instance.codeOfConduct).to.equal('my super coc')
128 expect(data.instance.moderationInformation).to.equal('my super moderation information')
129 expect(data.instance.administrator).to.equal('Kuja')
130 expect(data.instance.maintenanceLifetime).to.equal('forever')
131 expect(data.instance.businessModel).to.equal('my super business model')
132 expect(data.instance.hardwareInformation).to.equal('2vCore 3GB RAM')
134 expect(data.instance.languages).to.deep.equal([ 'en', 'es' ])
135 expect(data.instance.categories).to.deep.equal([ 1, 2 ])
137 expect(data.instance.defaultClientRoute).to.equal('/videos/recently-added')
138 expect(data.instance.isNSFW).to.be.true
139 expect(data.instance.defaultNSFWPolicy).to.equal('blur')
140 expect(data.instance.customizations.javascript).to.equal('alert("coucou")')
141 expect(data.instance.customizations.css).to.equal('body { background-color: red; }')
143 expect(data.services.twitter.username).to.equal('@Kuja')
144 expect(data.services.twitter.whitelisted).to.be.true
146 expect(data.cache.previews.size).to.equal(2)
147 expect(data.cache.captions.size).to.equal(3)
148 expect(data.cache.torrents.size).to.equal(4)
150 expect(data.signup.enabled).to.be.false
151 expect(data.signup.limit).to.equal(5)
152 expect(data.signup.requiresEmailVerification).to.be.false
154 // We override admin email in parallel tests, so skip this exception
155 if (parallelTests() === false) {
156 expect(data.admin.email).to.equal('superadmin1@example.com')
159 expect(data.contactForm.enabled).to.be.false
161 expect(data.user.videoQuota).to.equal(5242881)
162 expect(data.user.videoQuotaDaily).to.equal(318742)
164 expect(data.transcoding.enabled).to.be.true
165 expect(data.transcoding.threads).to.equal(1)
166 expect(data.transcoding.concurrency).to.equal(3)
167 expect(data.transcoding.allowAdditionalExtensions).to.be.true
168 expect(data.transcoding.allowAudioFiles).to.be.true
169 expect(data.transcoding.profile).to.equal('vod_profile')
170 expect(data.transcoding.resolutions['240p']).to.be.false
171 expect(data.transcoding.resolutions['360p']).to.be.true
172 expect(data.transcoding.resolutions['480p']).to.be.true
173 expect(data.transcoding.resolutions['720p']).to.be.false
174 expect(data.transcoding.resolutions['1080p']).to.be.false
175 expect(data.transcoding.resolutions['2160p']).to.be.false
176 expect(data.transcoding.hls.enabled).to.be.false
177 expect(data.transcoding.webtorrent.enabled).to.be.true
179 expect(data.live.enabled).to.be.true
180 expect(data.live.allowReplay).to.be.true
181 expect(data.live.maxDuration).to.equal(5000)
182 expect(data.live.maxInstanceLives).to.equal(-1)
183 expect(data.live.maxUserLives).to.equal(10)
184 expect(data.live.transcoding.enabled).to.be.true
185 expect(data.live.transcoding.threads).to.equal(4)
186 expect(data.live.transcoding.profile).to.equal('live_profile')
187 expect(data.live.transcoding.resolutions['240p']).to.be.true
188 expect(data.live.transcoding.resolutions['360p']).to.be.true
189 expect(data.live.transcoding.resolutions['480p']).to.be.true
190 expect(data.live.transcoding.resolutions['720p']).to.be.true
191 expect(data.live.transcoding.resolutions['1080p']).to.be.true
192 expect(data.live.transcoding.resolutions['2160p']).to.be.true
194 expect(data.import.videos.concurrency).to.equal(4)
195 expect(data.import.videos.http.enabled).to.be.false
196 expect(data.import.videos.torrent.enabled).to.be.false
197 expect(data.autoBlacklist.videos.ofUsers.enabled).to.be.true
199 expect(data.followers.instance.enabled).to.be.false
200 expect(data.followers.instance.manualApproval).to.be.true
202 expect(data.followings.instance.autoFollowBack.enabled).to.be.true
203 expect(data.followings.instance.autoFollowIndex.enabled).to.be.true
204 expect(data.followings.instance.autoFollowIndex.indexUrl).to.equal('https://updated.example.com')
206 expect(data.broadcastMessage.enabled).to.be.true
207 expect(data.broadcastMessage.level).to.equal('error')
208 expect(data.broadcastMessage.message).to.equal('super bad message')
209 expect(data.broadcastMessage.dismissable).to.be.true
212 describe('Test config', function () {
215 before(async function () {
218 server = await flushAndRunServer(1)
219 await setAccessTokensToServers([ server ])
222 it('Should have a correct config on a server with registration enabled', async function () {
223 const res = await getConfig(server.url)
224 const data: ServerConfig = res.body
226 expect(data.signup.allowed).to.be.true
229 it('Should have a correct config on a server with registration enabled and a users limit', async function () {
233 registerUser(server.url, 'user1', 'super password'),
234 registerUser(server.url, 'user2', 'super password'),
235 registerUser(server.url, 'user3', 'super password')
238 const res = await getConfig(server.url)
239 const data: ServerConfig = res.body
241 expect(data.signup.allowed).to.be.false
244 it('Should have the correct video allowed extensions', async function () {
245 const res = await getConfig(server.url)
246 const data: ServerConfig = res.body
248 expect(data.video.file.extensions).to.have.lengthOf(3)
249 expect(data.video.file.extensions).to.contain('.mp4')
250 expect(data.video.file.extensions).to.contain('.webm')
251 expect(data.video.file.extensions).to.contain('.ogv')
253 await uploadVideo(server.url, server.accessToken, { fixture: 'video_short.mkv' }, HttpStatusCode.UNSUPPORTED_MEDIA_TYPE_415)
254 await uploadVideo(server.url, server.accessToken, { fixture: 'sample.ogg' }, HttpStatusCode.UNSUPPORTED_MEDIA_TYPE_415)
256 expect(data.contactForm.enabled).to.be.true
259 it('Should get the customized configuration', async function () {
260 const res = await getCustomConfig(server.url, server.accessToken)
261 const data = res.body as CustomConfig
263 checkInitialConfig(server, data)
266 it('Should update the customized configuration', async function () {
267 const newCustomConfig: CustomConfig = {
269 name: 'PeerTube updated',
270 shortDescription: 'my short description',
271 description: 'my super description',
272 terms: 'my super terms',
273 codeOfConduct: 'my super coc',
275 creationReason: 'my super creation reason',
276 moderationInformation: 'my super moderation information',
277 administrator: 'Kuja',
278 maintenanceLifetime: 'forever',
279 businessModel: 'my super business model',
280 hardwareInformation: '2vCore 3GB RAM',
282 languages: [ 'en', 'es' ],
283 categories: [ 1, 2 ],
286 defaultNSFWPolicy: 'blur' as 'blur',
288 defaultClientRoute: '/videos/recently-added',
291 javascript: 'alert("coucou")',
292 css: 'body { background-color: red; }'
318 requiresEmailVerification: false
321 email: 'superadmin1@example.com'
328 videoQuotaDaily: 318742
332 allowAdditionalExtensions: true,
333 allowAudioFiles: true,
336 profile: 'vod_profile',
358 maxInstanceLives: -1,
363 profile: 'live_profile',
389 enabled: [ 'best', 'hot', 'most-viewed', 'most-liked' ],
414 indexUrl: 'https://updated.example.com'
421 message: 'super bad message',
431 url: 'https://search.joinpeertube.org',
432 disableLocalSearch: true,
433 isDefaultSearch: true
437 await updateCustomConfig(server.url, server.accessToken, newCustomConfig)
439 const res = await getCustomConfig(server.url, server.accessToken)
440 const data = res.body
442 checkUpdatedConfig(data)
445 it('Should have the correct updated video allowed extensions', async function () {
448 const res = await getConfig(server.url)
449 const data: ServerConfig = res.body
451 expect(data.video.file.extensions).to.have.length.above(4)
452 expect(data.video.file.extensions).to.contain('.mp4')
453 expect(data.video.file.extensions).to.contain('.webm')
454 expect(data.video.file.extensions).to.contain('.ogv')
455 expect(data.video.file.extensions).to.contain('.flv')
456 expect(data.video.file.extensions).to.contain('.wmv')
457 expect(data.video.file.extensions).to.contain('.mkv')
458 expect(data.video.file.extensions).to.contain('.mp3')
459 expect(data.video.file.extensions).to.contain('.ogg')
460 expect(data.video.file.extensions).to.contain('.flac')
462 await uploadVideo(server.url, server.accessToken, { fixture: 'video_short.mkv' }, HttpStatusCode.OK_200)
463 await uploadVideo(server.url, server.accessToken, { fixture: 'sample.ogg' }, HttpStatusCode.OK_200)
466 it('Should have the configuration updated after a restart', async function () {
469 killallServers([ server ])
471 await reRunServer(server)
473 const res = await getCustomConfig(server.url, server.accessToken)
474 const data = res.body
476 checkUpdatedConfig(data)
479 it('Should fetch the about information', async function () {
480 const res = await getAbout(server.url)
481 const data: About = res.body
483 expect(data.instance.name).to.equal('PeerTube updated')
484 expect(data.instance.shortDescription).to.equal('my short description')
485 expect(data.instance.description).to.equal('my super description')
486 expect(data.instance.terms).to.equal('my super terms')
487 expect(data.instance.codeOfConduct).to.equal('my super coc')
489 expect(data.instance.creationReason).to.equal('my super creation reason')
490 expect(data.instance.moderationInformation).to.equal('my super moderation information')
491 expect(data.instance.administrator).to.equal('Kuja')
492 expect(data.instance.maintenanceLifetime).to.equal('forever')
493 expect(data.instance.businessModel).to.equal('my super business model')
494 expect(data.instance.hardwareInformation).to.equal('2vCore 3GB RAM')
496 expect(data.instance.languages).to.deep.equal([ 'en', 'es' ])
497 expect(data.instance.categories).to.deep.equal([ 1, 2 ])
500 it('Should remove the custom configuration', async function () {
503 await deleteCustomConfig(server.url, server.accessToken)
505 const res = await getCustomConfig(server.url, server.accessToken)
506 const data = res.body
508 checkInitialConfig(server, data)
511 after(async function () {
512 await cleanupTests([ server ])