]>
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 | 75 | limit: 5, |
1f256e7d P |
76 | requiresEmailVerification: false, |
77 | minimumAge: 16 | |
fd206f0b C |
78 | }, |
79 | admin: { | |
80 | email: 'superadmin1@example.com' | |
81 | }, | |
a4101923 C |
82 | contactForm: { |
83 | enabled: false | |
84 | }, | |
fd206f0b | 85 | user: { |
bee0abff FA |
86 | videoQuota: 5242881, |
87 | videoQuotaDaily: 318742 | |
fd206f0b C |
88 | }, |
89 | transcoding: { | |
90 | enabled: true, | |
14e2014a | 91 | allowAdditionalExtensions: true, |
536598cf | 92 | allowAudioFiles: true, |
9129b769 | 93 | concurrency: 1, |
fd206f0b | 94 | threads: 1, |
1896bca0 | 95 | profile: 'vod_profile', |
fd206f0b | 96 | resolutions: { |
5c7d6508 | 97 | '0p': false, |
fd206f0b C |
98 | '240p': false, |
99 | '360p': true, | |
100 | '480p': true, | |
101 | '720p': false, | |
db714ab4 | 102 | '1080p': false, |
b7085c71 | 103 | '1440p': false, |
db714ab4 | 104 | '2160p': false |
09209296 | 105 | }, |
d7a25329 C |
106 | webtorrent: { |
107 | enabled: true | |
108 | }, | |
09209296 C |
109 | hls: { |
110 | enabled: false | |
fd206f0b | 111 | } |
5d08a6a7 | 112 | }, |
c6c0fa6c C |
113 | live: { |
114 | enabled: true, | |
115 | ||
fb719404 | 116 | allowReplay: false, |
c9bc850e | 117 | maxDuration: 30, |
a056ca48 C |
118 | maxInstanceLives: -1, |
119 | maxUserLives: 50, | |
fb719404 | 120 | |
c6c0fa6c C |
121 | transcoding: { |
122 | enabled: true, | |
123 | threads: 4, | |
1896bca0 | 124 | profile: 'live_profile', |
c6c0fa6c C |
125 | resolutions: { |
126 | '240p': true, | |
127 | '360p': true, | |
128 | '480p': true, | |
129 | '720p': true, | |
130 | '1080p': true, | |
b7085c71 | 131 | '1440p': true, |
c6c0fa6c C |
132 | '2160p': true |
133 | } | |
134 | } | |
135 | }, | |
5d08a6a7 C |
136 | import: { |
137 | videos: { | |
9129b769 | 138 | concurrency: 1, |
5d08a6a7 C |
139 | http: { |
140 | enabled: false | |
a84b8fa5 C |
141 | }, |
142 | torrent: { | |
143 | enabled: false | |
5d08a6a7 C |
144 | } |
145 | } | |
7ccddd7b | 146 | }, |
ba5d4a84 RK |
147 | trending: { |
148 | videos: { | |
149 | algorithms: { | |
3d4e112d | 150 | enabled: [ 'best', 'hot', 'most-viewed', 'most-liked' ], |
ba5d4a84 RK |
151 | default: 'most-viewed' |
152 | } | |
153 | } | |
154 | }, | |
7ccddd7b JM |
155 | autoBlacklist: { |
156 | videos: { | |
157 | ofUsers: { | |
158 | enabled: false | |
159 | } | |
160 | } | |
5b9c965d C |
161 | }, |
162 | followers: { | |
163 | instance: { | |
14893eb7 C |
164 | enabled: false, |
165 | manualApproval: true | |
5b9c965d | 166 | } |
8424c402 C |
167 | }, |
168 | followings: { | |
169 | instance: { | |
170 | autoFollowBack: { | |
171 | enabled: true | |
172 | }, | |
173 | autoFollowIndex: { | |
174 | enabled: true, | |
175 | indexUrl: 'https://index.example.com' | |
176 | } | |
177 | } | |
72c33e71 C |
178 | }, |
179 | broadcastMessage: { | |
180 | enabled: true, | |
181 | dismissable: true, | |
182 | message: 'super message', | |
183 | level: 'warning' | |
5fb2e288 C |
184 | }, |
185 | search: { | |
186 | remoteUri: { | |
187 | users: true, | |
188 | anonymous: true | |
189 | }, | |
190 | searchIndex: { | |
191 | enabled: true, | |
192 | url: 'https://search.joinpeertube.org', | |
193 | disableLocalSearch: true, | |
194 | isDefaultSearch: true | |
195 | } | |
fd206f0b C |
196 | } |
197 | } | |
198 | ||
199 | // --------------------------------------------------------------- | |
200 | ||
201 | before(async function () { | |
e212f887 | 202 | this.timeout(30000) |
fd206f0b | 203 | |
210feb6c | 204 | server = await flushAndRunServer(1) |
fd206f0b C |
205 | |
206 | await setAccessTokensToServers([ server ]) | |
207 | ||
208 | const user = { | |
209 | username: 'user1', | |
210 | password: 'password' | |
211 | } | |
1eddc9a7 | 212 | await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password }) |
fd206f0b C |
213 | userAccessToken = await userLogin(server, user) |
214 | }) | |
215 | ||
216 | describe('When getting the configuration', function () { | |
217 | it('Should fail without token', async function () { | |
218 | await makeGetRequest({ | |
219 | url: server.url, | |
220 | path, | |
2d53be02 | 221 | statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 |
fd206f0b C |
222 | }) |
223 | }) | |
224 | ||
225 | it('Should fail if the user is not an administrator', async function () { | |
226 | await makeGetRequest({ | |
227 | url: server.url, | |
228 | path, | |
229 | token: userAccessToken, | |
2d53be02 | 230 | statusCodeExpected: HttpStatusCode.FORBIDDEN_403 |
fd206f0b C |
231 | }) |
232 | }) | |
233 | }) | |
234 | ||
235 | describe('When updating the configuration', function () { | |
236 | it('Should fail without token', async function () { | |
237 | await makePutBodyRequest({ | |
238 | url: server.url, | |
239 | path, | |
240 | fields: updateParams, | |
2d53be02 | 241 | statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 |
fd206f0b C |
242 | }) |
243 | }) | |
244 | ||
245 | it('Should fail if the user is not an administrator', async function () { | |
246 | await makePutBodyRequest({ | |
247 | url: server.url, | |
248 | path, | |
249 | fields: updateParams, | |
250 | token: userAccessToken, | |
2d53be02 | 251 | statusCodeExpected: HttpStatusCode.FORBIDDEN_403 |
fd206f0b C |
252 | }) |
253 | }) | |
254 | ||
255 | it('Should fail if it misses a key', async function () { | |
256 | const newUpdateParams = omit(updateParams, 'admin.email') | |
257 | ||
258 | await makePutBodyRequest({ | |
259 | url: server.url, | |
260 | path, | |
0883b324 C |
261 | fields: newUpdateParams, |
262 | token: server.accessToken, | |
2d53be02 | 263 | statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 |
0883b324 C |
264 | }) |
265 | }) | |
266 | ||
267 | it('Should fail with a bad default NSFW policy', async function () { | |
268 | const newUpdateParams = immutableAssign(updateParams, { | |
269 | instance: { | |
270 | defaultNSFWPolicy: 'hello' | |
271 | } | |
272 | }) | |
273 | ||
274 | await makePutBodyRequest({ | |
275 | url: server.url, | |
276 | path, | |
576ad67a JM |
277 | fields: newUpdateParams, |
278 | token: server.accessToken, | |
2d53be02 | 279 | statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 |
576ad67a JM |
280 | }) |
281 | }) | |
282 | ||
283 | it('Should fail if email disabled and signup requires email verification', async function () { | |
7c3b7976 | 284 | // opposite scenario - success when enable enabled - covered via tests/api/users/user-verification.ts |
576ad67a JM |
285 | const newUpdateParams = immutableAssign(updateParams, { |
286 | signup: { | |
287 | enabled: true, | |
288 | limit: 5, | |
289 | requiresEmailVerification: true | |
290 | } | |
291 | }) | |
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 C |
302 | it('Should fail with a disabled webtorrent & hls transcoding', async function () { |
303 | const newUpdateParams = immutableAssign(updateParams, { | |
304 | transcoding: { | |
305 | hls: { | |
306 | enabled: false | |
307 | }, | |
308 | webtorrent: { | |
309 | enabled: false | |
310 | } | |
311 | } | |
312 | }) | |
313 | ||
314 | await makePutBodyRequest({ | |
315 | url: server.url, | |
316 | path, | |
317 | fields: newUpdateParams, | |
318 | token: server.accessToken, | |
2d53be02 | 319 | statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 |
d7a25329 C |
320 | }) |
321 | }) | |
322 | ||
fd206f0b C |
323 | it('Should success with the correct parameters', async function () { |
324 | await makePutBodyRequest({ | |
325 | url: server.url, | |
326 | path, | |
327 | fields: updateParams, | |
328 | token: server.accessToken, | |
2d53be02 | 329 | statusCodeExpected: HttpStatusCode.OK_200 |
fd206f0b C |
330 | }) |
331 | }) | |
332 | }) | |
333 | ||
334 | describe('When deleting the configuration', function () { | |
335 | it('Should fail without token', async function () { | |
336 | await makeDeleteRequest({ | |
337 | url: server.url, | |
338 | path, | |
2d53be02 | 339 | statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 |
fd206f0b C |
340 | }) |
341 | }) | |
342 | ||
343 | it('Should fail if the user is not an administrator', async function () { | |
344 | await makeDeleteRequest({ | |
345 | url: server.url, | |
346 | path, | |
347 | token: userAccessToken, | |
2d53be02 | 348 | statusCodeExpected: HttpStatusCode.FORBIDDEN_403 |
fd206f0b C |
349 | }) |
350 | }) | |
351 | }) | |
352 | ||
7c3b7976 C |
353 | after(async function () { |
354 | await cleanupTests([ server ]) | |
fd206f0b C |
355 | }) |
356 | }) |