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