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