1 /* tslint:disable:no-unused-expression */
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'
14 killallServers, parallelTests,
16 reRunServer, ServerInfo,
17 setAccessTokensToServers,
18 updateCustomConfig, uploadVideo
19 } from '../../../../shared/extra-utils'
20 import { ServerConfig } from '../../../../shared/models'
22 const expect = chai.expect
24 function checkInitialConfig (server: ServerInfo, data: CustomConfig) {
25 expect(data.instance.name).to.equal('PeerTube')
26 expect(data.instance.shortDescription).to.equal(
27 'PeerTube, a federated (ActivityPub) video streaming platform using P2P (BitTorrent) directly in the web browser ' +
28 'with WebTorrent and Angular.'
30 expect(data.instance.description).to.equal('Welcome to this PeerTube instance!')
32 expect(data.instance.terms).to.equal('No terms for now.')
33 expect(data.instance.creationReason).to.be.empty
34 expect(data.instance.codeOfConduct).to.be.empty
35 expect(data.instance.moderationInformation).to.be.empty
36 expect(data.instance.administrator).to.be.empty
37 expect(data.instance.maintenanceLifetime).to.be.empty
38 expect(data.instance.businessModel).to.be.empty
39 expect(data.instance.hardwareInformation).to.be.empty
41 expect(data.instance.languages).to.have.lengthOf(0)
42 expect(data.instance.categories).to.have.lengthOf(0)
44 expect(data.instance.defaultClientRoute).to.equal('/videos/trending')
45 expect(data.instance.isNSFW).to.be.false
46 expect(data.instance.defaultNSFWPolicy).to.equal('display')
47 expect(data.instance.customizations.css).to.be.empty
48 expect(data.instance.customizations.javascript).to.be.empty
50 expect(data.services.twitter.username).to.equal('@Chocobozzz')
51 expect(data.services.twitter.whitelisted).to.be.false
53 expect(data.cache.previews.size).to.equal(1)
54 expect(data.cache.captions.size).to.equal(1)
56 expect(data.signup.enabled).to.be.true
57 expect(data.signup.limit).to.equal(4)
58 expect(data.signup.requiresEmailVerification).to.be.false
60 expect(data.admin.email).to.equal('admin' + server.internalServerNumber + '@example.com')
61 expect(data.contactForm.enabled).to.be.true
63 expect(data.user.videoQuota).to.equal(5242880)
64 expect(data.user.videoQuotaDaily).to.equal(-1)
65 expect(data.transcoding.enabled).to.be.false
66 expect(data.transcoding.allowAdditionalExtensions).to.be.false
67 expect(data.transcoding.allowAudioFiles).to.be.false
68 expect(data.transcoding.threads).to.equal(2)
69 expect(data.transcoding.resolutions['240p']).to.be.true
70 expect(data.transcoding.resolutions['360p']).to.be.true
71 expect(data.transcoding.resolutions['480p']).to.be.true
72 expect(data.transcoding.resolutions['720p']).to.be.true
73 expect(data.transcoding.resolutions['1080p']).to.be.true
74 expect(data.transcoding.resolutions['2160p']).to.be.true
75 expect(data.transcoding.hls.enabled).to.be.true
77 expect(data.import.videos.http.enabled).to.be.true
78 expect(data.import.videos.torrent.enabled).to.be.true
79 expect(data.autoBlacklist.videos.ofUsers.enabled).to.be.false
81 expect(data.followers.instance.enabled).to.be.true
82 expect(data.followers.instance.manualApproval).to.be.false
84 expect(data.followings.instance.autoFollowBack.enabled).to.be.false
85 expect(data.followings.instance.autoFollowIndex.enabled).to.be.false
86 expect(data.followings.instance.autoFollowIndex.indexUrl).to.equal('https://instances.joinpeertube.org')
89 function checkUpdatedConfig (data: CustomConfig) {
90 expect(data.instance.name).to.equal('PeerTube updated')
91 expect(data.instance.shortDescription).to.equal('my short description')
92 expect(data.instance.description).to.equal('my super description')
94 expect(data.instance.terms).to.equal('my super terms')
95 expect(data.instance.creationReason).to.equal('my super creation reason')
96 expect(data.instance.codeOfConduct).to.equal('my super coc')
97 expect(data.instance.moderationInformation).to.equal('my super moderation information')
98 expect(data.instance.administrator).to.equal('Kuja')
99 expect(data.instance.maintenanceLifetime).to.equal('forever')
100 expect(data.instance.businessModel).to.equal('my super business model')
101 expect(data.instance.hardwareInformation).to.equal('2vCore 3GB RAM')
103 expect(data.instance.languages).to.deep.equal([ 'en', 'es' ])
104 expect(data.instance.categories).to.deep.equal([ 1, 2 ])
106 expect(data.instance.defaultClientRoute).to.equal('/videos/recently-added')
107 expect(data.instance.isNSFW).to.be.true
108 expect(data.instance.defaultNSFWPolicy).to.equal('blur')
109 expect(data.instance.customizations.javascript).to.equal('alert("coucou")')
110 expect(data.instance.customizations.css).to.equal('body { background-color: red; }')
112 expect(data.services.twitter.username).to.equal('@Kuja')
113 expect(data.services.twitter.whitelisted).to.be.true
115 expect(data.cache.previews.size).to.equal(2)
116 expect(data.cache.captions.size).to.equal(3)
118 expect(data.signup.enabled).to.be.false
119 expect(data.signup.limit).to.equal(5)
120 expect(data.signup.requiresEmailVerification).to.be.false
122 // We override admin email in parallel tests, so skip this exception
123 if (parallelTests() === false) {
124 expect(data.admin.email).to.equal('superadmin1@example.com')
127 expect(data.contactForm.enabled).to.be.false
129 expect(data.user.videoQuota).to.equal(5242881)
130 expect(data.user.videoQuotaDaily).to.equal(318742)
132 expect(data.transcoding.enabled).to.be.true
133 expect(data.transcoding.threads).to.equal(1)
134 expect(data.transcoding.allowAdditionalExtensions).to.be.true
135 expect(data.transcoding.allowAudioFiles).to.be.true
136 expect(data.transcoding.resolutions['240p']).to.be.false
137 expect(data.transcoding.resolutions['360p']).to.be.true
138 expect(data.transcoding.resolutions['480p']).to.be.true
139 expect(data.transcoding.resolutions['720p']).to.be.false
140 expect(data.transcoding.resolutions['1080p']).to.be.false
141 expect(data.transcoding.resolutions['2160p']).to.be.false
142 expect(data.transcoding.hls.enabled).to.be.false
144 expect(data.import.videos.http.enabled).to.be.false
145 expect(data.import.videos.torrent.enabled).to.be.false
146 expect(data.autoBlacklist.videos.ofUsers.enabled).to.be.true
148 expect(data.followers.instance.enabled).to.be.false
149 expect(data.followers.instance.manualApproval).to.be.true
151 expect(data.followings.instance.autoFollowBack.enabled).to.be.true
152 expect(data.followings.instance.autoFollowIndex.enabled).to.be.true
153 expect(data.followings.instance.autoFollowIndex.indexUrl).to.equal('https://updated.example.com')
156 describe('Test config', function () {
159 before(async function () {
162 server = await flushAndRunServer(1)
163 await setAccessTokensToServers([ server ])
166 it('Should have a correct config on a server with registration enabled', async function () {
167 const res = await getConfig(server.url)
168 const data: ServerConfig = res.body
170 expect(data.signup.allowed).to.be.true
173 it('Should have a correct config on a server with registration enabled and a users limit', async function () {
177 registerUser(server.url, 'user1', 'super password'),
178 registerUser(server.url, 'user2', 'super password'),
179 registerUser(server.url, 'user3', 'super password')
182 const res = await getConfig(server.url)
183 const data: ServerConfig = res.body
185 expect(data.signup.allowed).to.be.false
188 it('Should have the correct video allowed extensions', async function () {
189 const res = await getConfig(server.url)
190 const data: ServerConfig = res.body
192 expect(data.video.file.extensions).to.have.lengthOf(3)
193 expect(data.video.file.extensions).to.contain('.mp4')
194 expect(data.video.file.extensions).to.contain('.webm')
195 expect(data.video.file.extensions).to.contain('.ogv')
197 await uploadVideo(server.url, server.accessToken, { fixture: 'video_short.mkv' }, 400)
198 await uploadVideo(server.url, server.accessToken, { fixture: 'sample.ogg' }, 400)
200 expect(data.contactForm.enabled).to.be.true
203 it('Should get the customized configuration', async function () {
204 const res = await getCustomConfig(server.url, server.accessToken)
205 const data = res.body as CustomConfig
207 checkInitialConfig(server, data)
210 it('Should update the customized configuration', async function () {
211 const newCustomConfig: CustomConfig = {
213 name: 'PeerTube updated',
214 shortDescription: 'my short description',
215 description: 'my super description',
216 terms: 'my super terms',
217 codeOfConduct: 'my super coc',
219 creationReason: 'my super creation reason',
220 moderationInformation: 'my super moderation information',
221 administrator: 'Kuja',
222 maintenanceLifetime: 'forever',
223 businessModel: 'my super business model',
224 hardwareInformation: '2vCore 3GB RAM',
226 languages: [ 'en', 'es' ],
227 categories: [ 1, 2 ],
229 defaultClientRoute: '/videos/recently-added',
231 defaultNSFWPolicy: 'blur' as 'blur',
233 javascript: 'alert("coucou")',
234 css: 'body { background-color: red; }'
257 requiresEmailVerification: false
260 email: 'superadmin1@example.com'
267 videoQuotaDaily: 318742
271 allowAdditionalExtensions: true,
272 allowAudioFiles: true,
316 indexUrl: 'https://updated.example.com'
321 await updateCustomConfig(server.url, server.accessToken, newCustomConfig)
323 const res = await getCustomConfig(server.url, server.accessToken)
324 const data = res.body
326 checkUpdatedConfig(data)
329 it('Should have the correct updated video allowed extensions', async function () {
330 const res = await getConfig(server.url)
331 const data: ServerConfig = res.body
333 expect(data.video.file.extensions).to.have.length.above(3)
334 expect(data.video.file.extensions).to.contain('.mp4')
335 expect(data.video.file.extensions).to.contain('.webm')
336 expect(data.video.file.extensions).to.contain('.ogv')
337 expect(data.video.file.extensions).to.contain('.flv')
338 expect(data.video.file.extensions).to.contain('.mkv')
339 expect(data.video.file.extensions).to.contain('.mp3')
340 expect(data.video.file.extensions).to.contain('.ogg')
341 expect(data.video.file.extensions).to.contain('.flac')
343 await uploadVideo(server.url, server.accessToken, { fixture: 'video_short.mkv' }, 200)
344 await uploadVideo(server.url, server.accessToken, { fixture: 'sample.ogg' }, 200)
347 it('Should have the configuration updated after a restart', async function () {
350 killallServers([ server ])
352 await reRunServer(server)
354 const res = await getCustomConfig(server.url, server.accessToken)
355 const data = res.body
357 checkUpdatedConfig(data)
360 it('Should fetch the about information', async function () {
361 const res = await getAbout(server.url)
362 const data: About = res.body
364 expect(data.instance.name).to.equal('PeerTube updated')
365 expect(data.instance.shortDescription).to.equal('my short description')
366 expect(data.instance.description).to.equal('my super description')
367 expect(data.instance.terms).to.equal('my super terms')
368 expect(data.instance.codeOfConduct).to.equal('my super coc')
370 expect(data.instance.creationReason).to.equal('my super creation reason')
371 expect(data.instance.moderationInformation).to.equal('my super moderation information')
372 expect(data.instance.administrator).to.equal('Kuja')
373 expect(data.instance.maintenanceLifetime).to.equal('forever')
374 expect(data.instance.businessModel).to.equal('my super business model')
375 expect(data.instance.hardwareInformation).to.equal('2vCore 3GB RAM')
377 expect(data.instance.languages).to.deep.equal([ 'en', 'es' ])
378 expect(data.instance.categories).to.deep.equal([ 1, 2 ])
381 it('Should remove the custom configuration', async function () {
384 await deleteCustomConfig(server.url, server.accessToken)
386 const res = await getCustomConfig(server.url, server.accessToken)
387 const data = res.body
389 checkInitialConfig(server, data)
392 after(async function () {
393 await cleanupTests([ server ])