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