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!')
31 expect(data.instance.terms).to.equal('No terms for now.')
32 expect(data.instance.defaultClientRoute).to.equal('/videos/trending')
33 expect(data.instance.isNSFW).to.be.false
34 expect(data.instance.defaultNSFWPolicy).to.equal('display')
35 expect(data.instance.customizations.css).to.be.empty
36 expect(data.instance.customizations.javascript).to.be.empty
38 expect(data.services.twitter.username).to.equal('@Chocobozzz')
39 expect(data.services.twitter.whitelisted).to.be.false
41 expect(data.cache.previews.size).to.equal(1)
42 expect(data.cache.captions.size).to.equal(1)
44 expect(data.signup.enabled).to.be.true
45 expect(data.signup.limit).to.equal(4)
46 expect(data.signup.requiresEmailVerification).to.be.false
48 expect(data.admin.email).to.equal('admin' + server.internalServerNumber + '@example.com')
49 expect(data.contactForm.enabled).to.be.true
51 expect(data.user.videoQuota).to.equal(5242880)
52 expect(data.user.videoQuotaDaily).to.equal(-1)
53 expect(data.transcoding.enabled).to.be.false
54 expect(data.transcoding.allowAdditionalExtensions).to.be.false
55 expect(data.transcoding.allowAudioFiles).to.be.false
56 expect(data.transcoding.threads).to.equal(2)
57 expect(data.transcoding.resolutions['240p']).to.be.true
58 expect(data.transcoding.resolutions['360p']).to.be.true
59 expect(data.transcoding.resolutions['480p']).to.be.true
60 expect(data.transcoding.resolutions['720p']).to.be.true
61 expect(data.transcoding.resolutions['1080p']).to.be.true
62 expect(data.transcoding.resolutions['2160p']).to.be.true
63 expect(data.transcoding.hls.enabled).to.be.true
65 expect(data.import.videos.http.enabled).to.be.true
66 expect(data.import.videos.torrent.enabled).to.be.true
67 expect(data.autoBlacklist.videos.ofUsers.enabled).to.be.false
69 expect(data.followers.instance.enabled).to.be.true
70 expect(data.followers.instance.manualApproval).to.be.false
72 expect(data.followings.instance.autoFollowBack.enabled).to.be.false
73 expect(data.followings.instance.autoFollowIndex.enabled).to.be.false
74 expect(data.followings.instance.autoFollowIndex.indexUrl).to.equal('https://instances.joinpeertube.org')
77 function checkUpdatedConfig (data: CustomConfig) {
78 expect(data.instance.name).to.equal('PeerTube updated')
79 expect(data.instance.shortDescription).to.equal('my short description')
80 expect(data.instance.description).to.equal('my super description')
81 expect(data.instance.terms).to.equal('my super terms')
82 expect(data.instance.defaultClientRoute).to.equal('/videos/recently-added')
83 expect(data.instance.isNSFW).to.be.true
84 expect(data.instance.defaultNSFWPolicy).to.equal('blur')
85 expect(data.instance.customizations.javascript).to.equal('alert("coucou")')
86 expect(data.instance.customizations.css).to.equal('body { background-color: red; }')
88 expect(data.services.twitter.username).to.equal('@Kuja')
89 expect(data.services.twitter.whitelisted).to.be.true
91 expect(data.cache.previews.size).to.equal(2)
92 expect(data.cache.captions.size).to.equal(3)
94 expect(data.signup.enabled).to.be.false
95 expect(data.signup.limit).to.equal(5)
96 expect(data.signup.requiresEmailVerification).to.be.false
98 // We override admin email in parallel tests, so skip this exception
99 if (parallelTests() === false) {
100 expect(data.admin.email).to.equal('superadmin1@example.com')
103 expect(data.contactForm.enabled).to.be.false
105 expect(data.user.videoQuota).to.equal(5242881)
106 expect(data.user.videoQuotaDaily).to.equal(318742)
108 expect(data.transcoding.enabled).to.be.true
109 expect(data.transcoding.threads).to.equal(1)
110 expect(data.transcoding.allowAdditionalExtensions).to.be.true
111 expect(data.transcoding.allowAudioFiles).to.be.true
112 expect(data.transcoding.resolutions['240p']).to.be.false
113 expect(data.transcoding.resolutions['360p']).to.be.true
114 expect(data.transcoding.resolutions['480p']).to.be.true
115 expect(data.transcoding.resolutions['720p']).to.be.false
116 expect(data.transcoding.resolutions['1080p']).to.be.false
117 expect(data.transcoding.resolutions['2160p']).to.be.false
118 expect(data.transcoding.hls.enabled).to.be.false
120 expect(data.import.videos.http.enabled).to.be.false
121 expect(data.import.videos.torrent.enabled).to.be.false
122 expect(data.autoBlacklist.videos.ofUsers.enabled).to.be.true
124 expect(data.followers.instance.enabled).to.be.false
125 expect(data.followers.instance.manualApproval).to.be.true
127 expect(data.followings.instance.autoFollowBack.enabled).to.be.true
128 expect(data.followings.instance.autoFollowIndex.enabled).to.be.true
129 expect(data.followings.instance.autoFollowIndex.indexUrl).to.equal('https://updated.example.com')
132 describe('Test config', function () {
135 before(async function () {
138 server = await flushAndRunServer(1)
139 await setAccessTokensToServers([ server ])
142 it('Should have a correct config on a server with registration enabled', async function () {
143 const res = await getConfig(server.url)
144 const data: ServerConfig = res.body
146 expect(data.signup.allowed).to.be.true
149 it('Should have a correct config on a server with registration enabled and a users limit', async function () {
153 registerUser(server.url, 'user1', 'super password'),
154 registerUser(server.url, 'user2', 'super password'),
155 registerUser(server.url, 'user3', 'super password')
158 const res = await getConfig(server.url)
159 const data: ServerConfig = res.body
161 expect(data.signup.allowed).to.be.false
164 it('Should have the correct video allowed extensions', async function () {
165 const res = await getConfig(server.url)
166 const data: ServerConfig = res.body
168 expect(data.video.file.extensions).to.have.lengthOf(3)
169 expect(data.video.file.extensions).to.contain('.mp4')
170 expect(data.video.file.extensions).to.contain('.webm')
171 expect(data.video.file.extensions).to.contain('.ogv')
173 await uploadVideo(server.url, server.accessToken, { fixture: 'video_short.mkv' }, 400)
174 await uploadVideo(server.url, server.accessToken, { fixture: 'sample.ogg' }, 400)
176 expect(data.contactForm.enabled).to.be.true
179 it('Should get the customized configuration', async function () {
180 const res = await getCustomConfig(server.url, server.accessToken)
181 const data = res.body as CustomConfig
183 checkInitialConfig(server, data)
186 it('Should update the customized configuration', async function () {
187 const newCustomConfig: CustomConfig = {
189 name: 'PeerTube updated',
190 shortDescription: 'my short description',
191 description: 'my super description',
192 terms: 'my super terms',
193 defaultClientRoute: '/videos/recently-added',
195 defaultNSFWPolicy: 'blur' as 'blur',
197 javascript: 'alert("coucou")',
198 css: 'body { background-color: red; }'
221 requiresEmailVerification: false
224 email: 'superadmin1@example.com'
231 videoQuotaDaily: 318742
235 allowAdditionalExtensions: true,
236 allowAudioFiles: true,
280 indexUrl: 'https://updated.example.com'
285 await updateCustomConfig(server.url, server.accessToken, newCustomConfig)
287 const res = await getCustomConfig(server.url, server.accessToken)
288 const data = res.body
290 checkUpdatedConfig(data)
293 it('Should have the correct updated video allowed extensions', async function () {
294 const res = await getConfig(server.url)
295 const data: ServerConfig = res.body
297 expect(data.video.file.extensions).to.have.length.above(3)
298 expect(data.video.file.extensions).to.contain('.mp4')
299 expect(data.video.file.extensions).to.contain('.webm')
300 expect(data.video.file.extensions).to.contain('.ogv')
301 expect(data.video.file.extensions).to.contain('.flv')
302 expect(data.video.file.extensions).to.contain('.mkv')
303 expect(data.video.file.extensions).to.contain('.mp3')
304 expect(data.video.file.extensions).to.contain('.ogg')
305 expect(data.video.file.extensions).to.contain('.flac')
307 await uploadVideo(server.url, server.accessToken, { fixture: 'video_short.mkv' }, 200)
308 await uploadVideo(server.url, server.accessToken, { fixture: 'sample.ogg' }, 200)
311 it('Should have the configuration updated after a restart', async function () {
314 killallServers([ server ])
316 await reRunServer(server)
318 const res = await getCustomConfig(server.url, server.accessToken)
319 const data = res.body
321 checkUpdatedConfig(data)
324 it('Should fetch the about information', async function () {
325 const res = await getAbout(server.url)
326 const data: About = res.body
328 expect(data.instance.name).to.equal('PeerTube updated')
329 expect(data.instance.shortDescription).to.equal('my short description')
330 expect(data.instance.description).to.equal('my super description')
331 expect(data.instance.terms).to.equal('my super terms')
334 it('Should remove the custom configuration', async function () {
337 await deleteCustomConfig(server.url, server.accessToken)
339 const res = await getCustomConfig(server.url, server.accessToken)
340 const data = res.body
342 checkInitialConfig(server, data)
345 after(async function () {
346 await cleanupTests([ server ])