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