]>
Commit | Line | Data |
---|---|---|
a1587156 | 1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ |
fd206f0b | 2 | |
fd206f0b | 3 | import 'mocha' |
6c5065a0 | 4 | import { omit } from 'lodash' |
fd206f0b | 5 | import { |
8424c402 | 6 | cleanupTests, |
254d3579 | 7 | createSingleServer, |
8424c402 C |
8 | makeDeleteRequest, |
9 | makeGetRequest, | |
10 | makePutBodyRequest, | |
254d3579 | 11 | PeerTubeServer, |
41d1d075 | 12 | setAccessTokensToServers |
6c5065a0 | 13 | } from '@shared/extra-utils' |
4c7e60bc | 14 | import { CustomConfig, HttpStatusCode } from '@shared/models' |
fd206f0b C |
15 | |
16 | describe('Test config API validators', function () { | |
17 | const path = '/api/v1/config/custom' | |
254d3579 | 18 | let server: PeerTubeServer |
fd206f0b C |
19 | let userAccessToken: string |
20 | const updateParams: CustomConfig = { | |
66b16caf C |
21 | instance: { |
22 | name: 'PeerTube updated', | |
2e3a0215 | 23 | shortDescription: 'my short description', |
66b16caf | 24 | description: 'my super description', |
00b5556c | 25 | terms: 'my super terms', |
ccc00cb2 C |
26 | codeOfConduct: 'my super coc', |
27 | ||
8ae03c37 | 28 | creationReason: 'my super reason', |
ccc00cb2 C |
29 | moderationInformation: 'my super moderation information', |
30 | administrator: 'Kuja', | |
31 | maintenanceLifetime: 'forever', | |
32 | businessModel: 'my super business model', | |
be04c6fd | 33 | hardwareInformation: '2vCore 3GB RAM', |
ccc00cb2 C |
34 | |
35 | languages: [ 'en', 'es' ], | |
36 | categories: [ 1, 2 ], | |
37 | ||
f8802489 | 38 | isNSFW: true, |
0883b324 | 39 | defaultNSFWPolicy: 'blur', |
3da68f0a RK |
40 | |
41 | defaultClientRoute: '/videos/recently-added', | |
3da68f0a | 42 | |
00b5556c C |
43 | customizations: { |
44 | javascript: 'alert("coucou")', | |
45 | css: 'body { background-color: red; }' | |
46 | } | |
66b16caf | 47 | }, |
7cd4d2ba C |
48 | theme: { |
49 | default: 'default' | |
50 | }, | |
8be1afa1 C |
51 | services: { |
52 | twitter: { | |
53 | username: '@MySuperUsername', | |
54 | whitelisted: true | |
55 | } | |
56 | }, | |
fd206f0b C |
57 | cache: { |
58 | previews: { | |
59 | size: 2 | |
40e87e9e C |
60 | }, |
61 | captions: { | |
62 | size: 3 | |
b3d5cb92 C |
63 | }, |
64 | torrents: { | |
65 | size: 4 | |
fd206f0b C |
66 | } |
67 | }, | |
68 | signup: { | |
69 | enabled: false, | |
d9eaee39 | 70 | limit: 5, |
1f256e7d P |
71 | requiresEmailVerification: false, |
72 | minimumAge: 16 | |
fd206f0b C |
73 | }, |
74 | admin: { | |
75 | email: 'superadmin1@example.com' | |
76 | }, | |
a4101923 C |
77 | contactForm: { |
78 | enabled: false | |
79 | }, | |
fd206f0b | 80 | user: { |
bee0abff FA |
81 | videoQuota: 5242881, |
82 | videoQuotaDaily: 318742 | |
fd206f0b | 83 | }, |
754b6f5f FC |
84 | videoChannels: { |
85 | maxPerUser: 20 | |
86 | }, | |
fd206f0b C |
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, |
8dd754c7 | 96 | '144p': 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 | 124 | resolutions: { |
8dd754c7 | 125 | '144p': true, |
c6c0fa6c C |
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 | |
254d3579 | 204 | server = await createSingleServer(1) |
fd206f0b C |
205 | |
206 | await setAccessTokensToServers([ server ]) | |
207 | ||
208 | const user = { | |
209 | username: 'user1', | |
210 | password: 'password' | |
211 | } | |
89d241a7 C |
212 | await server.users.create({ username: user.username, password: user.password }) |
213 | userAccessToken = await server.login.getAccessToken(user) | |
fd206f0b C |
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, | |
c0e8b12e | 221 | expectedStatus: 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, | |
c0e8b12e | 230 | expectedStatus: 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, | |
c0e8b12e | 241 | expectedStatus: 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, | |
c0e8b12e | 251 | expectedStatus: 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, | |
c0e8b12e | 263 | expectedStatus: HttpStatusCode.BAD_REQUEST_400 |
0883b324 C |
264 | }) |
265 | }) | |
266 | ||
267 | it('Should fail with a bad default NSFW policy', async function () { | |
6c5065a0 C |
268 | const newUpdateParams = { |
269 | ...updateParams, | |
270 | ||
0883b324 C |
271 | instance: { |
272 | defaultNSFWPolicy: 'hello' | |
273 | } | |
6c5065a0 | 274 | } |
0883b324 C |
275 | |
276 | await makePutBodyRequest({ | |
277 | url: server.url, | |
278 | path, | |
576ad67a JM |
279 | fields: newUpdateParams, |
280 | token: server.accessToken, | |
c0e8b12e | 281 | expectedStatus: HttpStatusCode.BAD_REQUEST_400 |
576ad67a JM |
282 | }) |
283 | }) | |
284 | ||
285 | it('Should fail if email disabled and signup requires email verification', async function () { | |
7c3b7976 | 286 | // opposite scenario - success when enable enabled - covered via tests/api/users/user-verification.ts |
6c5065a0 C |
287 | const newUpdateParams = { |
288 | ...updateParams, | |
289 | ||
576ad67a JM |
290 | signup: { |
291 | enabled: true, | |
292 | limit: 5, | |
293 | requiresEmailVerification: true | |
294 | } | |
6c5065a0 | 295 | } |
576ad67a JM |
296 | |
297 | await makePutBodyRequest({ | |
298 | url: server.url, | |
299 | path, | |
fd206f0b C |
300 | fields: newUpdateParams, |
301 | token: server.accessToken, | |
c0e8b12e | 302 | expectedStatus: HttpStatusCode.BAD_REQUEST_400 |
fd206f0b C |
303 | }) |
304 | }) | |
305 | ||
d7a25329 | 306 | it('Should fail with a disabled webtorrent & hls transcoding', async function () { |
6c5065a0 C |
307 | const newUpdateParams = { |
308 | ...updateParams, | |
309 | ||
d7a25329 C |
310 | transcoding: { |
311 | hls: { | |
312 | enabled: false | |
313 | }, | |
314 | webtorrent: { | |
315 | enabled: false | |
316 | } | |
317 | } | |
6c5065a0 | 318 | } |
d7a25329 C |
319 | |
320 | await makePutBodyRequest({ | |
321 | url: server.url, | |
322 | path, | |
323 | fields: newUpdateParams, | |
324 | token: server.accessToken, | |
c0e8b12e | 325 | expectedStatus: HttpStatusCode.BAD_REQUEST_400 |
d7a25329 C |
326 | }) |
327 | }) | |
328 | ||
fd206f0b C |
329 | it('Should success with the correct parameters', async function () { |
330 | await makePutBodyRequest({ | |
331 | url: server.url, | |
332 | path, | |
333 | fields: updateParams, | |
334 | token: server.accessToken, | |
c0e8b12e | 335 | expectedStatus: HttpStatusCode.OK_200 |
fd206f0b C |
336 | }) |
337 | }) | |
338 | }) | |
339 | ||
340 | describe('When deleting the configuration', function () { | |
341 | it('Should fail without token', async function () { | |
342 | await makeDeleteRequest({ | |
343 | url: server.url, | |
344 | path, | |
c0e8b12e | 345 | expectedStatus: HttpStatusCode.UNAUTHORIZED_401 |
fd206f0b C |
346 | }) |
347 | }) | |
348 | ||
349 | it('Should fail if the user is not an administrator', async function () { | |
350 | await makeDeleteRequest({ | |
351 | url: server.url, | |
352 | path, | |
353 | token: userAccessToken, | |
c0e8b12e | 354 | expectedStatus: HttpStatusCode.FORBIDDEN_403 |
fd206f0b C |
355 | }) |
356 | }) | |
357 | }) | |
358 | ||
7c3b7976 C |
359 | after(async function () { |
360 | await cleanupTests([ server ]) | |
fd206f0b C |
361 | }) |
362 | }) |