]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/tests/api/server/config.ts
Try to fix subscriptions inconsistencies
[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 expect(data.instance.hardwareInformation).to.be.empty
40
41 expect(data.instance.languages).to.have.lengthOf(0)
42 expect(data.instance.categories).to.have.lengthOf(0)
43
44 expect(data.instance.defaultClientRoute).to.equal('/videos/trending')
45 expect(data.instance.isNSFW).to.be.false
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
49
50 expect(data.services.twitter.username).to.equal('@Chocobozzz')
51 expect(data.services.twitter.whitelisted).to.be.false
52
53 expect(data.cache.previews.size).to.equal(1)
54 expect(data.cache.captions.size).to.equal(1)
55
56 expect(data.signup.enabled).to.be.true
57 expect(data.signup.limit).to.equal(4)
58 expect(data.signup.requiresEmailVerification).to.be.false
59
60 expect(data.admin.email).to.equal('admin' + server.internalServerNumber + '@example.com')
61 expect(data.contactForm.enabled).to.be.true
62
63 expect(data.user.videoQuota).to.equal(5242880)
64 expect(data.user.videoQuotaDaily).to.equal(-1)
65 expect(data.transcoding.enabled).to.be.false
66 expect(data.transcoding.allowAdditionalExtensions).to.be.false
67 expect(data.transcoding.allowAudioFiles).to.be.false
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
74 expect(data.transcoding.resolutions['2160p']).to.be.true
75 expect(data.transcoding.webtorrent.enabled).to.be.true
76 expect(data.transcoding.hls.enabled).to.be.true
77
78 expect(data.import.videos.http.enabled).to.be.true
79 expect(data.import.videos.torrent.enabled).to.be.true
80 expect(data.autoBlacklist.videos.ofUsers.enabled).to.be.false
81
82 expect(data.followers.instance.enabled).to.be.true
83 expect(data.followers.instance.manualApproval).to.be.false
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')
88 }
89
90 function 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')
94
95 expect(data.instance.terms).to.equal('my super terms')
96 expect(data.instance.creationReason).to.equal('my super creation reason')
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')
102 expect(data.instance.hardwareInformation).to.equal('2vCore 3GB RAM')
103
104 expect(data.instance.languages).to.deep.equal([ 'en', 'es' ])
105 expect(data.instance.categories).to.deep.equal([ 1, 2 ])
106
107 expect(data.instance.defaultClientRoute).to.equal('/videos/recently-added')
108 expect(data.instance.isNSFW).to.be.true
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; }')
112
113 expect(data.services.twitter.username).to.equal('@Kuja')
114 expect(data.services.twitter.whitelisted).to.be.true
115
116 expect(data.cache.previews.size).to.equal(2)
117 expect(data.cache.captions.size).to.equal(3)
118
119 expect(data.signup.enabled).to.be.false
120 expect(data.signup.limit).to.equal(5)
121 expect(data.signup.requiresEmailVerification).to.be.false
122
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
128 expect(data.contactForm.enabled).to.be.false
129
130 expect(data.user.videoQuota).to.equal(5242881)
131 expect(data.user.videoQuotaDaily).to.equal(318742)
132
133 expect(data.transcoding.enabled).to.be.true
134 expect(data.transcoding.threads).to.equal(1)
135 expect(data.transcoding.allowAdditionalExtensions).to.be.true
136 expect(data.transcoding.allowAudioFiles).to.be.true
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
142 expect(data.transcoding.resolutions['2160p']).to.be.false
143 expect(data.transcoding.hls.enabled).to.be.false
144 expect(data.transcoding.webtorrent.enabled).to.be.true
145
146 expect(data.import.videos.http.enabled).to.be.false
147 expect(data.import.videos.torrent.enabled).to.be.false
148 expect(data.autoBlacklist.videos.ofUsers.enabled).to.be.true
149
150 expect(data.followers.instance.enabled).to.be.false
151 expect(data.followers.instance.manualApproval).to.be.true
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')
156 }
157
158 describe('Test config', function () {
159 let server = null
160
161 before(async function () {
162 this.timeout(30000)
163
164 server = await flushAndRunServer(1)
165 await setAccessTokensToServers([ server ])
166 })
167
168 it('Should have a correct config on a server with registration enabled', async function () {
169 const res = await getConfig(server.url)
170 const data: ServerConfig = res.body
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 () {
176 this.timeout(5000)
177
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 ])
183
184 const res = await getConfig(server.url)
185 const data: ServerConfig = res.body
186
187 expect(data.signup.allowed).to.be.false
188 })
189
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')
198
199 await uploadVideo(server.url, server.accessToken, { fixture: 'video_short.mkv' }, 400)
200 await uploadVideo(server.url, server.accessToken, { fixture: 'sample.ogg' }, 400)
201
202 expect(data.contactForm.enabled).to.be.true
203 })
204
205 it('Should get the customized configuration', async function () {
206 const res = await getCustomConfig(server.url, server.accessToken)
207 const data = res.body as CustomConfig
208
209 checkInitialConfig(server, data)
210 })
211
212 it('Should update the customized configuration', async function () {
213 const newCustomConfig: CustomConfig = {
214 instance: {
215 name: 'PeerTube updated',
216 shortDescription: 'my short description',
217 description: 'my super description',
218 terms: 'my super terms',
219 codeOfConduct: 'my super coc',
220
221 creationReason: 'my super creation reason',
222 moderationInformation: 'my super moderation information',
223 administrator: 'Kuja',
224 maintenanceLifetime: 'forever',
225 businessModel: 'my super business model',
226 hardwareInformation: '2vCore 3GB RAM',
227
228 languages: [ 'en', 'es' ],
229 categories: [ 1, 2 ],
230
231 defaultClientRoute: '/videos/recently-added',
232 isNSFW: true,
233 defaultNSFWPolicy: 'blur' as 'blur',
234 customizations: {
235 javascript: 'alert("coucou")',
236 css: 'body { background-color: red; }'
237 }
238 },
239 theme: {
240 default: 'default'
241 },
242 services: {
243 twitter: {
244 username: '@Kuja',
245 whitelisted: true
246 }
247 },
248 cache: {
249 previews: {
250 size: 2
251 },
252 captions: {
253 size: 3
254 }
255 },
256 signup: {
257 enabled: false,
258 limit: 5,
259 requiresEmailVerification: false
260 },
261 admin: {
262 email: 'superadmin1@example.com'
263 },
264 contactForm: {
265 enabled: false
266 },
267 user: {
268 videoQuota: 5242881,
269 videoQuotaDaily: 318742
270 },
271 transcoding: {
272 enabled: true,
273 allowAdditionalExtensions: true,
274 allowAudioFiles: true,
275 threads: 1,
276 resolutions: {
277 '0p': false,
278 '240p': false,
279 '360p': true,
280 '480p': true,
281 '720p': false,
282 '1080p': false,
283 '2160p': false
284 },
285 webtorrent: {
286 enabled: true
287 },
288 hls: {
289 enabled: false
290 }
291 },
292 import: {
293 videos: {
294 http: {
295 enabled: false
296 },
297 torrent: {
298 enabled: false
299 }
300 }
301 },
302 autoBlacklist: {
303 videos: {
304 ofUsers: {
305 enabled: true
306 }
307 }
308 },
309 followers: {
310 instance: {
311 enabled: false,
312 manualApproval: true
313 }
314 },
315 followings: {
316 instance: {
317 autoFollowBack: {
318 enabled: true
319 },
320 autoFollowIndex: {
321 enabled: true,
322 indexUrl: 'https://updated.example.com'
323 }
324 }
325 }
326 }
327 await updateCustomConfig(server.url, server.accessToken, newCustomConfig)
328
329 const res = await getCustomConfig(server.url, server.accessToken)
330 const data = res.body
331
332 checkUpdatedConfig(data)
333 })
334
335 it('Should have the correct updated video allowed extensions', async function () {
336 const res = await getConfig(server.url)
337 const data: ServerConfig = res.body
338
339 expect(data.video.file.extensions).to.have.length.above(3)
340 expect(data.video.file.extensions).to.contain('.mp4')
341 expect(data.video.file.extensions).to.contain('.webm')
342 expect(data.video.file.extensions).to.contain('.ogv')
343 expect(data.video.file.extensions).to.contain('.flv')
344 expect(data.video.file.extensions).to.contain('.mkv')
345 expect(data.video.file.extensions).to.contain('.mp3')
346 expect(data.video.file.extensions).to.contain('.ogg')
347 expect(data.video.file.extensions).to.contain('.flac')
348
349 await uploadVideo(server.url, server.accessToken, { fixture: 'video_short.mkv' }, 200)
350 await uploadVideo(server.url, server.accessToken, { fixture: 'sample.ogg' }, 200)
351 })
352
353 it('Should have the configuration updated after a restart', async function () {
354 this.timeout(10000)
355
356 killallServers([ server ])
357
358 await reRunServer(server)
359
360 const res = await getCustomConfig(server.url, server.accessToken)
361 const data = res.body
362
363 checkUpdatedConfig(data)
364 })
365
366 it('Should fetch the about information', async function () {
367 const res = await getAbout(server.url)
368 const data: About = res.body
369
370 expect(data.instance.name).to.equal('PeerTube updated')
371 expect(data.instance.shortDescription).to.equal('my short description')
372 expect(data.instance.description).to.equal('my super description')
373 expect(data.instance.terms).to.equal('my super terms')
374 expect(data.instance.codeOfConduct).to.equal('my super coc')
375
376 expect(data.instance.creationReason).to.equal('my super creation reason')
377 expect(data.instance.moderationInformation).to.equal('my super moderation information')
378 expect(data.instance.administrator).to.equal('Kuja')
379 expect(data.instance.maintenanceLifetime).to.equal('forever')
380 expect(data.instance.businessModel).to.equal('my super business model')
381 expect(data.instance.hardwareInformation).to.equal('2vCore 3GB RAM')
382
383 expect(data.instance.languages).to.deep.equal([ 'en', 'es' ])
384 expect(data.instance.categories).to.deep.equal([ 1, 2 ])
385 })
386
387 it('Should remove the custom configuration', async function () {
388 this.timeout(10000)
389
390 await deleteCustomConfig(server.url, server.accessToken)
391
392 const res = await getCustomConfig(server.url, server.accessToken)
393 const data = res.body
394
395 checkInitialConfig(server, data)
396 })
397
398 after(async function () {
399 await cleanupTests([ server ])
400 })
401 })