]>
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, | |
108 | ||
c6c0fa6c C |
109 | transcoding: { |
110 | enabled: true, | |
111 | threads: 4, | |
112 | resolutions: { | |
113 | '240p': true, | |
114 | '360p': true, | |
115 | '480p': true, | |
116 | '720p': true, | |
117 | '1080p': true, | |
118 | '2160p': true | |
119 | } | |
120 | } | |
121 | }, | |
5d08a6a7 C |
122 | import: { |
123 | videos: { | |
124 | http: { | |
125 | enabled: false | |
a84b8fa5 C |
126 | }, |
127 | torrent: { | |
128 | enabled: false | |
5d08a6a7 C |
129 | } |
130 | } | |
7ccddd7b JM |
131 | }, |
132 | autoBlacklist: { | |
133 | videos: { | |
134 | ofUsers: { | |
135 | enabled: false | |
136 | } | |
137 | } | |
5b9c965d C |
138 | }, |
139 | followers: { | |
140 | instance: { | |
14893eb7 C |
141 | enabled: false, |
142 | manualApproval: true | |
5b9c965d | 143 | } |
8424c402 C |
144 | }, |
145 | followings: { | |
146 | instance: { | |
147 | autoFollowBack: { | |
148 | enabled: true | |
149 | }, | |
150 | autoFollowIndex: { | |
151 | enabled: true, | |
152 | indexUrl: 'https://index.example.com' | |
153 | } | |
154 | } | |
72c33e71 C |
155 | }, |
156 | broadcastMessage: { | |
157 | enabled: true, | |
158 | dismissable: true, | |
159 | message: 'super message', | |
160 | level: 'warning' | |
5fb2e288 C |
161 | }, |
162 | search: { | |
163 | remoteUri: { | |
164 | users: true, | |
165 | anonymous: true | |
166 | }, | |
167 | searchIndex: { | |
168 | enabled: true, | |
169 | url: 'https://search.joinpeertube.org', | |
170 | disableLocalSearch: true, | |
171 | isDefaultSearch: true | |
172 | } | |
fd206f0b C |
173 | } |
174 | } | |
175 | ||
176 | // --------------------------------------------------------------- | |
177 | ||
178 | before(async function () { | |
e212f887 | 179 | this.timeout(30000) |
fd206f0b | 180 | |
210feb6c | 181 | server = await flushAndRunServer(1) |
fd206f0b C |
182 | |
183 | await setAccessTokensToServers([ server ]) | |
184 | ||
185 | const user = { | |
186 | username: 'user1', | |
187 | password: 'password' | |
188 | } | |
1eddc9a7 | 189 | await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password }) |
fd206f0b C |
190 | userAccessToken = await userLogin(server, user) |
191 | }) | |
192 | ||
193 | describe('When getting the configuration', function () { | |
194 | it('Should fail without token', async function () { | |
195 | await makeGetRequest({ | |
196 | url: server.url, | |
197 | path, | |
198 | statusCodeExpected: 401 | |
199 | }) | |
200 | }) | |
201 | ||
202 | it('Should fail if the user is not an administrator', async function () { | |
203 | await makeGetRequest({ | |
204 | url: server.url, | |
205 | path, | |
206 | token: userAccessToken, | |
207 | statusCodeExpected: 403 | |
208 | }) | |
209 | }) | |
210 | }) | |
211 | ||
212 | describe('When updating the configuration', function () { | |
213 | it('Should fail without token', async function () { | |
214 | await makePutBodyRequest({ | |
215 | url: server.url, | |
216 | path, | |
217 | fields: updateParams, | |
218 | statusCodeExpected: 401 | |
219 | }) | |
220 | }) | |
221 | ||
222 | it('Should fail if the user is not an administrator', async function () { | |
223 | await makePutBodyRequest({ | |
224 | url: server.url, | |
225 | path, | |
226 | fields: updateParams, | |
227 | token: userAccessToken, | |
228 | statusCodeExpected: 403 | |
229 | }) | |
230 | }) | |
231 | ||
232 | it('Should fail if it misses a key', async function () { | |
233 | const newUpdateParams = omit(updateParams, 'admin.email') | |
234 | ||
235 | await makePutBodyRequest({ | |
236 | url: server.url, | |
237 | path, | |
0883b324 C |
238 | fields: newUpdateParams, |
239 | token: server.accessToken, | |
240 | statusCodeExpected: 400 | |
241 | }) | |
242 | }) | |
243 | ||
244 | it('Should fail with a bad default NSFW policy', async function () { | |
245 | const newUpdateParams = immutableAssign(updateParams, { | |
246 | instance: { | |
247 | defaultNSFWPolicy: 'hello' | |
248 | } | |
249 | }) | |
250 | ||
251 | await makePutBodyRequest({ | |
252 | url: server.url, | |
253 | path, | |
576ad67a JM |
254 | fields: newUpdateParams, |
255 | token: server.accessToken, | |
256 | statusCodeExpected: 400 | |
257 | }) | |
258 | }) | |
259 | ||
260 | it('Should fail if email disabled and signup requires email verification', async function () { | |
7c3b7976 | 261 | // opposite scenario - success when enable enabled - covered via tests/api/users/user-verification.ts |
576ad67a JM |
262 | const newUpdateParams = immutableAssign(updateParams, { |
263 | signup: { | |
264 | enabled: true, | |
265 | limit: 5, | |
266 | requiresEmailVerification: true | |
267 | } | |
268 | }) | |
269 | ||
270 | await makePutBodyRequest({ | |
271 | url: server.url, | |
272 | path, | |
fd206f0b C |
273 | fields: newUpdateParams, |
274 | token: server.accessToken, | |
275 | statusCodeExpected: 400 | |
276 | }) | |
277 | }) | |
278 | ||
d7a25329 C |
279 | it('Should fail with a disabled webtorrent & hls transcoding', async function () { |
280 | const newUpdateParams = immutableAssign(updateParams, { | |
281 | transcoding: { | |
282 | hls: { | |
283 | enabled: false | |
284 | }, | |
285 | webtorrent: { | |
286 | enabled: false | |
287 | } | |
288 | } | |
289 | }) | |
290 | ||
291 | await makePutBodyRequest({ | |
292 | url: server.url, | |
293 | path, | |
294 | fields: newUpdateParams, | |
295 | token: server.accessToken, | |
296 | statusCodeExpected: 400 | |
297 | }) | |
298 | }) | |
299 | ||
fd206f0b C |
300 | it('Should success with the correct parameters', async function () { |
301 | await makePutBodyRequest({ | |
302 | url: server.url, | |
303 | path, | |
304 | fields: updateParams, | |
305 | token: server.accessToken, | |
306 | statusCodeExpected: 200 | |
307 | }) | |
308 | }) | |
309 | }) | |
310 | ||
311 | describe('When deleting the configuration', function () { | |
312 | it('Should fail without token', async function () { | |
313 | await makeDeleteRequest({ | |
314 | url: server.url, | |
315 | path, | |
316 | statusCodeExpected: 401 | |
317 | }) | |
318 | }) | |
319 | ||
320 | it('Should fail if the user is not an administrator', async function () { | |
321 | await makeDeleteRequest({ | |
322 | url: server.url, | |
323 | path, | |
324 | token: userAccessToken, | |
325 | statusCodeExpected: 403 | |
326 | }) | |
327 | }) | |
328 | }) | |
329 | ||
7c3b7976 C |
330 | after(async function () { |
331 | await cleanupTests([ server ]) | |
fd206f0b C |
332 | }) |
333 | }) |