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.hls.enabled).to.be.true
64 expect(data.import.videos.http.enabled).to.be.true
65 expect(data.import.videos.torrent.enabled).to.be.true
66 expect(data.autoBlacklist.videos.ofUsers.enabled).to.be.false
68 expect(data.followers.instance.enabled).to.be.true
69 expect(data.followers.instance.manualApproval).to.be.false
72 function checkUpdatedConfig (data: CustomConfig) {
73 expect(data.instance.name).to.equal('PeerTube updated')
74 expect(data.instance.shortDescription).to.equal('my short description')
75 expect(data.instance.description).to.equal('my super description')
76 expect(data.instance.terms).to.equal('my super terms')
77 expect(data.instance.defaultClientRoute).to.equal('/videos/recently-added')
78 expect(data.instance.isNSFW).to.be.true
79 expect(data.instance.defaultNSFWPolicy).to.equal('blur')
80 expect(data.instance.customizations.javascript).to.equal('alert("coucou")')
81 expect(data.instance.customizations.css).to.equal('body { background-color: red; }')
83 expect(data.services.twitter.username).to.equal('@Kuja')
84 expect(data.services.twitter.whitelisted).to.be.true
86 expect(data.cache.previews.size).to.equal(2)
87 expect(data.cache.captions.size).to.equal(3)
89 expect(data.signup.enabled).to.be.false
90 expect(data.signup.limit).to.equal(5)
91 expect(data.signup.requiresEmailVerification).to.be.false
93 // We override admin email in parallel tests, so skip this exception
94 if (parallelTests() === false) {
95 expect(data.admin.email).to.equal('superadmin1@example.com')
98 expect(data.contactForm.enabled).to.be.false
100 expect(data.user.videoQuota).to.equal(5242881)
101 expect(data.user.videoQuotaDaily).to.equal(318742)
103 expect(data.transcoding.enabled).to.be.true
104 expect(data.transcoding.threads).to.equal(1)
105 expect(data.transcoding.allowAdditionalExtensions).to.be.true
106 expect(data.transcoding.allowAudioFiles).to.be.true
107 expect(data.transcoding.resolutions['240p']).to.be.false
108 expect(data.transcoding.resolutions['360p']).to.be.true
109 expect(data.transcoding.resolutions['480p']).to.be.true
110 expect(data.transcoding.resolutions['720p']).to.be.false
111 expect(data.transcoding.resolutions['1080p']).to.be.false
112 expect(data.transcoding.hls.enabled).to.be.false
114 expect(data.import.videos.http.enabled).to.be.false
115 expect(data.import.videos.torrent.enabled).to.be.false
116 expect(data.autoBlacklist.videos.ofUsers.enabled).to.be.true
118 expect(data.followers.instance.enabled).to.be.false
119 expect(data.followers.instance.manualApproval).to.be.true
122 describe('Test config', function () {
125 before(async function () {
128 server = await flushAndRunServer(1)
129 await setAccessTokensToServers([ server ])
132 it('Should have a correct config on a server with registration enabled', async function () {
133 const res = await getConfig(server.url)
134 const data: ServerConfig = res.body
136 expect(data.signup.allowed).to.be.true
139 it('Should have a correct config on a server with registration enabled and a users limit', async function () {
143 registerUser(server.url, 'user1', 'super password'),
144 registerUser(server.url, 'user2', 'super password'),
145 registerUser(server.url, 'user3', 'super password')
148 const res = await getConfig(server.url)
149 const data: ServerConfig = res.body
151 expect(data.signup.allowed).to.be.false
154 it('Should have the correct video allowed extensions', async function () {
155 const res = await getConfig(server.url)
156 const data: ServerConfig = res.body
158 expect(data.video.file.extensions).to.have.lengthOf(3)
159 expect(data.video.file.extensions).to.contain('.mp4')
160 expect(data.video.file.extensions).to.contain('.webm')
161 expect(data.video.file.extensions).to.contain('.ogv')
163 await uploadVideo(server.url, server.accessToken, { fixture: 'video_short.mkv' }, 400)
164 await uploadVideo(server.url, server.accessToken, { fixture: 'sample.ogg' }, 400)
166 expect(data.contactForm.enabled).to.be.true
169 it('Should get the customized configuration', async function () {
170 const res = await getCustomConfig(server.url, server.accessToken)
171 const data = res.body as CustomConfig
173 checkInitialConfig(server, data)
176 it('Should update the customized configuration', async function () {
177 const newCustomConfig: CustomConfig = {
179 name: 'PeerTube updated',
180 shortDescription: 'my short description',
181 description: 'my super description',
182 terms: 'my super terms',
183 defaultClientRoute: '/videos/recently-added',
185 defaultNSFWPolicy: 'blur' as 'blur',
187 javascript: 'alert("coucou")',
188 css: 'body { background-color: red; }'
208 requiresEmailVerification: false
211 email: 'superadmin1@example.com'
218 videoQuotaDaily: 318742
222 allowAdditionalExtensions: true,
223 allowAudioFiles: true,
260 await updateCustomConfig(server.url, server.accessToken, newCustomConfig)
262 const res = await getCustomConfig(server.url, server.accessToken)
263 const data = res.body
265 checkUpdatedConfig(data)
268 it('Should have the correct updated video allowed extensions', async function () {
269 const res = await getConfig(server.url)
270 const data: ServerConfig = res.body
272 expect(data.video.file.extensions).to.have.length.above(3)
273 expect(data.video.file.extensions).to.contain('.mp4')
274 expect(data.video.file.extensions).to.contain('.webm')
275 expect(data.video.file.extensions).to.contain('.ogv')
276 expect(data.video.file.extensions).to.contain('.flv')
277 expect(data.video.file.extensions).to.contain('.mkv')
278 expect(data.video.file.extensions).to.contain('.mp3')
279 expect(data.video.file.extensions).to.contain('.ogg')
280 expect(data.video.file.extensions).to.contain('.flac')
282 await uploadVideo(server.url, server.accessToken, { fixture: 'video_short.mkv' }, 200)
283 await uploadVideo(server.url, server.accessToken, { fixture: 'sample.ogg' }, 200)
286 it('Should have the configuration updated after a restart', async function () {
289 killallServers([ server ])
291 await reRunServer(server)
293 const res = await getCustomConfig(server.url, server.accessToken)
294 const data = res.body
296 checkUpdatedConfig(data)
299 it('Should fetch the about information', async function () {
300 const res = await getAbout(server.url)
301 const data: About = res.body
303 expect(data.instance.name).to.equal('PeerTube updated')
304 expect(data.instance.shortDescription).to.equal('my short description')
305 expect(data.instance.description).to.equal('my super description')
306 expect(data.instance.terms).to.equal('my super terms')
309 it('Should remove the custom configuration', async function () {
312 await deleteCustomConfig(server.url, server.accessToken)
314 const res = await getCustomConfig(server.url, server.accessToken)
315 const data = res.body
317 checkInitialConfig(server, data)
320 after(async function () {
321 await cleanupTests([ server ])