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