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