]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/tests/api/server/config.ts
2ad477c995756ab69e5df029404edd5e2c07d226
[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
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.hls.enabled).to.be.true
63
64 expect(data.import.videos.http.enabled).to.be.true
65 expect(data.import.videos.torrent.enabled).to.be.true
66 expect(data.autoBlacklist.videos.ofUsers.enabled).to.be.false
67
68 expect(data.followers.instance.enabled).to.be.true
69 expect(data.followers.instance.manualApproval).to.be.false
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')
78 expect(data.instance.isNSFW).to.be.true
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; }')
82
83 expect(data.services.twitter.username).to.equal('@Kuja')
84 expect(data.services.twitter.whitelisted).to.be.true
85
86 expect(data.cache.previews.size).to.equal(2)
87 expect(data.cache.captions.size).to.equal(3)
88
89 expect(data.signup.enabled).to.be.false
90 expect(data.signup.limit).to.equal(5)
91 expect(data.signup.requiresEmailVerification).to.be.false
92
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
98 expect(data.contactForm.enabled).to.be.false
99
100 expect(data.user.videoQuota).to.equal(5242881)
101 expect(data.user.videoQuotaDaily).to.equal(318742)
102
103 expect(data.transcoding.enabled).to.be.true
104 expect(data.transcoding.threads).to.equal(1)
105 expect(data.transcoding.allowAdditionalExtensions).to.be.true
106 expect(data.transcoding.allowAudioFiles).to.be.true
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
112 expect(data.transcoding.hls.enabled).to.be.false
113
114 expect(data.import.videos.http.enabled).to.be.false
115 expect(data.import.videos.torrent.enabled).to.be.false
116 expect(data.autoBlacklist.videos.ofUsers.enabled).to.be.true
117
118 expect(data.followers.instance.enabled).to.be.false
119 expect(data.followers.instance.manualApproval).to.be.true
120 }
121
122 describe('Test config', function () {
123 let server = null
124
125 before(async function () {
126 this.timeout(30000)
127
128 server = await flushAndRunServer(1)
129 await setAccessTokensToServers([ server ])
130 })
131
132 it('Should have a correct config on a server with registration enabled', async function () {
133 const res = await getConfig(server.url)
134 const data: ServerConfig = res.body
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 () {
140 this.timeout(5000)
141
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 ])
147
148 const res = await getConfig(server.url)
149 const data: ServerConfig = res.body
150
151 expect(data.signup.allowed).to.be.false
152 })
153
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')
162
163 expect(data.contactForm.enabled).to.be.true
164 })
165
166 it('Should get the customized configuration', async function () {
167 const res = await getCustomConfig(server.url, server.accessToken)
168 const data = res.body as CustomConfig
169
170 checkInitialConfig(server, data)
171 })
172
173 it('Should update the customized configuration', async function () {
174 const newCustomConfig: CustomConfig = {
175 instance: {
176 name: 'PeerTube updated',
177 shortDescription: 'my short description',
178 description: 'my super description',
179 terms: 'my super terms',
180 defaultClientRoute: '/videos/recently-added',
181 isNSFW: true,
182 defaultNSFWPolicy: 'blur' as 'blur',
183 customizations: {
184 javascript: 'alert("coucou")',
185 css: 'body { background-color: red; }'
186 }
187 },
188 services: {
189 twitter: {
190 username: '@Kuja',
191 whitelisted: true
192 }
193 },
194 cache: {
195 previews: {
196 size: 2
197 },
198 captions: {
199 size: 3
200 }
201 },
202 signup: {
203 enabled: false,
204 limit: 5,
205 requiresEmailVerification: false
206 },
207 admin: {
208 email: 'superadmin1@example.com'
209 },
210 contactForm: {
211 enabled: false
212 },
213 user: {
214 videoQuota: 5242881,
215 videoQuotaDaily: 318742
216 },
217 transcoding: {
218 enabled: true,
219 allowAdditionalExtensions: true,
220 allowAudioFiles: true,
221 threads: 1,
222 resolutions: {
223 '240p': false,
224 '360p': true,
225 '480p': true,
226 '720p': false,
227 '1080p': false
228 },
229 hls: {
230 enabled: false
231 }
232 },
233 import: {
234 videos: {
235 http: {
236 enabled: false
237 },
238 torrent: {
239 enabled: false
240 }
241 }
242 },
243 autoBlacklist: {
244 videos: {
245 ofUsers: {
246 enabled: true
247 }
248 }
249 },
250 followers: {
251 instance: {
252 enabled: false,
253 manualApproval: true
254 }
255 }
256 }
257 await updateCustomConfig(server.url, server.accessToken, newCustomConfig)
258
259 const res = await getCustomConfig(server.url, server.accessToken)
260 const data = res.body
261
262 checkUpdatedConfig(data)
263 })
264
265 it('Should have the correct updated video allowed extensions', async function () {
266 const res = await getConfig(server.url)
267 const data: ServerConfig = res.body
268
269 expect(data.video.file.extensions).to.have.length.above(3)
270 expect(data.video.file.extensions).to.contain('.mp4')
271 expect(data.video.file.extensions).to.contain('.webm')
272 expect(data.video.file.extensions).to.contain('.ogv')
273 expect(data.video.file.extensions).to.contain('.flv')
274 expect(data.video.file.extensions).to.contain('.mkv')
275 })
276
277 it('Should have the configuration updated after a restart', async function () {
278 this.timeout(10000)
279
280 killallServers([ server ])
281
282 await reRunServer(server)
283
284 const res = await getCustomConfig(server.url, server.accessToken)
285 const data = res.body
286
287 checkUpdatedConfig(data)
288 })
289
290 it('Should fetch the about information', async function () {
291 const res = await getAbout(server.url)
292 const data: About = res.body
293
294 expect(data.instance.name).to.equal('PeerTube updated')
295 expect(data.instance.shortDescription).to.equal('my short description')
296 expect(data.instance.description).to.equal('my super description')
297 expect(data.instance.terms).to.equal('my super terms')
298 })
299
300 it('Should remove the custom configuration', async function () {
301 this.timeout(10000)
302
303 await deleteCustomConfig(server.url, server.accessToken)
304
305 const res = await getCustomConfig(server.url, server.accessToken)
306 const data = res.body
307
308 checkInitialConfig(server, data)
309 })
310
311 after(async function () {
312 await cleanupTests([ server ])
313 })
314 })