]>
Commit | Line | Data |
---|---|---|
1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ | |
2 | ||
3 | import 'mocha' | |
4 | import { omit } from 'lodash' | |
5 | import { | |
6 | cleanupTests, | |
7 | createSingleServer, | |
8 | makeDeleteRequest, | |
9 | makeGetRequest, | |
10 | makePutBodyRequest, | |
11 | PeerTubeServer, | |
12 | setAccessTokensToServers | |
13 | } from '@shared/server-commands' | |
14 | import { CustomConfig, HttpStatusCode } from '@shared/models' | |
15 | ||
16 | describe('Test config API validators', function () { | |
17 | const path = '/api/v1/config/custom' | |
18 | let server: PeerTubeServer | |
19 | let userAccessToken: string | |
20 | const updateParams: CustomConfig = { | |
21 | instance: { | |
22 | name: 'PeerTube updated', | |
23 | shortDescription: 'my short description', | |
24 | description: 'my super description', | |
25 | terms: 'my super terms', | |
26 | codeOfConduct: 'my super coc', | |
27 | ||
28 | creationReason: 'my super reason', | |
29 | moderationInformation: 'my super moderation information', | |
30 | administrator: 'Kuja', | |
31 | maintenanceLifetime: 'forever', | |
32 | businessModel: 'my super business model', | |
33 | hardwareInformation: '2vCore 3GB RAM', | |
34 | ||
35 | languages: [ 'en', 'es' ], | |
36 | categories: [ 1, 2 ], | |
37 | ||
38 | isNSFW: true, | |
39 | defaultNSFWPolicy: 'blur', | |
40 | ||
41 | defaultClientRoute: '/videos/recently-added', | |
42 | ||
43 | customizations: { | |
44 | javascript: 'alert("coucou")', | |
45 | css: 'body { background-color: red; }' | |
46 | } | |
47 | }, | |
48 | theme: { | |
49 | default: 'default' | |
50 | }, | |
51 | services: { | |
52 | twitter: { | |
53 | username: '@MySuperUsername', | |
54 | whitelisted: true | |
55 | } | |
56 | }, | |
57 | client: { | |
58 | videos: { | |
59 | miniature: { | |
60 | preferAuthorDisplayName: false | |
61 | } | |
62 | }, | |
63 | menu: { | |
64 | login: { | |
65 | redirectOnSingleExternalAuth: false | |
66 | } | |
67 | } | |
68 | }, | |
69 | cache: { | |
70 | previews: { | |
71 | size: 2 | |
72 | }, | |
73 | captions: { | |
74 | size: 3 | |
75 | }, | |
76 | torrents: { | |
77 | size: 4 | |
78 | } | |
79 | }, | |
80 | signup: { | |
81 | enabled: false, | |
82 | limit: 5, | |
83 | requiresEmailVerification: false, | |
84 | minimumAge: 16 | |
85 | }, | |
86 | admin: { | |
87 | email: 'superadmin1@example.com' | |
88 | }, | |
89 | contactForm: { | |
90 | enabled: false | |
91 | }, | |
92 | user: { | |
93 | videoQuota: 5242881, | |
94 | videoQuotaDaily: 318742 | |
95 | }, | |
96 | videoChannels: { | |
97 | maxPerUser: 20 | |
98 | }, | |
99 | transcoding: { | |
100 | enabled: true, | |
101 | allowAdditionalExtensions: true, | |
102 | allowAudioFiles: true, | |
103 | concurrency: 1, | |
104 | threads: 1, | |
105 | profile: 'vod_profile', | |
106 | resolutions: { | |
107 | '0p': false, | |
108 | '144p': false, | |
109 | '240p': false, | |
110 | '360p': true, | |
111 | '480p': true, | |
112 | '720p': false, | |
113 | '1080p': false, | |
114 | '1440p': false, | |
115 | '2160p': false | |
116 | }, | |
117 | webtorrent: { | |
118 | enabled: true | |
119 | }, | |
120 | hls: { | |
121 | enabled: false | |
122 | } | |
123 | }, | |
124 | live: { | |
125 | enabled: true, | |
126 | ||
127 | allowReplay: false, | |
128 | latencySetting: { | |
129 | enabled: false | |
130 | }, | |
131 | maxDuration: 30, | |
132 | maxInstanceLives: -1, | |
133 | maxUserLives: 50, | |
134 | ||
135 | transcoding: { | |
136 | enabled: true, | |
137 | threads: 4, | |
138 | profile: 'live_profile', | |
139 | resolutions: { | |
140 | '144p': true, | |
141 | '240p': true, | |
142 | '360p': true, | |
143 | '480p': true, | |
144 | '720p': true, | |
145 | '1080p': true, | |
146 | '1440p': true, | |
147 | '2160p': true | |
148 | } | |
149 | } | |
150 | }, | |
151 | videoStudio: { | |
152 | enabled: true | |
153 | }, | |
154 | import: { | |
155 | videos: { | |
156 | concurrency: 1, | |
157 | http: { | |
158 | enabled: false | |
159 | }, | |
160 | torrent: { | |
161 | enabled: false | |
162 | } | |
163 | } | |
164 | }, | |
165 | trending: { | |
166 | videos: { | |
167 | algorithms: { | |
168 | enabled: [ 'best', 'hot', 'most-viewed', 'most-liked' ], | |
169 | default: 'most-viewed' | |
170 | } | |
171 | } | |
172 | }, | |
173 | autoBlacklist: { | |
174 | videos: { | |
175 | ofUsers: { | |
176 | enabled: false | |
177 | } | |
178 | } | |
179 | }, | |
180 | followers: { | |
181 | instance: { | |
182 | enabled: false, | |
183 | manualApproval: true | |
184 | } | |
185 | }, | |
186 | followings: { | |
187 | instance: { | |
188 | autoFollowBack: { | |
189 | enabled: true | |
190 | }, | |
191 | autoFollowIndex: { | |
192 | enabled: true, | |
193 | indexUrl: 'https://index.example.com' | |
194 | } | |
195 | } | |
196 | }, | |
197 | broadcastMessage: { | |
198 | enabled: true, | |
199 | dismissable: true, | |
200 | message: 'super message', | |
201 | level: 'warning' | |
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 | } | |
214 | } | |
215 | } | |
216 | ||
217 | // --------------------------------------------------------------- | |
218 | ||
219 | before(async function () { | |
220 | this.timeout(30000) | |
221 | ||
222 | server = await createSingleServer(1) | |
223 | ||
224 | await setAccessTokensToServers([ server ]) | |
225 | ||
226 | const user = { | |
227 | username: 'user1', | |
228 | password: 'password' | |
229 | } | |
230 | await server.users.create({ username: user.username, password: user.password }) | |
231 | userAccessToken = await server.login.getAccessToken(user) | |
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, | |
239 | expectedStatus: HttpStatusCode.UNAUTHORIZED_401 | |
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, | |
248 | expectedStatus: HttpStatusCode.FORBIDDEN_403 | |
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, | |
259 | expectedStatus: HttpStatusCode.UNAUTHORIZED_401 | |
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, | |
269 | expectedStatus: HttpStatusCode.FORBIDDEN_403 | |
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, | |
279 | fields: newUpdateParams, | |
280 | token: server.accessToken, | |
281 | expectedStatus: HttpStatusCode.BAD_REQUEST_400 | |
282 | }) | |
283 | }) | |
284 | ||
285 | it('Should fail with a bad default NSFW policy', async function () { | |
286 | const newUpdateParams = { | |
287 | ...updateParams, | |
288 | ||
289 | instance: { | |
290 | defaultNSFWPolicy: 'hello' | |
291 | } | |
292 | } | |
293 | ||
294 | await makePutBodyRequest({ | |
295 | url: server.url, | |
296 | path, | |
297 | fields: newUpdateParams, | |
298 | token: server.accessToken, | |
299 | expectedStatus: HttpStatusCode.BAD_REQUEST_400 | |
300 | }) | |
301 | }) | |
302 | ||
303 | it('Should fail if email disabled and signup requires email verification', async function () { | |
304 | // opposite scenario - success when enable enabled - covered via tests/api/users/user-verification.ts | |
305 | const newUpdateParams = { | |
306 | ...updateParams, | |
307 | ||
308 | signup: { | |
309 | enabled: true, | |
310 | limit: 5, | |
311 | requiresEmailVerification: true | |
312 | } | |
313 | } | |
314 | ||
315 | await makePutBodyRequest({ | |
316 | url: server.url, | |
317 | path, | |
318 | fields: newUpdateParams, | |
319 | token: server.accessToken, | |
320 | expectedStatus: HttpStatusCode.BAD_REQUEST_400 | |
321 | }) | |
322 | }) | |
323 | ||
324 | it('Should fail with a disabled webtorrent & hls transcoding', async function () { | |
325 | const newUpdateParams = { | |
326 | ...updateParams, | |
327 | ||
328 | transcoding: { | |
329 | hls: { | |
330 | enabled: false | |
331 | }, | |
332 | webtorrent: { | |
333 | enabled: false | |
334 | } | |
335 | } | |
336 | } | |
337 | ||
338 | await makePutBodyRequest({ | |
339 | url: server.url, | |
340 | path, | |
341 | fields: newUpdateParams, | |
342 | token: server.accessToken, | |
343 | expectedStatus: HttpStatusCode.BAD_REQUEST_400 | |
344 | }) | |
345 | }) | |
346 | ||
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, | |
353 | expectedStatus: HttpStatusCode.OK_200 | |
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, | |
363 | expectedStatus: HttpStatusCode.UNAUTHORIZED_401 | |
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, | |
372 | expectedStatus: HttpStatusCode.FORBIDDEN_403 | |
373 | }) | |
374 | }) | |
375 | }) | |
376 | ||
377 | after(async function () { | |
378 | await cleanupTests([ server ]) | |
379 | }) | |
380 | }) |