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