diff options
Diffstat (limited to 'server/tests/api/check-params/config.ts')
-rw-r--r-- | server/tests/api/check-params/config.ts | 428 |
1 files changed, 0 insertions, 428 deletions
diff --git a/server/tests/api/check-params/config.ts b/server/tests/api/check-params/config.ts deleted file mode 100644 index 2f523d4ce..000000000 --- a/server/tests/api/check-params/config.ts +++ /dev/null | |||
@@ -1,428 +0,0 @@ | |||
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 | storyboards: { | ||
79 | size: 5 | ||
80 | } | ||
81 | }, | ||
82 | signup: { | ||
83 | enabled: false, | ||
84 | limit: 5, | ||
85 | requiresApproval: false, | ||
86 | requiresEmailVerification: false, | ||
87 | minimumAge: 16 | ||
88 | }, | ||
89 | admin: { | ||
90 | email: 'superadmin1@example.com' | ||
91 | }, | ||
92 | contactForm: { | ||
93 | enabled: false | ||
94 | }, | ||
95 | user: { | ||
96 | history: { | ||
97 | videos: { | ||
98 | enabled: true | ||
99 | } | ||
100 | }, | ||
101 | videoQuota: 5242881, | ||
102 | videoQuotaDaily: 318742 | ||
103 | }, | ||
104 | videoChannels: { | ||
105 | maxPerUser: 20 | ||
106 | }, | ||
107 | transcoding: { | ||
108 | enabled: true, | ||
109 | remoteRunners: { | ||
110 | enabled: true | ||
111 | }, | ||
112 | allowAdditionalExtensions: true, | ||
113 | allowAudioFiles: true, | ||
114 | concurrency: 1, | ||
115 | threads: 1, | ||
116 | profile: 'vod_profile', | ||
117 | resolutions: { | ||
118 | '0p': false, | ||
119 | '144p': false, | ||
120 | '240p': false, | ||
121 | '360p': true, | ||
122 | '480p': true, | ||
123 | '720p': false, | ||
124 | '1080p': false, | ||
125 | '1440p': false, | ||
126 | '2160p': false | ||
127 | }, | ||
128 | alwaysTranscodeOriginalResolution: false, | ||
129 | webVideos: { | ||
130 | enabled: true | ||
131 | }, | ||
132 | hls: { | ||
133 | enabled: false | ||
134 | } | ||
135 | }, | ||
136 | live: { | ||
137 | enabled: true, | ||
138 | |||
139 | allowReplay: false, | ||
140 | latencySetting: { | ||
141 | enabled: false | ||
142 | }, | ||
143 | maxDuration: 30, | ||
144 | maxInstanceLives: -1, | ||
145 | maxUserLives: 50, | ||
146 | |||
147 | transcoding: { | ||
148 | enabled: true, | ||
149 | remoteRunners: { | ||
150 | enabled: true | ||
151 | }, | ||
152 | threads: 4, | ||
153 | profile: 'live_profile', | ||
154 | resolutions: { | ||
155 | '144p': true, | ||
156 | '240p': true, | ||
157 | '360p': true, | ||
158 | '480p': true, | ||
159 | '720p': true, | ||
160 | '1080p': true, | ||
161 | '1440p': true, | ||
162 | '2160p': true | ||
163 | }, | ||
164 | alwaysTranscodeOriginalResolution: false | ||
165 | } | ||
166 | }, | ||
167 | videoStudio: { | ||
168 | enabled: true, | ||
169 | remoteRunners: { | ||
170 | enabled: true | ||
171 | } | ||
172 | }, | ||
173 | videoFile: { | ||
174 | update: { | ||
175 | enabled: true | ||
176 | } | ||
177 | }, | ||
178 | import: { | ||
179 | videos: { | ||
180 | concurrency: 1, | ||
181 | http: { | ||
182 | enabled: false | ||
183 | }, | ||
184 | torrent: { | ||
185 | enabled: false | ||
186 | } | ||
187 | }, | ||
188 | videoChannelSynchronization: { | ||
189 | enabled: false, | ||
190 | maxPerUser: 10 | ||
191 | } | ||
192 | }, | ||
193 | trending: { | ||
194 | videos: { | ||
195 | algorithms: { | ||
196 | enabled: [ 'hot', 'most-viewed', 'most-liked' ], | ||
197 | default: 'most-viewed' | ||
198 | } | ||
199 | } | ||
200 | }, | ||
201 | autoBlacklist: { | ||
202 | videos: { | ||
203 | ofUsers: { | ||
204 | enabled: false | ||
205 | } | ||
206 | } | ||
207 | }, | ||
208 | followers: { | ||
209 | instance: { | ||
210 | enabled: false, | ||
211 | manualApproval: true | ||
212 | } | ||
213 | }, | ||
214 | followings: { | ||
215 | instance: { | ||
216 | autoFollowBack: { | ||
217 | enabled: true | ||
218 | }, | ||
219 | autoFollowIndex: { | ||
220 | enabled: true, | ||
221 | indexUrl: 'https://index.example.com' | ||
222 | } | ||
223 | } | ||
224 | }, | ||
225 | broadcastMessage: { | ||
226 | enabled: true, | ||
227 | dismissable: true, | ||
228 | message: 'super message', | ||
229 | level: 'warning' | ||
230 | }, | ||
231 | search: { | ||
232 | remoteUri: { | ||
233 | users: true, | ||
234 | anonymous: true | ||
235 | }, | ||
236 | searchIndex: { | ||
237 | enabled: true, | ||
238 | url: 'https://search.joinpeertube.org', | ||
239 | disableLocalSearch: true, | ||
240 | isDefaultSearch: true | ||
241 | } | ||
242 | } | ||
243 | } | ||
244 | |||
245 | // --------------------------------------------------------------- | ||
246 | |||
247 | before(async function () { | ||
248 | this.timeout(30000) | ||
249 | |||
250 | server = await createSingleServer(1) | ||
251 | |||
252 | await setAccessTokensToServers([ server ]) | ||
253 | |||
254 | const user = { | ||
255 | username: 'user1', | ||
256 | password: 'password' | ||
257 | } | ||
258 | await server.users.create({ username: user.username, password: user.password }) | ||
259 | userAccessToken = await server.login.getAccessToken(user) | ||
260 | }) | ||
261 | |||
262 | describe('When getting the configuration', function () { | ||
263 | it('Should fail without token', async function () { | ||
264 | await makeGetRequest({ | ||
265 | url: server.url, | ||
266 | path, | ||
267 | expectedStatus: HttpStatusCode.UNAUTHORIZED_401 | ||
268 | }) | ||
269 | }) | ||
270 | |||
271 | it('Should fail if the user is not an administrator', async function () { | ||
272 | await makeGetRequest({ | ||
273 | url: server.url, | ||
274 | path, | ||
275 | token: userAccessToken, | ||
276 | expectedStatus: HttpStatusCode.FORBIDDEN_403 | ||
277 | }) | ||
278 | }) | ||
279 | }) | ||
280 | |||
281 | describe('When updating the configuration', function () { | ||
282 | it('Should fail without token', async function () { | ||
283 | await makePutBodyRequest({ | ||
284 | url: server.url, | ||
285 | path, | ||
286 | fields: updateParams, | ||
287 | expectedStatus: HttpStatusCode.UNAUTHORIZED_401 | ||
288 | }) | ||
289 | }) | ||
290 | |||
291 | it('Should fail if the user is not an administrator', async function () { | ||
292 | await makePutBodyRequest({ | ||
293 | url: server.url, | ||
294 | path, | ||
295 | fields: updateParams, | ||
296 | token: userAccessToken, | ||
297 | expectedStatus: HttpStatusCode.FORBIDDEN_403 | ||
298 | }) | ||
299 | }) | ||
300 | |||
301 | it('Should fail if it misses a key', async function () { | ||
302 | const newUpdateParams = { ...updateParams, admin: omit(updateParams.admin, [ 'email' ]) } | ||
303 | |||
304 | await makePutBodyRequest({ | ||
305 | url: server.url, | ||
306 | path, | ||
307 | fields: newUpdateParams, | ||
308 | token: server.accessToken, | ||
309 | expectedStatus: HttpStatusCode.BAD_REQUEST_400 | ||
310 | }) | ||
311 | }) | ||
312 | |||
313 | it('Should fail with a bad default NSFW policy', async function () { | ||
314 | const newUpdateParams = { | ||
315 | ...updateParams, | ||
316 | |||
317 | instance: { | ||
318 | defaultNSFWPolicy: 'hello' | ||
319 | } | ||
320 | } | ||
321 | |||
322 | await makePutBodyRequest({ | ||
323 | url: server.url, | ||
324 | path, | ||
325 | fields: newUpdateParams, | ||
326 | token: server.accessToken, | ||
327 | expectedStatus: HttpStatusCode.BAD_REQUEST_400 | ||
328 | }) | ||
329 | }) | ||
330 | |||
331 | it('Should fail if email disabled and signup requires email verification', async function () { | ||
332 | // opposite scenario - success when enable enabled - covered via tests/api/users/user-verification.ts | ||
333 | const newUpdateParams = { | ||
334 | ...updateParams, | ||
335 | |||
336 | signup: { | ||
337 | enabled: true, | ||
338 | limit: 5, | ||
339 | requiresApproval: true, | ||
340 | requiresEmailVerification: true | ||
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 web videos & hls transcoding', async function () { | ||
354 | const newUpdateParams = { | ||
355 | ...updateParams, | ||
356 | |||
357 | transcoding: { | ||
358 | hls: { | ||
359 | enabled: false | ||
360 | }, | ||
361 | web_videos: { | ||
362 | enabled: false | ||
363 | } | ||
364 | } | ||
365 | } | ||
366 | |||
367 | await makePutBodyRequest({ | ||
368 | url: server.url, | ||
369 | path, | ||
370 | fields: newUpdateParams, | ||
371 | token: server.accessToken, | ||
372 | expectedStatus: HttpStatusCode.BAD_REQUEST_400 | ||
373 | }) | ||
374 | }) | ||
375 | |||
376 | it('Should fail with a disabled http upload & enabled sync', async function () { | ||
377 | const newUpdateParams: CustomConfig = merge({}, updateParams, { | ||
378 | import: { | ||
379 | videos: { | ||
380 | http: { enabled: false } | ||
381 | }, | ||
382 | videoChannelSynchronization: { enabled: true } | ||
383 | } | ||
384 | }) | ||
385 | |||
386 | await makePutBodyRequest({ | ||
387 | url: server.url, | ||
388 | path, | ||
389 | fields: newUpdateParams, | ||
390 | token: server.accessToken, | ||
391 | expectedStatus: HttpStatusCode.BAD_REQUEST_400 | ||
392 | }) | ||
393 | }) | ||
394 | |||
395 | it('Should succeed with the correct parameters', async function () { | ||
396 | await makePutBodyRequest({ | ||
397 | url: server.url, | ||
398 | path, | ||
399 | fields: updateParams, | ||
400 | token: server.accessToken, | ||
401 | expectedStatus: HttpStatusCode.OK_200 | ||
402 | }) | ||
403 | }) | ||
404 | }) | ||
405 | |||
406 | describe('When deleting the configuration', function () { | ||
407 | it('Should fail without token', async function () { | ||
408 | await makeDeleteRequest({ | ||
409 | url: server.url, | ||
410 | path, | ||
411 | expectedStatus: HttpStatusCode.UNAUTHORIZED_401 | ||
412 | }) | ||
413 | }) | ||
414 | |||
415 | it('Should fail if the user is not an administrator', async function () { | ||
416 | await makeDeleteRequest({ | ||
417 | url: server.url, | ||
418 | path, | ||
419 | token: userAccessToken, | ||
420 | expectedStatus: HttpStatusCode.FORBIDDEN_403 | ||
421 | }) | ||
422 | }) | ||
423 | }) | ||
424 | |||
425 | after(async function () { | ||
426 | await cleanupTests([ server ]) | ||
427 | }) | ||
428 | }) | ||