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