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.codeOfConduct).to.be.empty
34 expect(data.instance.moderationInformation).to.be.empty
35 expect(data.instance.administrator).to.be.empty
36 expect(data.instance.maintenanceLifetime).to.be.empty
37 expect(data.instance.businessModel).to.be.empty
39 expect(data.instance.languages).to.have.lengthOf(0)
40 expect(data.instance.categories).to.have.lengthOf(0)
42 expect(data.instance.defaultClientRoute).to.equal('/videos/trending')
43 expect(data.instance.isNSFW).to.be.false
44 expect(data.instance.defaultNSFWPolicy).to.equal('display')
45 expect(data.instance.customizations.css).to.be.empty
46 expect(data.instance.customizations.javascript).to.be.empty
48 expect(data.services.twitter.username).to.equal('@Chocobozzz')
49 expect(data.services.twitter.whitelisted).to.be.false
51 expect(data.cache.previews.size).to.equal(1)
52 expect(data.cache.captions.size).to.equal(1)
54 expect(data.signup.enabled).to.be.true
55 expect(data.signup.limit).to.equal(4)
56 expect(data.signup.requiresEmailVerification).to.be.false
58 expect(data.admin.email).to.equal('admin' + server.internalServerNumber + '@example.com')
59 expect(data.contactForm.enabled).to.be.true
61 expect(data.user.videoQuota).to.equal(5242880)
62 expect(data.user.videoQuotaDaily).to.equal(-1)
63 expect(data.transcoding.enabled).to.be.false
64 expect(data.transcoding.allowAdditionalExtensions).to.be.false
65 expect(data.transcoding.allowAudioFiles).to.be.false
66 expect(data.transcoding.threads).to.equal(2)
67 expect(data.transcoding.resolutions['240p']).to.be.true
68 expect(data.transcoding.resolutions['360p']).to.be.true
69 expect(data.transcoding.resolutions['480p']).to.be.true
70 expect(data.transcoding.resolutions['720p']).to.be.true
71 expect(data.transcoding.resolutions['1080p']).to.be.true
72 expect(data.transcoding.resolutions['2160p']).to.be.true
73 expect(data.transcoding.hls.enabled).to.be.true
75 expect(data.import.videos.http.enabled).to.be.true
76 expect(data.import.videos.torrent.enabled).to.be.true
77 expect(data.autoBlacklist.videos.ofUsers.enabled).to.be.false
79 expect(data.followers.instance.enabled).to.be.true
80 expect(data.followers.instance.manualApproval).to.be.false
82 expect(data.followings.instance.autoFollowBack.enabled).to.be.false
83 expect(data.followings.instance.autoFollowIndex.enabled).to.be.false
84 expect(data.followings.instance.autoFollowIndex.indexUrl).to.equal('https://instances.joinpeertube.org')
87 function checkUpdatedConfig (data: CustomConfig) {
88 expect(data.instance.name).to.equal('PeerTube updated')
89 expect(data.instance.shortDescription).to.equal('my short description')
90 expect(data.instance.description).to.equal('my super description')
92 expect(data.instance.terms).to.equal('my super terms')
93 expect(data.instance.codeOfConduct).to.equal('my super coc')
94 expect(data.instance.moderationInformation).to.equal('my super moderation information')
95 expect(data.instance.administrator).to.equal('Kuja')
96 expect(data.instance.maintenanceLifetime).to.equal('forever')
97 expect(data.instance.businessModel).to.equal('my super business model')
99 expect(data.instance.languages).to.deep.equal([ 'en', 'es' ])
100 expect(data.instance.categories).to.deep.equal([ 1, 2 ])
102 expect(data.instance.defaultClientRoute).to.equal('/videos/recently-added')
103 expect(data.instance.isNSFW).to.be.true
104 expect(data.instance.defaultNSFWPolicy).to.equal('blur')
105 expect(data.instance.customizations.javascript).to.equal('alert("coucou")')
106 expect(data.instance.customizations.css).to.equal('body { background-color: red; }')
108 expect(data.services.twitter.username).to.equal('@Kuja')
109 expect(data.services.twitter.whitelisted).to.be.true
111 expect(data.cache.previews.size).to.equal(2)
112 expect(data.cache.captions.size).to.equal(3)
114 expect(data.signup.enabled).to.be.false
115 expect(data.signup.limit).to.equal(5)
116 expect(data.signup.requiresEmailVerification).to.be.false
118 // We override admin email in parallel tests, so skip this exception
119 if (parallelTests() === false) {
120 expect(data.admin.email).to.equal('superadmin1@example.com')
123 expect(data.contactForm.enabled).to.be.false
125 expect(data.user.videoQuota).to.equal(5242881)
126 expect(data.user.videoQuotaDaily).to.equal(318742)
128 expect(data.transcoding.enabled).to.be.true
129 expect(data.transcoding.threads).to.equal(1)
130 expect(data.transcoding.allowAdditionalExtensions).to.be.true
131 expect(data.transcoding.allowAudioFiles).to.be.true
132 expect(data.transcoding.resolutions['240p']).to.be.false
133 expect(data.transcoding.resolutions['360p']).to.be.true
134 expect(data.transcoding.resolutions['480p']).to.be.true
135 expect(data.transcoding.resolutions['720p']).to.be.false
136 expect(data.transcoding.resolutions['1080p']).to.be.false
137 expect(data.transcoding.resolutions['2160p']).to.be.false
138 expect(data.transcoding.hls.enabled).to.be.false
140 expect(data.import.videos.http.enabled).to.be.false
141 expect(data.import.videos.torrent.enabled).to.be.false
142 expect(data.autoBlacklist.videos.ofUsers.enabled).to.be.true
144 expect(data.followers.instance.enabled).to.be.false
145 expect(data.followers.instance.manualApproval).to.be.true
147 expect(data.followings.instance.autoFollowBack.enabled).to.be.true
148 expect(data.followings.instance.autoFollowIndex.enabled).to.be.true
149 expect(data.followings.instance.autoFollowIndex.indexUrl).to.equal('https://updated.example.com')
152 describe('Test config', function () {
155 before(async function () {
158 server = await flushAndRunServer(1)
159 await setAccessTokensToServers([ server ])
162 it('Should have a correct config on a server with registration enabled', async function () {
163 const res = await getConfig(server.url)
164 const data: ServerConfig = res.body
166 expect(data.signup.allowed).to.be.true
169 it('Should have a correct config on a server with registration enabled and a users limit', async function () {
173 registerUser(server.url, 'user1', 'super password'),
174 registerUser(server.url, 'user2', 'super password'),
175 registerUser(server.url, 'user3', 'super password')
178 const res = await getConfig(server.url)
179 const data: ServerConfig = res.body
181 expect(data.signup.allowed).to.be.false
184 it('Should have the correct video allowed extensions', async function () {
185 const res = await getConfig(server.url)
186 const data: ServerConfig = res.body
188 expect(data.video.file.extensions).to.have.lengthOf(3)
189 expect(data.video.file.extensions).to.contain('.mp4')
190 expect(data.video.file.extensions).to.contain('.webm')
191 expect(data.video.file.extensions).to.contain('.ogv')
193 await uploadVideo(server.url, server.accessToken, { fixture: 'video_short.mkv' }, 400)
194 await uploadVideo(server.url, server.accessToken, { fixture: 'sample.ogg' }, 400)
196 expect(data.contactForm.enabled).to.be.true
199 it('Should get the customized configuration', async function () {
200 const res = await getCustomConfig(server.url, server.accessToken)
201 const data = res.body as CustomConfig
203 checkInitialConfig(server, data)
206 it('Should update the customized configuration', async function () {
207 const newCustomConfig: CustomConfig = {
209 name: 'PeerTube updated',
210 shortDescription: 'my short description',
211 description: 'my super description',
212 terms: 'my super terms',
213 codeOfConduct: 'my super coc',
215 moderationInformation: 'my super moderation information',
216 administrator: 'Kuja',
217 maintenanceLifetime: 'forever',
218 businessModel: 'my super business model',
220 languages: [ 'en', 'es' ],
221 categories: [ 1, 2 ],
223 defaultClientRoute: '/videos/recently-added',
225 defaultNSFWPolicy: 'blur' as 'blur',
227 javascript: 'alert("coucou")',
228 css: 'body { background-color: red; }'
251 requiresEmailVerification: false
254 email: 'superadmin1@example.com'
261 videoQuotaDaily: 318742
265 allowAdditionalExtensions: true,
266 allowAudioFiles: true,
310 indexUrl: 'https://updated.example.com'
315 await updateCustomConfig(server.url, server.accessToken, newCustomConfig)
317 const res = await getCustomConfig(server.url, server.accessToken)
318 const data = res.body
320 checkUpdatedConfig(data)
323 it('Should have the correct updated video allowed extensions', async function () {
324 const res = await getConfig(server.url)
325 const data: ServerConfig = res.body
327 expect(data.video.file.extensions).to.have.length.above(3)
328 expect(data.video.file.extensions).to.contain('.mp4')
329 expect(data.video.file.extensions).to.contain('.webm')
330 expect(data.video.file.extensions).to.contain('.ogv')
331 expect(data.video.file.extensions).to.contain('.flv')
332 expect(data.video.file.extensions).to.contain('.mkv')
333 expect(data.video.file.extensions).to.contain('.mp3')
334 expect(data.video.file.extensions).to.contain('.ogg')
335 expect(data.video.file.extensions).to.contain('.flac')
337 await uploadVideo(server.url, server.accessToken, { fixture: 'video_short.mkv' }, 200)
338 await uploadVideo(server.url, server.accessToken, { fixture: 'sample.ogg' }, 200)
341 it('Should have the configuration updated after a restart', async function () {
344 killallServers([ server ])
346 await reRunServer(server)
348 const res = await getCustomConfig(server.url, server.accessToken)
349 const data = res.body
351 checkUpdatedConfig(data)
354 it('Should fetch the about information', async function () {
355 const res = await getAbout(server.url)
356 const data: About = res.body
358 expect(data.instance.name).to.equal('PeerTube updated')
359 expect(data.instance.shortDescription).to.equal('my short description')
360 expect(data.instance.description).to.equal('my super description')
361 expect(data.instance.terms).to.equal('my super terms')
364 it('Should remove the custom configuration', async function () {
367 await deleteCustomConfig(server.url, server.accessToken)
369 const res = await getCustomConfig(server.url, server.accessToken)
370 const data = res.body
372 checkInitialConfig(server, data)
375 after(async function () {
376 await cleanupTests([ server ])