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