]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/tests/api/check-params/config.ts
Live streaming implementation first step
[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
20 describe('Test config API validators', function () {
21 const path = '/api/v1/config/custom'
22 let server: ServerInfo
23 let userAccessToken: string
24 const updateParams: CustomConfig = {
25 instance: {
26 name: 'PeerTube updated',
27 shortDescription: 'my short description',
28 description: 'my super description',
29 terms: 'my super terms',
30 codeOfConduct: 'my super coc',
31
32 creationReason: 'my super reason',
33 moderationInformation: 'my super moderation information',
34 administrator: 'Kuja',
35 maintenanceLifetime: 'forever',
36 businessModel: 'my super business model',
37 hardwareInformation: '2vCore 3GB RAM',
38
39 languages: [ 'en', 'es' ],
40 categories: [ 1, 2 ],
41
42 isNSFW: true,
43 defaultClientRoute: '/videos/recently-added',
44 defaultNSFWPolicy: 'blur',
45 customizations: {
46 javascript: 'alert("coucou")',
47 css: 'body { background-color: red; }'
48 }
49 },
50 theme: {
51 default: 'default'
52 },
53 services: {
54 twitter: {
55 username: '@MySuperUsername',
56 whitelisted: true
57 }
58 },
59 cache: {
60 previews: {
61 size: 2
62 },
63 captions: {
64 size: 3
65 }
66 },
67 signup: {
68 enabled: false,
69 limit: 5,
70 requiresEmailVerification: false
71 },
72 admin: {
73 email: 'superadmin1@example.com'
74 },
75 contactForm: {
76 enabled: false
77 },
78 user: {
79 videoQuota: 5242881,
80 videoQuotaDaily: 318742
81 },
82 transcoding: {
83 enabled: true,
84 allowAdditionalExtensions: true,
85 allowAudioFiles: true,
86 threads: 1,
87 resolutions: {
88 '0p': false,
89 '240p': false,
90 '360p': true,
91 '480p': true,
92 '720p': false,
93 '1080p': false,
94 '2160p': false
95 },
96 webtorrent: {
97 enabled: true
98 },
99 hls: {
100 enabled: false
101 }
102 },
103 live: {
104 enabled: true,
105
106 transcoding: {
107 enabled: true,
108 threads: 4,
109 resolutions: {
110 '240p': true,
111 '360p': true,
112 '480p': true,
113 '720p': true,
114 '1080p': true,
115 '2160p': true
116 }
117 }
118 },
119 import: {
120 videos: {
121 http: {
122 enabled: false
123 },
124 torrent: {
125 enabled: false
126 }
127 }
128 },
129 autoBlacklist: {
130 videos: {
131 ofUsers: {
132 enabled: false
133 }
134 }
135 },
136 followers: {
137 instance: {
138 enabled: false,
139 manualApproval: true
140 }
141 },
142 followings: {
143 instance: {
144 autoFollowBack: {
145 enabled: true
146 },
147 autoFollowIndex: {
148 enabled: true,
149 indexUrl: 'https://index.example.com'
150 }
151 }
152 },
153 broadcastMessage: {
154 enabled: true,
155 dismissable: true,
156 message: 'super message',
157 level: 'warning'
158 },
159 search: {
160 remoteUri: {
161 users: true,
162 anonymous: true
163 },
164 searchIndex: {
165 enabled: true,
166 url: 'https://search.joinpeertube.org',
167 disableLocalSearch: true,
168 isDefaultSearch: true
169 }
170 }
171 }
172
173 // ---------------------------------------------------------------
174
175 before(async function () {
176 this.timeout(30000)
177
178 server = await flushAndRunServer(1)
179
180 await setAccessTokensToServers([ server ])
181
182 const user = {
183 username: 'user1',
184 password: 'password'
185 }
186 await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password })
187 userAccessToken = await userLogin(server, user)
188 })
189
190 describe('When getting the configuration', function () {
191 it('Should fail without token', async function () {
192 await makeGetRequest({
193 url: server.url,
194 path,
195 statusCodeExpected: 401
196 })
197 })
198
199 it('Should fail if the user is not an administrator', async function () {
200 await makeGetRequest({
201 url: server.url,
202 path,
203 token: userAccessToken,
204 statusCodeExpected: 403
205 })
206 })
207 })
208
209 describe('When updating the configuration', function () {
210 it('Should fail without token', async function () {
211 await makePutBodyRequest({
212 url: server.url,
213 path,
214 fields: updateParams,
215 statusCodeExpected: 401
216 })
217 })
218
219 it('Should fail if the user is not an administrator', async function () {
220 await makePutBodyRequest({
221 url: server.url,
222 path,
223 fields: updateParams,
224 token: userAccessToken,
225 statusCodeExpected: 403
226 })
227 })
228
229 it('Should fail if it misses a key', async function () {
230 const newUpdateParams = omit(updateParams, 'admin.email')
231
232 await makePutBodyRequest({
233 url: server.url,
234 path,
235 fields: newUpdateParams,
236 token: server.accessToken,
237 statusCodeExpected: 400
238 })
239 })
240
241 it('Should fail with a bad default NSFW policy', async function () {
242 const newUpdateParams = immutableAssign(updateParams, {
243 instance: {
244 defaultNSFWPolicy: 'hello'
245 }
246 })
247
248 await makePutBodyRequest({
249 url: server.url,
250 path,
251 fields: newUpdateParams,
252 token: server.accessToken,
253 statusCodeExpected: 400
254 })
255 })
256
257 it('Should fail if email disabled and signup requires email verification', async function () {
258 // opposite scenario - success when enable enabled - covered via tests/api/users/user-verification.ts
259 const newUpdateParams = immutableAssign(updateParams, {
260 signup: {
261 enabled: true,
262 limit: 5,
263 requiresEmailVerification: true
264 }
265 })
266
267 await makePutBodyRequest({
268 url: server.url,
269 path,
270 fields: newUpdateParams,
271 token: server.accessToken,
272 statusCodeExpected: 400
273 })
274 })
275
276 it('Should fail with a disabled webtorrent & hls transcoding', async function () {
277 const newUpdateParams = immutableAssign(updateParams, {
278 transcoding: {
279 hls: {
280 enabled: false
281 },
282 webtorrent: {
283 enabled: false
284 }
285 }
286 })
287
288 await makePutBodyRequest({
289 url: server.url,
290 path,
291 fields: newUpdateParams,
292 token: server.accessToken,
293 statusCodeExpected: 400
294 })
295 })
296
297 it('Should success with the correct parameters', async function () {
298 await makePutBodyRequest({
299 url: server.url,
300 path,
301 fields: updateParams,
302 token: server.accessToken,
303 statusCodeExpected: 200
304 })
305 })
306 })
307
308 describe('When deleting the configuration', function () {
309 it('Should fail without token', async function () {
310 await makeDeleteRequest({
311 url: server.url,
312 path,
313 statusCodeExpected: 401
314 })
315 })
316
317 it('Should fail if the user is not an administrator', async function () {
318 await makeDeleteRequest({
319 url: server.url,
320 path,
321 token: userAccessToken,
322 statusCodeExpected: 403
323 })
324 })
325 })
326
327 after(async function () {
328 await cleanupTests([ server ])
329 })
330 })