]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/tests/api/check-params/config.ts
Use a profile manager for transcoding
[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
C
2
3import { omit } from 'lodash'
4import 'mocha'
09cababd 5import { CustomConfig } from '../../../../shared/models/server/custom-config.model'
fd206f0b
C
6
7import {
8424c402
C
8 cleanupTests,
9 createUser,
10 flushAndRunServer,
11 immutableAssign,
12 makeDeleteRequest,
13 makeGetRequest,
14 makePutBodyRequest,
15 ServerInfo,
16 setAccessTokensToServers,
17 userLogin
94565d52 18} from '../../../../shared/extra-utils'
2d53be02 19import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
fd206f0b
C
20
21describe('Test config API validators', function () {
22 const path = '/api/v1/config/custom'
23 let server: ServerInfo
24 let userAccessToken: string
25 const updateParams: CustomConfig = {
66b16caf
C
26 instance: {
27 name: 'PeerTube updated',
2e3a0215 28 shortDescription: 'my short description',
66b16caf 29 description: 'my super description',
00b5556c 30 terms: 'my super terms',
ccc00cb2
C
31 codeOfConduct: 'my super coc',
32
8ae03c37 33 creationReason: 'my super reason',
ccc00cb2
C
34 moderationInformation: 'my super moderation information',
35 administrator: 'Kuja',
36 maintenanceLifetime: 'forever',
37 businessModel: 'my super business model',
be04c6fd 38 hardwareInformation: '2vCore 3GB RAM',
ccc00cb2
C
39
40 languages: [ 'en', 'es' ],
41 categories: [ 1, 2 ],
42
f8802489 43 isNSFW: true,
0883b324 44 defaultNSFWPolicy: 'blur',
3da68f0a
RK
45
46 defaultClientRoute: '/videos/recently-added',
3da68f0a 47
00b5556c
C
48 customizations: {
49 javascript: 'alert("coucou")',
50 css: 'body { background-color: red; }'
51 }
66b16caf 52 },
7cd4d2ba
C
53 theme: {
54 default: 'default'
55 },
8be1afa1
C
56 services: {
57 twitter: {
58 username: '@MySuperUsername',
59 whitelisted: true
60 }
61 },
fd206f0b
C
62 cache: {
63 previews: {
64 size: 2
40e87e9e
C
65 },
66 captions: {
67 size: 3
fd206f0b
C
68 }
69 },
70 signup: {
71 enabled: false,
d9eaee39
JM
72 limit: 5,
73 requiresEmailVerification: false
fd206f0b
C
74 },
75 admin: {
76 email: 'superadmin1@example.com'
77 },
a4101923
C
78 contactForm: {
79 enabled: false
80 },
fd206f0b 81 user: {
bee0abff
FA
82 videoQuota: 5242881,
83 videoQuotaDaily: 318742
fd206f0b
C
84 },
85 transcoding: {
86 enabled: true,
14e2014a 87 allowAdditionalExtensions: true,
536598cf 88 allowAudioFiles: true,
fd206f0b
C
89 threads: 1,
90 resolutions: {
5c7d6508 91 '0p': false,
fd206f0b
C
92 '240p': false,
93 '360p': true,
94 '480p': true,
95 '720p': false,
db714ab4 96 '1080p': false,
b7085c71 97 '1440p': false,
db714ab4 98 '2160p': false
09209296 99 },
d7a25329
C
100 webtorrent: {
101 enabled: true
102 },
09209296
C
103 hls: {
104 enabled: false
fd206f0b 105 }
5d08a6a7 106 },
c6c0fa6c
C
107 live: {
108 enabled: true,
109
fb719404 110 allowReplay: false,
c9bc850e 111 maxDuration: 30,
a056ca48
C
112 maxInstanceLives: -1,
113 maxUserLives: 50,
fb719404 114
c6c0fa6c
C
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,
b7085c71 124 '1440p': true,
c6c0fa6c
C
125 '2160p': true
126 }
127 }
128 },
5d08a6a7
C
129 import: {
130 videos: {
131 http: {
132 enabled: false
a84b8fa5
C
133 },
134 torrent: {
135 enabled: false
5d08a6a7
C
136 }
137 }
7ccddd7b 138 },
ba5d4a84
RK
139 trending: {
140 videos: {
141 algorithms: {
142 enabled: [ 'hot', 'most-viewed', 'most-liked' ],
143 default: 'most-viewed'
144 }
145 }
146 },
7ccddd7b
JM
147 autoBlacklist: {
148 videos: {
149 ofUsers: {
150 enabled: false
151 }
152 }
5b9c965d
C
153 },
154 followers: {
155 instance: {
14893eb7
C
156 enabled: false,
157 manualApproval: true
5b9c965d 158 }
8424c402
C
159 },
160 followings: {
161 instance: {
162 autoFollowBack: {
163 enabled: true
164 },
165 autoFollowIndex: {
166 enabled: true,
167 indexUrl: 'https://index.example.com'
168 }
169 }
72c33e71
C
170 },
171 broadcastMessage: {
172 enabled: true,
173 dismissable: true,
174 message: 'super message',
175 level: 'warning'
5fb2e288
C
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 }
fd206f0b
C
188 }
189 }
190
191 // ---------------------------------------------------------------
192
193 before(async function () {
e212f887 194 this.timeout(30000)
fd206f0b 195
210feb6c 196 server = await flushAndRunServer(1)
fd206f0b
C
197
198 await setAccessTokensToServers([ server ])
199
200 const user = {
201 username: 'user1',
202 password: 'password'
203 }
1eddc9a7 204 await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password })
fd206f0b
C
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,
2d53be02 213 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401
fd206f0b
C
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,
2d53be02 222 statusCodeExpected: HttpStatusCode.FORBIDDEN_403
fd206f0b
C
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,
2d53be02 233 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401
fd206f0b
C
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,
2d53be02 243 statusCodeExpected: HttpStatusCode.FORBIDDEN_403
fd206f0b
C
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,
0883b324
C
253 fields: newUpdateParams,
254 token: server.accessToken,
2d53be02 255 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400
0883b324
C
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,
576ad67a
JM
269 fields: newUpdateParams,
270 token: server.accessToken,
2d53be02 271 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400
576ad67a
JM
272 })
273 })
274
275 it('Should fail if email disabled and signup requires email verification', async function () {
7c3b7976 276 // opposite scenario - success when enable enabled - covered via tests/api/users/user-verification.ts
576ad67a
JM
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,
fd206f0b
C
288 fields: newUpdateParams,
289 token: server.accessToken,
2d53be02 290 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400
fd206f0b
C
291 })
292 })
293
d7a25329
C
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,
2d53be02 311 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400
d7a25329
C
312 })
313 })
314
fd206f0b
C
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,
2d53be02 321 statusCodeExpected: HttpStatusCode.OK_200
fd206f0b
C
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,
2d53be02 331 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401
fd206f0b
C
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,
2d53be02 340 statusCodeExpected: HttpStatusCode.FORBIDDEN_403
fd206f0b
C
341 })
342 })
343 })
344
7c3b7976
C
345 after(async function () {
346 await cleanupTests([ server ])
fd206f0b
C
347 })
348})