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