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