]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/tests/api/server/config.ts
85d0f970215198fb8ccab404f3988cf8de1e46fb
[github/Chocobozzz/PeerTube.git] / server / tests / api / server / config.ts
1 /* tslint:disable:no-unused-expression */
2
3 import 'mocha'
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'
7 import {
8 cleanupTests,
9 deleteCustomConfig,
10 flushAndRunServer,
11 getAbout,
12 getConfig,
13 getCustomConfig,
14 killallServers, parallelTests,
15 registerUser,
16 reRunServer, ServerInfo,
17 setAccessTokensToServers,
18 updateCustomConfig, uploadVideo
19 } from '../../../../shared/extra-utils'
20 import { ServerConfig } from '../../../../shared/models'
21
22 const expect = chai.expect
23
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.'
29 )
30 expect(data.instance.description).to.equal('Welcome to this PeerTube instance!')
31
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
40 expect(data.instance.languages).to.have.lengthOf(0)
41 expect(data.instance.categories).to.have.lengthOf(0)
42
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
48
49 expect(data.services.twitter.username).to.equal('@Chocobozzz')
50 expect(data.services.twitter.whitelisted).to.be.false
51
52 expect(data.cache.previews.size).to.equal(1)
53 expect(data.cache.captions.size).to.equal(1)
54
55 expect(data.signup.enabled).to.be.true
56 expect(data.signup.limit).to.equal(4)
57 expect(data.signup.requiresEmailVerification).to.be.false
58
59 expect(data.admin.email).to.equal('admin' + server.internalServerNumber + '@example.com')
60 expect(data.contactForm.enabled).to.be.true
61
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
75
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
79
80 expect(data.followers.instance.enabled).to.be.true
81 expect(data.followers.instance.manualApproval).to.be.false
82
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')
86 }
87
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')
92
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')
100
101 expect(data.instance.languages).to.deep.equal([ 'en', 'es' ])
102 expect(data.instance.categories).to.deep.equal([ 1, 2 ])
103
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; }')
109
110 expect(data.services.twitter.username).to.equal('@Kuja')
111 expect(data.services.twitter.whitelisted).to.be.true
112
113 expect(data.cache.previews.size).to.equal(2)
114 expect(data.cache.captions.size).to.equal(3)
115
116 expect(data.signup.enabled).to.be.false
117 expect(data.signup.limit).to.equal(5)
118 expect(data.signup.requiresEmailVerification).to.be.false
119
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')
123 }
124
125 expect(data.contactForm.enabled).to.be.false
126
127 expect(data.user.videoQuota).to.equal(5242881)
128 expect(data.user.videoQuotaDaily).to.equal(318742)
129
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
141
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
145
146 expect(data.followers.instance.enabled).to.be.false
147 expect(data.followers.instance.manualApproval).to.be.true
148
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')
152 }
153
154 describe('Test config', function () {
155 let server = null
156
157 before(async function () {
158 this.timeout(30000)
159
160 server = await flushAndRunServer(1)
161 await setAccessTokensToServers([ server ])
162 })
163
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
167
168 expect(data.signup.allowed).to.be.true
169 })
170
171 it('Should have a correct config on a server with registration enabled and a users limit', async function () {
172 this.timeout(5000)
173
174 await Promise.all([
175 registerUser(server.url, 'user1', 'super password'),
176 registerUser(server.url, 'user2', 'super password'),
177 registerUser(server.url, 'user3', 'super password')
178 ])
179
180 const res = await getConfig(server.url)
181 const data: ServerConfig = res.body
182
183 expect(data.signup.allowed).to.be.false
184 })
185
186 it('Should have the correct video allowed extensions', async function () {
187 const res = await getConfig(server.url)
188 const data: ServerConfig = res.body
189
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')
194
195 await uploadVideo(server.url, server.accessToken, { fixture: 'video_short.mkv' }, 400)
196 await uploadVideo(server.url, server.accessToken, { fixture: 'sample.ogg' }, 400)
197
198 expect(data.contactForm.enabled).to.be.true
199 })
200
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
204
205 checkInitialConfig(server, data)
206 })
207
208 it('Should update the customized configuration', async function () {
209 const newCustomConfig: CustomConfig = {
210 instance: {
211 name: 'PeerTube updated',
212 shortDescription: 'my short description',
213 description: 'my super description',
214 terms: 'my super terms',
215 codeOfConduct: 'my super coc',
216
217 creationReason: 'my super creation reason',
218 moderationInformation: 'my super moderation information',
219 administrator: 'Kuja',
220 maintenanceLifetime: 'forever',
221 businessModel: 'my super business model',
222
223 languages: [ 'en', 'es' ],
224 categories: [ 1, 2 ],
225
226 defaultClientRoute: '/videos/recently-added',
227 isNSFW: true,
228 defaultNSFWPolicy: 'blur' as 'blur',
229 customizations: {
230 javascript: 'alert("coucou")',
231 css: 'body { background-color: red; }'
232 }
233 },
234 theme: {
235 default: 'default'
236 },
237 services: {
238 twitter: {
239 username: '@Kuja',
240 whitelisted: true
241 }
242 },
243 cache: {
244 previews: {
245 size: 2
246 },
247 captions: {
248 size: 3
249 }
250 },
251 signup: {
252 enabled: false,
253 limit: 5,
254 requiresEmailVerification: false
255 },
256 admin: {
257 email: 'superadmin1@example.com'
258 },
259 contactForm: {
260 enabled: false
261 },
262 user: {
263 videoQuota: 5242881,
264 videoQuotaDaily: 318742
265 },
266 transcoding: {
267 enabled: true,
268 allowAdditionalExtensions: true,
269 allowAudioFiles: true,
270 threads: 1,
271 resolutions: {
272 '240p': false,
273 '360p': true,
274 '480p': true,
275 '720p': false,
276 '1080p': false,
277 '2160p': false
278 },
279 hls: {
280 enabled: false
281 }
282 },
283 import: {
284 videos: {
285 http: {
286 enabled: false
287 },
288 torrent: {
289 enabled: false
290 }
291 }
292 },
293 autoBlacklist: {
294 videos: {
295 ofUsers: {
296 enabled: true
297 }
298 }
299 },
300 followers: {
301 instance: {
302 enabled: false,
303 manualApproval: true
304 }
305 },
306 followings: {
307 instance: {
308 autoFollowBack: {
309 enabled: true
310 },
311 autoFollowIndex: {
312 enabled: true,
313 indexUrl: 'https://updated.example.com'
314 }
315 }
316 }
317 }
318 await updateCustomConfig(server.url, server.accessToken, newCustomConfig)
319
320 const res = await getCustomConfig(server.url, server.accessToken)
321 const data = res.body
322
323 checkUpdatedConfig(data)
324 })
325
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
329
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')
339
340 await uploadVideo(server.url, server.accessToken, { fixture: 'video_short.mkv' }, 200)
341 await uploadVideo(server.url, server.accessToken, { fixture: 'sample.ogg' }, 200)
342 })
343
344 it('Should have the configuration updated after a restart', async function () {
345 this.timeout(10000)
346
347 killallServers([ server ])
348
349 await reRunServer(server)
350
351 const res = await getCustomConfig(server.url, server.accessToken)
352 const data = res.body
353
354 checkUpdatedConfig(data)
355 })
356
357 it('Should fetch the about information', async function () {
358 const res = await getAbout(server.url)
359 const data: About = res.body
360
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')
365 })
366
367 it('Should remove the custom configuration', async function () {
368 this.timeout(10000)
369
370 await deleteCustomConfig(server.url, server.accessToken)
371
372 const res = await getCustomConfig(server.url, server.accessToken)
373 const data = res.body
374
375 checkInitialConfig(server, data)
376 })
377
378 after(async function () {
379 await cleanupTests([ server ])
380 })
381 })