]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/tests/api/server/config.ts
Fix total videos stats
[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
89 expect(data.followings.instance.autoFollowIndex.indexUrl).to.equal('https://instances.joinpeertube.org')
40e87e9e
C
90}
91
92function checkUpdatedConfig (data: CustomConfig) {
93 expect(data.instance.name).to.equal('PeerTube updated')
94 expect(data.instance.shortDescription).to.equal('my short description')
95 expect(data.instance.description).to.equal('my super description')
ccc00cb2 96
40e87e9e 97 expect(data.instance.terms).to.equal('my super terms')
8ae03c37 98 expect(data.instance.creationReason).to.equal('my super creation reason')
ccc00cb2
C
99 expect(data.instance.codeOfConduct).to.equal('my super coc')
100 expect(data.instance.moderationInformation).to.equal('my super moderation information')
101 expect(data.instance.administrator).to.equal('Kuja')
102 expect(data.instance.maintenanceLifetime).to.equal('forever')
103 expect(data.instance.businessModel).to.equal('my super business model')
be04c6fd 104 expect(data.instance.hardwareInformation).to.equal('2vCore 3GB RAM')
ccc00cb2
C
105
106 expect(data.instance.languages).to.deep.equal([ 'en', 'es' ])
107 expect(data.instance.categories).to.deep.equal([ 1, 2 ])
108
40e87e9e 109 expect(data.instance.defaultClientRoute).to.equal('/videos/recently-added')
f8802489 110 expect(data.instance.isNSFW).to.be.true
40e87e9e
C
111 expect(data.instance.defaultNSFWPolicy).to.equal('blur')
112 expect(data.instance.customizations.javascript).to.equal('alert("coucou")')
113 expect(data.instance.customizations.css).to.equal('body { background-color: red; }')
a4101923 114
40e87e9e
C
115 expect(data.services.twitter.username).to.equal('@Kuja')
116 expect(data.services.twitter.whitelisted).to.be.true
a4101923 117
40e87e9e
C
118 expect(data.cache.previews.size).to.equal(2)
119 expect(data.cache.captions.size).to.equal(3)
a4101923 120
40e87e9e
C
121 expect(data.signup.enabled).to.be.false
122 expect(data.signup.limit).to.equal(5)
576ad67a 123 expect(data.signup.requiresEmailVerification).to.be.false
a4101923 124
48f07b4a
C
125 // We override admin email in parallel tests, so skip this exception
126 if (parallelTests() === false) {
127 expect(data.admin.email).to.equal('superadmin1@example.com')
128 }
129
a4101923
C
130 expect(data.contactForm.enabled).to.be.false
131
40e87e9e 132 expect(data.user.videoQuota).to.equal(5242881)
bee0abff 133 expect(data.user.videoQuotaDaily).to.equal(318742)
a4101923 134
40e87e9e
C
135 expect(data.transcoding.enabled).to.be.true
136 expect(data.transcoding.threads).to.equal(1)
14e2014a 137 expect(data.transcoding.allowAdditionalExtensions).to.be.true
536598cf 138 expect(data.transcoding.allowAudioFiles).to.be.true
40e87e9e
C
139 expect(data.transcoding.resolutions['240p']).to.be.false
140 expect(data.transcoding.resolutions['360p']).to.be.true
141 expect(data.transcoding.resolutions['480p']).to.be.true
142 expect(data.transcoding.resolutions['720p']).to.be.false
143 expect(data.transcoding.resolutions['1080p']).to.be.false
db714ab4 144 expect(data.transcoding.resolutions['2160p']).to.be.false
09209296 145 expect(data.transcoding.hls.enabled).to.be.false
d7a25329 146 expect(data.transcoding.webtorrent.enabled).to.be.true
a4101923 147
5d08a6a7 148 expect(data.import.videos.http.enabled).to.be.false
a84b8fa5 149 expect(data.import.videos.torrent.enabled).to.be.false
7ccddd7b 150 expect(data.autoBlacklist.videos.ofUsers.enabled).to.be.true
5b9c965d
C
151
152 expect(data.followers.instance.enabled).to.be.false
14893eb7 153 expect(data.followers.instance.manualApproval).to.be.true
8424c402
C
154
155 expect(data.followings.instance.autoFollowBack.enabled).to.be.true
156 expect(data.followings.instance.autoFollowIndex.enabled).to.be.true
157 expect(data.followings.instance.autoFollowIndex.indexUrl).to.equal('https://updated.example.com')
40e87e9e
C
158}
159
0e1dc3e7
C
160describe('Test config', function () {
161 let server = null
162
163 before(async function () {
e212f887 164 this.timeout(30000)
48f07b4a 165
210feb6c 166 server = await flushAndRunServer(1)
fd206f0b 167 await setAccessTokensToServers([ server ])
0e1dc3e7
C
168 })
169
170 it('Should have a correct config on a server with registration enabled', async function () {
171 const res = await getConfig(server.url)
14e2014a 172 const data: ServerConfig = res.body
0e1dc3e7
C
173
174 expect(data.signup.allowed).to.be.true
175 })
176
177 it('Should have a correct config on a server with registration enabled and a users limit', async function () {
652b3056
C
178 this.timeout(5000)
179
47e0652b
C
180 await Promise.all([
181 registerUser(server.url, 'user1', 'super password'),
182 registerUser(server.url, 'user2', 'super password'),
183 registerUser(server.url, 'user3', 'super password')
184 ])
0e1dc3e7
C
185
186 const res = await getConfig(server.url)
14e2014a 187 const data: ServerConfig = res.body
0e1dc3e7
C
188
189 expect(data.signup.allowed).to.be.false
190 })
191
14e2014a
C
192 it('Should have the correct video allowed extensions', async function () {
193 const res = await getConfig(server.url)
194 const data: ServerConfig = res.body
195
196 expect(data.video.file.extensions).to.have.lengthOf(3)
197 expect(data.video.file.extensions).to.contain('.mp4')
198 expect(data.video.file.extensions).to.contain('.webm')
199 expect(data.video.file.extensions).to.contain('.ogv')
a4101923 200
b345a804
C
201 await uploadVideo(server.url, server.accessToken, { fixture: 'video_short.mkv' }, 400)
202 await uploadVideo(server.url, server.accessToken, { fixture: 'sample.ogg' }, 400)
203
a4101923 204 expect(data.contactForm.enabled).to.be.true
14e2014a
C
205 })
206
fd206f0b
C
207 it('Should get the customized configuration', async function () {
208 const res = await getCustomConfig(server.url, server.accessToken)
00b5556c 209 const data = res.body as CustomConfig
fd206f0b 210
48f07b4a 211 checkInitialConfig(server, data)
fd206f0b
C
212 })
213
214 it('Should update the customized configuration', async function () {
40e87e9e 215 const newCustomConfig: CustomConfig = {
66b16caf
C
216 instance: {
217 name: 'PeerTube updated',
2e3a0215 218 shortDescription: 'my short description',
66b16caf 219 description: 'my super description',
00b5556c 220 terms: 'my super terms',
ccc00cb2
C
221 codeOfConduct: 'my super coc',
222
8ae03c37 223 creationReason: 'my super creation reason',
ccc00cb2
C
224 moderationInformation: 'my super moderation information',
225 administrator: 'Kuja',
226 maintenanceLifetime: 'forever',
227 businessModel: 'my super business model',
be04c6fd 228 hardwareInformation: '2vCore 3GB RAM',
ccc00cb2
C
229
230 languages: [ 'en', 'es' ],
231 categories: [ 1, 2 ],
232
901637bb 233 defaultClientRoute: '/videos/recently-added',
f8802489 234 isNSFW: true,
0883b324 235 defaultNSFWPolicy: 'blur' as 'blur',
00b5556c
C
236 customizations: {
237 javascript: 'alert("coucou")',
238 css: 'body { background-color: red; }'
239 }
66b16caf 240 },
7cd4d2ba
C
241 theme: {
242 default: 'default'
243 },
8be1afa1
C
244 services: {
245 twitter: {
246 username: '@Kuja',
247 whitelisted: true
248 }
249 },
fd206f0b
C
250 cache: {
251 previews: {
252 size: 2
40e87e9e
C
253 },
254 captions: {
255 size: 3
fd206f0b
C
256 }
257 },
258 signup: {
259 enabled: false,
d9eaee39 260 limit: 5,
576ad67a 261 requiresEmailVerification: false
fd206f0b
C
262 },
263 admin: {
264 email: 'superadmin1@example.com'
265 },
a4101923
C
266 contactForm: {
267 enabled: false
268 },
fd206f0b 269 user: {
bee0abff
FA
270 videoQuota: 5242881,
271 videoQuotaDaily: 318742
fd206f0b
C
272 },
273 transcoding: {
274 enabled: true,
14e2014a 275 allowAdditionalExtensions: true,
536598cf 276 allowAudioFiles: true,
fd206f0b
C
277 threads: 1,
278 resolutions: {
5c7d6508 279 '0p': false,
fd206f0b
C
280 '240p': false,
281 '360p': true,
282 '480p': true,
283 '720p': false,
db714ab4
C
284 '1080p': false,
285 '2160p': false
09209296 286 },
d7a25329
C
287 webtorrent: {
288 enabled: true
289 },
09209296
C
290 hls: {
291 enabled: false
fd206f0b 292 }
5d08a6a7
C
293 },
294 import: {
295 videos: {
296 http: {
297 enabled: false
a84b8fa5
C
298 },
299 torrent: {
300 enabled: false
5d08a6a7
C
301 }
302 }
7ccddd7b
JM
303 },
304 autoBlacklist: {
305 videos: {
306 ofUsers: {
307 enabled: true
308 }
309 }
5b9c965d
C
310 },
311 followers: {
312 instance: {
14893eb7
C
313 enabled: false,
314 manualApproval: true
5b9c965d 315 }
8424c402
C
316 },
317 followings: {
318 instance: {
319 autoFollowBack: {
320 enabled: true
321 },
322 autoFollowIndex: {
323 enabled: true,
324 indexUrl: 'https://updated.example.com'
325 }
326 }
fd206f0b
C
327 }
328 }
329 await updateCustomConfig(server.url, server.accessToken, newCustomConfig)
330
331 const res = await getCustomConfig(server.url, server.accessToken)
332 const data = res.body
333
40e87e9e 334 checkUpdatedConfig(data)
fd206f0b
C
335 })
336
14e2014a
C
337 it('Should have the correct updated video allowed extensions', async function () {
338 const res = await getConfig(server.url)
339 const data: ServerConfig = res.body
340
341 expect(data.video.file.extensions).to.have.length.above(3)
342 expect(data.video.file.extensions).to.contain('.mp4')
343 expect(data.video.file.extensions).to.contain('.webm')
344 expect(data.video.file.extensions).to.contain('.ogv')
345 expect(data.video.file.extensions).to.contain('.flv')
346 expect(data.video.file.extensions).to.contain('.mkv')
b345a804
C
347 expect(data.video.file.extensions).to.contain('.mp3')
348 expect(data.video.file.extensions).to.contain('.ogg')
349 expect(data.video.file.extensions).to.contain('.flac')
350
351 await uploadVideo(server.url, server.accessToken, { fixture: 'video_short.mkv' }, 200)
352 await uploadVideo(server.url, server.accessToken, { fixture: 'sample.ogg' }, 200)
14e2014a
C
353 })
354
fd206f0b 355 it('Should have the configuration updated after a restart', async function () {
23e27dd5
C
356 this.timeout(10000)
357
fd206f0b
C
358 killallServers([ server ])
359
360 await reRunServer(server)
361
362 const res = await getCustomConfig(server.url, server.accessToken)
363 const data = res.body
364
40e87e9e 365 checkUpdatedConfig(data)
fd206f0b
C
366 })
367
36f9424f
C
368 it('Should fetch the about information', async function () {
369 const res = await getAbout(server.url)
370 const data: About = res.body
371
372 expect(data.instance.name).to.equal('PeerTube updated')
2e3a0215 373 expect(data.instance.shortDescription).to.equal('my short description')
36f9424f
C
374 expect(data.instance.description).to.equal('my super description')
375 expect(data.instance.terms).to.equal('my super terms')
be04c6fd
C
376 expect(data.instance.codeOfConduct).to.equal('my super coc')
377
378 expect(data.instance.creationReason).to.equal('my super creation reason')
379 expect(data.instance.moderationInformation).to.equal('my super moderation information')
380 expect(data.instance.administrator).to.equal('Kuja')
381 expect(data.instance.maintenanceLifetime).to.equal('forever')
382 expect(data.instance.businessModel).to.equal('my super business model')
383 expect(data.instance.hardwareInformation).to.equal('2vCore 3GB RAM')
384
385 expect(data.instance.languages).to.deep.equal([ 'en', 'es' ])
386 expect(data.instance.categories).to.deep.equal([ 1, 2 ])
36f9424f
C
387 })
388
fd206f0b 389 it('Should remove the custom configuration', async function () {
23e27dd5
C
390 this.timeout(10000)
391
fd206f0b
C
392 await deleteCustomConfig(server.url, server.accessToken)
393
394 const res = await getCustomConfig(server.url, server.accessToken)
395 const data = res.body
396
48f07b4a 397 checkInitialConfig(server, data)
fd206f0b
C
398 })
399
7c3b7976
C
400 after(async function () {
401 await cleanupTests([ server ])
0e1dc3e7
C
402 })
403})