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