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