]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/tests/api/check-params/config.ts
Remove unnecessary logs
[github/Chocobozzz/PeerTube.git] / server / tests / api / check-params / config.ts
CommitLineData
a1587156 1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
fd206f0b 2
fd206f0b 3import 'mocha'
2a491182
F
4import { merge, omit } from 'lodash'
5import { CustomConfig, HttpStatusCode } from '@shared/models'
fd206f0b 6import {
8424c402 7 cleanupTests,
254d3579 8 createSingleServer,
8424c402
C
9 makeDeleteRequest,
10 makeGetRequest,
11 makePutBodyRequest,
254d3579 12 PeerTubeServer,
41d1d075 13 setAccessTokensToServers
bf54587a 14} from '@shared/server-commands'
fd206f0b
C
15
16describe('Test config API validators', function () {
17 const path = '/api/v1/config/custom'
254d3579 18 let server: PeerTubeServer
fd206f0b
C
19 let userAccessToken: string
20 const updateParams: CustomConfig = {
66b16caf
C
21 instance: {
22 name: 'PeerTube updated',
2e3a0215 23 shortDescription: 'my short description',
66b16caf 24 description: 'my super description',
00b5556c 25 terms: 'my super terms',
ccc00cb2
C
26 codeOfConduct: 'my super coc',
27
8ae03c37 28 creationReason: 'my super reason',
ccc00cb2
C
29 moderationInformation: 'my super moderation information',
30 administrator: 'Kuja',
31 maintenanceLifetime: 'forever',
32 businessModel: 'my super business model',
be04c6fd 33 hardwareInformation: '2vCore 3GB RAM',
ccc00cb2
C
34
35 languages: [ 'en', 'es' ],
36 categories: [ 1, 2 ],
37
f8802489 38 isNSFW: true,
0883b324 39 defaultNSFWPolicy: 'blur',
3da68f0a
RK
40
41 defaultClientRoute: '/videos/recently-added',
3da68f0a 42
00b5556c
C
43 customizations: {
44 javascript: 'alert("coucou")',
45 css: 'body { background-color: red; }'
46 }
66b16caf 47 },
7cd4d2ba
C
48 theme: {
49 default: 'default'
50 },
8be1afa1
C
51 services: {
52 twitter: {
53 username: '@MySuperUsername',
54 whitelisted: true
55 }
56 },
0bc53e20
C
57 client: {
58 videos: {
59 miniature: {
60 preferAuthorDisplayName: false
61 }
62 },
63 menu: {
64 login: {
65 redirectOnSingleExternalAuth: false
66 }
67 }
68 },
fd206f0b
C
69 cache: {
70 previews: {
71 size: 2
40e87e9e
C
72 },
73 captions: {
74 size: 3
b3d5cb92
C
75 },
76 torrents: {
77 size: 4
fd206f0b
C
78 }
79 },
80 signup: {
81 enabled: false,
d9eaee39 82 limit: 5,
1f256e7d
P
83 requiresEmailVerification: false,
84 minimumAge: 16
fd206f0b
C
85 },
86 admin: {
87 email: 'superadmin1@example.com'
88 },
a4101923
C
89 contactForm: {
90 enabled: false
91 },
fd206f0b 92 user: {
bee0abff
FA
93 videoQuota: 5242881,
94 videoQuotaDaily: 318742
fd206f0b 95 },
754b6f5f
FC
96 videoChannels: {
97 maxPerUser: 20
98 },
fd206f0b
C
99 transcoding: {
100 enabled: true,
14e2014a 101 allowAdditionalExtensions: true,
536598cf 102 allowAudioFiles: true,
9129b769 103 concurrency: 1,
fd206f0b 104 threads: 1,
1896bca0 105 profile: 'vod_profile',
fd206f0b 106 resolutions: {
5c7d6508 107 '0p': false,
8dd754c7 108 '144p': false,
fd206f0b
C
109 '240p': false,
110 '360p': true,
111 '480p': true,
112 '720p': false,
db714ab4 113 '1080p': false,
b7085c71 114 '1440p': false,
db714ab4 115 '2160p': false
09209296 116 },
84cae54e 117 alwaysTranscodeOriginalResolution: false,
d7a25329
C
118 webtorrent: {
119 enabled: true
120 },
09209296
C
121 hls: {
122 enabled: false
fd206f0b 123 }
5d08a6a7 124 },
c6c0fa6c
C
125 live: {
126 enabled: true,
127
fb719404 128 allowReplay: false,
f443a746
C
129 latencySetting: {
130 enabled: false
131 },
c9bc850e 132 maxDuration: 30,
a056ca48
C
133 maxInstanceLives: -1,
134 maxUserLives: 50,
fb719404 135
c6c0fa6c
C
136 transcoding: {
137 enabled: true,
138 threads: 4,
1896bca0 139 profile: 'live_profile',
c6c0fa6c 140 resolutions: {
8dd754c7 141 '144p': true,
c6c0fa6c
C
142 '240p': true,
143 '360p': true,
144 '480p': true,
145 '720p': true,
146 '1080p': true,
b7085c71 147 '1440p': true,
c6c0fa6c 148 '2160p': true
84cae54e
C
149 },
150 alwaysTranscodeOriginalResolution: false
c6c0fa6c
C
151 }
152 },
92e66e04 153 videoStudio: {
c729caf6
C
154 enabled: true
155 },
5d08a6a7
C
156 import: {
157 videos: {
9129b769 158 concurrency: 1,
5d08a6a7
C
159 http: {
160 enabled: false
a84b8fa5
C
161 },
162 torrent: {
163 enabled: false
5d08a6a7 164 }
2a491182
F
165 },
166 videoChannelSynchronization: {
167 enabled: false,
168 maxPerUser: 10
5d08a6a7 169 }
7ccddd7b 170 },
ba5d4a84
RK
171 trending: {
172 videos: {
173 algorithms: {
010382b6 174 enabled: [ 'hot', 'most-viewed', 'most-liked' ],
ba5d4a84
RK
175 default: 'most-viewed'
176 }
177 }
178 },
7ccddd7b
JM
179 autoBlacklist: {
180 videos: {
181 ofUsers: {
182 enabled: false
183 }
184 }
5b9c965d
C
185 },
186 followers: {
187 instance: {
14893eb7
C
188 enabled: false,
189 manualApproval: true
5b9c965d 190 }
8424c402
C
191 },
192 followings: {
193 instance: {
194 autoFollowBack: {
195 enabled: true
196 },
197 autoFollowIndex: {
198 enabled: true,
199 indexUrl: 'https://index.example.com'
200 }
201 }
72c33e71
C
202 },
203 broadcastMessage: {
204 enabled: true,
205 dismissable: true,
206 message: 'super message',
207 level: 'warning'
5fb2e288
C
208 },
209 search: {
210 remoteUri: {
211 users: true,
212 anonymous: true
213 },
214 searchIndex: {
215 enabled: true,
216 url: 'https://search.joinpeertube.org',
217 disableLocalSearch: true,
218 isDefaultSearch: true
219 }
fd206f0b
C
220 }
221 }
222
223 // ---------------------------------------------------------------
224
225 before(async function () {
e212f887 226 this.timeout(30000)
fd206f0b 227
254d3579 228 server = await createSingleServer(1)
fd206f0b
C
229
230 await setAccessTokensToServers([ server ])
231
232 const user = {
233 username: 'user1',
234 password: 'password'
235 }
89d241a7
C
236 await server.users.create({ username: user.username, password: user.password })
237 userAccessToken = await server.login.getAccessToken(user)
fd206f0b
C
238 })
239
240 describe('When getting the configuration', function () {
241 it('Should fail without token', async function () {
242 await makeGetRequest({
243 url: server.url,
244 path,
c0e8b12e 245 expectedStatus: HttpStatusCode.UNAUTHORIZED_401
fd206f0b
C
246 })
247 })
248
249 it('Should fail if the user is not an administrator', async function () {
250 await makeGetRequest({
251 url: server.url,
252 path,
253 token: userAccessToken,
c0e8b12e 254 expectedStatus: HttpStatusCode.FORBIDDEN_403
fd206f0b
C
255 })
256 })
257 })
258
259 describe('When updating the configuration', function () {
260 it('Should fail without token', async function () {
261 await makePutBodyRequest({
262 url: server.url,
263 path,
264 fields: updateParams,
c0e8b12e 265 expectedStatus: HttpStatusCode.UNAUTHORIZED_401
fd206f0b
C
266 })
267 })
268
269 it('Should fail if the user is not an administrator', async function () {
270 await makePutBodyRequest({
271 url: server.url,
272 path,
273 fields: updateParams,
274 token: userAccessToken,
c0e8b12e 275 expectedStatus: HttpStatusCode.FORBIDDEN_403
fd206f0b
C
276 })
277 })
278
279 it('Should fail if it misses a key', async function () {
280 const newUpdateParams = omit(updateParams, 'admin.email')
281
282 await makePutBodyRequest({
283 url: server.url,
284 path,
0883b324
C
285 fields: newUpdateParams,
286 token: server.accessToken,
c0e8b12e 287 expectedStatus: HttpStatusCode.BAD_REQUEST_400
0883b324
C
288 })
289 })
290
291 it('Should fail with a bad default NSFW policy', async function () {
6c5065a0
C
292 const newUpdateParams = {
293 ...updateParams,
294
0883b324
C
295 instance: {
296 defaultNSFWPolicy: 'hello'
297 }
6c5065a0 298 }
0883b324
C
299
300 await makePutBodyRequest({
301 url: server.url,
302 path,
576ad67a
JM
303 fields: newUpdateParams,
304 token: server.accessToken,
c0e8b12e 305 expectedStatus: HttpStatusCode.BAD_REQUEST_400
576ad67a
JM
306 })
307 })
308
309 it('Should fail if email disabled and signup requires email verification', async function () {
7c3b7976 310 // opposite scenario - success when enable enabled - covered via tests/api/users/user-verification.ts
6c5065a0
C
311 const newUpdateParams = {
312 ...updateParams,
313
576ad67a
JM
314 signup: {
315 enabled: true,
316 limit: 5,
317 requiresEmailVerification: true
318 }
6c5065a0 319 }
576ad67a
JM
320
321 await makePutBodyRequest({
322 url: server.url,
323 path,
fd206f0b
C
324 fields: newUpdateParams,
325 token: server.accessToken,
c0e8b12e 326 expectedStatus: HttpStatusCode.BAD_REQUEST_400
fd206f0b
C
327 })
328 })
329
d7a25329 330 it('Should fail with a disabled webtorrent & hls transcoding', async function () {
6c5065a0
C
331 const newUpdateParams = {
332 ...updateParams,
333
d7a25329
C
334 transcoding: {
335 hls: {
336 enabled: false
337 },
338 webtorrent: {
339 enabled: false
340 }
341 }
6c5065a0 342 }
d7a25329
C
343
344 await makePutBodyRequest({
345 url: server.url,
346 path,
347 fields: newUpdateParams,
348 token: server.accessToken,
c0e8b12e 349 expectedStatus: HttpStatusCode.BAD_REQUEST_400
d7a25329
C
350 })
351 })
352
2a491182
F
353 it('Should fail with a disabled http upload & enabled sync', async function () {
354 const newUpdateParams: CustomConfig = merge({}, updateParams, {
355 import: {
356 videos: {
357 http: { enabled: false }
358 },
359 videoChannelSynchronization: { enabled: true }
360 }
361 })
362
363 await makePutBodyRequest({
364 url: server.url,
365 path,
366 fields: newUpdateParams,
367 token: server.accessToken,
368 expectedStatus: HttpStatusCode.BAD_REQUEST_400
369 })
370 })
371
372 it('Should succeed with the correct parameters', async function () {
fd206f0b
C
373 await makePutBodyRequest({
374 url: server.url,
375 path,
376 fields: updateParams,
377 token: server.accessToken,
c0e8b12e 378 expectedStatus: HttpStatusCode.OK_200
fd206f0b
C
379 })
380 })
381 })
382
383 describe('When deleting the configuration', function () {
384 it('Should fail without token', async function () {
385 await makeDeleteRequest({
386 url: server.url,
387 path,
c0e8b12e 388 expectedStatus: HttpStatusCode.UNAUTHORIZED_401
fd206f0b
C
389 })
390 })
391
392 it('Should fail if the user is not an administrator', async function () {
393 await makeDeleteRequest({
394 url: server.url,
395 path,
396 token: userAccessToken,
c0e8b12e 397 expectedStatus: HttpStatusCode.FORBIDDEN_403
fd206f0b
C
398 })
399 })
400 })
401
7c3b7976
C
402 after(async function () {
403 await cleanupTests([ server ])
fd206f0b
C
404 })
405})