]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/tests/api/server/config.ts
Update dependencies
[github/Chocobozzz/PeerTube.git] / server / tests / api / server / config.ts
1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
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,
15 parallelTests,
16 registerUser,
17 reRunServer,
18 ServerInfo,
19 setAccessTokensToServers,
20 updateCustomConfig,
21 uploadVideo
22 } from '../../../../shared/extra-utils'
23 import { ServerConfig } from '../../../../shared/models'
24
25 const expect = chai.expect
26
27 function checkInitialConfig (server: ServerInfo, data: CustomConfig) {
28 expect(data.instance.name).to.equal('PeerTube')
29 expect(data.instance.shortDescription).to.equal(
30 'PeerTube, a federated (ActivityPub) video streaming platform using P2P (BitTorrent) directly in the web browser ' +
31 'with WebTorrent and Angular.'
32 )
33 expect(data.instance.description).to.equal('Welcome to this PeerTube instance!')
34
35 expect(data.instance.terms).to.equal('No terms for now.')
36 expect(data.instance.creationReason).to.be.empty
37 expect(data.instance.codeOfConduct).to.be.empty
38 expect(data.instance.moderationInformation).to.be.empty
39 expect(data.instance.administrator).to.be.empty
40 expect(data.instance.maintenanceLifetime).to.be.empty
41 expect(data.instance.businessModel).to.be.empty
42 expect(data.instance.hardwareInformation).to.be.empty
43
44 expect(data.instance.languages).to.have.lengthOf(0)
45 expect(data.instance.categories).to.have.lengthOf(0)
46
47 expect(data.instance.defaultClientRoute).to.equal('/videos/trending')
48 expect(data.instance.isNSFW).to.be.false
49 expect(data.instance.defaultNSFWPolicy).to.equal('display')
50 expect(data.instance.customizations.css).to.be.empty
51 expect(data.instance.customizations.javascript).to.be.empty
52
53 expect(data.services.twitter.username).to.equal('@Chocobozzz')
54 expect(data.services.twitter.whitelisted).to.be.false
55
56 expect(data.cache.previews.size).to.equal(1)
57 expect(data.cache.captions.size).to.equal(1)
58
59 expect(data.signup.enabled).to.be.true
60 expect(data.signup.limit).to.equal(4)
61 expect(data.signup.requiresEmailVerification).to.be.false
62
63 expect(data.admin.email).to.equal('admin' + server.internalServerNumber + '@example.com')
64 expect(data.contactForm.enabled).to.be.true
65
66 expect(data.user.videoQuota).to.equal(5242880)
67 expect(data.user.videoQuotaDaily).to.equal(-1)
68 expect(data.transcoding.enabled).to.be.false
69 expect(data.transcoding.allowAdditionalExtensions).to.be.false
70 expect(data.transcoding.allowAudioFiles).to.be.false
71 expect(data.transcoding.threads).to.equal(2)
72 expect(data.transcoding.resolutions['240p']).to.be.true
73 expect(data.transcoding.resolutions['360p']).to.be.true
74 expect(data.transcoding.resolutions['480p']).to.be.true
75 expect(data.transcoding.resolutions['720p']).to.be.true
76 expect(data.transcoding.resolutions['1080p']).to.be.true
77 expect(data.transcoding.resolutions['2160p']).to.be.true
78 expect(data.transcoding.webtorrent.enabled).to.be.true
79 expect(data.transcoding.hls.enabled).to.be.true
80
81 expect(data.import.videos.http.enabled).to.be.true
82 expect(data.import.videos.torrent.enabled).to.be.true
83 expect(data.autoBlacklist.videos.ofUsers.enabled).to.be.false
84
85 expect(data.followers.instance.enabled).to.be.true
86 expect(data.followers.instance.manualApproval).to.be.false
87
88 expect(data.followings.instance.autoFollowBack.enabled).to.be.false
89 expect(data.followings.instance.autoFollowIndex.enabled).to.be.false
90 expect(data.followings.instance.autoFollowIndex.indexUrl).to.equal('https://instances.joinpeertube.org')
91 }
92
93 function checkUpdatedConfig (data: CustomConfig) {
94 expect(data.instance.name).to.equal('PeerTube updated')
95 expect(data.instance.shortDescription).to.equal('my short description')
96 expect(data.instance.description).to.equal('my super description')
97
98 expect(data.instance.terms).to.equal('my super terms')
99 expect(data.instance.creationReason).to.equal('my super creation reason')
100 expect(data.instance.codeOfConduct).to.equal('my super coc')
101 expect(data.instance.moderationInformation).to.equal('my super moderation information')
102 expect(data.instance.administrator).to.equal('Kuja')
103 expect(data.instance.maintenanceLifetime).to.equal('forever')
104 expect(data.instance.businessModel).to.equal('my super business model')
105 expect(data.instance.hardwareInformation).to.equal('2vCore 3GB RAM')
106
107 expect(data.instance.languages).to.deep.equal([ 'en', 'es' ])
108 expect(data.instance.categories).to.deep.equal([ 1, 2 ])
109
110 expect(data.instance.defaultClientRoute).to.equal('/videos/recently-added')
111 expect(data.instance.isNSFW).to.be.true
112 expect(data.instance.defaultNSFWPolicy).to.equal('blur')
113 expect(data.instance.customizations.javascript).to.equal('alert("coucou")')
114 expect(data.instance.customizations.css).to.equal('body { background-color: red; }')
115
116 expect(data.services.twitter.username).to.equal('@Kuja')
117 expect(data.services.twitter.whitelisted).to.be.true
118
119 expect(data.cache.previews.size).to.equal(2)
120 expect(data.cache.captions.size).to.equal(3)
121
122 expect(data.signup.enabled).to.be.false
123 expect(data.signup.limit).to.equal(5)
124 expect(data.signup.requiresEmailVerification).to.be.false
125
126 // We override admin email in parallel tests, so skip this exception
127 if (parallelTests() === false) {
128 expect(data.admin.email).to.equal('superadmin1@example.com')
129 }
130
131 expect(data.contactForm.enabled).to.be.false
132
133 expect(data.user.videoQuota).to.equal(5242881)
134 expect(data.user.videoQuotaDaily).to.equal(318742)
135
136 expect(data.transcoding.enabled).to.be.true
137 expect(data.transcoding.threads).to.equal(1)
138 expect(data.transcoding.allowAdditionalExtensions).to.be.true
139 expect(data.transcoding.allowAudioFiles).to.be.true
140 expect(data.transcoding.resolutions['240p']).to.be.false
141 expect(data.transcoding.resolutions['360p']).to.be.true
142 expect(data.transcoding.resolutions['480p']).to.be.true
143 expect(data.transcoding.resolutions['720p']).to.be.false
144 expect(data.transcoding.resolutions['1080p']).to.be.false
145 expect(data.transcoding.resolutions['2160p']).to.be.false
146 expect(data.transcoding.hls.enabled).to.be.false
147 expect(data.transcoding.webtorrent.enabled).to.be.true
148
149 expect(data.import.videos.http.enabled).to.be.false
150 expect(data.import.videos.torrent.enabled).to.be.false
151 expect(data.autoBlacklist.videos.ofUsers.enabled).to.be.true
152
153 expect(data.followers.instance.enabled).to.be.false
154 expect(data.followers.instance.manualApproval).to.be.true
155
156 expect(data.followings.instance.autoFollowBack.enabled).to.be.true
157 expect(data.followings.instance.autoFollowIndex.enabled).to.be.true
158 expect(data.followings.instance.autoFollowIndex.indexUrl).to.equal('https://updated.example.com')
159 }
160
161 describe('Test config', function () {
162 let server = null
163
164 before(async function () {
165 this.timeout(30000)
166
167 server = await flushAndRunServer(1)
168 await setAccessTokensToServers([ server ])
169 })
170
171 it('Should have a correct config on a server with registration enabled', async function () {
172 const res = await getConfig(server.url)
173 const data: ServerConfig = res.body
174
175 expect(data.signup.allowed).to.be.true
176 })
177
178 it('Should have a correct config on a server with registration enabled and a users limit', async function () {
179 this.timeout(5000)
180
181 await Promise.all([
182 registerUser(server.url, 'user1', 'super password'),
183 registerUser(server.url, 'user2', 'super password'),
184 registerUser(server.url, 'user3', 'super password')
185 ])
186
187 const res = await getConfig(server.url)
188 const data: ServerConfig = res.body
189
190 expect(data.signup.allowed).to.be.false
191 })
192
193 it('Should have the correct video allowed extensions', async function () {
194 const res = await getConfig(server.url)
195 const data: ServerConfig = res.body
196
197 expect(data.video.file.extensions).to.have.lengthOf(3)
198 expect(data.video.file.extensions).to.contain('.mp4')
199 expect(data.video.file.extensions).to.contain('.webm')
200 expect(data.video.file.extensions).to.contain('.ogv')
201
202 await uploadVideo(server.url, server.accessToken, { fixture: 'video_short.mkv' }, 400)
203 await uploadVideo(server.url, server.accessToken, { fixture: 'sample.ogg' }, 400)
204
205 expect(data.contactForm.enabled).to.be.true
206 })
207
208 it('Should get the customized configuration', async function () {
209 const res = await getCustomConfig(server.url, server.accessToken)
210 const data = res.body as CustomConfig
211
212 checkInitialConfig(server, data)
213 })
214
215 it('Should update the customized configuration', async function () {
216 const newCustomConfig: CustomConfig = {
217 instance: {
218 name: 'PeerTube updated',
219 shortDescription: 'my short description',
220 description: 'my super description',
221 terms: 'my super terms',
222 codeOfConduct: 'my super coc',
223
224 creationReason: 'my super creation reason',
225 moderationInformation: 'my super moderation information',
226 administrator: 'Kuja',
227 maintenanceLifetime: 'forever',
228 businessModel: 'my super business model',
229 hardwareInformation: '2vCore 3GB RAM',
230
231 languages: [ 'en', 'es' ],
232 categories: [ 1, 2 ],
233
234 defaultClientRoute: '/videos/recently-added',
235 isNSFW: true,
236 defaultNSFWPolicy: 'blur' as 'blur',
237 customizations: {
238 javascript: 'alert("coucou")',
239 css: 'body { background-color: red; }'
240 }
241 },
242 theme: {
243 default: 'default'
244 },
245 services: {
246 twitter: {
247 username: '@Kuja',
248 whitelisted: true
249 }
250 },
251 cache: {
252 previews: {
253 size: 2
254 },
255 captions: {
256 size: 3
257 }
258 },
259 signup: {
260 enabled: false,
261 limit: 5,
262 requiresEmailVerification: false
263 },
264 admin: {
265 email: 'superadmin1@example.com'
266 },
267 contactForm: {
268 enabled: false
269 },
270 user: {
271 videoQuota: 5242881,
272 videoQuotaDaily: 318742
273 },
274 transcoding: {
275 enabled: true,
276 allowAdditionalExtensions: true,
277 allowAudioFiles: true,
278 threads: 1,
279 resolutions: {
280 '0p': false,
281 '240p': false,
282 '360p': true,
283 '480p': true,
284 '720p': false,
285 '1080p': false,
286 '2160p': false
287 },
288 webtorrent: {
289 enabled: true
290 },
291 hls: {
292 enabled: false
293 }
294 },
295 import: {
296 videos: {
297 http: {
298 enabled: false
299 },
300 torrent: {
301 enabled: false
302 }
303 }
304 },
305 autoBlacklist: {
306 videos: {
307 ofUsers: {
308 enabled: true
309 }
310 }
311 },
312 followers: {
313 instance: {
314 enabled: false,
315 manualApproval: true
316 }
317 },
318 followings: {
319 instance: {
320 autoFollowBack: {
321 enabled: true
322 },
323 autoFollowIndex: {
324 enabled: true,
325 indexUrl: 'https://updated.example.com'
326 }
327 }
328 }
329 }
330 await updateCustomConfig(server.url, server.accessToken, newCustomConfig)
331
332 const res = await getCustomConfig(server.url, server.accessToken)
333 const data = res.body
334
335 checkUpdatedConfig(data)
336 })
337
338 it('Should have the correct updated video allowed extensions', async function () {
339 const res = await getConfig(server.url)
340 const data: ServerConfig = res.body
341
342 expect(data.video.file.extensions).to.have.length.above(3)
343 expect(data.video.file.extensions).to.contain('.mp4')
344 expect(data.video.file.extensions).to.contain('.webm')
345 expect(data.video.file.extensions).to.contain('.ogv')
346 expect(data.video.file.extensions).to.contain('.flv')
347 expect(data.video.file.extensions).to.contain('.mkv')
348 expect(data.video.file.extensions).to.contain('.mp3')
349 expect(data.video.file.extensions).to.contain('.ogg')
350 expect(data.video.file.extensions).to.contain('.flac')
351
352 await uploadVideo(server.url, server.accessToken, { fixture: 'video_short.mkv' }, 200)
353 await uploadVideo(server.url, server.accessToken, { fixture: 'sample.ogg' }, 200)
354 })
355
356 it('Should have the configuration updated after a restart', async function () {
357 this.timeout(10000)
358
359 killallServers([ server ])
360
361 await reRunServer(server)
362
363 const res = await getCustomConfig(server.url, server.accessToken)
364 const data = res.body
365
366 checkUpdatedConfig(data)
367 })
368
369 it('Should fetch the about information', async function () {
370 const res = await getAbout(server.url)
371 const data: About = res.body
372
373 expect(data.instance.name).to.equal('PeerTube updated')
374 expect(data.instance.shortDescription).to.equal('my short description')
375 expect(data.instance.description).to.equal('my super description')
376 expect(data.instance.terms).to.equal('my super terms')
377 expect(data.instance.codeOfConduct).to.equal('my super coc')
378
379 expect(data.instance.creationReason).to.equal('my super creation reason')
380 expect(data.instance.moderationInformation).to.equal('my super moderation information')
381 expect(data.instance.administrator).to.equal('Kuja')
382 expect(data.instance.maintenanceLifetime).to.equal('forever')
383 expect(data.instance.businessModel).to.equal('my super business model')
384 expect(data.instance.hardwareInformation).to.equal('2vCore 3GB RAM')
385
386 expect(data.instance.languages).to.deep.equal([ 'en', 'es' ])
387 expect(data.instance.categories).to.deep.equal([ 1, 2 ])
388 })
389
390 it('Should remove the custom configuration', async function () {
391 this.timeout(10000)
392
393 await deleteCustomConfig(server.url, server.accessToken)
394
395 const res = await getCustomConfig(server.url, server.accessToken)
396 const data = res.body
397
398 checkInitialConfig(server, data)
399 })
400
401 after(async function () {
402 await cleanupTests([ server ])
403 })
404 })