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