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