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