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