]>
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 | }, |
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 C |
147 | '2160p': true |
148 | } | |
149 | } | |
150 | }, | |
92e66e04 | 151 | videoStudio: { |
c729caf6 C |
152 | enabled: true |
153 | }, | |
5d08a6a7 C |
154 | import: { |
155 | videos: { | |
9129b769 | 156 | concurrency: 1, |
5d08a6a7 C |
157 | http: { |
158 | enabled: false | |
a84b8fa5 C |
159 | }, |
160 | torrent: { | |
161 | enabled: false | |
5d08a6a7 C |
162 | } |
163 | } | |
7ccddd7b | 164 | }, |
ba5d4a84 RK |
165 | trending: { |
166 | videos: { | |
167 | algorithms: { | |
010382b6 | 168 | enabled: [ 'hot', 'most-viewed', 'most-liked' ], |
ba5d4a84 RK |
169 | default: 'most-viewed' |
170 | } | |
171 | } | |
172 | }, | |
7ccddd7b JM |
173 | autoBlacklist: { |
174 | videos: { | |
175 | ofUsers: { | |
176 | enabled: false | |
177 | } | |
178 | } | |
5b9c965d C |
179 | }, |
180 | followers: { | |
181 | instance: { | |
14893eb7 C |
182 | enabled: false, |
183 | manualApproval: true | |
5b9c965d | 184 | } |
8424c402 C |
185 | }, |
186 | followings: { | |
187 | instance: { | |
188 | autoFollowBack: { | |
189 | enabled: true | |
190 | }, | |
191 | autoFollowIndex: { | |
192 | enabled: true, | |
193 | indexUrl: 'https://index.example.com' | |
194 | } | |
195 | } | |
72c33e71 C |
196 | }, |
197 | broadcastMessage: { | |
198 | enabled: true, | |
199 | dismissable: true, | |
200 | message: 'super message', | |
201 | level: 'warning' | |
5fb2e288 C |
202 | }, |
203 | search: { | |
204 | remoteUri: { | |
205 | users: true, | |
206 | anonymous: true | |
207 | }, | |
208 | searchIndex: { | |
209 | enabled: true, | |
210 | url: 'https://search.joinpeertube.org', | |
211 | disableLocalSearch: true, | |
212 | isDefaultSearch: true | |
213 | } | |
fd206f0b C |
214 | } |
215 | } | |
216 | ||
217 | // --------------------------------------------------------------- | |
218 | ||
219 | before(async function () { | |
e212f887 | 220 | this.timeout(30000) |
fd206f0b | 221 | |
254d3579 | 222 | server = await createSingleServer(1) |
fd206f0b C |
223 | |
224 | await setAccessTokensToServers([ server ]) | |
225 | ||
226 | const user = { | |
227 | username: 'user1', | |
228 | password: 'password' | |
229 | } | |
89d241a7 C |
230 | await server.users.create({ username: user.username, password: user.password }) |
231 | userAccessToken = await server.login.getAccessToken(user) | |
fd206f0b C |
232 | }) |
233 | ||
234 | describe('When getting the configuration', function () { | |
235 | it('Should fail without token', async function () { | |
236 | await makeGetRequest({ | |
237 | url: server.url, | |
238 | path, | |
c0e8b12e | 239 | expectedStatus: HttpStatusCode.UNAUTHORIZED_401 |
fd206f0b C |
240 | }) |
241 | }) | |
242 | ||
243 | it('Should fail if the user is not an administrator', async function () { | |
244 | await makeGetRequest({ | |
245 | url: server.url, | |
246 | path, | |
247 | token: userAccessToken, | |
c0e8b12e | 248 | expectedStatus: HttpStatusCode.FORBIDDEN_403 |
fd206f0b C |
249 | }) |
250 | }) | |
251 | }) | |
252 | ||
253 | describe('When updating the configuration', function () { | |
254 | it('Should fail without token', async function () { | |
255 | await makePutBodyRequest({ | |
256 | url: server.url, | |
257 | path, | |
258 | fields: updateParams, | |
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 makePutBodyRequest({ | |
265 | url: server.url, | |
266 | path, | |
267 | fields: updateParams, | |
268 | token: userAccessToken, | |
c0e8b12e | 269 | expectedStatus: HttpStatusCode.FORBIDDEN_403 |
fd206f0b C |
270 | }) |
271 | }) | |
272 | ||
273 | it('Should fail if it misses a key', async function () { | |
274 | const newUpdateParams = omit(updateParams, 'admin.email') | |
275 | ||
276 | await makePutBodyRequest({ | |
277 | url: server.url, | |
278 | path, | |
0883b324 C |
279 | fields: newUpdateParams, |
280 | token: server.accessToken, | |
c0e8b12e | 281 | expectedStatus: HttpStatusCode.BAD_REQUEST_400 |
0883b324 C |
282 | }) |
283 | }) | |
284 | ||
285 | it('Should fail with a bad default NSFW policy', async function () { | |
6c5065a0 C |
286 | const newUpdateParams = { |
287 | ...updateParams, | |
288 | ||
0883b324 C |
289 | instance: { |
290 | defaultNSFWPolicy: 'hello' | |
291 | } | |
6c5065a0 | 292 | } |
0883b324 C |
293 | |
294 | await makePutBodyRequest({ | |
295 | url: server.url, | |
296 | path, | |
576ad67a JM |
297 | fields: newUpdateParams, |
298 | token: server.accessToken, | |
c0e8b12e | 299 | expectedStatus: HttpStatusCode.BAD_REQUEST_400 |
576ad67a JM |
300 | }) |
301 | }) | |
302 | ||
303 | it('Should fail if email disabled and signup requires email verification', async function () { | |
7c3b7976 | 304 | // opposite scenario - success when enable enabled - covered via tests/api/users/user-verification.ts |
6c5065a0 C |
305 | const newUpdateParams = { |
306 | ...updateParams, | |
307 | ||
576ad67a JM |
308 | signup: { |
309 | enabled: true, | |
310 | limit: 5, | |
311 | requiresEmailVerification: true | |
312 | } | |
6c5065a0 | 313 | } |
576ad67a JM |
314 | |
315 | await makePutBodyRequest({ | |
316 | url: server.url, | |
317 | path, | |
fd206f0b C |
318 | fields: newUpdateParams, |
319 | token: server.accessToken, | |
c0e8b12e | 320 | expectedStatus: HttpStatusCode.BAD_REQUEST_400 |
fd206f0b C |
321 | }) |
322 | }) | |
323 | ||
d7a25329 | 324 | it('Should fail with a disabled webtorrent & hls transcoding', async function () { |
6c5065a0 C |
325 | const newUpdateParams = { |
326 | ...updateParams, | |
327 | ||
d7a25329 C |
328 | transcoding: { |
329 | hls: { | |
330 | enabled: false | |
331 | }, | |
332 | webtorrent: { | |
333 | enabled: false | |
334 | } | |
335 | } | |
6c5065a0 | 336 | } |
d7a25329 C |
337 | |
338 | await makePutBodyRequest({ | |
339 | url: server.url, | |
340 | path, | |
341 | fields: newUpdateParams, | |
342 | token: server.accessToken, | |
c0e8b12e | 343 | expectedStatus: HttpStatusCode.BAD_REQUEST_400 |
d7a25329 C |
344 | }) |
345 | }) | |
346 | ||
fd206f0b C |
347 | it('Should success with the correct parameters', async function () { |
348 | await makePutBodyRequest({ | |
349 | url: server.url, | |
350 | path, | |
351 | fields: updateParams, | |
352 | token: server.accessToken, | |
c0e8b12e | 353 | expectedStatus: HttpStatusCode.OK_200 |
fd206f0b C |
354 | }) |
355 | }) | |
356 | }) | |
357 | ||
358 | describe('When deleting the configuration', function () { | |
359 | it('Should fail without token', async function () { | |
360 | await makeDeleteRequest({ | |
361 | url: server.url, | |
362 | path, | |
c0e8b12e | 363 | expectedStatus: HttpStatusCode.UNAUTHORIZED_401 |
fd206f0b C |
364 | }) |
365 | }) | |
366 | ||
367 | it('Should fail if the user is not an administrator', async function () { | |
368 | await makeDeleteRequest({ | |
369 | url: server.url, | |
370 | path, | |
371 | token: userAccessToken, | |
c0e8b12e | 372 | expectedStatus: HttpStatusCode.FORBIDDEN_403 |
fd206f0b C |
373 | }) |
374 | }) | |
375 | }) | |
376 | ||
7c3b7976 C |
377 | after(async function () { |
378 | await cleanupTests([ server ]) | |
fd206f0b C |
379 | }) |
380 | }) |