]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/tests/api/check-params/config.ts
Translated using Weblate (Persian)
[github/Chocobozzz/PeerTube.git] / server / tests / api / check-params / config.ts
1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2 import { merge } from 'lodash'
3 import { omit } from '@shared/core-utils'
4 import { CustomConfig, HttpStatusCode } from '@shared/models'
5 import {
6 cleanupTests,
7 createSingleServer,
8 makeDeleteRequest,
9 makeGetRequest,
10 makePutBodyRequest,
11 PeerTubeServer,
12 setAccessTokensToServers
13 } from '@shared/server-commands'
14
15 describe('Test config API validators', function () {
16 const path = '/api/v1/config/custom'
17 let server: PeerTubeServer
18 let userAccessToken: string
19 const updateParams: CustomConfig = {
20 instance: {
21 name: 'PeerTube updated',
22 shortDescription: 'my short description',
23 description: 'my super description',
24 terms: 'my super terms',
25 codeOfConduct: 'my super coc',
26
27 creationReason: 'my super reason',
28 moderationInformation: 'my super moderation information',
29 administrator: 'Kuja',
30 maintenanceLifetime: 'forever',
31 businessModel: 'my super business model',
32 hardwareInformation: '2vCore 3GB RAM',
33
34 languages: [ 'en', 'es' ],
35 categories: [ 1, 2 ],
36
37 isNSFW: true,
38 defaultNSFWPolicy: 'blur',
39
40 defaultClientRoute: '/videos/recently-added',
41
42 customizations: {
43 javascript: 'alert("coucou")',
44 css: 'body { background-color: red; }'
45 }
46 },
47 theme: {
48 default: 'default'
49 },
50 services: {
51 twitter: {
52 username: '@MySuperUsername',
53 whitelisted: true
54 }
55 },
56 client: {
57 videos: {
58 miniature: {
59 preferAuthorDisplayName: false
60 }
61 },
62 menu: {
63 login: {
64 redirectOnSingleExternalAuth: false
65 }
66 }
67 },
68 cache: {
69 previews: {
70 size: 2
71 },
72 captions: {
73 size: 3
74 },
75 torrents: {
76 size: 4
77 }
78 },
79 signup: {
80 enabled: false,
81 limit: 5,
82 requiresApproval: false,
83 requiresEmailVerification: false,
84 minimumAge: 16
85 },
86 admin: {
87 email: 'superadmin1@example.com'
88 },
89 contactForm: {
90 enabled: false
91 },
92 user: {
93 history: {
94 videos: {
95 enabled: true
96 }
97 },
98 videoQuota: 5242881,
99 videoQuotaDaily: 318742
100 },
101 videoChannels: {
102 maxPerUser: 20
103 },
104 transcoding: {
105 enabled: true,
106 allowAdditionalExtensions: true,
107 allowAudioFiles: true,
108 concurrency: 1,
109 threads: 1,
110 profile: 'vod_profile',
111 resolutions: {
112 '0p': false,
113 '144p': false,
114 '240p': false,
115 '360p': true,
116 '480p': true,
117 '720p': false,
118 '1080p': false,
119 '1440p': false,
120 '2160p': false
121 },
122 alwaysTranscodeOriginalResolution: false,
123 webtorrent: {
124 enabled: true
125 },
126 hls: {
127 enabled: false
128 }
129 },
130 live: {
131 enabled: true,
132
133 allowReplay: false,
134 latencySetting: {
135 enabled: false
136 },
137 maxDuration: 30,
138 maxInstanceLives: -1,
139 maxUserLives: 50,
140
141 transcoding: {
142 enabled: true,
143 threads: 4,
144 profile: 'live_profile',
145 resolutions: {
146 '144p': true,
147 '240p': true,
148 '360p': true,
149 '480p': true,
150 '720p': true,
151 '1080p': true,
152 '1440p': true,
153 '2160p': true
154 },
155 alwaysTranscodeOriginalResolution: false
156 }
157 },
158 videoStudio: {
159 enabled: true
160 },
161 import: {
162 videos: {
163 concurrency: 1,
164 http: {
165 enabled: false
166 },
167 torrent: {
168 enabled: false
169 }
170 },
171 videoChannelSynchronization: {
172 enabled: false,
173 maxPerUser: 10
174 }
175 },
176 trending: {
177 videos: {
178 algorithms: {
179 enabled: [ 'hot', 'most-viewed', 'most-liked' ],
180 default: 'most-viewed'
181 }
182 }
183 },
184 autoBlacklist: {
185 videos: {
186 ofUsers: {
187 enabled: false
188 }
189 }
190 },
191 followers: {
192 instance: {
193 enabled: false,
194 manualApproval: true
195 }
196 },
197 followings: {
198 instance: {
199 autoFollowBack: {
200 enabled: true
201 },
202 autoFollowIndex: {
203 enabled: true,
204 indexUrl: 'https://index.example.com'
205 }
206 }
207 },
208 broadcastMessage: {
209 enabled: true,
210 dismissable: true,
211 message: 'super message',
212 level: 'warning'
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 }
225 }
226 }
227
228 // ---------------------------------------------------------------
229
230 before(async function () {
231 this.timeout(30000)
232
233 server = await createSingleServer(1)
234
235 await setAccessTokensToServers([ server ])
236
237 const user = {
238 username: 'user1',
239 password: 'password'
240 }
241 await server.users.create({ username: user.username, password: user.password })
242 userAccessToken = await server.login.getAccessToken(user)
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,
250 expectedStatus: HttpStatusCode.UNAUTHORIZED_401
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,
259 expectedStatus: HttpStatusCode.FORBIDDEN_403
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,
270 expectedStatus: HttpStatusCode.UNAUTHORIZED_401
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,
280 expectedStatus: HttpStatusCode.FORBIDDEN_403
281 })
282 })
283
284 it('Should fail if it misses a key', async function () {
285 const newUpdateParams = { ...updateParams, admin: omit(updateParams.admin, [ 'email' ]) }
286
287 await makePutBodyRequest({
288 url: server.url,
289 path,
290 fields: newUpdateParams,
291 token: server.accessToken,
292 expectedStatus: HttpStatusCode.BAD_REQUEST_400
293 })
294 })
295
296 it('Should fail with a bad default NSFW policy', async function () {
297 const newUpdateParams = {
298 ...updateParams,
299
300 instance: {
301 defaultNSFWPolicy: 'hello'
302 }
303 }
304
305 await makePutBodyRequest({
306 url: server.url,
307 path,
308 fields: newUpdateParams,
309 token: server.accessToken,
310 expectedStatus: HttpStatusCode.BAD_REQUEST_400
311 })
312 })
313
314 it('Should fail if email disabled and signup requires email verification', async function () {
315 // opposite scenario - success when enable enabled - covered via tests/api/users/user-verification.ts
316 const newUpdateParams = {
317 ...updateParams,
318
319 signup: {
320 enabled: true,
321 limit: 5,
322 requiresApproval: true,
323 requiresEmailVerification: true
324 }
325 }
326
327 await makePutBodyRequest({
328 url: server.url,
329 path,
330 fields: newUpdateParams,
331 token: server.accessToken,
332 expectedStatus: HttpStatusCode.BAD_REQUEST_400
333 })
334 })
335
336 it('Should fail with a disabled webtorrent & hls transcoding', async function () {
337 const newUpdateParams = {
338 ...updateParams,
339
340 transcoding: {
341 hls: {
342 enabled: false
343 },
344 webtorrent: {
345 enabled: false
346 }
347 }
348 }
349
350 await makePutBodyRequest({
351 url: server.url,
352 path,
353 fields: newUpdateParams,
354 token: server.accessToken,
355 expectedStatus: HttpStatusCode.BAD_REQUEST_400
356 })
357 })
358
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 () {
379 await makePutBodyRequest({
380 url: server.url,
381 path,
382 fields: updateParams,
383 token: server.accessToken,
384 expectedStatus: HttpStatusCode.OK_200
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,
394 expectedStatus: HttpStatusCode.UNAUTHORIZED_401
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,
403 expectedStatus: HttpStatusCode.FORBIDDEN_403
404 })
405 })
406 })
407
408 after(async function () {
409 await cleanupTests([ server ])
410 })
411 })