]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/tests/api/check-params/config.ts
Merge branch 'release/4.0.0' into develop
[github/Chocobozzz/PeerTube.git] / server / tests / api / check-params / config.ts
CommitLineData
a1587156 1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
fd206f0b 2
fd206f0b 3import 'mocha'
6c5065a0 4import { omit } from 'lodash'
fd206f0b 5import {
8424c402 6 cleanupTests,
254d3579 7 createSingleServer,
8424c402
C
8 makeDeleteRequest,
9 makeGetRequest,
10 makePutBodyRequest,
254d3579 11 PeerTubeServer,
41d1d075 12 setAccessTokensToServers
bf54587a 13} from '@shared/server-commands'
4c7e60bc 14import { CustomConfig, HttpStatusCode } from '@shared/models'
fd206f0b
C
15
16describe('Test config API validators', function () {
17 const path = '/api/v1/config/custom'
254d3579 18 let server: PeerTubeServer
fd206f0b
C
19 let userAccessToken: string
20 const updateParams: CustomConfig = {
66b16caf
C
21 instance: {
22 name: 'PeerTube updated',
2e3a0215 23 shortDescription: 'my short description',
66b16caf 24 description: 'my super description',
00b5556c 25 terms: 'my super terms',
ccc00cb2
C
26 codeOfConduct: 'my super coc',
27
8ae03c37 28 creationReason: 'my super reason',
ccc00cb2
C
29 moderationInformation: 'my super moderation information',
30 administrator: 'Kuja',
31 maintenanceLifetime: 'forever',
32 businessModel: 'my super business model',
be04c6fd 33 hardwareInformation: '2vCore 3GB RAM',
ccc00cb2
C
34
35 languages: [ 'en', 'es' ],
36 categories: [ 1, 2 ],
37
f8802489 38 isNSFW: true,
0883b324 39 defaultNSFWPolicy: 'blur',
3da68f0a
RK
40
41 defaultClientRoute: '/videos/recently-added',
3da68f0a 42
00b5556c
C
43 customizations: {
44 javascript: 'alert("coucou")',
45 css: 'body { background-color: red; }'
46 }
66b16caf 47 },
7cd4d2ba
C
48 theme: {
49 default: 'default'
50 },
8be1afa1
C
51 services: {
52 twitter: {
53 username: '@MySuperUsername',
54 whitelisted: true
55 }
56 },
0bc53e20
C
57 client: {
58 videos: {
59 miniature: {
60 preferAuthorDisplayName: false
61 }
62 },
63 menu: {
64 login: {
65 redirectOnSingleExternalAuth: false
66 }
67 }
68 },
fd206f0b
C
69 cache: {
70 previews: {
71 size: 2
40e87e9e
C
72 },
73 captions: {
74 size: 3
b3d5cb92
C
75 },
76 torrents: {
77 size: 4
fd206f0b
C
78 }
79 },
80 signup: {
81 enabled: false,
d9eaee39 82 limit: 5,
1f256e7d
P
83 requiresEmailVerification: false,
84 minimumAge: 16
fd206f0b
C
85 },
86 admin: {
87 email: 'superadmin1@example.com'
88 },
a4101923
C
89 contactForm: {
90 enabled: false
91 },
fd206f0b 92 user: {
bee0abff
FA
93 videoQuota: 5242881,
94 videoQuotaDaily: 318742
fd206f0b 95 },
754b6f5f
FC
96 videoChannels: {
97 maxPerUser: 20
98 },
fd206f0b
C
99 transcoding: {
100 enabled: true,
14e2014a 101 allowAdditionalExtensions: true,
536598cf 102 allowAudioFiles: true,
9129b769 103 concurrency: 1,
fd206f0b 104 threads: 1,
1896bca0 105 profile: 'vod_profile',
fd206f0b 106 resolutions: {
5c7d6508 107 '0p': false,
8dd754c7 108 '144p': false,
fd206f0b
C
109 '240p': false,
110 '360p': true,
111 '480p': true,
112 '720p': false,
db714ab4 113 '1080p': false,
b7085c71 114 '1440p': false,
db714ab4 115 '2160p': false
09209296 116 },
d7a25329
C
117 webtorrent: {
118 enabled: true
119 },
09209296
C
120 hls: {
121 enabled: false
fd206f0b 122 }
5d08a6a7 123 },
c6c0fa6c
C
124 live: {
125 enabled: true,
126
fb719404 127 allowReplay: false,
c9bc850e 128 maxDuration: 30,
a056ca48
C
129 maxInstanceLives: -1,
130 maxUserLives: 50,
fb719404 131
c6c0fa6c
C
132 transcoding: {
133 enabled: true,
134 threads: 4,
1896bca0 135 profile: 'live_profile',
c6c0fa6c 136 resolutions: {
8dd754c7 137 '144p': true,
c6c0fa6c
C
138 '240p': true,
139 '360p': true,
140 '480p': true,
141 '720p': true,
142 '1080p': true,
b7085c71 143 '1440p': true,
c6c0fa6c
C
144 '2160p': true
145 }
146 }
147 },
5d08a6a7
C
148 import: {
149 videos: {
9129b769 150 concurrency: 1,
5d08a6a7
C
151 http: {
152 enabled: false
a84b8fa5
C
153 },
154 torrent: {
155 enabled: false
5d08a6a7
C
156 }
157 }
7ccddd7b 158 },
ba5d4a84
RK
159 trending: {
160 videos: {
161 algorithms: {
3d4e112d 162 enabled: [ 'best', 'hot', 'most-viewed', 'most-liked' ],
ba5d4a84
RK
163 default: 'most-viewed'
164 }
165 }
166 },
7ccddd7b
JM
167 autoBlacklist: {
168 videos: {
169 ofUsers: {
170 enabled: false
171 }
172 }
5b9c965d
C
173 },
174 followers: {
175 instance: {
14893eb7
C
176 enabled: false,
177 manualApproval: true
5b9c965d 178 }
8424c402
C
179 },
180 followings: {
181 instance: {
182 autoFollowBack: {
183 enabled: true
184 },
185 autoFollowIndex: {
186 enabled: true,
187 indexUrl: 'https://index.example.com'
188 }
189 }
72c33e71
C
190 },
191 broadcastMessage: {
192 enabled: true,
193 dismissable: true,
194 message: 'super message',
195 level: 'warning'
5fb2e288
C
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 }
fd206f0b
C
208 }
209 }
210
211 // ---------------------------------------------------------------
212
213 before(async function () {
e212f887 214 this.timeout(30000)
fd206f0b 215
254d3579 216 server = await createSingleServer(1)
fd206f0b
C
217
218 await setAccessTokensToServers([ server ])
219
220 const user = {
221 username: 'user1',
222 password: 'password'
223 }
89d241a7
C
224 await server.users.create({ username: user.username, password: user.password })
225 userAccessToken = await server.login.getAccessToken(user)
fd206f0b
C
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,
c0e8b12e 233 expectedStatus: HttpStatusCode.UNAUTHORIZED_401
fd206f0b
C
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,
c0e8b12e 242 expectedStatus: HttpStatusCode.FORBIDDEN_403
fd206f0b
C
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,
c0e8b12e 253 expectedStatus: HttpStatusCode.UNAUTHORIZED_401
fd206f0b
C
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,
c0e8b12e 263 expectedStatus: HttpStatusCode.FORBIDDEN_403
fd206f0b
C
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,
0883b324
C
273 fields: newUpdateParams,
274 token: server.accessToken,
c0e8b12e 275 expectedStatus: HttpStatusCode.BAD_REQUEST_400
0883b324
C
276 })
277 })
278
279 it('Should fail with a bad default NSFW policy', async function () {
6c5065a0
C
280 const newUpdateParams = {
281 ...updateParams,
282
0883b324
C
283 instance: {
284 defaultNSFWPolicy: 'hello'
285 }
6c5065a0 286 }
0883b324
C
287
288 await makePutBodyRequest({
289 url: server.url,
290 path,
576ad67a
JM
291 fields: newUpdateParams,
292 token: server.accessToken,
c0e8b12e 293 expectedStatus: HttpStatusCode.BAD_REQUEST_400
576ad67a
JM
294 })
295 })
296
297 it('Should fail if email disabled and signup requires email verification', async function () {
7c3b7976 298 // opposite scenario - success when enable enabled - covered via tests/api/users/user-verification.ts
6c5065a0
C
299 const newUpdateParams = {
300 ...updateParams,
301
576ad67a
JM
302 signup: {
303 enabled: true,
304 limit: 5,
305 requiresEmailVerification: true
306 }
6c5065a0 307 }
576ad67a
JM
308
309 await makePutBodyRequest({
310 url: server.url,
311 path,
fd206f0b
C
312 fields: newUpdateParams,
313 token: server.accessToken,
c0e8b12e 314 expectedStatus: HttpStatusCode.BAD_REQUEST_400
fd206f0b
C
315 })
316 })
317
d7a25329 318 it('Should fail with a disabled webtorrent & hls transcoding', async function () {
6c5065a0
C
319 const newUpdateParams = {
320 ...updateParams,
321
d7a25329
C
322 transcoding: {
323 hls: {
324 enabled: false
325 },
326 webtorrent: {
327 enabled: false
328 }
329 }
6c5065a0 330 }
d7a25329
C
331
332 await makePutBodyRequest({
333 url: server.url,
334 path,
335 fields: newUpdateParams,
336 token: server.accessToken,
c0e8b12e 337 expectedStatus: HttpStatusCode.BAD_REQUEST_400
d7a25329
C
338 })
339 })
340
fd206f0b
C
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,
c0e8b12e 347 expectedStatus: HttpStatusCode.OK_200
fd206f0b
C
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,
c0e8b12e 357 expectedStatus: HttpStatusCode.UNAUTHORIZED_401
fd206f0b
C
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,
c0e8b12e 366 expectedStatus: HttpStatusCode.FORBIDDEN_403
fd206f0b
C
367 })
368 })
369 })
370
7c3b7976
C
371 after(async function () {
372 await cleanupTests([ server ])
fd206f0b
C
373 })
374})