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