]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/tests/api/check-params/config.ts
Shorter live methods
[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 torrents: {
70 size: 4
71 }
72 },
73 signup: {
74 enabled: false,
75 limit: 5,
76 requiresEmailVerification: false,
77 minimumAge: 16
78 },
79 admin: {
80 email: 'superadmin1@example.com'
81 },
82 contactForm: {
83 enabled: false
84 },
85 user: {
86 videoQuota: 5242881,
87 videoQuotaDaily: 318742
88 },
89 transcoding: {
90 enabled: true,
91 allowAdditionalExtensions: true,
92 allowAudioFiles: true,
93 concurrency: 1,
94 threads: 1,
95 profile: 'vod_profile',
96 resolutions: {
97 '0p': false,
98 '240p': false,
99 '360p': true,
100 '480p': true,
101 '720p': false,
102 '1080p': false,
103 '1440p': false,
104 '2160p': false
105 },
106 webtorrent: {
107 enabled: true
108 },
109 hls: {
110 enabled: false
111 }
112 },
113 live: {
114 enabled: true,
115
116 allowReplay: false,
117 maxDuration: 30,
118 maxInstanceLives: -1,
119 maxUserLives: 50,
120
121 transcoding: {
122 enabled: true,
123 threads: 4,
124 profile: 'live_profile',
125 resolutions: {
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 flushAndRunServer(1)
205
206 await setAccessTokensToServers([ server ])
207
208 const user = {
209 username: 'user1',
210 password: 'password'
211 }
212 await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password })
213 userAccessToken = await userLogin(server, 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 statusCodeExpected: 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 statusCodeExpected: 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 statusCodeExpected: 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 statusCodeExpected: 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 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400
264 })
265 })
266
267 it('Should fail with a bad default NSFW policy', async function () {
268 const newUpdateParams = immutableAssign(updateParams, {
269 instance: {
270 defaultNSFWPolicy: 'hello'
271 }
272 })
273
274 await makePutBodyRequest({
275 url: server.url,
276 path,
277 fields: newUpdateParams,
278 token: server.accessToken,
279 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400
280 })
281 })
282
283 it('Should fail if email disabled and signup requires email verification', async function () {
284 // opposite scenario - success when enable enabled - covered via tests/api/users/user-verification.ts
285 const newUpdateParams = immutableAssign(updateParams, {
286 signup: {
287 enabled: true,
288 limit: 5,
289 requiresEmailVerification: true
290 }
291 })
292
293 await makePutBodyRequest({
294 url: server.url,
295 path,
296 fields: newUpdateParams,
297 token: server.accessToken,
298 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400
299 })
300 })
301
302 it('Should fail with a disabled webtorrent & hls transcoding', async function () {
303 const newUpdateParams = immutableAssign(updateParams, {
304 transcoding: {
305 hls: {
306 enabled: false
307 },
308 webtorrent: {
309 enabled: false
310 }
311 }
312 })
313
314 await makePutBodyRequest({
315 url: server.url,
316 path,
317 fields: newUpdateParams,
318 token: server.accessToken,
319 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400
320 })
321 })
322
323 it('Should success with the correct parameters', async function () {
324 await makePutBodyRequest({
325 url: server.url,
326 path,
327 fields: updateParams,
328 token: server.accessToken,
329 statusCodeExpected: HttpStatusCode.OK_200
330 })
331 })
332 })
333
334 describe('When deleting the configuration', function () {
335 it('Should fail without token', async function () {
336 await makeDeleteRequest({
337 url: server.url,
338 path,
339 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401
340 })
341 })
342
343 it('Should fail if the user is not an administrator', async function () {
344 await makeDeleteRequest({
345 url: server.url,
346 path,
347 token: userAccessToken,
348 statusCodeExpected: HttpStatusCode.FORBIDDEN_403
349 })
350 })
351 })
352
353 after(async function () {
354 await cleanupTests([ server ])
355 })
356 })