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