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