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
40 expect(data.instance.languages).to.have.lengthOf(0)
41 expect(data.instance.categories).to.have.lengthOf(0)
43 expect(data.instance.defaultClientRoute).to.equal('/videos/trending')
44 expect(data.instance.isNSFW).to.be.false
45 expect(data.instance.defaultNSFWPolicy).to.equal('display')
46 expect(data.instance.customizations.css).to.be.empty
47 expect(data.instance.customizations.javascript).to.be.empty
49 expect(data.services.twitter.username).to.equal('@Chocobozzz')
50 expect(data.services.twitter.whitelisted).to.be.false
52 expect(data.cache.previews.size).to.equal(1)
53 expect(data.cache.captions.size).to.equal(1)
55 expect(data.signup.enabled).to.be.true
56 expect(data.signup.limit).to.equal(4)
57 expect(data.signup.requiresEmailVerification).to.be.false
59 expect(data.admin.email).to.equal('admin' + server.internalServerNumber + '@example.com')
60 expect(data.contactForm.enabled).to.be.true
62 expect(data.user.videoQuota).to.equal(5242880)
63 expect(data.user.videoQuotaDaily).to.equal(-1)
64 expect(data.transcoding.enabled).to.be.false
65 expect(data.transcoding.allowAdditionalExtensions).to.be.false
66 expect(data.transcoding.allowAudioFiles).to.be.false
67 expect(data.transcoding.threads).to.equal(2)
68 expect(data.transcoding.resolutions['240p']).to.be.true
69 expect(data.transcoding.resolutions['360p']).to.be.true
70 expect(data.transcoding.resolutions['480p']).to.be.true
71 expect(data.transcoding.resolutions['720p']).to.be.true
72 expect(data.transcoding.resolutions['1080p']).to.be.true
73 expect(data.transcoding.resolutions['2160p']).to.be.true
74 expect(data.transcoding.hls.enabled).to.be.true
76 expect(data.import.videos.http.enabled).to.be.true
77 expect(data.import.videos.torrent.enabled).to.be.true
78 expect(data.autoBlacklist.videos.ofUsers.enabled).to.be.false
80 expect(data.followers.instance.enabled).to.be.true
81 expect(data.followers.instance.manualApproval).to.be.false
83 expect(data.followings.instance.autoFollowBack.enabled).to.be.false
84 expect(data.followings.instance.autoFollowIndex.enabled).to.be.false
85 expect(data.followings.instance.autoFollowIndex.indexUrl).to.equal('https://instances.joinpeertube.org')
88 function checkUpdatedConfig (data: CustomConfig) {
89 expect(data.instance.name).to.equal('PeerTube updated')
90 expect(data.instance.shortDescription).to.equal('my short description')
91 expect(data.instance.description).to.equal('my super description')
93 expect(data.instance.terms).to.equal('my super terms')
94 expect(data.instance.creationReason).to.equal('my super creation reason')
95 expect(data.instance.codeOfConduct).to.equal('my super coc')
96 expect(data.instance.moderationInformation).to.equal('my super moderation information')
97 expect(data.instance.administrator).to.equal('Kuja')
98 expect(data.instance.maintenanceLifetime).to.equal('forever')
99 expect(data.instance.businessModel).to.equal('my super business model')
101 expect(data.instance.languages).to.deep.equal([ 'en', 'es' ])
102 expect(data.instance.categories).to.deep.equal([ 1, 2 ])
104 expect(data.instance.defaultClientRoute).to.equal('/videos/recently-added')
105 expect(data.instance.isNSFW).to.be.true
106 expect(data.instance.defaultNSFWPolicy).to.equal('blur')
107 expect(data.instance.customizations.javascript).to.equal('alert("coucou")')
108 expect(data.instance.customizations.css).to.equal('body { background-color: red; }')
110 expect(data.services.twitter.username).to.equal('@Kuja')
111 expect(data.services.twitter.whitelisted).to.be.true
113 expect(data.cache.previews.size).to.equal(2)
114 expect(data.cache.captions.size).to.equal(3)
116 expect(data.signup.enabled).to.be.false
117 expect(data.signup.limit).to.equal(5)
118 expect(data.signup.requiresEmailVerification).to.be.false
120 // We override admin email in parallel tests, so skip this exception
121 if (parallelTests() === false) {
122 expect(data.admin.email).to.equal('superadmin1@example.com')
125 expect(data.contactForm.enabled).to.be.false
127 expect(data.user.videoQuota).to.equal(5242881)
128 expect(data.user.videoQuotaDaily).to.equal(318742)
130 expect(data.transcoding.enabled).to.be.true
131 expect(data.transcoding.threads).to.equal(1)
132 expect(data.transcoding.allowAdditionalExtensions).to.be.true
133 expect(data.transcoding.allowAudioFiles).to.be.true
134 expect(data.transcoding.resolutions['240p']).to.be.false
135 expect(data.transcoding.resolutions['360p']).to.be.true
136 expect(data.transcoding.resolutions['480p']).to.be.true
137 expect(data.transcoding.resolutions['720p']).to.be.false
138 expect(data.transcoding.resolutions['1080p']).to.be.false
139 expect(data.transcoding.resolutions['2160p']).to.be.false
140 expect(data.transcoding.hls.enabled).to.be.false
142 expect(data.import.videos.http.enabled).to.be.false
143 expect(data.import.videos.torrent.enabled).to.be.false
144 expect(data.autoBlacklist.videos.ofUsers.enabled).to.be.true
146 expect(data.followers.instance.enabled).to.be.false
147 expect(data.followers.instance.manualApproval).to.be.true
149 expect(data.followings.instance.autoFollowBack.enabled).to.be.true
150 expect(data.followings.instance.autoFollowIndex.enabled).to.be.true
151 expect(data.followings.instance.autoFollowIndex.indexUrl).to.equal('https://updated.example.com')
154 describe('Test config', function () {
157 before(async function () {
160 server = await flushAndRunServer(1)
161 await setAccessTokensToServers([ server ])
164 it('Should have a correct config on a server with registration enabled', async function () {
165 const res = await getConfig(server.url)
166 const data: ServerConfig = res.body
168 expect(data.signup.allowed).to.be.true
171 it('Should have a correct config on a server with registration enabled and a users limit', async function () {
175 registerUser(server.url, 'user1', 'super password'),
176 registerUser(server.url, 'user2', 'super password'),
177 registerUser(server.url, 'user3', 'super password')
180 const res = await getConfig(server.url)
181 const data: ServerConfig = res.body
183 expect(data.signup.allowed).to.be.false
186 it('Should have the correct video allowed extensions', async function () {
187 const res = await getConfig(server.url)
188 const data: ServerConfig = res.body
190 expect(data.video.file.extensions).to.have.lengthOf(3)
191 expect(data.video.file.extensions).to.contain('.mp4')
192 expect(data.video.file.extensions).to.contain('.webm')
193 expect(data.video.file.extensions).to.contain('.ogv')
195 await uploadVideo(server.url, server.accessToken, { fixture: 'video_short.mkv' }, 400)
196 await uploadVideo(server.url, server.accessToken, { fixture: 'sample.ogg' }, 400)
198 expect(data.contactForm.enabled).to.be.true
201 it('Should get the customized configuration', async function () {
202 const res = await getCustomConfig(server.url, server.accessToken)
203 const data = res.body as CustomConfig
205 checkInitialConfig(server, data)
208 it('Should update the customized configuration', async function () {
209 const newCustomConfig: CustomConfig = {
211 name: 'PeerTube updated',
212 shortDescription: 'my short description',
213 description: 'my super description',
214 terms: 'my super terms',
215 codeOfConduct: 'my super coc',
217 creationReason: 'my super creation reason',
218 moderationInformation: 'my super moderation information',
219 administrator: 'Kuja',
220 maintenanceLifetime: 'forever',
221 businessModel: 'my super business model',
223 languages: [ 'en', 'es' ],
224 categories: [ 1, 2 ],
226 defaultClientRoute: '/videos/recently-added',
228 defaultNSFWPolicy: 'blur' as 'blur',
230 javascript: 'alert("coucou")',
231 css: 'body { background-color: red; }'
254 requiresEmailVerification: false
257 email: 'superadmin1@example.com'
264 videoQuotaDaily: 318742
268 allowAdditionalExtensions: true,
269 allowAudioFiles: true,
313 indexUrl: 'https://updated.example.com'
318 await updateCustomConfig(server.url, server.accessToken, newCustomConfig)
320 const res = await getCustomConfig(server.url, server.accessToken)
321 const data = res.body
323 checkUpdatedConfig(data)
326 it('Should have the correct updated video allowed extensions', async function () {
327 const res = await getConfig(server.url)
328 const data: ServerConfig = res.body
330 expect(data.video.file.extensions).to.have.length.above(3)
331 expect(data.video.file.extensions).to.contain('.mp4')
332 expect(data.video.file.extensions).to.contain('.webm')
333 expect(data.video.file.extensions).to.contain('.ogv')
334 expect(data.video.file.extensions).to.contain('.flv')
335 expect(data.video.file.extensions).to.contain('.mkv')
336 expect(data.video.file.extensions).to.contain('.mp3')
337 expect(data.video.file.extensions).to.contain('.ogg')
338 expect(data.video.file.extensions).to.contain('.flac')
340 await uploadVideo(server.url, server.accessToken, { fixture: 'video_short.mkv' }, 200)
341 await uploadVideo(server.url, server.accessToken, { fixture: 'sample.ogg' }, 200)
344 it('Should have the configuration updated after a restart', async function () {
347 killallServers([ server ])
349 await reRunServer(server)
351 const res = await getCustomConfig(server.url, server.accessToken)
352 const data = res.body
354 checkUpdatedConfig(data)
357 it('Should fetch the about information', async function () {
358 const res = await getAbout(server.url)
359 const data: About = res.body
361 expect(data.instance.name).to.equal('PeerTube updated')
362 expect(data.instance.shortDescription).to.equal('my short description')
363 expect(data.instance.description).to.equal('my super description')
364 expect(data.instance.terms).to.equal('my super terms')
367 it('Should remove the custom configuration', async function () {
370 await deleteCustomConfig(server.url, server.accessToken)
372 const res = await getCustomConfig(server.url, server.accessToken)
373 const data = res.body
375 checkInitialConfig(server, data)
378 after(async function () {
379 await cleanupTests([ server ])