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