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