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.webtorrent.enabled).to.be.true
76 expect(data.transcoding.hls.enabled).to.be.true
78 expect(data.import.videos.http.enabled).to.be.true
79 expect(data.import.videos.torrent.enabled).to.be.true
80 expect(data.autoBlacklist.videos.ofUsers.enabled).to.be.false
82 expect(data.followers.instance.enabled).to.be.true
83 expect(data.followers.instance.manualApproval).to.be.false
85 expect(data.followings.instance.autoFollowBack.enabled).to.be.false
86 expect(data.followings.instance.autoFollowIndex.enabled).to.be.false
87 expect(data.followings.instance.autoFollowIndex.indexUrl).to.equal('https://instances.joinpeertube.org')
90 function checkUpdatedConfig (data: CustomConfig) {
91 expect(data.instance.name).to.equal('PeerTube updated')
92 expect(data.instance.shortDescription).to.equal('my short description')
93 expect(data.instance.description).to.equal('my super description')
95 expect(data.instance.terms).to.equal('my super terms')
96 expect(data.instance.creationReason).to.equal('my super creation reason')
97 expect(data.instance.codeOfConduct).to.equal('my super coc')
98 expect(data.instance.moderationInformation).to.equal('my super moderation information')
99 expect(data.instance.administrator).to.equal('Kuja')
100 expect(data.instance.maintenanceLifetime).to.equal('forever')
101 expect(data.instance.businessModel).to.equal('my super business model')
102 expect(data.instance.hardwareInformation).to.equal('2vCore 3GB RAM')
104 expect(data.instance.languages).to.deep.equal([ 'en', 'es' ])
105 expect(data.instance.categories).to.deep.equal([ 1, 2 ])
107 expect(data.instance.defaultClientRoute).to.equal('/videos/recently-added')
108 expect(data.instance.isNSFW).to.be.true
109 expect(data.instance.defaultNSFWPolicy).to.equal('blur')
110 expect(data.instance.customizations.javascript).to.equal('alert("coucou")')
111 expect(data.instance.customizations.css).to.equal('body { background-color: red; }')
113 expect(data.services.twitter.username).to.equal('@Kuja')
114 expect(data.services.twitter.whitelisted).to.be.true
116 expect(data.cache.previews.size).to.equal(2)
117 expect(data.cache.captions.size).to.equal(3)
119 expect(data.signup.enabled).to.be.false
120 expect(data.signup.limit).to.equal(5)
121 expect(data.signup.requiresEmailVerification).to.be.false
123 // We override admin email in parallel tests, so skip this exception
124 if (parallelTests() === false) {
125 expect(data.admin.email).to.equal('superadmin1@example.com')
128 expect(data.contactForm.enabled).to.be.false
130 expect(data.user.videoQuota).to.equal(5242881)
131 expect(data.user.videoQuotaDaily).to.equal(318742)
133 expect(data.transcoding.enabled).to.be.true
134 expect(data.transcoding.threads).to.equal(1)
135 expect(data.transcoding.allowAdditionalExtensions).to.be.true
136 expect(data.transcoding.allowAudioFiles).to.be.true
137 expect(data.transcoding.resolutions['240p']).to.be.false
138 expect(data.transcoding.resolutions['360p']).to.be.true
139 expect(data.transcoding.resolutions['480p']).to.be.true
140 expect(data.transcoding.resolutions['720p']).to.be.false
141 expect(data.transcoding.resolutions['1080p']).to.be.false
142 expect(data.transcoding.resolutions['2160p']).to.be.false
143 expect(data.transcoding.hls.enabled).to.be.false
144 expect(data.transcoding.webtorrent.enabled).to.be.true
146 expect(data.import.videos.http.enabled).to.be.false
147 expect(data.import.videos.torrent.enabled).to.be.false
148 expect(data.autoBlacklist.videos.ofUsers.enabled).to.be.true
150 expect(data.followers.instance.enabled).to.be.false
151 expect(data.followers.instance.manualApproval).to.be.true
153 expect(data.followings.instance.autoFollowBack.enabled).to.be.true
154 expect(data.followings.instance.autoFollowIndex.enabled).to.be.true
155 expect(data.followings.instance.autoFollowIndex.indexUrl).to.equal('https://updated.example.com')
158 describe('Test config', function () {
161 before(async function () {
164 server = await flushAndRunServer(1)
165 await setAccessTokensToServers([ server ])
168 it('Should have a correct config on a server with registration enabled', async function () {
169 const res = await getConfig(server.url)
170 const data: ServerConfig = res.body
172 expect(data.signup.allowed).to.be.true
175 it('Should have a correct config on a server with registration enabled and a users limit', async function () {
179 registerUser(server.url, 'user1', 'super password'),
180 registerUser(server.url, 'user2', 'super password'),
181 registerUser(server.url, 'user3', 'super password')
184 const res = await getConfig(server.url)
185 const data: ServerConfig = res.body
187 expect(data.signup.allowed).to.be.false
190 it('Should have the correct video allowed extensions', async function () {
191 const res = await getConfig(server.url)
192 const data: ServerConfig = res.body
194 expect(data.video.file.extensions).to.have.lengthOf(3)
195 expect(data.video.file.extensions).to.contain('.mp4')
196 expect(data.video.file.extensions).to.contain('.webm')
197 expect(data.video.file.extensions).to.contain('.ogv')
199 await uploadVideo(server.url, server.accessToken, { fixture: 'video_short.mkv' }, 400)
200 await uploadVideo(server.url, server.accessToken, { fixture: 'sample.ogg' }, 400)
202 expect(data.contactForm.enabled).to.be.true
205 it('Should get the customized configuration', async function () {
206 const res = await getCustomConfig(server.url, server.accessToken)
207 const data = res.body as CustomConfig
209 checkInitialConfig(server, data)
212 it('Should update the customized configuration', async function () {
213 const newCustomConfig: CustomConfig = {
215 name: 'PeerTube updated',
216 shortDescription: 'my short description',
217 description: 'my super description',
218 terms: 'my super terms',
219 codeOfConduct: 'my super coc',
221 creationReason: 'my super creation reason',
222 moderationInformation: 'my super moderation information',
223 administrator: 'Kuja',
224 maintenanceLifetime: 'forever',
225 businessModel: 'my super business model',
226 hardwareInformation: '2vCore 3GB RAM',
228 languages: [ 'en', 'es' ],
229 categories: [ 1, 2 ],
231 defaultClientRoute: '/videos/recently-added',
233 defaultNSFWPolicy: 'blur' as 'blur',
235 javascript: 'alert("coucou")',
236 css: 'body { background-color: red; }'
259 requiresEmailVerification: false
262 email: 'superadmin1@example.com'
269 videoQuotaDaily: 318742
273 allowAdditionalExtensions: true,
274 allowAudioFiles: true,
322 indexUrl: 'https://updated.example.com'
327 await updateCustomConfig(server.url, server.accessToken, newCustomConfig)
329 const res = await getCustomConfig(server.url, server.accessToken)
330 const data = res.body
332 checkUpdatedConfig(data)
335 it('Should have the correct updated video allowed extensions', async function () {
336 const res = await getConfig(server.url)
337 const data: ServerConfig = res.body
339 expect(data.video.file.extensions).to.have.length.above(3)
340 expect(data.video.file.extensions).to.contain('.mp4')
341 expect(data.video.file.extensions).to.contain('.webm')
342 expect(data.video.file.extensions).to.contain('.ogv')
343 expect(data.video.file.extensions).to.contain('.flv')
344 expect(data.video.file.extensions).to.contain('.mkv')
345 expect(data.video.file.extensions).to.contain('.mp3')
346 expect(data.video.file.extensions).to.contain('.ogg')
347 expect(data.video.file.extensions).to.contain('.flac')
349 await uploadVideo(server.url, server.accessToken, { fixture: 'video_short.mkv' }, 200)
350 await uploadVideo(server.url, server.accessToken, { fixture: 'sample.ogg' }, 200)
353 it('Should have the configuration updated after a restart', async function () {
356 killallServers([ server ])
358 await reRunServer(server)
360 const res = await getCustomConfig(server.url, server.accessToken)
361 const data = res.body
363 checkUpdatedConfig(data)
366 it('Should fetch the about information', async function () {
367 const res = await getAbout(server.url)
368 const data: About = res.body
370 expect(data.instance.name).to.equal('PeerTube updated')
371 expect(data.instance.shortDescription).to.equal('my short description')
372 expect(data.instance.description).to.equal('my super description')
373 expect(data.instance.terms).to.equal('my super terms')
374 expect(data.instance.codeOfConduct).to.equal('my super coc')
376 expect(data.instance.creationReason).to.equal('my super creation reason')
377 expect(data.instance.moderationInformation).to.equal('my super moderation information')
378 expect(data.instance.administrator).to.equal('Kuja')
379 expect(data.instance.maintenanceLifetime).to.equal('forever')
380 expect(data.instance.businessModel).to.equal('my super business model')
381 expect(data.instance.hardwareInformation).to.equal('2vCore 3GB RAM')
383 expect(data.instance.languages).to.deep.equal([ 'en', 'es' ])
384 expect(data.instance.categories).to.deep.equal([ 1, 2 ])
387 it('Should remove the custom configuration', async function () {
390 await deleteCustomConfig(server.url, server.accessToken)
392 const res = await getCustomConfig(server.url, server.accessToken)
393 const data = res.body
395 checkInitialConfig(server, data)
398 after(async function () {
399 await cleanupTests([ server ])