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