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