]>
Commit | Line | Data |
---|---|---|
a1587156 | 1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ |
fd206f0b | 2 | |
fd206f0b | 3 | import 'mocha' |
6c5065a0 | 4 | import { omit } from 'lodash' |
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' |
4c7e60bc | 14 | import { CustomConfig, HttpStatusCode } from '@shared/models' |
fd206f0b C |
15 | |
16 | describe('Test config API validators', function () { | |
17 | const path = '/api/v1/config/custom' | |
254d3579 | 18 | let server: PeerTubeServer |
fd206f0b C |
19 | let userAccessToken: string |
20 | const updateParams: CustomConfig = { | |
66b16caf C |
21 | instance: { |
22 | name: 'PeerTube updated', | |
2e3a0215 | 23 | shortDescription: 'my short description', |
66b16caf | 24 | description: 'my super description', |
00b5556c | 25 | terms: 'my super terms', |
ccc00cb2 C |
26 | codeOfConduct: 'my super coc', |
27 | ||
8ae03c37 | 28 | creationReason: 'my super reason', |
ccc00cb2 C |
29 | moderationInformation: 'my super moderation information', |
30 | administrator: 'Kuja', | |
31 | maintenanceLifetime: 'forever', | |
32 | businessModel: 'my super business model', | |
be04c6fd | 33 | hardwareInformation: '2vCore 3GB RAM', |
ccc00cb2 C |
34 | |
35 | languages: [ 'en', 'es' ], | |
36 | categories: [ 1, 2 ], | |
37 | ||
f8802489 | 38 | isNSFW: true, |
0883b324 | 39 | defaultNSFWPolicy: 'blur', |
3da68f0a RK |
40 | |
41 | defaultClientRoute: '/videos/recently-added', | |
3da68f0a | 42 | |
00b5556c C |
43 | customizations: { |
44 | javascript: 'alert("coucou")', | |
45 | css: 'body { background-color: red; }' | |
46 | } | |
66b16caf | 47 | }, |
7cd4d2ba C |
48 | theme: { |
49 | default: 'default' | |
50 | }, | |
8be1afa1 C |
51 | services: { |
52 | twitter: { | |
53 | username: '@MySuperUsername', | |
54 | whitelisted: true | |
55 | } | |
56 | }, | |
0bc53e20 C |
57 | client: { |
58 | videos: { | |
59 | miniature: { | |
60 | preferAuthorDisplayName: false | |
61 | } | |
62 | }, | |
63 | menu: { | |
64 | login: { | |
65 | redirectOnSingleExternalAuth: false | |
66 | } | |
67 | } | |
68 | }, | |
fd206f0b C |
69 | cache: { |
70 | previews: { | |
71 | size: 2 | |
40e87e9e C |
72 | }, |
73 | captions: { | |
74 | size: 3 | |
b3d5cb92 C |
75 | }, |
76 | torrents: { | |
77 | size: 4 | |
fd206f0b C |
78 | } |
79 | }, | |
80 | signup: { | |
81 | enabled: false, | |
d9eaee39 | 82 | limit: 5, |
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 C |
164 | } |
165 | } | |
7ccddd7b | 166 | }, |
ba5d4a84 RK |
167 | trending: { |
168 | videos: { | |
169 | algorithms: { | |
010382b6 | 170 | enabled: [ 'hot', 'most-viewed', 'most-liked' ], |
ba5d4a84 RK |
171 | default: 'most-viewed' |
172 | } | |
173 | } | |
174 | }, | |
7ccddd7b JM |
175 | autoBlacklist: { |
176 | videos: { | |
177 | ofUsers: { | |
178 | enabled: false | |
179 | } | |
180 | } | |
5b9c965d C |
181 | }, |
182 | followers: { | |
183 | instance: { | |
14893eb7 C |
184 | enabled: false, |
185 | manualApproval: true | |
5b9c965d | 186 | } |
8424c402 C |
187 | }, |
188 | followings: { | |
189 | instance: { | |
190 | autoFollowBack: { | |
191 | enabled: true | |
192 | }, | |
193 | autoFollowIndex: { | |
194 | enabled: true, | |
195 | indexUrl: 'https://index.example.com' | |
196 | } | |
197 | } | |
72c33e71 C |
198 | }, |
199 | broadcastMessage: { | |
200 | enabled: true, | |
201 | dismissable: true, | |
202 | message: 'super message', | |
203 | level: 'warning' | |
5fb2e288 C |
204 | }, |
205 | search: { | |
206 | remoteUri: { | |
207 | users: true, | |
208 | anonymous: true | |
209 | }, | |
210 | searchIndex: { | |
211 | enabled: true, | |
212 | url: 'https://search.joinpeertube.org', | |
213 | disableLocalSearch: true, | |
214 | isDefaultSearch: true | |
215 | } | |
fd206f0b C |
216 | } |
217 | } | |
218 | ||
219 | // --------------------------------------------------------------- | |
220 | ||
221 | before(async function () { | |
e212f887 | 222 | this.timeout(30000) |
fd206f0b | 223 | |
254d3579 | 224 | server = await createSingleServer(1) |
fd206f0b C |
225 | |
226 | await setAccessTokensToServers([ server ]) | |
227 | ||
228 | const user = { | |
229 | username: 'user1', | |
230 | password: 'password' | |
231 | } | |
89d241a7 C |
232 | await server.users.create({ username: user.username, password: user.password }) |
233 | userAccessToken = await server.login.getAccessToken(user) | |
fd206f0b C |
234 | }) |
235 | ||
236 | describe('When getting the configuration', function () { | |
237 | it('Should fail without token', async function () { | |
238 | await makeGetRequest({ | |
239 | url: server.url, | |
240 | path, | |
c0e8b12e | 241 | expectedStatus: HttpStatusCode.UNAUTHORIZED_401 |
fd206f0b C |
242 | }) |
243 | }) | |
244 | ||
245 | it('Should fail if the user is not an administrator', async function () { | |
246 | await makeGetRequest({ | |
247 | url: server.url, | |
248 | path, | |
249 | token: userAccessToken, | |
c0e8b12e | 250 | expectedStatus: HttpStatusCode.FORBIDDEN_403 |
fd206f0b C |
251 | }) |
252 | }) | |
253 | }) | |
254 | ||
255 | describe('When updating the configuration', function () { | |
256 | it('Should fail without token', async function () { | |
257 | await makePutBodyRequest({ | |
258 | url: server.url, | |
259 | path, | |
260 | fields: updateParams, | |
c0e8b12e | 261 | expectedStatus: HttpStatusCode.UNAUTHORIZED_401 |
fd206f0b C |
262 | }) |
263 | }) | |
264 | ||
265 | it('Should fail if the user is not an administrator', async function () { | |
266 | await makePutBodyRequest({ | |
267 | url: server.url, | |
268 | path, | |
269 | fields: updateParams, | |
270 | token: userAccessToken, | |
c0e8b12e | 271 | expectedStatus: HttpStatusCode.FORBIDDEN_403 |
fd206f0b C |
272 | }) |
273 | }) | |
274 | ||
275 | it('Should fail if it misses a key', async function () { | |
276 | const newUpdateParams = omit(updateParams, 'admin.email') | |
277 | ||
278 | await makePutBodyRequest({ | |
279 | url: server.url, | |
280 | path, | |
0883b324 C |
281 | fields: newUpdateParams, |
282 | token: server.accessToken, | |
c0e8b12e | 283 | expectedStatus: HttpStatusCode.BAD_REQUEST_400 |
0883b324 C |
284 | }) |
285 | }) | |
286 | ||
287 | it('Should fail with a bad default NSFW policy', async function () { | |
6c5065a0 C |
288 | const newUpdateParams = { |
289 | ...updateParams, | |
290 | ||
0883b324 C |
291 | instance: { |
292 | defaultNSFWPolicy: 'hello' | |
293 | } | |
6c5065a0 | 294 | } |
0883b324 C |
295 | |
296 | await makePutBodyRequest({ | |
297 | url: server.url, | |
298 | path, | |
576ad67a JM |
299 | fields: newUpdateParams, |
300 | token: server.accessToken, | |
c0e8b12e | 301 | expectedStatus: HttpStatusCode.BAD_REQUEST_400 |
576ad67a JM |
302 | }) |
303 | }) | |
304 | ||
305 | it('Should fail if email disabled and signup requires email verification', async function () { | |
7c3b7976 | 306 | // opposite scenario - success when enable enabled - covered via tests/api/users/user-verification.ts |
6c5065a0 C |
307 | const newUpdateParams = { |
308 | ...updateParams, | |
309 | ||
576ad67a JM |
310 | signup: { |
311 | enabled: true, | |
312 | limit: 5, | |
313 | requiresEmailVerification: true | |
314 | } | |
6c5065a0 | 315 | } |
576ad67a JM |
316 | |
317 | await makePutBodyRequest({ | |
318 | url: server.url, | |
319 | path, | |
fd206f0b C |
320 | fields: newUpdateParams, |
321 | token: server.accessToken, | |
c0e8b12e | 322 | expectedStatus: HttpStatusCode.BAD_REQUEST_400 |
fd206f0b C |
323 | }) |
324 | }) | |
325 | ||
d7a25329 | 326 | it('Should fail with a disabled webtorrent & hls transcoding', async function () { |
6c5065a0 C |
327 | const newUpdateParams = { |
328 | ...updateParams, | |
329 | ||
d7a25329 C |
330 | transcoding: { |
331 | hls: { | |
332 | enabled: false | |
333 | }, | |
334 | webtorrent: { | |
335 | enabled: false | |
336 | } | |
337 | } | |
6c5065a0 | 338 | } |
d7a25329 C |
339 | |
340 | await makePutBodyRequest({ | |
341 | url: server.url, | |
342 | path, | |
343 | fields: newUpdateParams, | |
344 | token: server.accessToken, | |
c0e8b12e | 345 | expectedStatus: HttpStatusCode.BAD_REQUEST_400 |
d7a25329 C |
346 | }) |
347 | }) | |
348 | ||
fd206f0b C |
349 | it('Should success with the correct parameters', async function () { |
350 | await makePutBodyRequest({ | |
351 | url: server.url, | |
352 | path, | |
353 | fields: updateParams, | |
354 | token: server.accessToken, | |
c0e8b12e | 355 | expectedStatus: HttpStatusCode.OK_200 |
fd206f0b C |
356 | }) |
357 | }) | |
358 | }) | |
359 | ||
360 | describe('When deleting the configuration', function () { | |
361 | it('Should fail without token', async function () { | |
362 | await makeDeleteRequest({ | |
363 | url: server.url, | |
364 | path, | |
c0e8b12e | 365 | expectedStatus: HttpStatusCode.UNAUTHORIZED_401 |
fd206f0b C |
366 | }) |
367 | }) | |
368 | ||
369 | it('Should fail if the user is not an administrator', async function () { | |
370 | await makeDeleteRequest({ | |
371 | url: server.url, | |
372 | path, | |
373 | token: userAccessToken, | |
c0e8b12e | 374 | expectedStatus: HttpStatusCode.FORBIDDEN_403 |
fd206f0b C |
375 | }) |
376 | }) | |
377 | }) | |
378 | ||
7c3b7976 C |
379 | after(async function () { |
380 | await cleanupTests([ server ]) | |
fd206f0b C |
381 | }) |
382 | }) |