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