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