]>
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: { |
bee0abff FA |
93 | videoQuota: 5242881, |
94 | videoQuotaDaily: 318742 | |
fd206f0b | 95 | }, |
754b6f5f FC |
96 | videoChannels: { |
97 | maxPerUser: 20 | |
98 | }, | |
fd206f0b C |
99 | transcoding: { |
100 | enabled: true, | |
14e2014a | 101 | allowAdditionalExtensions: true, |
536598cf | 102 | allowAudioFiles: true, |
9129b769 | 103 | concurrency: 1, |
fd206f0b | 104 | threads: 1, |
1896bca0 | 105 | profile: 'vod_profile', |
fd206f0b | 106 | resolutions: { |
5c7d6508 | 107 | '0p': false, |
8dd754c7 | 108 | '144p': false, |
fd206f0b C |
109 | '240p': false, |
110 | '360p': true, | |
111 | '480p': true, | |
112 | '720p': false, | |
db714ab4 | 113 | '1080p': false, |
b7085c71 | 114 | '1440p': false, |
db714ab4 | 115 | '2160p': false |
09209296 | 116 | }, |
84cae54e | 117 | alwaysTranscodeOriginalResolution: false, |
d7a25329 C |
118 | webtorrent: { |
119 | enabled: true | |
120 | }, | |
09209296 C |
121 | hls: { |
122 | enabled: false | |
fd206f0b | 123 | } |
5d08a6a7 | 124 | }, |
c6c0fa6c C |
125 | live: { |
126 | enabled: true, | |
127 | ||
fb719404 | 128 | allowReplay: false, |
f443a746 C |
129 | latencySetting: { |
130 | enabled: false | |
131 | }, | |
c9bc850e | 132 | maxDuration: 30, |
a056ca48 C |
133 | maxInstanceLives: -1, |
134 | maxUserLives: 50, | |
fb719404 | 135 | |
c6c0fa6c C |
136 | transcoding: { |
137 | enabled: true, | |
138 | threads: 4, | |
1896bca0 | 139 | profile: 'live_profile', |
c6c0fa6c | 140 | resolutions: { |
8dd754c7 | 141 | '144p': true, |
c6c0fa6c C |
142 | '240p': true, |
143 | '360p': true, | |
144 | '480p': true, | |
145 | '720p': true, | |
146 | '1080p': true, | |
b7085c71 | 147 | '1440p': true, |
c6c0fa6c | 148 | '2160p': true |
84cae54e C |
149 | }, |
150 | alwaysTranscodeOriginalResolution: false | |
c6c0fa6c C |
151 | } |
152 | }, | |
92e66e04 | 153 | videoStudio: { |
c729caf6 C |
154 | enabled: true |
155 | }, | |
5d08a6a7 C |
156 | import: { |
157 | videos: { | |
9129b769 | 158 | concurrency: 1, |
5d08a6a7 C |
159 | http: { |
160 | enabled: false | |
a84b8fa5 C |
161 | }, |
162 | torrent: { | |
163 | enabled: false | |
5d08a6a7 | 164 | } |
2a491182 F |
165 | }, |
166 | videoChannelSynchronization: { | |
167 | enabled: false, | |
168 | maxPerUser: 10 | |
5d08a6a7 | 169 | } |
7ccddd7b | 170 | }, |
ba5d4a84 RK |
171 | trending: { |
172 | videos: { | |
173 | algorithms: { | |
010382b6 | 174 | enabled: [ 'hot', 'most-viewed', 'most-liked' ], |
ba5d4a84 RK |
175 | default: 'most-viewed' |
176 | } | |
177 | } | |
178 | }, | |
7ccddd7b JM |
179 | autoBlacklist: { |
180 | videos: { | |
181 | ofUsers: { | |
182 | enabled: false | |
183 | } | |
184 | } | |
5b9c965d C |
185 | }, |
186 | followers: { | |
187 | instance: { | |
14893eb7 C |
188 | enabled: false, |
189 | manualApproval: true | |
5b9c965d | 190 | } |
8424c402 C |
191 | }, |
192 | followings: { | |
193 | instance: { | |
194 | autoFollowBack: { | |
195 | enabled: true | |
196 | }, | |
197 | autoFollowIndex: { | |
198 | enabled: true, | |
199 | indexUrl: 'https://index.example.com' | |
200 | } | |
201 | } | |
72c33e71 C |
202 | }, |
203 | broadcastMessage: { | |
204 | enabled: true, | |
205 | dismissable: true, | |
206 | message: 'super message', | |
207 | level: 'warning' | |
5fb2e288 C |
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 | } | |
fd206f0b C |
220 | } |
221 | } | |
222 | ||
223 | // --------------------------------------------------------------- | |
224 | ||
225 | before(async function () { | |
e212f887 | 226 | this.timeout(30000) |
fd206f0b | 227 | |
254d3579 | 228 | server = await createSingleServer(1) |
fd206f0b C |
229 | |
230 | await setAccessTokensToServers([ server ]) | |
231 | ||
232 | const user = { | |
233 | username: 'user1', | |
234 | password: 'password' | |
235 | } | |
89d241a7 C |
236 | await server.users.create({ username: user.username, password: user.password }) |
237 | userAccessToken = await server.login.getAccessToken(user) | |
fd206f0b C |
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, | |
c0e8b12e | 245 | expectedStatus: HttpStatusCode.UNAUTHORIZED_401 |
fd206f0b C |
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, | |
c0e8b12e | 254 | expectedStatus: HttpStatusCode.FORBIDDEN_403 |
fd206f0b C |
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, | |
c0e8b12e | 265 | expectedStatus: HttpStatusCode.UNAUTHORIZED_401 |
fd206f0b C |
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, | |
c0e8b12e | 275 | expectedStatus: HttpStatusCode.FORBIDDEN_403 |
fd206f0b C |
276 | }) |
277 | }) | |
278 | ||
279 | it('Should fail if it misses a key', async function () { | |
bbd5aa7e | 280 | const newUpdateParams = { ...updateParams, admin: omit(updateParams.admin, [ 'email' ]) } |
fd206f0b C |
281 | |
282 | await makePutBodyRequest({ | |
283 | url: server.url, | |
284 | path, | |
0883b324 C |
285 | fields: newUpdateParams, |
286 | token: server.accessToken, | |
c0e8b12e | 287 | expectedStatus: HttpStatusCode.BAD_REQUEST_400 |
0883b324 C |
288 | }) |
289 | }) | |
290 | ||
291 | it('Should fail with a bad default NSFW policy', async function () { | |
6c5065a0 C |
292 | const newUpdateParams = { |
293 | ...updateParams, | |
294 | ||
0883b324 C |
295 | instance: { |
296 | defaultNSFWPolicy: 'hello' | |
297 | } | |
6c5065a0 | 298 | } |
0883b324 C |
299 | |
300 | await makePutBodyRequest({ | |
301 | url: server.url, | |
302 | path, | |
576ad67a JM |
303 | fields: newUpdateParams, |
304 | token: server.accessToken, | |
c0e8b12e | 305 | expectedStatus: HttpStatusCode.BAD_REQUEST_400 |
576ad67a JM |
306 | }) |
307 | }) | |
308 | ||
309 | it('Should fail if email disabled and signup requires email verification', async function () { | |
7c3b7976 | 310 | // opposite scenario - success when enable enabled - covered via tests/api/users/user-verification.ts |
6c5065a0 C |
311 | const newUpdateParams = { |
312 | ...updateParams, | |
313 | ||
576ad67a JM |
314 | signup: { |
315 | enabled: true, | |
316 | limit: 5, | |
b379759f | 317 | requiresApproval: true, |
576ad67a JM |
318 | requiresEmailVerification: true |
319 | } | |
6c5065a0 | 320 | } |
576ad67a JM |
321 | |
322 | await makePutBodyRequest({ | |
323 | url: server.url, | |
324 | path, | |
fd206f0b C |
325 | fields: newUpdateParams, |
326 | token: server.accessToken, | |
c0e8b12e | 327 | expectedStatus: HttpStatusCode.BAD_REQUEST_400 |
fd206f0b C |
328 | }) |
329 | }) | |
330 | ||
d7a25329 | 331 | it('Should fail with a disabled webtorrent & hls transcoding', async function () { |
6c5065a0 C |
332 | const newUpdateParams = { |
333 | ...updateParams, | |
334 | ||
d7a25329 C |
335 | transcoding: { |
336 | hls: { | |
337 | enabled: false | |
338 | }, | |
339 | webtorrent: { | |
340 | enabled: false | |
341 | } | |
342 | } | |
6c5065a0 | 343 | } |
d7a25329 C |
344 | |
345 | await makePutBodyRequest({ | |
346 | url: server.url, | |
347 | path, | |
348 | fields: newUpdateParams, | |
349 | token: server.accessToken, | |
c0e8b12e | 350 | expectedStatus: HttpStatusCode.BAD_REQUEST_400 |
d7a25329 C |
351 | }) |
352 | }) | |
353 | ||
2a491182 F |
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 () { | |
fd206f0b C |
374 | await makePutBodyRequest({ |
375 | url: server.url, | |
376 | path, | |
377 | fields: updateParams, | |
378 | token: server.accessToken, | |
c0e8b12e | 379 | expectedStatus: HttpStatusCode.OK_200 |
fd206f0b C |
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, | |
c0e8b12e | 389 | expectedStatus: HttpStatusCode.UNAUTHORIZED_401 |
fd206f0b C |
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, | |
c0e8b12e | 398 | expectedStatus: HttpStatusCode.FORBIDDEN_403 |
fd206f0b C |
399 | }) |
400 | }) | |
401 | }) | |
402 | ||
7c3b7976 C |
403 | after(async function () { |
404 | await cleanupTests([ server ]) | |
fd206f0b C |
405 | }) |
406 | }) |