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