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