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