]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/tests/api/check-params/config.ts
291de93ea8cf4068de05c7c26d1d52d30ee193c2
[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 { HttpStatusCode } from '@shared/core-utils'
6 import {
7 cleanupTests,
8 createUser,
9 flushAndRunServer,
10 makeDeleteRequest,
11 makeGetRequest,
12 makePutBodyRequest,
13 ServerInfo,
14 setAccessTokensToServers,
15 userLogin
16 } from '@shared/extra-utils'
17 import { CustomConfig } from '@shared/models'
18
19 describe('Test config API validators', function () {
20 const path = '/api/v1/config/custom'
21 let server: ServerInfo
22 let userAccessToken: string
23 const updateParams: CustomConfig = {
24 instance: {
25 name: 'PeerTube updated',
26 shortDescription: 'my short description',
27 description: 'my super description',
28 terms: 'my super terms',
29 codeOfConduct: 'my super coc',
30
31 creationReason: 'my super reason',
32 moderationInformation: 'my super moderation information',
33 administrator: 'Kuja',
34 maintenanceLifetime: 'forever',
35 businessModel: 'my super business model',
36 hardwareInformation: '2vCore 3GB RAM',
37
38 languages: [ 'en', 'es' ],
39 categories: [ 1, 2 ],
40
41 isNSFW: true,
42 defaultNSFWPolicy: 'blur',
43
44 defaultClientRoute: '/videos/recently-added',
45
46 customizations: {
47 javascript: 'alert("coucou")',
48 css: 'body { background-color: red; }'
49 }
50 },
51 theme: {
52 default: 'default'
53 },
54 services: {
55 twitter: {
56 username: '@MySuperUsername',
57 whitelisted: true
58 }
59 },
60 cache: {
61 previews: {
62 size: 2
63 },
64 captions: {
65 size: 3
66 },
67 torrents: {
68 size: 4
69 }
70 },
71 signup: {
72 enabled: false,
73 limit: 5,
74 requiresEmailVerification: false,
75 minimumAge: 16
76 },
77 admin: {
78 email: 'superadmin1@example.com'
79 },
80 contactForm: {
81 enabled: false
82 },
83 user: {
84 videoQuota: 5242881,
85 videoQuotaDaily: 318742
86 },
87 transcoding: {
88 enabled: true,
89 allowAdditionalExtensions: true,
90 allowAudioFiles: true,
91 concurrency: 1,
92 threads: 1,
93 profile: 'vod_profile',
94 resolutions: {
95 '0p': false,
96 '240p': false,
97 '360p': true,
98 '480p': true,
99 '720p': false,
100 '1080p': false,
101 '1440p': false,
102 '2160p': false
103 },
104 webtorrent: {
105 enabled: true
106 },
107 hls: {
108 enabled: false
109 }
110 },
111 live: {
112 enabled: true,
113
114 allowReplay: false,
115 maxDuration: 30,
116 maxInstanceLives: -1,
117 maxUserLives: 50,
118
119 transcoding: {
120 enabled: true,
121 threads: 4,
122 profile: 'live_profile',
123 resolutions: {
124 '240p': true,
125 '360p': true,
126 '480p': true,
127 '720p': true,
128 '1080p': true,
129 '1440p': true,
130 '2160p': true
131 }
132 }
133 },
134 import: {
135 videos: {
136 concurrency: 1,
137 http: {
138 enabled: false
139 },
140 torrent: {
141 enabled: false
142 }
143 }
144 },
145 trending: {
146 videos: {
147 algorithms: {
148 enabled: [ 'best', 'hot', 'most-viewed', 'most-liked' ],
149 default: 'most-viewed'
150 }
151 }
152 },
153 autoBlacklist: {
154 videos: {
155 ofUsers: {
156 enabled: false
157 }
158 }
159 },
160 followers: {
161 instance: {
162 enabled: false,
163 manualApproval: true
164 }
165 },
166 followings: {
167 instance: {
168 autoFollowBack: {
169 enabled: true
170 },
171 autoFollowIndex: {
172 enabled: true,
173 indexUrl: 'https://index.example.com'
174 }
175 }
176 },
177 broadcastMessage: {
178 enabled: true,
179 dismissable: true,
180 message: 'super message',
181 level: 'warning'
182 },
183 search: {
184 remoteUri: {
185 users: true,
186 anonymous: true
187 },
188 searchIndex: {
189 enabled: true,
190 url: 'https://search.joinpeertube.org',
191 disableLocalSearch: true,
192 isDefaultSearch: true
193 }
194 }
195 }
196
197 // ---------------------------------------------------------------
198
199 before(async function () {
200 this.timeout(30000)
201
202 server = await flushAndRunServer(1)
203
204 await setAccessTokensToServers([ server ])
205
206 const user = {
207 username: 'user1',
208 password: 'password'
209 }
210 await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password })
211 userAccessToken = await userLogin(server, user)
212 })
213
214 describe('When getting the configuration', function () {
215 it('Should fail without token', async function () {
216 await makeGetRequest({
217 url: server.url,
218 path,
219 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401
220 })
221 })
222
223 it('Should fail if the user is not an administrator', async function () {
224 await makeGetRequest({
225 url: server.url,
226 path,
227 token: userAccessToken,
228 statusCodeExpected: HttpStatusCode.FORBIDDEN_403
229 })
230 })
231 })
232
233 describe('When updating the configuration', function () {
234 it('Should fail without token', async function () {
235 await makePutBodyRequest({
236 url: server.url,
237 path,
238 fields: updateParams,
239 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401
240 })
241 })
242
243 it('Should fail if the user is not an administrator', async function () {
244 await makePutBodyRequest({
245 url: server.url,
246 path,
247 fields: updateParams,
248 token: userAccessToken,
249 statusCodeExpected: HttpStatusCode.FORBIDDEN_403
250 })
251 })
252
253 it('Should fail if it misses a key', async function () {
254 const newUpdateParams = omit(updateParams, 'admin.email')
255
256 await makePutBodyRequest({
257 url: server.url,
258 path,
259 fields: newUpdateParams,
260 token: server.accessToken,
261 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400
262 })
263 })
264
265 it('Should fail with a bad default NSFW policy', async function () {
266 const newUpdateParams = {
267 ...updateParams,
268
269 instance: {
270 defaultNSFWPolicy: 'hello'
271 }
272 }
273
274 await makePutBodyRequest({
275 url: server.url,
276 path,
277 fields: newUpdateParams,
278 token: server.accessToken,
279 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400
280 })
281 })
282
283 it('Should fail if email disabled and signup requires email verification', async function () {
284 // opposite scenario - success when enable enabled - covered via tests/api/users/user-verification.ts
285 const newUpdateParams = {
286 ...updateParams,
287
288 signup: {
289 enabled: true,
290 limit: 5,
291 requiresEmailVerification: true
292 }
293 }
294
295 await makePutBodyRequest({
296 url: server.url,
297 path,
298 fields: newUpdateParams,
299 token: server.accessToken,
300 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400
301 })
302 })
303
304 it('Should fail with a disabled webtorrent & hls transcoding', async function () {
305 const newUpdateParams = {
306 ...updateParams,
307
308 transcoding: {
309 hls: {
310 enabled: false
311 },
312 webtorrent: {
313 enabled: false
314 }
315 }
316 }
317
318 await makePutBodyRequest({
319 url: server.url,
320 path,
321 fields: newUpdateParams,
322 token: server.accessToken,
323 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400
324 })
325 })
326
327 it('Should success with the correct parameters', async function () {
328 await makePutBodyRequest({
329 url: server.url,
330 path,
331 fields: updateParams,
332 token: server.accessToken,
333 statusCodeExpected: HttpStatusCode.OK_200
334 })
335 })
336 })
337
338 describe('When deleting the configuration', function () {
339 it('Should fail without token', async function () {
340 await makeDeleteRequest({
341 url: server.url,
342 path,
343 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401
344 })
345 })
346
347 it('Should fail if the user is not an administrator', async function () {
348 await makeDeleteRequest({
349 url: server.url,
350 path,
351 token: userAccessToken,
352 statusCodeExpected: HttpStatusCode.FORBIDDEN_403
353 })
354 })
355 })
356
357 after(async function () {
358 await cleanupTests([ server ])
359 })
360 })