]>
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: { |
c729caf6 C |
165 | enabled: true |
166 | }, | |
5d08a6a7 C |
167 | import: { |
168 | videos: { | |
9129b769 | 169 | concurrency: 1, |
5d08a6a7 C |
170 | http: { |
171 | enabled: false | |
a84b8fa5 C |
172 | }, |
173 | torrent: { | |
174 | enabled: false | |
5d08a6a7 | 175 | } |
2a491182 F |
176 | }, |
177 | videoChannelSynchronization: { | |
178 | enabled: false, | |
179 | maxPerUser: 10 | |
5d08a6a7 | 180 | } |
7ccddd7b | 181 | }, |
ba5d4a84 RK |
182 | trending: { |
183 | videos: { | |
184 | algorithms: { | |
010382b6 | 185 | enabled: [ 'hot', 'most-viewed', 'most-liked' ], |
ba5d4a84 RK |
186 | default: 'most-viewed' |
187 | } | |
188 | } | |
189 | }, | |
7ccddd7b JM |
190 | autoBlacklist: { |
191 | videos: { | |
192 | ofUsers: { | |
193 | enabled: false | |
194 | } | |
195 | } | |
5b9c965d C |
196 | }, |
197 | followers: { | |
198 | instance: { | |
14893eb7 C |
199 | enabled: false, |
200 | manualApproval: true | |
5b9c965d | 201 | } |
8424c402 C |
202 | }, |
203 | followings: { | |
204 | instance: { | |
205 | autoFollowBack: { | |
206 | enabled: true | |
207 | }, | |
208 | autoFollowIndex: { | |
209 | enabled: true, | |
210 | indexUrl: 'https://index.example.com' | |
211 | } | |
212 | } | |
72c33e71 C |
213 | }, |
214 | broadcastMessage: { | |
215 | enabled: true, | |
216 | dismissable: true, | |
217 | message: 'super message', | |
218 | level: 'warning' | |
5fb2e288 C |
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 | } | |
fd206f0b C |
231 | } |
232 | } | |
233 | ||
234 | // --------------------------------------------------------------- | |
235 | ||
236 | before(async function () { | |
e212f887 | 237 | this.timeout(30000) |
fd206f0b | 238 | |
254d3579 | 239 | server = await createSingleServer(1) |
fd206f0b C |
240 | |
241 | await setAccessTokensToServers([ server ]) | |
242 | ||
243 | const user = { | |
244 | username: 'user1', | |
245 | password: 'password' | |
246 | } | |
89d241a7 C |
247 | await server.users.create({ username: user.username, password: user.password }) |
248 | userAccessToken = await server.login.getAccessToken(user) | |
fd206f0b C |
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, | |
c0e8b12e | 256 | expectedStatus: HttpStatusCode.UNAUTHORIZED_401 |
fd206f0b C |
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, | |
c0e8b12e | 265 | expectedStatus: HttpStatusCode.FORBIDDEN_403 |
fd206f0b C |
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, | |
c0e8b12e | 276 | expectedStatus: HttpStatusCode.UNAUTHORIZED_401 |
fd206f0b C |
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, | |
c0e8b12e | 286 | expectedStatus: HttpStatusCode.FORBIDDEN_403 |
fd206f0b C |
287 | }) |
288 | }) | |
289 | ||
290 | it('Should fail if it misses a key', async function () { | |
bbd5aa7e | 291 | const newUpdateParams = { ...updateParams, admin: omit(updateParams.admin, [ 'email' ]) } |
fd206f0b C |
292 | |
293 | await makePutBodyRequest({ | |
294 | url: server.url, | |
295 | path, | |
0883b324 C |
296 | fields: newUpdateParams, |
297 | token: server.accessToken, | |
c0e8b12e | 298 | expectedStatus: HttpStatusCode.BAD_REQUEST_400 |
0883b324 C |
299 | }) |
300 | }) | |
301 | ||
302 | it('Should fail with a bad default NSFW policy', async function () { | |
6c5065a0 C |
303 | const newUpdateParams = { |
304 | ...updateParams, | |
305 | ||
0883b324 C |
306 | instance: { |
307 | defaultNSFWPolicy: 'hello' | |
308 | } | |
6c5065a0 | 309 | } |
0883b324 C |
310 | |
311 | await makePutBodyRequest({ | |
312 | url: server.url, | |
313 | path, | |
576ad67a JM |
314 | fields: newUpdateParams, |
315 | token: server.accessToken, | |
c0e8b12e | 316 | expectedStatus: HttpStatusCode.BAD_REQUEST_400 |
576ad67a JM |
317 | }) |
318 | }) | |
319 | ||
320 | it('Should fail if email disabled and signup requires email verification', async function () { | |
7c3b7976 | 321 | // opposite scenario - success when enable enabled - covered via tests/api/users/user-verification.ts |
6c5065a0 C |
322 | const newUpdateParams = { |
323 | ...updateParams, | |
324 | ||
576ad67a JM |
325 | signup: { |
326 | enabled: true, | |
327 | limit: 5, | |
b379759f | 328 | requiresApproval: true, |
576ad67a JM |
329 | requiresEmailVerification: true |
330 | } | |
6c5065a0 | 331 | } |
576ad67a JM |
332 | |
333 | await makePutBodyRequest({ | |
334 | url: server.url, | |
335 | path, | |
fd206f0b C |
336 | fields: newUpdateParams, |
337 | token: server.accessToken, | |
c0e8b12e | 338 | expectedStatus: HttpStatusCode.BAD_REQUEST_400 |
fd206f0b C |
339 | }) |
340 | }) | |
341 | ||
d7a25329 | 342 | it('Should fail with a disabled webtorrent & hls transcoding', async function () { |
6c5065a0 C |
343 | const newUpdateParams = { |
344 | ...updateParams, | |
345 | ||
d7a25329 C |
346 | transcoding: { |
347 | hls: { | |
348 | enabled: false | |
349 | }, | |
350 | webtorrent: { | |
351 | enabled: false | |
352 | } | |
353 | } | |
6c5065a0 | 354 | } |
d7a25329 C |
355 | |
356 | await makePutBodyRequest({ | |
357 | url: server.url, | |
358 | path, | |
359 | fields: newUpdateParams, | |
360 | token: server.accessToken, | |
c0e8b12e | 361 | expectedStatus: HttpStatusCode.BAD_REQUEST_400 |
d7a25329 C |
362 | }) |
363 | }) | |
364 | ||
2a491182 F |
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 () { | |
fd206f0b C |
385 | await makePutBodyRequest({ |
386 | url: server.url, | |
387 | path, | |
388 | fields: updateParams, | |
389 | token: server.accessToken, | |
c0e8b12e | 390 | expectedStatus: HttpStatusCode.OK_200 |
fd206f0b C |
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, | |
c0e8b12e | 400 | expectedStatus: HttpStatusCode.UNAUTHORIZED_401 |
fd206f0b C |
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, | |
c0e8b12e | 409 | expectedStatus: HttpStatusCode.FORBIDDEN_403 |
fd206f0b C |
410 | }) |
411 | }) | |
412 | }) | |
413 | ||
7c3b7976 C |
414 | after(async function () { |
415 | await cleanupTests([ server ]) | |
fd206f0b C |
416 | }) |
417 | }) |