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