]>
Commit | Line | Data |
---|---|---|
1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ | |
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, | |
15 | makeGetRequest, | |
16 | parallelTests, | |
17 | registerUser, | |
18 | reRunServer, | |
19 | ServerInfo, | |
20 | setAccessTokensToServers, | |
21 | updateCustomConfig, | |
22 | uploadVideo | |
23 | } from '../../../../shared/extra-utils' | |
24 | import { ServerConfig } from '../../../../shared/models' | |
25 | import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' | |
26 | ||
27 | const expect = chai.expect | |
28 | ||
29 | function checkInitialConfig (server: ServerInfo, data: CustomConfig) { | |
30 | expect(data.instance.name).to.equal('PeerTube') | |
31 | expect(data.instance.shortDescription).to.equal( | |
32 | 'PeerTube, an ActivityPub-federated video streaming platform using P2P directly in your web browser.' | |
33 | ) | |
34 | expect(data.instance.description).to.equal('Welcome to this PeerTube instance!') | |
35 | ||
36 | expect(data.instance.terms).to.equal('No terms for now.') | |
37 | expect(data.instance.creationReason).to.be.empty | |
38 | expect(data.instance.codeOfConduct).to.be.empty | |
39 | expect(data.instance.moderationInformation).to.be.empty | |
40 | expect(data.instance.administrator).to.be.empty | |
41 | expect(data.instance.maintenanceLifetime).to.be.empty | |
42 | expect(data.instance.businessModel).to.be.empty | |
43 | expect(data.instance.hardwareInformation).to.be.empty | |
44 | ||
45 | expect(data.instance.languages).to.have.lengthOf(0) | |
46 | expect(data.instance.categories).to.have.lengthOf(0) | |
47 | ||
48 | expect(data.instance.defaultClientRoute).to.equal('/videos/trending') | |
49 | expect(data.instance.isNSFW).to.be.false | |
50 | expect(data.instance.defaultNSFWPolicy).to.equal('display') | |
51 | expect(data.instance.customizations.css).to.be.empty | |
52 | expect(data.instance.customizations.javascript).to.be.empty | |
53 | ||
54 | expect(data.services.twitter.username).to.equal('@Chocobozzz') | |
55 | expect(data.services.twitter.whitelisted).to.be.false | |
56 | ||
57 | expect(data.cache.previews.size).to.equal(1) | |
58 | expect(data.cache.captions.size).to.equal(1) | |
59 | expect(data.cache.torrents.size).to.equal(1) | |
60 | ||
61 | expect(data.signup.enabled).to.be.true | |
62 | expect(data.signup.limit).to.equal(4) | |
63 | expect(data.signup.requiresEmailVerification).to.be.false | |
64 | ||
65 | expect(data.admin.email).to.equal('admin' + server.internalServerNumber + '@example.com') | |
66 | expect(data.contactForm.enabled).to.be.true | |
67 | ||
68 | expect(data.user.videoQuota).to.equal(5242880) | |
69 | expect(data.user.videoQuotaDaily).to.equal(-1) | |
70 | ||
71 | expect(data.transcoding.enabled).to.be.false | |
72 | expect(data.transcoding.allowAdditionalExtensions).to.be.false | |
73 | expect(data.transcoding.allowAudioFiles).to.be.false | |
74 | expect(data.transcoding.threads).to.equal(2) | |
75 | expect(data.transcoding.concurrency).to.equal(2) | |
76 | expect(data.transcoding.profile).to.equal('default') | |
77 | expect(data.transcoding.resolutions['240p']).to.be.true | |
78 | expect(data.transcoding.resolutions['360p']).to.be.true | |
79 | expect(data.transcoding.resolutions['480p']).to.be.true | |
80 | expect(data.transcoding.resolutions['720p']).to.be.true | |
81 | expect(data.transcoding.resolutions['1080p']).to.be.true | |
82 | expect(data.transcoding.resolutions['1440p']).to.be.true | |
83 | expect(data.transcoding.resolutions['2160p']).to.be.true | |
84 | expect(data.transcoding.webtorrent.enabled).to.be.true | |
85 | expect(data.transcoding.hls.enabled).to.be.true | |
86 | ||
87 | expect(data.live.enabled).to.be.false | |
88 | expect(data.live.allowReplay).to.be.false | |
89 | expect(data.live.maxDuration).to.equal(-1) | |
90 | expect(data.live.maxInstanceLives).to.equal(20) | |
91 | expect(data.live.maxUserLives).to.equal(3) | |
92 | expect(data.live.transcoding.enabled).to.be.false | |
93 | expect(data.live.transcoding.threads).to.equal(2) | |
94 | expect(data.live.transcoding.profile).to.equal('default') | |
95 | expect(data.live.transcoding.resolutions['240p']).to.be.false | |
96 | expect(data.live.transcoding.resolutions['360p']).to.be.false | |
97 | expect(data.live.transcoding.resolutions['480p']).to.be.false | |
98 | expect(data.live.transcoding.resolutions['720p']).to.be.false | |
99 | expect(data.live.transcoding.resolutions['1080p']).to.be.false | |
100 | expect(data.live.transcoding.resolutions['1440p']).to.be.false | |
101 | expect(data.live.transcoding.resolutions['2160p']).to.be.false | |
102 | ||
103 | expect(data.import.videos.concurrency).to.equal(2) | |
104 | expect(data.import.videos.http.enabled).to.be.true | |
105 | expect(data.import.videos.torrent.enabled).to.be.true | |
106 | expect(data.autoBlacklist.videos.ofUsers.enabled).to.be.false | |
107 | ||
108 | expect(data.followers.instance.enabled).to.be.true | |
109 | expect(data.followers.instance.manualApproval).to.be.false | |
110 | ||
111 | expect(data.followings.instance.autoFollowBack.enabled).to.be.false | |
112 | expect(data.followings.instance.autoFollowIndex.enabled).to.be.false | |
113 | expect(data.followings.instance.autoFollowIndex.indexUrl).to.equal('') | |
114 | ||
115 | expect(data.broadcastMessage.enabled).to.be.false | |
116 | expect(data.broadcastMessage.level).to.equal('info') | |
117 | expect(data.broadcastMessage.message).to.equal('') | |
118 | expect(data.broadcastMessage.dismissable).to.be.false | |
119 | } | |
120 | ||
121 | function checkUpdatedConfig (data: CustomConfig) { | |
122 | expect(data.instance.name).to.equal('PeerTube updated') | |
123 | expect(data.instance.shortDescription).to.equal('my short description') | |
124 | expect(data.instance.description).to.equal('my super description') | |
125 | ||
126 | expect(data.instance.terms).to.equal('my super terms') | |
127 | expect(data.instance.creationReason).to.equal('my super creation reason') | |
128 | expect(data.instance.codeOfConduct).to.equal('my super coc') | |
129 | expect(data.instance.moderationInformation).to.equal('my super moderation information') | |
130 | expect(data.instance.administrator).to.equal('Kuja') | |
131 | expect(data.instance.maintenanceLifetime).to.equal('forever') | |
132 | expect(data.instance.businessModel).to.equal('my super business model') | |
133 | expect(data.instance.hardwareInformation).to.equal('2vCore 3GB RAM') | |
134 | ||
135 | expect(data.instance.languages).to.deep.equal([ 'en', 'es' ]) | |
136 | expect(data.instance.categories).to.deep.equal([ 1, 2 ]) | |
137 | ||
138 | expect(data.instance.defaultClientRoute).to.equal('/videos/recently-added') | |
139 | expect(data.instance.isNSFW).to.be.true | |
140 | expect(data.instance.defaultNSFWPolicy).to.equal('blur') | |
141 | expect(data.instance.customizations.javascript).to.equal('alert("coucou")') | |
142 | expect(data.instance.customizations.css).to.equal('body { background-color: red; }') | |
143 | ||
144 | expect(data.services.twitter.username).to.equal('@Kuja') | |
145 | expect(data.services.twitter.whitelisted).to.be.true | |
146 | ||
147 | expect(data.cache.previews.size).to.equal(2) | |
148 | expect(data.cache.captions.size).to.equal(3) | |
149 | expect(data.cache.torrents.size).to.equal(4) | |
150 | ||
151 | expect(data.signup.enabled).to.be.false | |
152 | expect(data.signup.limit).to.equal(5) | |
153 | expect(data.signup.requiresEmailVerification).to.be.false | |
154 | ||
155 | // We override admin email in parallel tests, so skip this exception | |
156 | if (parallelTests() === false) { | |
157 | expect(data.admin.email).to.equal('superadmin1@example.com') | |
158 | } | |
159 | ||
160 | expect(data.contactForm.enabled).to.be.false | |
161 | ||
162 | expect(data.user.videoQuota).to.equal(5242881) | |
163 | expect(data.user.videoQuotaDaily).to.equal(318742) | |
164 | ||
165 | expect(data.transcoding.enabled).to.be.true | |
166 | expect(data.transcoding.threads).to.equal(1) | |
167 | expect(data.transcoding.concurrency).to.equal(3) | |
168 | expect(data.transcoding.allowAdditionalExtensions).to.be.true | |
169 | expect(data.transcoding.allowAudioFiles).to.be.true | |
170 | expect(data.transcoding.profile).to.equal('vod_profile') | |
171 | expect(data.transcoding.resolutions['240p']).to.be.false | |
172 | expect(data.transcoding.resolutions['360p']).to.be.true | |
173 | expect(data.transcoding.resolutions['480p']).to.be.true | |
174 | expect(data.transcoding.resolutions['720p']).to.be.false | |
175 | expect(data.transcoding.resolutions['1080p']).to.be.false | |
176 | expect(data.transcoding.resolutions['2160p']).to.be.false | |
177 | expect(data.transcoding.hls.enabled).to.be.false | |
178 | expect(data.transcoding.webtorrent.enabled).to.be.true | |
179 | ||
180 | expect(data.live.enabled).to.be.true | |
181 | expect(data.live.allowReplay).to.be.true | |
182 | expect(data.live.maxDuration).to.equal(5000) | |
183 | expect(data.live.maxInstanceLives).to.equal(-1) | |
184 | expect(data.live.maxUserLives).to.equal(10) | |
185 | expect(data.live.transcoding.enabled).to.be.true | |
186 | expect(data.live.transcoding.threads).to.equal(4) | |
187 | expect(data.live.transcoding.profile).to.equal('live_profile') | |
188 | expect(data.live.transcoding.resolutions['240p']).to.be.true | |
189 | expect(data.live.transcoding.resolutions['360p']).to.be.true | |
190 | expect(data.live.transcoding.resolutions['480p']).to.be.true | |
191 | expect(data.live.transcoding.resolutions['720p']).to.be.true | |
192 | expect(data.live.transcoding.resolutions['1080p']).to.be.true | |
193 | expect(data.live.transcoding.resolutions['2160p']).to.be.true | |
194 | ||
195 | expect(data.import.videos.concurrency).to.equal(4) | |
196 | expect(data.import.videos.http.enabled).to.be.false | |
197 | expect(data.import.videos.torrent.enabled).to.be.false | |
198 | expect(data.autoBlacklist.videos.ofUsers.enabled).to.be.true | |
199 | ||
200 | expect(data.followers.instance.enabled).to.be.false | |
201 | expect(data.followers.instance.manualApproval).to.be.true | |
202 | ||
203 | expect(data.followings.instance.autoFollowBack.enabled).to.be.true | |
204 | expect(data.followings.instance.autoFollowIndex.enabled).to.be.true | |
205 | expect(data.followings.instance.autoFollowIndex.indexUrl).to.equal('https://updated.example.com') | |
206 | ||
207 | expect(data.broadcastMessage.enabled).to.be.true | |
208 | expect(data.broadcastMessage.level).to.equal('error') | |
209 | expect(data.broadcastMessage.message).to.equal('super bad message') | |
210 | expect(data.broadcastMessage.dismissable).to.be.true | |
211 | } | |
212 | ||
213 | describe('Test config', function () { | |
214 | let server = null | |
215 | ||
216 | before(async function () { | |
217 | this.timeout(30000) | |
218 | ||
219 | server = await flushAndRunServer(1) | |
220 | await setAccessTokensToServers([ server ]) | |
221 | }) | |
222 | ||
223 | it('Should have a correct config on a server with registration enabled', async function () { | |
224 | const res = await getConfig(server.url) | |
225 | const data: ServerConfig = res.body | |
226 | ||
227 | expect(data.signup.allowed).to.be.true | |
228 | }) | |
229 | ||
230 | it('Should have a correct config on a server with registration enabled and a users limit', async function () { | |
231 | this.timeout(5000) | |
232 | ||
233 | await Promise.all([ | |
234 | registerUser(server.url, 'user1', 'super password'), | |
235 | registerUser(server.url, 'user2', 'super password'), | |
236 | registerUser(server.url, 'user3', 'super password') | |
237 | ]) | |
238 | ||
239 | const res = await getConfig(server.url) | |
240 | const data: ServerConfig = res.body | |
241 | ||
242 | expect(data.signup.allowed).to.be.false | |
243 | }) | |
244 | ||
245 | it('Should have the correct video allowed extensions', async function () { | |
246 | const res = await getConfig(server.url) | |
247 | const data: ServerConfig = res.body | |
248 | ||
249 | expect(data.video.file.extensions).to.have.lengthOf(3) | |
250 | expect(data.video.file.extensions).to.contain('.mp4') | |
251 | expect(data.video.file.extensions).to.contain('.webm') | |
252 | expect(data.video.file.extensions).to.contain('.ogv') | |
253 | ||
254 | await uploadVideo(server.url, server.accessToken, { fixture: 'video_short.mkv' }, HttpStatusCode.UNSUPPORTED_MEDIA_TYPE_415) | |
255 | await uploadVideo(server.url, server.accessToken, { fixture: 'sample.ogg' }, HttpStatusCode.UNSUPPORTED_MEDIA_TYPE_415) | |
256 | ||
257 | expect(data.contactForm.enabled).to.be.true | |
258 | }) | |
259 | ||
260 | it('Should get the customized configuration', async function () { | |
261 | const res = await getCustomConfig(server.url, server.accessToken) | |
262 | const data = res.body as CustomConfig | |
263 | ||
264 | checkInitialConfig(server, data) | |
265 | }) | |
266 | ||
267 | it('Should update the customized configuration', async function () { | |
268 | const newCustomConfig: CustomConfig = { | |
269 | instance: { | |
270 | name: 'PeerTube updated', | |
271 | shortDescription: 'my short description', | |
272 | description: 'my super description', | |
273 | terms: 'my super terms', | |
274 | codeOfConduct: 'my super coc', | |
275 | ||
276 | creationReason: 'my super creation reason', | |
277 | moderationInformation: 'my super moderation information', | |
278 | administrator: 'Kuja', | |
279 | maintenanceLifetime: 'forever', | |
280 | businessModel: 'my super business model', | |
281 | hardwareInformation: '2vCore 3GB RAM', | |
282 | ||
283 | languages: [ 'en', 'es' ], | |
284 | categories: [ 1, 2 ], | |
285 | ||
286 | isNSFW: true, | |
287 | defaultNSFWPolicy: 'blur' as 'blur', | |
288 | ||
289 | defaultClientRoute: '/videos/recently-added', | |
290 | ||
291 | customizations: { | |
292 | javascript: 'alert("coucou")', | |
293 | css: 'body { background-color: red; }' | |
294 | } | |
295 | }, | |
296 | theme: { | |
297 | default: 'default' | |
298 | }, | |
299 | services: { | |
300 | twitter: { | |
301 | username: '@Kuja', | |
302 | whitelisted: true | |
303 | } | |
304 | }, | |
305 | cache: { | |
306 | previews: { | |
307 | size: 2 | |
308 | }, | |
309 | captions: { | |
310 | size: 3 | |
311 | }, | |
312 | torrents: { | |
313 | size: 4 | |
314 | } | |
315 | }, | |
316 | signup: { | |
317 | enabled: false, | |
318 | limit: 5, | |
319 | requiresEmailVerification: false | |
320 | }, | |
321 | admin: { | |
322 | email: 'superadmin1@example.com' | |
323 | }, | |
324 | contactForm: { | |
325 | enabled: false | |
326 | }, | |
327 | user: { | |
328 | videoQuota: 5242881, | |
329 | videoQuotaDaily: 318742 | |
330 | }, | |
331 | transcoding: { | |
332 | enabled: true, | |
333 | allowAdditionalExtensions: true, | |
334 | allowAudioFiles: true, | |
335 | threads: 1, | |
336 | concurrency: 3, | |
337 | profile: 'vod_profile', | |
338 | resolutions: { | |
339 | '0p': false, | |
340 | '240p': false, | |
341 | '360p': true, | |
342 | '480p': true, | |
343 | '720p': false, | |
344 | '1080p': false, | |
345 | '1440p': false, | |
346 | '2160p': false | |
347 | }, | |
348 | webtorrent: { | |
349 | enabled: true | |
350 | }, | |
351 | hls: { | |
352 | enabled: false | |
353 | } | |
354 | }, | |
355 | live: { | |
356 | enabled: true, | |
357 | allowReplay: true, | |
358 | maxDuration: 5000, | |
359 | maxInstanceLives: -1, | |
360 | maxUserLives: 10, | |
361 | transcoding: { | |
362 | enabled: true, | |
363 | threads: 4, | |
364 | profile: 'live_profile', | |
365 | resolutions: { | |
366 | '240p': true, | |
367 | '360p': true, | |
368 | '480p': true, | |
369 | '720p': true, | |
370 | '1080p': true, | |
371 | '1440p': true, | |
372 | '2160p': true | |
373 | } | |
374 | } | |
375 | }, | |
376 | import: { | |
377 | videos: { | |
378 | concurrency: 4, | |
379 | http: { | |
380 | enabled: false | |
381 | }, | |
382 | torrent: { | |
383 | enabled: false | |
384 | } | |
385 | } | |
386 | }, | |
387 | trending: { | |
388 | videos: { | |
389 | algorithms: { | |
390 | enabled: [ 'best', 'hot', 'most-viewed', 'most-liked' ], | |
391 | default: 'hot' | |
392 | } | |
393 | } | |
394 | }, | |
395 | autoBlacklist: { | |
396 | videos: { | |
397 | ofUsers: { | |
398 | enabled: true | |
399 | } | |
400 | } | |
401 | }, | |
402 | followers: { | |
403 | instance: { | |
404 | enabled: false, | |
405 | manualApproval: true | |
406 | } | |
407 | }, | |
408 | followings: { | |
409 | instance: { | |
410 | autoFollowBack: { | |
411 | enabled: true | |
412 | }, | |
413 | autoFollowIndex: { | |
414 | enabled: true, | |
415 | indexUrl: 'https://updated.example.com' | |
416 | } | |
417 | } | |
418 | }, | |
419 | broadcastMessage: { | |
420 | enabled: true, | |
421 | level: 'error', | |
422 | message: 'super bad message', | |
423 | dismissable: true | |
424 | }, | |
425 | search: { | |
426 | remoteUri: { | |
427 | anonymous: true, | |
428 | users: true | |
429 | }, | |
430 | searchIndex: { | |
431 | enabled: true, | |
432 | url: 'https://search.joinpeertube.org', | |
433 | disableLocalSearch: true, | |
434 | isDefaultSearch: true | |
435 | } | |
436 | } | |
437 | } | |
438 | await updateCustomConfig(server.url, server.accessToken, newCustomConfig) | |
439 | ||
440 | const res = await getCustomConfig(server.url, server.accessToken) | |
441 | const data = res.body | |
442 | ||
443 | checkUpdatedConfig(data) | |
444 | }) | |
445 | ||
446 | it('Should have the correct updated video allowed extensions', async function () { | |
447 | this.timeout(10000) | |
448 | ||
449 | const res = await getConfig(server.url) | |
450 | const data: ServerConfig = res.body | |
451 | ||
452 | expect(data.video.file.extensions).to.have.length.above(4) | |
453 | expect(data.video.file.extensions).to.contain('.mp4') | |
454 | expect(data.video.file.extensions).to.contain('.webm') | |
455 | expect(data.video.file.extensions).to.contain('.ogv') | |
456 | expect(data.video.file.extensions).to.contain('.flv') | |
457 | expect(data.video.file.extensions).to.contain('.wmv') | |
458 | expect(data.video.file.extensions).to.contain('.mkv') | |
459 | expect(data.video.file.extensions).to.contain('.mp3') | |
460 | expect(data.video.file.extensions).to.contain('.ogg') | |
461 | expect(data.video.file.extensions).to.contain('.flac') | |
462 | ||
463 | await uploadVideo(server.url, server.accessToken, { fixture: 'video_short.mkv' }, HttpStatusCode.OK_200) | |
464 | await uploadVideo(server.url, server.accessToken, { fixture: 'sample.ogg' }, HttpStatusCode.OK_200) | |
465 | }) | |
466 | ||
467 | it('Should have the configuration updated after a restart', async function () { | |
468 | this.timeout(10000) | |
469 | ||
470 | killallServers([ server ]) | |
471 | ||
472 | await reRunServer(server) | |
473 | ||
474 | const res = await getCustomConfig(server.url, server.accessToken) | |
475 | const data = res.body | |
476 | ||
477 | checkUpdatedConfig(data) | |
478 | }) | |
479 | ||
480 | it('Should fetch the about information', async function () { | |
481 | const res = await getAbout(server.url) | |
482 | const data: About = res.body | |
483 | ||
484 | expect(data.instance.name).to.equal('PeerTube updated') | |
485 | expect(data.instance.shortDescription).to.equal('my short description') | |
486 | expect(data.instance.description).to.equal('my super description') | |
487 | expect(data.instance.terms).to.equal('my super terms') | |
488 | expect(data.instance.codeOfConduct).to.equal('my super coc') | |
489 | ||
490 | expect(data.instance.creationReason).to.equal('my super creation reason') | |
491 | expect(data.instance.moderationInformation).to.equal('my super moderation information') | |
492 | expect(data.instance.administrator).to.equal('Kuja') | |
493 | expect(data.instance.maintenanceLifetime).to.equal('forever') | |
494 | expect(data.instance.businessModel).to.equal('my super business model') | |
495 | expect(data.instance.hardwareInformation).to.equal('2vCore 3GB RAM') | |
496 | ||
497 | expect(data.instance.languages).to.deep.equal([ 'en', 'es' ]) | |
498 | expect(data.instance.categories).to.deep.equal([ 1, 2 ]) | |
499 | }) | |
500 | ||
501 | it('Should remove the custom configuration', async function () { | |
502 | this.timeout(10000) | |
503 | ||
504 | await deleteCustomConfig(server.url, server.accessToken) | |
505 | ||
506 | const res = await getCustomConfig(server.url, server.accessToken) | |
507 | const data = res.body | |
508 | ||
509 | checkInitialConfig(server, data) | |
510 | }) | |
511 | ||
512 | it('Should enable frameguard', async function () { | |
513 | this.timeout(25000) | |
514 | ||
515 | { | |
516 | const res = await makeGetRequest({ | |
517 | url: server.url, | |
518 | path: '/api/v1/config', | |
519 | statusCodeExpected: 200 | |
520 | }) | |
521 | ||
522 | expect(res.headers['x-frame-options']).to.exist | |
523 | } | |
524 | ||
525 | killallServers([ server ]) | |
526 | ||
527 | const config = { | |
528 | security: { | |
529 | frameguard: { enabled: false } | |
530 | } | |
531 | } | |
532 | server = await reRunServer(server, config) | |
533 | ||
534 | { | |
535 | const res = await makeGetRequest({ | |
536 | url: server.url, | |
537 | path: '/api/v1/config', | |
538 | statusCodeExpected: 200 | |
539 | }) | |
540 | ||
541 | expect(res.headers['x-frame-options']).to.not.exist | |
542 | } | |
543 | }) | |
544 | ||
545 | after(async function () { | |
546 | await cleanupTests([ server ]) | |
547 | }) | |
548 | }) |