]>
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 | 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 = { ...updateParams, admin: 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 | requiresApproval: true, | |
318 | requiresEmailVerification: true | |
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 with a disabled webtorrent & hls transcoding', async function () { | |
332 | const newUpdateParams = { | |
333 | ...updateParams, | |
334 | ||
335 | transcoding: { | |
336 | hls: { | |
337 | enabled: false | |
338 | }, | |
339 | webtorrent: { | |
340 | enabled: false | |
341 | } | |
342 | } | |
343 | } | |
344 | ||
345 | await makePutBodyRequest({ | |
346 | url: server.url, | |
347 | path, | |
348 | fields: newUpdateParams, | |
349 | token: server.accessToken, | |
350 | expectedStatus: HttpStatusCode.BAD_REQUEST_400 | |
351 | }) | |
352 | }) | |
353 | ||
354 | it('Should fail with a disabled http upload & enabled sync', async function () { | |
355 | const newUpdateParams: CustomConfig = merge({}, updateParams, { | |
356 | import: { | |
357 | videos: { | |
358 | http: { enabled: false } | |
359 | }, | |
360 | videoChannelSynchronization: { enabled: true } | |
361 | } | |
362 | }) | |
363 | ||
364 | await makePutBodyRequest({ | |
365 | url: server.url, | |
366 | path, | |
367 | fields: newUpdateParams, | |
368 | token: server.accessToken, | |
369 | expectedStatus: HttpStatusCode.BAD_REQUEST_400 | |
370 | }) | |
371 | }) | |
372 | ||
373 | it('Should succeed with the correct parameters', async function () { | |
374 | await makePutBodyRequest({ | |
375 | url: server.url, | |
376 | path, | |
377 | fields: updateParams, | |
378 | token: server.accessToken, | |
379 | expectedStatus: HttpStatusCode.OK_200 | |
380 | }) | |
381 | }) | |
382 | }) | |
383 | ||
384 | describe('When deleting the configuration', function () { | |
385 | it('Should fail without token', async function () { | |
386 | await makeDeleteRequest({ | |
387 | url: server.url, | |
388 | path, | |
389 | expectedStatus: HttpStatusCode.UNAUTHORIZED_401 | |
390 | }) | |
391 | }) | |
392 | ||
393 | it('Should fail if the user is not an administrator', async function () { | |
394 | await makeDeleteRequest({ | |
395 | url: server.url, | |
396 | path, | |
397 | token: userAccessToken, | |
398 | expectedStatus: HttpStatusCode.FORBIDDEN_403 | |
399 | }) | |
400 | }) | |
401 | }) | |
402 | ||
403 | after(async function () { | |
404 | await cleanupTests([ server ]) | |
405 | }) | |
406 | }) |