]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/tests/api/check-params/config.ts
Fix job queue tests
[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 alwaysTranscodeOriginalResolution: false,
118 webtorrent: {
119 enabled: true
120 },
121 hls: {
122 enabled: false
123 }
124 },
125 live: {
126 enabled: true,
127
128 allowReplay: false,
129 latencySetting: {
130 enabled: false
131 },
132 maxDuration: 30,
133 maxInstanceLives: -1,
134 maxUserLives: 50,
135
136 transcoding: {
137 enabled: true,
138 threads: 4,
139 profile: 'live_profile',
140 resolutions: {
141 '144p': true,
142 '240p': true,
143 '360p': true,
144 '480p': true,
145 '720p': true,
146 '1080p': true,
147 '1440p': true,
148 '2160p': true
149 },
150 alwaysTranscodeOriginalResolution: false
151 }
152 },
153 videoStudio: {
154 enabled: true
155 },
156 import: {
157 videos: {
158 concurrency: 1,
159 http: {
160 enabled: false
161 },
162 torrent: {
163 enabled: false
164 }
165 }
166 },
167 trending: {
168 videos: {
169 algorithms: {
170 enabled: [ 'hot', 'most-viewed', 'most-liked' ],
171 default: 'most-viewed'
172 }
173 }
174 },
175 autoBlacklist: {
176 videos: {
177 ofUsers: {
178 enabled: false
179 }
180 }
181 },
182 followers: {
183 instance: {
184 enabled: false,
185 manualApproval: true
186 }
187 },
188 followings: {
189 instance: {
190 autoFollowBack: {
191 enabled: true
192 },
193 autoFollowIndex: {
194 enabled: true,
195 indexUrl: 'https://index.example.com'
196 }
197 }
198 },
199 broadcastMessage: {
200 enabled: true,
201 dismissable: true,
202 message: 'super message',
203 level: 'warning'
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 }
216 }
217 }
218
219 // ---------------------------------------------------------------
220
221 before(async function () {
222 this.timeout(30000)
223
224 server = await createSingleServer(1)
225
226 await setAccessTokensToServers([ server ])
227
228 const user = {
229 username: 'user1',
230 password: 'password'
231 }
232 await server.users.create({ username: user.username, password: user.password })
233 userAccessToken = await server.login.getAccessToken(user)
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,
241 expectedStatus: HttpStatusCode.UNAUTHORIZED_401
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,
250 expectedStatus: HttpStatusCode.FORBIDDEN_403
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,
261 expectedStatus: HttpStatusCode.UNAUTHORIZED_401
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,
271 expectedStatus: HttpStatusCode.FORBIDDEN_403
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,
281 fields: newUpdateParams,
282 token: server.accessToken,
283 expectedStatus: HttpStatusCode.BAD_REQUEST_400
284 })
285 })
286
287 it('Should fail with a bad default NSFW policy', async function () {
288 const newUpdateParams = {
289 ...updateParams,
290
291 instance: {
292 defaultNSFWPolicy: 'hello'
293 }
294 }
295
296 await makePutBodyRequest({
297 url: server.url,
298 path,
299 fields: newUpdateParams,
300 token: server.accessToken,
301 expectedStatus: HttpStatusCode.BAD_REQUEST_400
302 })
303 })
304
305 it('Should fail if email disabled and signup requires email verification', async function () {
306 // opposite scenario - success when enable enabled - covered via tests/api/users/user-verification.ts
307 const newUpdateParams = {
308 ...updateParams,
309
310 signup: {
311 enabled: true,
312 limit: 5,
313 requiresEmailVerification: true
314 }
315 }
316
317 await makePutBodyRequest({
318 url: server.url,
319 path,
320 fields: newUpdateParams,
321 token: server.accessToken,
322 expectedStatus: HttpStatusCode.BAD_REQUEST_400
323 })
324 })
325
326 it('Should fail with a disabled webtorrent & hls transcoding', async function () {
327 const newUpdateParams = {
328 ...updateParams,
329
330 transcoding: {
331 hls: {
332 enabled: false
333 },
334 webtorrent: {
335 enabled: false
336 }
337 }
338 }
339
340 await makePutBodyRequest({
341 url: server.url,
342 path,
343 fields: newUpdateParams,
344 token: server.accessToken,
345 expectedStatus: HttpStatusCode.BAD_REQUEST_400
346 })
347 })
348
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,
355 expectedStatus: HttpStatusCode.OK_200
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,
365 expectedStatus: HttpStatusCode.UNAUTHORIZED_401
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,
374 expectedStatus: HttpStatusCode.FORBIDDEN_403
375 })
376 })
377 })
378
379 after(async function () {
380 await cleanupTests([ server ])
381 })
382 })