]>
Commit | Line | Data |
---|---|---|
a1587156 | 1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ |
bbd5aa7e C |
2 | import { merge } from 'lodash' |
3 | import { omit } from '@shared/core-utils' | |
2a491182 | 4 | import { CustomConfig, HttpStatusCode } from '@shared/models' |
fd206f0b | 5 | import { |
8424c402 | 6 | cleanupTests, |
254d3579 | 7 | createSingleServer, |
8424c402 C |
8 | makeDeleteRequest, |
9 | makeGetRequest, | |
10 | makePutBodyRequest, | |
254d3579 | 11 | PeerTubeServer, |
41d1d075 | 12 | setAccessTokensToServers |
bf54587a | 13 | } from '@shared/server-commands' |
fd206f0b C |
14 | |
15 | describe('Test config API validators', function () { | |
16 | const path = '/api/v1/config/custom' | |
254d3579 | 17 | let server: PeerTubeServer |
fd206f0b C |
18 | let userAccessToken: string |
19 | const updateParams: CustomConfig = { | |
66b16caf C |
20 | instance: { |
21 | name: 'PeerTube updated', | |
2e3a0215 | 22 | shortDescription: 'my short description', |
66b16caf | 23 | description: 'my super description', |
00b5556c | 24 | terms: 'my super terms', |
ccc00cb2 C |
25 | codeOfConduct: 'my super coc', |
26 | ||
8ae03c37 | 27 | creationReason: 'my super reason', |
ccc00cb2 C |
28 | moderationInformation: 'my super moderation information', |
29 | administrator: 'Kuja', | |
30 | maintenanceLifetime: 'forever', | |
31 | businessModel: 'my super business model', | |
be04c6fd | 32 | hardwareInformation: '2vCore 3GB RAM', |
ccc00cb2 C |
33 | |
34 | languages: [ 'en', 'es' ], | |
35 | categories: [ 1, 2 ], | |
36 | ||
f8802489 | 37 | isNSFW: true, |
0883b324 | 38 | defaultNSFWPolicy: 'blur', |
3da68f0a RK |
39 | |
40 | defaultClientRoute: '/videos/recently-added', | |
3da68f0a | 41 | |
00b5556c C |
42 | customizations: { |
43 | javascript: 'alert("coucou")', | |
44 | css: 'body { background-color: red; }' | |
45 | } | |
66b16caf | 46 | }, |
7cd4d2ba C |
47 | theme: { |
48 | default: 'default' | |
49 | }, | |
8be1afa1 C |
50 | services: { |
51 | twitter: { | |
52 | username: '@MySuperUsername', | |
53 | whitelisted: true | |
54 | } | |
55 | }, | |
0bc53e20 C |
56 | client: { |
57 | videos: { | |
58 | miniature: { | |
59 | preferAuthorDisplayName: false | |
60 | } | |
61 | }, | |
62 | menu: { | |
63 | login: { | |
64 | redirectOnSingleExternalAuth: false | |
65 | } | |
66 | } | |
67 | }, | |
fd206f0b C |
68 | cache: { |
69 | previews: { | |
70 | size: 2 | |
40e87e9e C |
71 | }, |
72 | captions: { | |
73 | size: 3 | |
b3d5cb92 C |
74 | }, |
75 | torrents: { | |
76 | size: 4 | |
fd206f0b C |
77 | } |
78 | }, | |
79 | signup: { | |
80 | enabled: false, | |
d9eaee39 | 81 | limit: 5, |
b379759f | 82 | requiresApproval: false, |
1f256e7d P |
83 | requiresEmailVerification: false, |
84 | minimumAge: 16 | |
fd206f0b C |
85 | }, |
86 | admin: { | |
87 | email: 'superadmin1@example.com' | |
88 | }, | |
a4101923 C |
89 | contactForm: { |
90 | enabled: false | |
91 | }, | |
fd206f0b | 92 | user: { |
b302c80d W |
93 | history: { |
94 | videos: { | |
95 | enabled: true | |
96 | } | |
97 | }, | |
bee0abff FA |
98 | videoQuota: 5242881, |
99 | videoQuotaDaily: 318742 | |
fd206f0b | 100 | }, |
754b6f5f FC |
101 | videoChannels: { |
102 | maxPerUser: 20 | |
103 | }, | |
fd206f0b C |
104 | transcoding: { |
105 | enabled: true, | |
d102de1b C |
106 | remoteRunners: { |
107 | enabled: true | |
108 | }, | |
14e2014a | 109 | allowAdditionalExtensions: true, |
536598cf | 110 | allowAudioFiles: true, |
9129b769 | 111 | concurrency: 1, |
fd206f0b | 112 | threads: 1, |
1896bca0 | 113 | profile: 'vod_profile', |
fd206f0b | 114 | resolutions: { |
5c7d6508 | 115 | '0p': false, |
8dd754c7 | 116 | '144p': false, |
fd206f0b C |
117 | '240p': false, |
118 | '360p': true, | |
119 | '480p': true, | |
120 | '720p': false, | |
db714ab4 | 121 | '1080p': false, |
b7085c71 | 122 | '1440p': false, |
db714ab4 | 123 | '2160p': false |
09209296 | 124 | }, |
84cae54e | 125 | alwaysTranscodeOriginalResolution: false, |
d7a25329 C |
126 | webtorrent: { |
127 | enabled: true | |
128 | }, | |
09209296 C |
129 | hls: { |
130 | enabled: false | |
fd206f0b | 131 | } |
5d08a6a7 | 132 | }, |
c6c0fa6c C |
133 | live: { |
134 | enabled: true, | |
135 | ||
fb719404 | 136 | allowReplay: false, |
f443a746 C |
137 | latencySetting: { |
138 | enabled: false | |
139 | }, | |
c9bc850e | 140 | maxDuration: 30, |
a056ca48 C |
141 | maxInstanceLives: -1, |
142 | maxUserLives: 50, | |
fb719404 | 143 | |
c6c0fa6c C |
144 | transcoding: { |
145 | enabled: true, | |
d102de1b C |
146 | remoteRunners: { |
147 | enabled: true | |
148 | }, | |
c6c0fa6c | 149 | threads: 4, |
1896bca0 | 150 | profile: 'live_profile', |
c6c0fa6c | 151 | resolutions: { |
8dd754c7 | 152 | '144p': true, |
c6c0fa6c C |
153 | '240p': true, |
154 | '360p': true, | |
155 | '480p': true, | |
156 | '720p': true, | |
157 | '1080p': true, | |
b7085c71 | 158 | '1440p': true, |
c6c0fa6c | 159 | '2160p': true |
84cae54e C |
160 | }, |
161 | alwaysTranscodeOriginalResolution: false | |
c6c0fa6c C |
162 | } |
163 | }, | |
92e66e04 | 164 | videoStudio: { |
5e47f6ab C |
165 | enabled: true, |
166 | remoteRunners: { | |
167 | enabled: true | |
168 | } | |
c729caf6 | 169 | }, |
5d08a6a7 C |
170 | import: { |
171 | videos: { | |
9129b769 | 172 | concurrency: 1, |
5d08a6a7 C |
173 | http: { |
174 | enabled: false | |
a84b8fa5 C |
175 | }, |
176 | torrent: { | |
177 | enabled: false | |
5d08a6a7 | 178 | } |
2a491182 F |
179 | }, |
180 | videoChannelSynchronization: { | |
181 | enabled: false, | |
182 | maxPerUser: 10 | |
5d08a6a7 | 183 | } |
7ccddd7b | 184 | }, |
ba5d4a84 RK |
185 | trending: { |
186 | videos: { | |
187 | algorithms: { | |
010382b6 | 188 | enabled: [ 'hot', 'most-viewed', 'most-liked' ], |
ba5d4a84 RK |
189 | default: 'most-viewed' |
190 | } | |
191 | } | |
192 | }, | |
7ccddd7b JM |
193 | autoBlacklist: { |
194 | videos: { | |
195 | ofUsers: { | |
196 | enabled: false | |
197 | } | |
198 | } | |
5b9c965d C |
199 | }, |
200 | followers: { | |
201 | instance: { | |
14893eb7 C |
202 | enabled: false, |
203 | manualApproval: true | |
5b9c965d | 204 | } |
8424c402 C |
205 | }, |
206 | followings: { | |
207 | instance: { | |
208 | autoFollowBack: { | |
209 | enabled: true | |
210 | }, | |
211 | autoFollowIndex: { | |
212 | enabled: true, | |
213 | indexUrl: 'https://index.example.com' | |
214 | } | |
215 | } | |
72c33e71 C |
216 | }, |
217 | broadcastMessage: { | |
218 | enabled: true, | |
219 | dismissable: true, | |
220 | message: 'super message', | |
221 | level: 'warning' | |
5fb2e288 C |
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 | } | |
fd206f0b C |
234 | } |
235 | } | |
236 | ||
237 | // --------------------------------------------------------------- | |
238 | ||
239 | before(async function () { | |
e212f887 | 240 | this.timeout(30000) |
fd206f0b | 241 | |
254d3579 | 242 | server = await createSingleServer(1) |
fd206f0b C |
243 | |
244 | await setAccessTokensToServers([ server ]) | |
245 | ||
246 | const user = { | |
247 | username: 'user1', | |
248 | password: 'password' | |
249 | } | |
89d241a7 C |
250 | await server.users.create({ username: user.username, password: user.password }) |
251 | userAccessToken = await server.login.getAccessToken(user) | |
fd206f0b C |
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, | |
c0e8b12e | 259 | expectedStatus: HttpStatusCode.UNAUTHORIZED_401 |
fd206f0b C |
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, | |
c0e8b12e | 268 | expectedStatus: HttpStatusCode.FORBIDDEN_403 |
fd206f0b C |
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, | |
c0e8b12e | 279 | expectedStatus: HttpStatusCode.UNAUTHORIZED_401 |
fd206f0b C |
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, | |
c0e8b12e | 289 | expectedStatus: HttpStatusCode.FORBIDDEN_403 |
fd206f0b C |
290 | }) |
291 | }) | |
292 | ||
293 | it('Should fail if it misses a key', async function () { | |
bbd5aa7e | 294 | const newUpdateParams = { ...updateParams, admin: omit(updateParams.admin, [ 'email' ]) } |
fd206f0b C |
295 | |
296 | await makePutBodyRequest({ | |
297 | url: server.url, | |
298 | path, | |
0883b324 C |
299 | fields: newUpdateParams, |
300 | token: server.accessToken, | |
c0e8b12e | 301 | expectedStatus: HttpStatusCode.BAD_REQUEST_400 |
0883b324 C |
302 | }) |
303 | }) | |
304 | ||
305 | it('Should fail with a bad default NSFW policy', async function () { | |
6c5065a0 C |
306 | const newUpdateParams = { |
307 | ...updateParams, | |
308 | ||
0883b324 C |
309 | instance: { |
310 | defaultNSFWPolicy: 'hello' | |
311 | } | |
6c5065a0 | 312 | } |
0883b324 C |
313 | |
314 | await makePutBodyRequest({ | |
315 | url: server.url, | |
316 | path, | |
576ad67a JM |
317 | fields: newUpdateParams, |
318 | token: server.accessToken, | |
c0e8b12e | 319 | expectedStatus: HttpStatusCode.BAD_REQUEST_400 |
576ad67a JM |
320 | }) |
321 | }) | |
322 | ||
323 | it('Should fail if email disabled and signup requires email verification', async function () { | |
7c3b7976 | 324 | // opposite scenario - success when enable enabled - covered via tests/api/users/user-verification.ts |
6c5065a0 C |
325 | const newUpdateParams = { |
326 | ...updateParams, | |
327 | ||
576ad67a JM |
328 | signup: { |
329 | enabled: true, | |
330 | limit: 5, | |
b379759f | 331 | requiresApproval: true, |
576ad67a JM |
332 | requiresEmailVerification: true |
333 | } | |
6c5065a0 | 334 | } |
576ad67a JM |
335 | |
336 | await makePutBodyRequest({ | |
337 | url: server.url, | |
338 | path, | |
fd206f0b C |
339 | fields: newUpdateParams, |
340 | token: server.accessToken, | |
c0e8b12e | 341 | expectedStatus: HttpStatusCode.BAD_REQUEST_400 |
fd206f0b C |
342 | }) |
343 | }) | |
344 | ||
d7a25329 | 345 | it('Should fail with a disabled webtorrent & hls transcoding', async function () { |
6c5065a0 C |
346 | const newUpdateParams = { |
347 | ...updateParams, | |
348 | ||
d7a25329 C |
349 | transcoding: { |
350 | hls: { | |
351 | enabled: false | |
352 | }, | |
353 | webtorrent: { | |
354 | enabled: false | |
355 | } | |
356 | } | |
6c5065a0 | 357 | } |
d7a25329 C |
358 | |
359 | await makePutBodyRequest({ | |
360 | url: server.url, | |
361 | path, | |
362 | fields: newUpdateParams, | |
363 | token: server.accessToken, | |
c0e8b12e | 364 | expectedStatus: HttpStatusCode.BAD_REQUEST_400 |
d7a25329 C |
365 | }) |
366 | }) | |
367 | ||
2a491182 F |
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 () { | |
fd206f0b C |
388 | await makePutBodyRequest({ |
389 | url: server.url, | |
390 | path, | |
391 | fields: updateParams, | |
392 | token: server.accessToken, | |
c0e8b12e | 393 | expectedStatus: HttpStatusCode.OK_200 |
fd206f0b C |
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, | |
c0e8b12e | 403 | expectedStatus: HttpStatusCode.UNAUTHORIZED_401 |
fd206f0b C |
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, | |
c0e8b12e | 412 | expectedStatus: HttpStatusCode.FORBIDDEN_403 |
fd206f0b C |
413 | }) |
414 | }) | |
415 | }) | |
416 | ||
7c3b7976 C |
417 | after(async function () { |
418 | await cleanupTests([ server ]) | |
fd206f0b C |
419 | }) |
420 | }) |