]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/tests/api/server/config.ts
Fix socket.io websocket connection
[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 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)
42 expect(data.signup.requiresEmailVerification).to.be.false
43 expect(data.admin.email).to.equal('admin1@example.com')
44 expect(data.user.videoQuota).to.equal(5242880)
45 expect(data.user.videoQuotaDaily).to.equal(-1)
46 expect(data.transcoding.enabled).to.be.false
47 expect(data.transcoding.allowAdditionalExtensions).to.be.false
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
54 expect(data.import.videos.http.enabled).to.be.true
55 expect(data.import.videos.torrent.enabled).to.be.true
56 }
57
58 function 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)
73 expect(data.signup.requiresEmailVerification).to.be.true
74 expect(data.admin.email).to.equal('superadmin1@example.com')
75 expect(data.user.videoQuota).to.equal(5242881)
76 expect(data.user.videoQuotaDaily).to.equal(318742)
77 expect(data.transcoding.enabled).to.be.true
78 expect(data.transcoding.threads).to.equal(1)
79 expect(data.transcoding.allowAdditionalExtensions).to.be.true
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
85 expect(data.import.videos.http.enabled).to.be.false
86 expect(data.import.videos.torrent.enabled).to.be.false
87 }
88
89 describe('Test config', function () {
90 let server = null
91
92 before(async function () {
93 this.timeout(30000)
94
95 await flushTests()
96 server = await runServer(1)
97 await setAccessTokensToServers([ server ])
98 })
99
100 it('Should have a correct config on a server with registration enabled', async function () {
101 const res = await getConfig(server.url)
102 const data: ServerConfig = res.body
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 () {
108 this.timeout(5000)
109
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 ])
115
116 const res = await getConfig(server.url)
117 const data: ServerConfig = res.body
118
119 expect(data.signup.allowed).to.be.false
120 })
121
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
132 it('Should get the customized configuration', async function () {
133 const res = await getCustomConfig(server.url, server.accessToken)
134 const data = res.body as CustomConfig
135
136 checkInitialConfig(data)
137 })
138
139 it('Should update the customized configuration', async function () {
140 const newCustomConfig: CustomConfig = {
141 instance: {
142 name: 'PeerTube updated',
143 shortDescription: 'my short description',
144 description: 'my super description',
145 terms: 'my super terms',
146 defaultClientRoute: '/videos/recently-added',
147 defaultNSFWPolicy: 'blur' as 'blur',
148 customizations: {
149 javascript: 'alert("coucou")',
150 css: 'body { background-color: red; }'
151 }
152 },
153 services: {
154 twitter: {
155 username: '@Kuja',
156 whitelisted: true
157 }
158 },
159 cache: {
160 previews: {
161 size: 2
162 },
163 captions: {
164 size: 3
165 }
166 },
167 signup: {
168 enabled: false,
169 limit: 5,
170 requiresEmailVerification: true
171 },
172 admin: {
173 email: 'superadmin1@example.com'
174 },
175 user: {
176 videoQuota: 5242881,
177 videoQuotaDaily: 318742
178 },
179 transcoding: {
180 enabled: true,
181 allowAdditionalExtensions: true,
182 threads: 1,
183 resolutions: {
184 '240p': false,
185 '360p': true,
186 '480p': true,
187 '720p': false,
188 '1080p': false
189 }
190 },
191 import: {
192 videos: {
193 http: {
194 enabled: false
195 },
196 torrent: {
197 enabled: false
198 }
199 }
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
207 checkUpdatedConfig(data)
208 })
209
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
222 it('Should have the configuration updated after a restart', async function () {
223 this.timeout(10000)
224
225 killallServers([ server ])
226
227 await reRunServer(server)
228
229 const res = await getCustomConfig(server.url, server.accessToken)
230 const data = res.body
231
232 checkUpdatedConfig(data)
233 })
234
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')
240 expect(data.instance.shortDescription).to.equal('my short description')
241 expect(data.instance.description).to.equal('my super description')
242 expect(data.instance.terms).to.equal('my super terms')
243 })
244
245 it('Should remove the custom configuration', async function () {
246 this.timeout(10000)
247
248 await deleteCustomConfig(server.url, server.accessToken)
249
250 const res = await getCustomConfig(server.url, server.accessToken)
251 const data = res.body
252
253 checkInitialConfig(data)
254 })
255
256 after(async function () {
257 killallServers([ server ])
258 })
259 })