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