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