]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/tests/api/server/config.ts
Fix broken playlist api
[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 {
7c3b7976 8 cleanupTests,
9639bd17 9 deleteCustomConfig,
7c3b7976 10 flushAndRunServer,
9639bd17 11 getAbout,
5bcfd029
C
12 getConfig,
13 getCustomConfig,
48f07b4a 14 killallServers, parallelTests,
5bcfd029 15 registerUser,
48f07b4a 16 reRunServer, ServerInfo,
5bcfd029 17 setAccessTokensToServers,
b345a804 18 updateCustomConfig, uploadVideo
94565d52 19} from '../../../../shared/extra-utils'
14e2014a 20import { ServerConfig } from '../../../../shared/models'
0e1dc3e7 21
5bcfd029
C
22const expect = chai.expect
23
48f07b4a 24function checkInitialConfig (server: ServerInfo, data: CustomConfig) {
40e87e9e
C
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
48f07b4a 48 expect(data.admin.email).to.equal('admin' + server.internalServerNumber + '@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
536598cf 55 expect(data.transcoding.allowAudioFiles).to.be.false
40e87e9e
C
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
db714ab4 62 expect(data.transcoding.resolutions['2160p']).to.be.true
09209296
C
63 expect(data.transcoding.hls.enabled).to.be.true
64
5d08a6a7 65 expect(data.import.videos.http.enabled).to.be.true
a84b8fa5 66 expect(data.import.videos.torrent.enabled).to.be.true
7ccddd7b 67 expect(data.autoBlacklist.videos.ofUsers.enabled).to.be.false
5b9c965d
C
68
69 expect(data.followers.instance.enabled).to.be.true
14893eb7 70 expect(data.followers.instance.manualApproval).to.be.false
40e87e9e
C
71}
72
73function 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')
f8802489 79 expect(data.instance.isNSFW).to.be.true
40e87e9e
C
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; }')
a4101923 83
40e87e9e
C
84 expect(data.services.twitter.username).to.equal('@Kuja')
85 expect(data.services.twitter.whitelisted).to.be.true
a4101923 86
40e87e9e
C
87 expect(data.cache.previews.size).to.equal(2)
88 expect(data.cache.captions.size).to.equal(3)
a4101923 89
40e87e9e
C
90 expect(data.signup.enabled).to.be.false
91 expect(data.signup.limit).to.equal(5)
576ad67a 92 expect(data.signup.requiresEmailVerification).to.be.false
a4101923 93
48f07b4a
C
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
a4101923
C
99 expect(data.contactForm.enabled).to.be.false
100
40e87e9e 101 expect(data.user.videoQuota).to.equal(5242881)
bee0abff 102 expect(data.user.videoQuotaDaily).to.equal(318742)
a4101923 103
40e87e9e
C
104 expect(data.transcoding.enabled).to.be.true
105 expect(data.transcoding.threads).to.equal(1)
14e2014a 106 expect(data.transcoding.allowAdditionalExtensions).to.be.true
536598cf 107 expect(data.transcoding.allowAudioFiles).to.be.true
40e87e9e
C
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
db714ab4 113 expect(data.transcoding.resolutions['2160p']).to.be.false
09209296 114 expect(data.transcoding.hls.enabled).to.be.false
a4101923 115
5d08a6a7 116 expect(data.import.videos.http.enabled).to.be.false
a84b8fa5 117 expect(data.import.videos.torrent.enabled).to.be.false
7ccddd7b 118 expect(data.autoBlacklist.videos.ofUsers.enabled).to.be.true
5b9c965d
C
119
120 expect(data.followers.instance.enabled).to.be.false
14893eb7 121 expect(data.followers.instance.manualApproval).to.be.true
40e87e9e
C
122}
123
0e1dc3e7
C
124describe('Test config', function () {
125 let server = null
126
127 before(async function () {
e212f887 128 this.timeout(30000)
48f07b4a 129
210feb6c 130 server = await flushAndRunServer(1)
fd206f0b 131 await setAccessTokensToServers([ server ])
0e1dc3e7
C
132 })
133
134 it('Should have a correct config on a server with registration enabled', async function () {
135 const res = await getConfig(server.url)
14e2014a 136 const data: ServerConfig = res.body
0e1dc3e7
C
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 () {
652b3056
C
142 this.timeout(5000)
143
47e0652b
C
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 ])
0e1dc3e7
C
149
150 const res = await getConfig(server.url)
14e2014a 151 const data: ServerConfig = res.body
0e1dc3e7
C
152
153 expect(data.signup.allowed).to.be.false
154 })
155
14e2014a
C
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')
a4101923 164
b345a804
C
165 await uploadVideo(server.url, server.accessToken, { fixture: 'video_short.mkv' }, 400)
166 await uploadVideo(server.url, server.accessToken, { fixture: 'sample.ogg' }, 400)
167
a4101923 168 expect(data.contactForm.enabled).to.be.true
14e2014a
C
169 })
170
fd206f0b
C
171 it('Should get the customized configuration', async function () {
172 const res = await getCustomConfig(server.url, server.accessToken)
00b5556c 173 const data = res.body as CustomConfig
fd206f0b 174
48f07b4a 175 checkInitialConfig(server, data)
fd206f0b
C
176 })
177
178 it('Should update the customized configuration', async function () {
40e87e9e 179 const newCustomConfig: CustomConfig = {
66b16caf
C
180 instance: {
181 name: 'PeerTube updated',
2e3a0215 182 shortDescription: 'my short description',
66b16caf 183 description: 'my super description',
00b5556c 184 terms: 'my super terms',
901637bb 185 defaultClientRoute: '/videos/recently-added',
f8802489 186 isNSFW: true,
0883b324 187 defaultNSFWPolicy: 'blur' as 'blur',
00b5556c
C
188 customizations: {
189 javascript: 'alert("coucou")',
190 css: 'body { background-color: red; }'
191 }
66b16caf 192 },
7cd4d2ba
C
193 theme: {
194 default: 'default'
195 },
8be1afa1
C
196 services: {
197 twitter: {
198 username: '@Kuja',
199 whitelisted: true
200 }
201 },
fd206f0b
C
202 cache: {
203 previews: {
204 size: 2
40e87e9e
C
205 },
206 captions: {
207 size: 3
fd206f0b
C
208 }
209 },
210 signup: {
211 enabled: false,
d9eaee39 212 limit: 5,
576ad67a 213 requiresEmailVerification: false
fd206f0b
C
214 },
215 admin: {
216 email: 'superadmin1@example.com'
217 },
a4101923
C
218 contactForm: {
219 enabled: false
220 },
fd206f0b 221 user: {
bee0abff
FA
222 videoQuota: 5242881,
223 videoQuotaDaily: 318742
fd206f0b
C
224 },
225 transcoding: {
226 enabled: true,
14e2014a 227 allowAdditionalExtensions: true,
536598cf 228 allowAudioFiles: true,
fd206f0b
C
229 threads: 1,
230 resolutions: {
231 '240p': false,
232 '360p': true,
233 '480p': true,
234 '720p': false,
db714ab4
C
235 '1080p': false,
236 '2160p': false
09209296
C
237 },
238 hls: {
239 enabled: false
fd206f0b 240 }
5d08a6a7
C
241 },
242 import: {
243 videos: {
244 http: {
245 enabled: false
a84b8fa5
C
246 },
247 torrent: {
248 enabled: false
5d08a6a7
C
249 }
250 }
7ccddd7b
JM
251 },
252 autoBlacklist: {
253 videos: {
254 ofUsers: {
255 enabled: true
256 }
257 }
5b9c965d
C
258 },
259 followers: {
260 instance: {
14893eb7
C
261 enabled: false,
262 manualApproval: true
5b9c965d 263 }
fd206f0b
C
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
40e87e9e 271 checkUpdatedConfig(data)
fd206f0b
C
272 })
273
14e2014a
C
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')
b345a804
C
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)
14e2014a
C
290 })
291
fd206f0b 292 it('Should have the configuration updated after a restart', async function () {
23e27dd5
C
293 this.timeout(10000)
294
fd206f0b
C
295 killallServers([ server ])
296
297 await reRunServer(server)
298
299 const res = await getCustomConfig(server.url, server.accessToken)
300 const data = res.body
301
40e87e9e 302 checkUpdatedConfig(data)
fd206f0b
C
303 })
304
36f9424f
C
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')
2e3a0215 310 expect(data.instance.shortDescription).to.equal('my short description')
36f9424f
C
311 expect(data.instance.description).to.equal('my super description')
312 expect(data.instance.terms).to.equal('my super terms')
313 })
314
fd206f0b 315 it('Should remove the custom configuration', async function () {
23e27dd5
C
316 this.timeout(10000)
317
fd206f0b
C
318 await deleteCustomConfig(server.url, server.accessToken)
319
320 const res = await getCustomConfig(server.url, server.accessToken)
321 const data = res.body
322
48f07b4a 323 checkInitialConfig(server, data)
fd206f0b
C
324 })
325
7c3b7976
C
326 after(async function () {
327 await cleanupTests([ server ])
0e1dc3e7
C
328 })
329})