]>
Commit | Line | Data |
---|---|---|
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 | import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' | |
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 = { | |
26 | instance: { | |
27 | name: 'PeerTube updated', | |
28 | shortDescription: 'my short description', | |
29 | description: 'my super description', | |
30 | terms: 'my super terms', | |
31 | codeOfConduct: 'my super coc', | |
32 | ||
33 | creationReason: 'my super reason', | |
34 | moderationInformation: 'my super moderation information', | |
35 | administrator: 'Kuja', | |
36 | maintenanceLifetime: 'forever', | |
37 | businessModel: 'my super business model', | |
38 | hardwareInformation: '2vCore 3GB RAM', | |
39 | ||
40 | languages: [ 'en', 'es' ], | |
41 | categories: [ 1, 2 ], | |
42 | ||
43 | isNSFW: true, | |
44 | defaultNSFWPolicy: 'blur', | |
45 | ||
46 | defaultClientRoute: '/videos/recently-added', | |
47 | ||
48 | customizations: { | |
49 | javascript: 'alert("coucou")', | |
50 | css: 'body { background-color: red; }' | |
51 | } | |
52 | }, | |
53 | theme: { | |
54 | default: 'default' | |
55 | }, | |
56 | services: { | |
57 | twitter: { | |
58 | username: '@MySuperUsername', | |
59 | whitelisted: true | |
60 | } | |
61 | }, | |
62 | cache: { | |
63 | previews: { | |
64 | size: 2 | |
65 | }, | |
66 | captions: { | |
67 | size: 3 | |
68 | }, | |
69 | torrents: { | |
70 | size: 4 | |
71 | } | |
72 | }, | |
73 | signup: { | |
74 | enabled: false, | |
75 | limit: 5, | |
76 | requiresEmailVerification: false | |
77 | }, | |
78 | admin: { | |
79 | email: 'superadmin1@example.com' | |
80 | }, | |
81 | contactForm: { | |
82 | enabled: false | |
83 | }, | |
84 | user: { | |
85 | videoQuota: 5242881, | |
86 | videoQuotaDaily: 318742 | |
87 | }, | |
88 | transcoding: { | |
89 | enabled: true, | |
90 | allowAdditionalExtensions: true, | |
91 | allowAudioFiles: true, | |
92 | concurrency: 1, | |
93 | threads: 1, | |
94 | profile: 'vod_profile', | |
95 | resolutions: { | |
96 | '0p': false, | |
97 | '240p': false, | |
98 | '360p': true, | |
99 | '480p': true, | |
100 | '720p': false, | |
101 | '1080p': false, | |
102 | '1440p': false, | |
103 | '2160p': false | |
104 | }, | |
105 | webtorrent: { | |
106 | enabled: true | |
107 | }, | |
108 | hls: { | |
109 | enabled: false | |
110 | } | |
111 | }, | |
112 | live: { | |
113 | enabled: true, | |
114 | ||
115 | allowReplay: false, | |
116 | maxDuration: 30, | |
117 | maxInstanceLives: -1, | |
118 | maxUserLives: 50, | |
119 | ||
120 | transcoding: { | |
121 | enabled: true, | |
122 | threads: 4, | |
123 | profile: 'live_profile', | |
124 | resolutions: { | |
125 | '240p': true, | |
126 | '360p': true, | |
127 | '480p': true, | |
128 | '720p': true, | |
129 | '1080p': true, | |
130 | '1440p': true, | |
131 | '2160p': true | |
132 | } | |
133 | } | |
134 | }, | |
135 | import: { | |
136 | videos: { | |
137 | concurrency: 1, | |
138 | http: { | |
139 | enabled: false | |
140 | }, | |
141 | torrent: { | |
142 | enabled: false | |
143 | } | |
144 | } | |
145 | }, | |
146 | trending: { | |
147 | videos: { | |
148 | algorithms: { | |
149 | enabled: [ 'best', 'hot', 'most-viewed', 'most-liked' ], | |
150 | default: 'most-viewed' | |
151 | } | |
152 | } | |
153 | }, | |
154 | autoBlacklist: { | |
155 | videos: { | |
156 | ofUsers: { | |
157 | enabled: false | |
158 | } | |
159 | } | |
160 | }, | |
161 | followers: { | |
162 | instance: { | |
163 | enabled: false, | |
164 | manualApproval: true | |
165 | } | |
166 | }, | |
167 | followings: { | |
168 | instance: { | |
169 | autoFollowBack: { | |
170 | enabled: true | |
171 | }, | |
172 | autoFollowIndex: { | |
173 | enabled: true, | |
174 | indexUrl: 'https://index.example.com' | |
175 | } | |
176 | } | |
177 | }, | |
178 | broadcastMessage: { | |
179 | enabled: true, | |
180 | dismissable: true, | |
181 | message: 'super message', | |
182 | level: 'warning' | |
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 | } | |
195 | } | |
196 | } | |
197 | ||
198 | // --------------------------------------------------------------- | |
199 | ||
200 | before(async function () { | |
201 | this.timeout(30000) | |
202 | ||
203 | server = await flushAndRunServer(1) | |
204 | ||
205 | await setAccessTokensToServers([ server ]) | |
206 | ||
207 | const user = { | |
208 | username: 'user1', | |
209 | password: 'password' | |
210 | } | |
211 | await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password }) | |
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, | |
220 | statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 | |
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, | |
229 | statusCodeExpected: HttpStatusCode.FORBIDDEN_403 | |
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, | |
240 | statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 | |
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, | |
250 | statusCodeExpected: HttpStatusCode.FORBIDDEN_403 | |
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, | |
260 | fields: newUpdateParams, | |
261 | token: server.accessToken, | |
262 | statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 | |
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, | |
276 | fields: newUpdateParams, | |
277 | token: server.accessToken, | |
278 | statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 | |
279 | }) | |
280 | }) | |
281 | ||
282 | it('Should fail if email disabled and signup requires email verification', async function () { | |
283 | // opposite scenario - success when enable enabled - covered via tests/api/users/user-verification.ts | |
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, | |
295 | fields: newUpdateParams, | |
296 | token: server.accessToken, | |
297 | statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 | |
298 | }) | |
299 | }) | |
300 | ||
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, | |
318 | statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 | |
319 | }) | |
320 | }) | |
321 | ||
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, | |
328 | statusCodeExpected: HttpStatusCode.OK_200 | |
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, | |
338 | statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 | |
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, | |
347 | statusCodeExpected: HttpStatusCode.FORBIDDEN_403 | |
348 | }) | |
349 | }) | |
350 | }) | |
351 | ||
352 | after(async function () { | |
353 | await cleanupTests([ server ]) | |
354 | }) | |
355 | }) |