]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/tests/api/server/config.ts
78fdc9cc09479faa98919e8cb3ad7b13c3881d5b
[github/Chocobozzz/PeerTube.git] / server / tests / api / server / config.ts
1 /* tslint:disable:no-unused-expression */
2
3 import 'mocha'
4 import * as chai from 'chai'
5 import { About } from '../../../../shared/models/server/about.model'
6 import { CustomConfig } from '../../../../shared/models/server/custom-config.model'
7 import {
8 cleanupTests,
9 deleteCustomConfig,
10 flushAndRunServer,
11 getAbout,
12 getConfig,
13 getCustomConfig,
14 killallServers, parallelTests,
15 registerUser,
16 reRunServer, ServerInfo,
17 setAccessTokensToServers,
18 updateCustomConfig, uploadVideo
19 } from '../../../../shared/extra-utils'
20 import { ServerConfig } from '../../../../shared/models'
21
22 const expect = chai.expect
23
24 function checkInitialConfig (server: ServerInfo, data: CustomConfig) {
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')
33 expect(data.instance.isNSFW).to.be.false
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
37
38 expect(data.services.twitter.username).to.equal('@Chocobozzz')
39 expect(data.services.twitter.whitelisted).to.be.false
40
41 expect(data.cache.previews.size).to.equal(1)
42 expect(data.cache.captions.size).to.equal(1)
43
44 expect(data.signup.enabled).to.be.true
45 expect(data.signup.limit).to.equal(4)
46 expect(data.signup.requiresEmailVerification).to.be.false
47
48 expect(data.admin.email).to.equal('admin' + server.internalServerNumber + '@example.com')
49 expect(data.contactForm.enabled).to.be.true
50
51 expect(data.user.videoQuota).to.equal(5242880)
52 expect(data.user.videoQuotaDaily).to.equal(-1)
53 expect(data.transcoding.enabled).to.be.false
54 expect(data.transcoding.allowAdditionalExtensions).to.be.false
55 expect(data.transcoding.allowAudioFiles).to.be.false
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
62 expect(data.transcoding.resolutions['2160p']).to.be.true
63 expect(data.transcoding.hls.enabled).to.be.true
64
65 expect(data.import.videos.http.enabled).to.be.true
66 expect(data.import.videos.torrent.enabled).to.be.true
67 expect(data.autoBlacklist.videos.ofUsers.enabled).to.be.false
68
69 expect(data.followers.instance.enabled).to.be.true
70 expect(data.followers.instance.manualApproval).to.be.false
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')
79 expect(data.instance.isNSFW).to.be.true
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; }')
83
84 expect(data.services.twitter.username).to.equal('@Kuja')
85 expect(data.services.twitter.whitelisted).to.be.true
86
87 expect(data.cache.previews.size).to.equal(2)
88 expect(data.cache.captions.size).to.equal(3)
89
90 expect(data.signup.enabled).to.be.false
91 expect(data.signup.limit).to.equal(5)
92 expect(data.signup.requiresEmailVerification).to.be.false
93
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
99 expect(data.contactForm.enabled).to.be.false
100
101 expect(data.user.videoQuota).to.equal(5242881)
102 expect(data.user.videoQuotaDaily).to.equal(318742)
103
104 expect(data.transcoding.enabled).to.be.true
105 expect(data.transcoding.threads).to.equal(1)
106 expect(data.transcoding.allowAdditionalExtensions).to.be.true
107 expect(data.transcoding.allowAudioFiles).to.be.true
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
113 expect(data.transcoding.resolutions['2160p']).to.be.false
114 expect(data.transcoding.hls.enabled).to.be.false
115
116 expect(data.import.videos.http.enabled).to.be.false
117 expect(data.import.videos.torrent.enabled).to.be.false
118 expect(data.autoBlacklist.videos.ofUsers.enabled).to.be.true
119
120 expect(data.followers.instance.enabled).to.be.false
121 expect(data.followers.instance.manualApproval).to.be.true
122 }
123
124 describe('Test config', function () {
125 let server = null
126
127 before(async function () {
128 this.timeout(30000)
129
130 server = await flushAndRunServer(1)
131 await setAccessTokensToServers([ server ])
132 })
133
134 it('Should have a correct config on a server with registration enabled', async function () {
135 const res = await getConfig(server.url)
136 const data: ServerConfig = res.body
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 () {
142 this.timeout(5000)
143
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 ])
149
150 const res = await getConfig(server.url)
151 const data: ServerConfig = res.body
152
153 expect(data.signup.allowed).to.be.false
154 })
155
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')
164
165 await uploadVideo(server.url, server.accessToken, { fixture: 'video_short.mkv' }, 400)
166 await uploadVideo(server.url, server.accessToken, { fixture: 'sample.ogg' }, 400)
167
168 expect(data.contactForm.enabled).to.be.true
169 })
170
171 it('Should get the customized configuration', async function () {
172 const res = await getCustomConfig(server.url, server.accessToken)
173 const data = res.body as CustomConfig
174
175 checkInitialConfig(server, data)
176 })
177
178 it('Should update the customized configuration', async function () {
179 const newCustomConfig: CustomConfig = {
180 instance: {
181 name: 'PeerTube updated',
182 shortDescription: 'my short description',
183 description: 'my super description',
184 terms: 'my super terms',
185 defaultClientRoute: '/videos/recently-added',
186 isNSFW: true,
187 defaultNSFWPolicy: 'blur' as 'blur',
188 customizations: {
189 javascript: 'alert("coucou")',
190 css: 'body { background-color: red; }'
191 }
192 },
193 theme: {
194 default: 'default'
195 },
196 services: {
197 twitter: {
198 username: '@Kuja',
199 whitelisted: true
200 }
201 },
202 cache: {
203 previews: {
204 size: 2
205 },
206 captions: {
207 size: 3
208 }
209 },
210 signup: {
211 enabled: false,
212 limit: 5,
213 requiresEmailVerification: false
214 },
215 admin: {
216 email: 'superadmin1@example.com'
217 },
218 contactForm: {
219 enabled: false
220 },
221 user: {
222 videoQuota: 5242881,
223 videoQuotaDaily: 318742
224 },
225 transcoding: {
226 enabled: true,
227 allowAdditionalExtensions: true,
228 allowAudioFiles: true,
229 threads: 1,
230 resolutions: {
231 '240p': false,
232 '360p': true,
233 '480p': true,
234 '720p': false,
235 '1080p': false,
236 '2160p': false
237 },
238 hls: {
239 enabled: false
240 }
241 },
242 import: {
243 videos: {
244 http: {
245 enabled: false
246 },
247 torrent: {
248 enabled: false
249 }
250 }
251 },
252 autoBlacklist: {
253 videos: {
254 ofUsers: {
255 enabled: true
256 }
257 }
258 },
259 followers: {
260 instance: {
261 enabled: false,
262 manualApproval: true
263 }
264 }
265 }
266 await updateCustomConfig(server.url, server.accessToken, newCustomConfig)
267
268 const res = await getCustomConfig(server.url, server.accessToken)
269 const data = res.body
270
271 checkUpdatedConfig(data)
272 })
273
274 it('Should have the correct updated video allowed extensions', async function () {
275 const res = await getConfig(server.url)
276 const data: ServerConfig = res.body
277
278 expect(data.video.file.extensions).to.have.length.above(3)
279 expect(data.video.file.extensions).to.contain('.mp4')
280 expect(data.video.file.extensions).to.contain('.webm')
281 expect(data.video.file.extensions).to.contain('.ogv')
282 expect(data.video.file.extensions).to.contain('.flv')
283 expect(data.video.file.extensions).to.contain('.mkv')
284 expect(data.video.file.extensions).to.contain('.mp3')
285 expect(data.video.file.extensions).to.contain('.ogg')
286 expect(data.video.file.extensions).to.contain('.flac')
287
288 await uploadVideo(server.url, server.accessToken, { fixture: 'video_short.mkv' }, 200)
289 await uploadVideo(server.url, server.accessToken, { fixture: 'sample.ogg' }, 200)
290 })
291
292 it('Should have the configuration updated after a restart', async function () {
293 this.timeout(10000)
294
295 killallServers([ server ])
296
297 await reRunServer(server)
298
299 const res = await getCustomConfig(server.url, server.accessToken)
300 const data = res.body
301
302 checkUpdatedConfig(data)
303 })
304
305 it('Should fetch the about information', async function () {
306 const res = await getAbout(server.url)
307 const data: About = res.body
308
309 expect(data.instance.name).to.equal('PeerTube updated')
310 expect(data.instance.shortDescription).to.equal('my short description')
311 expect(data.instance.description).to.equal('my super description')
312 expect(data.instance.terms).to.equal('my super terms')
313 })
314
315 it('Should remove the custom configuration', async function () {
316 this.timeout(10000)
317
318 await deleteCustomConfig(server.url, server.accessToken)
319
320 const res = await getCustomConfig(server.url, server.accessToken)
321 const data = res.body
322
323 checkInitialConfig(server, data)
324 })
325
326 after(async function () {
327 await cleanupTests([ server ])
328 })
329 })