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