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