]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/tests/api/check-params/config.ts
Shorter server command names
[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
C
4import { omit } from 'lodash'
5import { HttpStatusCode } from '@shared/core-utils'
fd206f0b 6import {
8424c402 7 cleanupTests,
8424c402 8 flushAndRunServer,
8424c402
C
9 makeDeleteRequest,
10 makeGetRequest,
11 makePutBodyRequest,
12 ServerInfo,
41d1d075 13 setAccessTokensToServers
6c5065a0
C
14} from '@shared/extra-utils'
15import { CustomConfig } from '@shared/models'
fd206f0b
C
16
17describe('Test config API validators', function () {
18 const path = '/api/v1/config/custom'
19 let server: ServerInfo
20 let userAccessToken: string
21 const updateParams: CustomConfig = {
66b16caf
C
22 instance: {
23 name: 'PeerTube updated',
2e3a0215 24 shortDescription: 'my short description',
66b16caf 25 description: 'my super description',
00b5556c 26 terms: 'my super terms',
ccc00cb2
C
27 codeOfConduct: 'my super coc',
28
8ae03c37 29 creationReason: 'my super reason',
ccc00cb2
C
30 moderationInformation: 'my super moderation information',
31 administrator: 'Kuja',
32 maintenanceLifetime: 'forever',
33 businessModel: 'my super business model',
be04c6fd 34 hardwareInformation: '2vCore 3GB RAM',
ccc00cb2
C
35
36 languages: [ 'en', 'es' ],
37 categories: [ 1, 2 ],
38
f8802489 39 isNSFW: true,
0883b324 40 defaultNSFWPolicy: 'blur',
3da68f0a
RK
41
42 defaultClientRoute: '/videos/recently-added',
3da68f0a 43
00b5556c
C
44 customizations: {
45 javascript: 'alert("coucou")',
46 css: 'body { background-color: red; }'
47 }
66b16caf 48 },
7cd4d2ba
C
49 theme: {
50 default: 'default'
51 },
8be1afa1
C
52 services: {
53 twitter: {
54 username: '@MySuperUsername',
55 whitelisted: true
56 }
57 },
fd206f0b
C
58 cache: {
59 previews: {
60 size: 2
40e87e9e
C
61 },
62 captions: {
63 size: 3
b3d5cb92
C
64 },
65 torrents: {
66 size: 4
fd206f0b
C
67 }
68 },
69 signup: {
70 enabled: false,
d9eaee39 71 limit: 5,
1f256e7d
P
72 requiresEmailVerification: false,
73 minimumAge: 16
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,
9129b769 89 concurrency: 1,
fd206f0b 90 threads: 1,
1896bca0 91 profile: 'vod_profile',
fd206f0b 92 resolutions: {
5c7d6508 93 '0p': false,
fd206f0b
C
94 '240p': false,
95 '360p': true,
96 '480p': true,
97 '720p': false,
db714ab4 98 '1080p': false,
b7085c71 99 '1440p': false,
db714ab4 100 '2160p': false
09209296 101 },
d7a25329
C
102 webtorrent: {
103 enabled: true
104 },
09209296
C
105 hls: {
106 enabled: false
fd206f0b 107 }
5d08a6a7 108 },
c6c0fa6c
C
109 live: {
110 enabled: true,
111
fb719404 112 allowReplay: false,
c9bc850e 113 maxDuration: 30,
a056ca48
C
114 maxInstanceLives: -1,
115 maxUserLives: 50,
fb719404 116
c6c0fa6c
C
117 transcoding: {
118 enabled: true,
119 threads: 4,
1896bca0 120 profile: 'live_profile',
c6c0fa6c
C
121 resolutions: {
122 '240p': true,
123 '360p': true,
124 '480p': true,
125 '720p': true,
126 '1080p': true,
b7085c71 127 '1440p': true,
c6c0fa6c
C
128 '2160p': true
129 }
130 }
131 },
5d08a6a7
C
132 import: {
133 videos: {
9129b769 134 concurrency: 1,
5d08a6a7
C
135 http: {
136 enabled: false
a84b8fa5
C
137 },
138 torrent: {
139 enabled: false
5d08a6a7
C
140 }
141 }
7ccddd7b 142 },
ba5d4a84
RK
143 trending: {
144 videos: {
145 algorithms: {
3d4e112d 146 enabled: [ 'best', 'hot', 'most-viewed', 'most-liked' ],
ba5d4a84
RK
147 default: 'most-viewed'
148 }
149 }
150 },
7ccddd7b
JM
151 autoBlacklist: {
152 videos: {
153 ofUsers: {
154 enabled: false
155 }
156 }
5b9c965d
C
157 },
158 followers: {
159 instance: {
14893eb7
C
160 enabled: false,
161 manualApproval: true
5b9c965d 162 }
8424c402
C
163 },
164 followings: {
165 instance: {
166 autoFollowBack: {
167 enabled: true
168 },
169 autoFollowIndex: {
170 enabled: true,
171 indexUrl: 'https://index.example.com'
172 }
173 }
72c33e71
C
174 },
175 broadcastMessage: {
176 enabled: true,
177 dismissable: true,
178 message: 'super message',
179 level: 'warning'
5fb2e288
C
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 }
fd206f0b
C
192 }
193 }
194
195 // ---------------------------------------------------------------
196
197 before(async function () {
e212f887 198 this.timeout(30000)
fd206f0b 199
210feb6c 200 server = await flushAndRunServer(1)
fd206f0b
C
201
202 await setAccessTokensToServers([ server ])
203
204 const user = {
205 username: 'user1',
206 password: 'password'
207 }
89d241a7
C
208 await server.users.create({ username: user.username, password: user.password })
209 userAccessToken = await server.login.getAccessToken(user)
fd206f0b
C
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,
2d53be02 217 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401
fd206f0b
C
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,
2d53be02 226 statusCodeExpected: HttpStatusCode.FORBIDDEN_403
fd206f0b
C
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,
2d53be02 237 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401
fd206f0b
C
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,
2d53be02 247 statusCodeExpected: HttpStatusCode.FORBIDDEN_403
fd206f0b
C
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,
0883b324
C
257 fields: newUpdateParams,
258 token: server.accessToken,
2d53be02 259 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400
0883b324
C
260 })
261 })
262
263 it('Should fail with a bad default NSFW policy', async function () {
6c5065a0
C
264 const newUpdateParams = {
265 ...updateParams,
266
0883b324
C
267 instance: {
268 defaultNSFWPolicy: 'hello'
269 }
6c5065a0 270 }
0883b324
C
271
272 await makePutBodyRequest({
273 url: server.url,
274 path,
576ad67a
JM
275 fields: newUpdateParams,
276 token: server.accessToken,
2d53be02 277 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400
576ad67a
JM
278 })
279 })
280
281 it('Should fail if email disabled and signup requires email verification', async function () {
7c3b7976 282 // opposite scenario - success when enable enabled - covered via tests/api/users/user-verification.ts
6c5065a0
C
283 const newUpdateParams = {
284 ...updateParams,
285
576ad67a
JM
286 signup: {
287 enabled: true,
288 limit: 5,
289 requiresEmailVerification: true
290 }
6c5065a0 291 }
576ad67a
JM
292
293 await makePutBodyRequest({
294 url: server.url,
295 path,
fd206f0b
C
296 fields: newUpdateParams,
297 token: server.accessToken,
2d53be02 298 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400
fd206f0b
C
299 })
300 })
301
d7a25329 302 it('Should fail with a disabled webtorrent & hls transcoding', async function () {
6c5065a0
C
303 const newUpdateParams = {
304 ...updateParams,
305
d7a25329
C
306 transcoding: {
307 hls: {
308 enabled: false
309 },
310 webtorrent: {
311 enabled: false
312 }
313 }
6c5065a0 314 }
d7a25329
C
315
316 await makePutBodyRequest({
317 url: server.url,
318 path,
319 fields: newUpdateParams,
320 token: server.accessToken,
2d53be02 321 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400
d7a25329
C
322 })
323 })
324
fd206f0b
C
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,
2d53be02 331 statusCodeExpected: HttpStatusCode.OK_200
fd206f0b
C
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,
2d53be02 341 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401
fd206f0b
C
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,
2d53be02 350 statusCodeExpected: HttpStatusCode.FORBIDDEN_403
fd206f0b
C
351 })
352 })
353 })
354
7c3b7976
C
355 after(async function () {
356 await cleanupTests([ server ])
fd206f0b
C
357 })
358})